half-orm-dev 0.17.2a11__py3-none-any.whl → 0.17.3a2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
half_orm_dev/database.py CHANGED
@@ -1362,25 +1362,23 @@ class Database:
1362
1362
  pass
1363
1363
  """
1364
1364
  try:
1365
- result = self._execute_pg_command(
1366
- self.__name,
1367
- self._get_connection_params(),
1368
- *['psql', '-d', 'postgres', '-t', '-A', '-c', 'SHOW server_version;'],
1369
- )
1365
+ # Use existing database connection via half_orm Model API
1366
+ # Query returns: "PostgreSQL 16.1 (Ubuntu 16.1-1.pgdg22.04+1) on ..."
1367
+ result = self.__model.execute_query('SELECT version()')
1368
+ version_str = result[0]['version']
1370
1369
 
1371
- # Output format: "16.1 (Ubuntu 16.1-1.pgdg22.04+1)"
1372
- # Extract version: "16.1"
1373
- version_str = result.stdout.strip().split()[0]
1370
+ # Extract version number: split on space, take 2nd element (e.g., "16.1")
1371
+ # Then split on dot to get [major, minor, patch]
1372
+ version_parts = [int(part) for part in version_str.split(' ')[1].split('.')]
1374
1373
 
1375
- # Parse major.minor
1376
- parts = version_str.split('.')
1377
- major = int(parts[0])
1378
- minor = int(parts[1]) if len(parts) > 1 else 0
1374
+ # Return (major, minor) tuple
1375
+ major = version_parts[0]
1376
+ minor = version_parts[1] if len(version_parts) > 1 else 0
1379
1377
 
1380
1378
  return (major, minor)
1381
1379
 
1382
1380
  except Exception as e:
1383
1381
  raise DatabaseError(
1384
1382
  f"Failed to get PostgreSQL version: {e}\n"
1385
- f"Ensure PostgreSQL is installed and accessible."
1386
- )
1383
+ f"Ensure database connection is available."
1384
+ )
half_orm_dev/repo.py CHANGED
@@ -2186,26 +2186,35 @@ See docs/half_orm_dev.md for complete documentation.
2186
2186
  # Validation passed
2187
2187
  return True
2188
2188
 
2189
+ def _reset_database_schemas(self) -> None:
2190
+ """Drop all user schemas with CASCADE (including half_orm_meta)."""
2191
+ # Get user schemas from half_orm metadata
2192
+ relations = self.model.desc()
2193
+ schemas = {'half_orm_meta', 'half_orm_meta.view'}
2194
+ _ = [schemas.add(rel[1][1]) for rel in relations]
2195
+
2196
+ # Drop each schema with CASCADE
2197
+ for schema_name in schemas:
2198
+ self.model.execute_query(f'DROP SCHEMA IF EXISTS "{schema_name}" CASCADE')
2199
+
2189
2200
  def restore_database_from_schema(self) -> None:
2190
2201
  """
2191
2202
  Restore database from model/schema.sql and model/metadata-X.Y.Z.sql.
2192
2203
 
2193
- Restores database to clean production state by dropping and recreating
2194
- database, then loading schema structure and half_orm_meta data. This provides
2204
+ Restores database to clean production state by dropping all user schemas
2205
+ and reloading schema structure and half_orm_meta data. This provides
2195
2206
  a clean baseline before applying patch files during patch development.
2196
2207
 
2197
2208
  Process:
2198
2209
  1. Verify model/schema.sql exists (file or symlink)
2199
- 2. Disconnect halfORM Model from database
2200
- 3. Drop existing database using dropdb command
2201
- 4. Create fresh empty database using createdb command
2202
- 5. Load schema structure from model/schema.sql using psql -f
2203
- 5b. Load half_orm_meta data from model/metadata-X.Y.Z.sql using psql -f (if exists)
2204
- 6. Reconnect halfORM Model to restored database
2210
+ 2. Drop all user schemas with CASCADE (no superuser privileges needed)
2211
+ 3. Load schema structure from model/schema.sql using psql -f
2212
+ 4. Load half_orm_meta data from model/metadata-X.Y.Z.sql using psql -f (if exists)
2213
+ 5. Reload halfORM Model metadata cache
2205
2214
 
2206
- The method uses Database.execute_pg_command() for all PostgreSQL
2207
- operations (dropdb, createdb, psql) with connection parameters from
2208
- repository configuration.
2215
+ The method uses DROP SCHEMA CASCADE instead of dropdb/createdb, allowing
2216
+ operation without CREATEDB privilege or superuser access. This makes it
2217
+ compatible with cloud databases (RDS, Azure) and restricted environments.
2209
2218
 
2210
2219
  File Resolution:
2211
2220
  - Accepts model/schema.sql as regular file or symlink
@@ -2216,8 +2225,7 @@ See docs/half_orm_dev.md for complete documentation.
2216
2225
 
2217
2226
  Error Handling:
2218
2227
  - Raises RepoError if model/schema.sql not found
2219
- - Raises RepoError if dropdb fails
2220
- - Raises RepoError if createdb fails
2228
+ - Raises RepoError if schema drop fails
2221
2229
  - Raises RepoError if psql schema load fails
2222
2230
  - Raises RepoError if psql metadata load fails (when file exists)
2223
2231
  - Database state rolled back on any failure
@@ -2255,8 +2263,9 @@ See docs/half_orm_dev.md for complete documentation.
2255
2263
  # Handle error: check schema.sql exists, verify permissions
2256
2264
 
2257
2265
  Notes:
2258
- - Silences psql output using stdout=subprocess.DEVNULL
2259
- - Uses Model.ping() for reconnection after restoration
2266
+ - Uses DROP SCHEMA CASCADE - no superuser or CREATEDB privilege required
2267
+ - Works on cloud databases (AWS RDS, Azure Database, etc.)
2268
+ - Uses Model.reconnect(reload=True) to refresh metadata cache
2260
2269
  - Supports both schema.sql file and schema.sql -> schema-X.Y.Z.sql symlink
2261
2270
  - Metadata file is optional (backward compatibility with older schemas)
2262
2271
  - All PostgreSQL commands use repository connection configuration
@@ -2272,26 +2281,10 @@ See docs/half_orm_dev.md for complete documentation.
2272
2281
  )
2273
2282
 
2274
2283
  try:
2275
- # 2. Disconnect Model from database
2276
- self.model.disconnect()
2277
- pg_version = self.database.get_postgres_version()
2278
- drop_cmd = ['dropdb', self.name]
2279
- if pg_version > (13, 0):
2280
- drop_cmd.append('--force')
2281
-
2282
- # 3. Drop existing database
2283
- try:
2284
- self.database.execute_pg_command(*drop_cmd)
2285
- except Exception as e:
2286
- raise RepoError(f"Failed to drop database: {e}") from e
2287
-
2288
- # 4. Create fresh empty database
2289
- try:
2290
- self.database.execute_pg_command('createdb', self.name)
2291
- except Exception as e:
2292
- raise RepoError(f"Failed to create database: {e}") from e
2284
+ # 2. Drop all schemas (no superuser privileges needed)
2285
+ self._reset_database_schemas()
2293
2286
 
2294
- # 5. Load schema from model/schema.sql
2287
+ # 3. Load schema from model/schema.sql
2295
2288
  try:
2296
2289
  self.database.execute_pg_command(
2297
2290
  'psql', '-d', self.name, '-f', str(schema_path)
@@ -2299,7 +2292,7 @@ See docs/half_orm_dev.md for complete documentation.
2299
2292
  except Exception as e:
2300
2293
  raise RepoError(f"Failed to load schema from {schema_path.name}: {e}") from e
2301
2294
 
2302
- # 5b. Load metadata from model/metadata-X.Y.Z.sql (if exists)
2295
+ # 4. Load metadata from model/metadata-X.Y.Z.sql (if exists)
2303
2296
  metadata_path = self._deduce_metadata_path(schema_path)
2304
2297
 
2305
2298
  if metadata_path and metadata_path.exists():
@@ -2315,8 +2308,8 @@ See docs/half_orm_dev.md for complete documentation.
2315
2308
  ) from e
2316
2309
  # else: metadata file doesn't exist, continue without error (backward compatibility)
2317
2310
 
2318
- # 6. Reconnect Model to restored database
2319
- self.model.ping()
2311
+ # 5. Reload half_orm metadata cache
2312
+ self.model.reconnect(reload=True)
2320
2313
 
2321
2314
  except RepoError:
2322
2315
  # Re-raise RepoError as-is
half_orm_dev/version.txt CHANGED
@@ -1 +1 @@
1
- 0.17.2-a11
1
+ 0.17.3-a2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: half_orm_dev
3
- Version: 0.17.2a11
3
+ Version: 0.17.3a2
4
4
  Summary: half_orm development Framework.
5
5
  Author-email: Joël Maïzi <joel.maizi@collorg.org>
6
6
  License-Expression: GPL-3.0-or-later
@@ -23,7 +23,7 @@ Requires-Dist: GitPython
23
23
  Requires-Dist: click
24
24
  Requires-Dist: pydash
25
25
  Requires-Dist: pytest
26
- Requires-Dist: half_orm<0.18.0,>=0.17.0
26
+ Requires-Dist: half_orm<0.18.0,>=0.17.1
27
27
  Requires-Dist: tomli>=2.0.0; python_version < "3.11"
28
28
  Requires-Dist: tomli_w>=1.0.0
29
29
  Dynamic: license-file
@@ -1,6 +1,6 @@
1
1
  half_orm_dev/__init__.py,sha256=0JpUPey1gacxXuIFGcpD2nTGso73fkak72qzTHttAJk,18
2
2
  half_orm_dev/cli_extension.py,sha256=kwX3M11_rwr0pFcqHK_bpI3Pp4ztfTCVz2gLfTmzfeA,1066
3
- half_orm_dev/database.py,sha256=kQKdkGXXxIvGxKAh01AFOMBLC7NETsJ981qWbD8m7Ho,59994
3
+ half_orm_dev/database.py,sha256=aRfCvxolJPN0kQUoEleaVjZAnyiWo-dEXq8xkKYC8pM,60088
4
4
  half_orm_dev/decorators.py,sha256=JKv_Z_JZUr-s-Vz551temHZhhecPfbvyhTbByRDjVAQ,4901
5
5
  half_orm_dev/hgit.py,sha256=VdzCCQ__xG1IGJaGq4-rrhbA1bNkDw_dBqkUNIeTONg,58045
6
6
  half_orm_dev/migration_manager.py,sha256=9RpciH8nyQrF0xV31kAeaYKkQl24Di1VHt-mAjjHhzM,14854
@@ -9,9 +9,9 @@ half_orm_dev/patch_manager.py,sha256=0GwixfNbzpRMtmUKPazlXn-IESSw_KR6S0qLOy02KKY
9
9
  half_orm_dev/patch_validator.py,sha256=QNe1L6k_xwsnrOTcb3vkW2D0LbqrCRcZOGPnVyspVRk,10871
10
10
  half_orm_dev/release_file.py,sha256=s-f4ITbZGBzQ5cS1oIp516bCQJQylXON31A615ghIQE,9877
11
11
  half_orm_dev/release_manager.py,sha256=W51XzQoiq3UUW9E1mcodUGkxfoTBvz3vXhjBv2mrKag,113286
12
- half_orm_dev/repo.py,sha256=8KNub5A9g9DLpl-bNfh6sNBGFZKh8OaS89aukP3X93s,94967
12
+ half_orm_dev/repo.py,sha256=A1AXqFXF37p6C2qQCUbOqY6M6axkBTpweUQGhGkBVz8,94849
13
13
  half_orm_dev/utils.py,sha256=M3yViUFfsO7Cp9MYSoUSkCZ6R9w_4jW45UDZUOT8FhI,1493
14
- half_orm_dev/version.txt,sha256=4mNSLHYRTp9iUn9eZqhRqo01PuD3V05YkTxEd5lgjrg,11
14
+ half_orm_dev/version.txt,sha256=fpHrKpGErE8hMg3cojNvIV-3IACguP3WRjTMJUzPK0U,10
15
15
  half_orm_dev/cli/__init__.py,sha256=0CbMj8OIhZmglWakK7NhYPn302erUTEg2VHOdm1hRTQ,163
16
16
  half_orm_dev/cli/main.py,sha256=cECdUUPexx2vUeCipPnknjq_HmMjdVRwhMxz7A08S8s,11709
17
17
  half_orm_dev/cli/commands/__init__.py,sha256=UhWf0AnWqy4gyFo2SJQv8pL_YJ43pE_c9TgopcjzKDg,1490
@@ -50,9 +50,9 @@ half_orm_dev/templates/sql_adapter,sha256=kAP5y7Qml3DKsbZLUeoVpeXjbQcWltHjkDznED
50
50
  half_orm_dev/templates/warning,sha256=4hlZ_rRdpmkXxOeRoVd9xnXBARYXn95e-iXrD1f2u7k,490
51
51
  half_orm_dev/templates/git-hooks/pre-commit,sha256=-MIAQU3kujzkO8fKcRl7sk-qzbmUsNQJsP005ToUQi8,4592
52
52
  half_orm_dev/templates/git-hooks/prepare-commit-msg,sha256=zknOGGoaWKC97zfga2Xl2i_psnNo9MJbrEBuN91eHNw,1070
53
- half_orm_dev-0.17.2a11.dist-info/licenses/AUTHORS,sha256=eWxqzRdLOt2gX0FMQj_wui03Od3jdlwa8xNe9tl84g0,113
54
- half_orm_dev-0.17.2a11.dist-info/licenses/LICENSE,sha256=ufhxlSi6mttkGQTsGWrEoB3WA_fCPJ6-k07GSVBgyPw,644
55
- half_orm_dev-0.17.2a11.dist-info/METADATA,sha256=g7q_mJiSXAC06fy1NjSd4MKm3jqZ_45vzmXqlhZYjmA,41867
56
- half_orm_dev-0.17.2a11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
57
- half_orm_dev-0.17.2a11.dist-info/top_level.txt,sha256=M5hEsWfn5Kw0HL-VnNmS6Jw-3cwRyjims5a8cr18eTM,13
58
- half_orm_dev-0.17.2a11.dist-info/RECORD,,
53
+ half_orm_dev-0.17.3a2.dist-info/licenses/AUTHORS,sha256=eWxqzRdLOt2gX0FMQj_wui03Od3jdlwa8xNe9tl84g0,113
54
+ half_orm_dev-0.17.3a2.dist-info/licenses/LICENSE,sha256=ufhxlSi6mttkGQTsGWrEoB3WA_fCPJ6-k07GSVBgyPw,644
55
+ half_orm_dev-0.17.3a2.dist-info/METADATA,sha256=GUk8ni9Z98ec4db5m0wzx45WB7moUbhXm4jEsBVQwok,41866
56
+ half_orm_dev-0.17.3a2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
57
+ half_orm_dev-0.17.3a2.dist-info/top_level.txt,sha256=M5hEsWfn5Kw0HL-VnNmS6Jw-3cwRyjims5a8cr18eTM,13
58
+ half_orm_dev-0.17.3a2.dist-info/RECORD,,