half-orm-dev 0.17.3a1__tar.gz → 0.17.3a3__tar.gz

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.
Files changed (65) hide show
  1. {half_orm_dev-0.17.3a1/half_orm_dev.egg-info → half_orm_dev-0.17.3a3}/PKG-INFO +1 -1
  2. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/database.py +12 -14
  3. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/repo.py +36 -37
  4. half_orm_dev-0.17.3a3/half_orm_dev/version.txt +1 -0
  5. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3/half_orm_dev.egg-info}/PKG-INFO +1 -1
  6. half_orm_dev-0.17.3a1/half_orm_dev/version.txt +0 -1
  7. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/AUTHORS +0 -0
  8. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/LICENSE +0 -0
  9. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/README.md +0 -0
  10. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/__init__.py +0 -0
  11. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/__init__.py +0 -0
  12. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/__init__.py +0 -0
  13. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/apply.py +0 -0
  14. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/check.py +0 -0
  15. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/clone.py +0 -0
  16. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/init.py +0 -0
  17. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/migrate.py +0 -0
  18. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/patch.py +0 -0
  19. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/release.py +0 -0
  20. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/restore.py +0 -0
  21. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/sync.py +0 -0
  22. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/todo.py +0 -0
  23. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/undo.py +0 -0
  24. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/update.py +0 -0
  25. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/commands/upgrade.py +0 -0
  26. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli/main.py +0 -0
  27. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/cli_extension.py +0 -0
  28. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/decorators.py +0 -0
  29. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/hgit.py +0 -0
  30. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/migration_manager.py +0 -0
  31. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/migrations/0/17/1/00_move_to_hop.py +0 -0
  32. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/migrations/0/17/1/01_txt_to_toml.py +0 -0
  33. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/modules.py +0 -0
  34. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/patch_manager.py +0 -0
  35. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/patch_validator.py +0 -0
  36. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/patches/0/1/0/00_half_orm_meta.database.sql +0 -0
  37. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/patches/0/1/0/01_alter_half_orm_meta.hop_release.sql +0 -0
  38. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/patches/0/1/0/02_half_orm_meta.view.hop_penultimate_release.sql +0 -0
  39. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/patches/log +0 -0
  40. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/patches/sql/half_orm_meta.sql +0 -0
  41. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/release_file.py +0 -0
  42. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/release_manager.py +0 -0
  43. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/.gitignore +0 -0
  44. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/MANIFEST.in +0 -0
  45. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/Pipfile +0 -0
  46. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/README +0 -0
  47. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/conftest_template +0 -0
  48. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/git-hooks/pre-commit +0 -0
  49. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/git-hooks/prepare-commit-msg +0 -0
  50. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/init_module_template +0 -0
  51. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/module_template_1 +0 -0
  52. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/module_template_2 +0 -0
  53. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/module_template_3 +0 -0
  54. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/pyproject.toml +0 -0
  55. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/relation_test +0 -0
  56. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/sql_adapter +0 -0
  57. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/templates/warning +0 -0
  58. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev/utils.py +0 -0
  59. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev.egg-info/SOURCES.txt +0 -0
  60. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev.egg-info/dependency_links.txt +0 -0
  61. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev.egg-info/requires.txt +0 -0
  62. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/half_orm_dev.egg-info/top_level.txt +0 -0
  63. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/pyproject.toml +0 -0
  64. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/setup.cfg +0 -0
  65. {half_orm_dev-0.17.3a1 → half_orm_dev-0.17.3a3}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: half_orm_dev
3
- Version: 0.17.3a1
3
+ Version: 0.17.3a3
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
@@ -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
+ )
@@ -2186,26 +2186,41 @@ 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
+
2200
+ # Recreate public schema (PostgreSQL standard schema)
2201
+ # The public schema is expected to exist by many applications and tools
2202
+ if 'public' in schemas:
2203
+ self.model.execute_query('CREATE SCHEMA public')
2204
+ self.model.execute_query('GRANT ALL ON SCHEMA public TO public')
2205
+
2189
2206
  def restore_database_from_schema(self) -> None:
2190
2207
  """
2191
2208
  Restore database from model/schema.sql and model/metadata-X.Y.Z.sql.
2192
2209
 
2193
- Restores database to clean production state by dropping and recreating
2194
- database, then loading schema structure and half_orm_meta data. This provides
2210
+ Restores database to clean production state by dropping all user schemas
2211
+ and reloading schema structure and half_orm_meta data. This provides
2195
2212
  a clean baseline before applying patch files during patch development.
2196
2213
 
2197
2214
  Process:
2198
2215
  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
2216
+ 2. Drop all user schemas with CASCADE (no superuser privileges needed)
2217
+ 3. Load schema structure from model/schema.sql using psql -f
2218
+ 4. Load half_orm_meta data from model/metadata-X.Y.Z.sql using psql -f (if exists)
2219
+ 5. Reload halfORM Model metadata cache
2205
2220
 
2206
- The method uses Database.execute_pg_command() for all PostgreSQL
2207
- operations (dropdb, createdb, psql) with connection parameters from
2208
- repository configuration.
2221
+ The method uses DROP SCHEMA CASCADE instead of dropdb/createdb, allowing
2222
+ operation without CREATEDB privilege or superuser access. This makes it
2223
+ compatible with cloud databases (RDS, Azure) and restricted environments.
2209
2224
 
2210
2225
  File Resolution:
2211
2226
  - Accepts model/schema.sql as regular file or symlink
@@ -2216,8 +2231,7 @@ See docs/half_orm_dev.md for complete documentation.
2216
2231
 
2217
2232
  Error Handling:
2218
2233
  - Raises RepoError if model/schema.sql not found
2219
- - Raises RepoError if dropdb fails
2220
- - Raises RepoError if createdb fails
2234
+ - Raises RepoError if schema drop fails
2221
2235
  - Raises RepoError if psql schema load fails
2222
2236
  - Raises RepoError if psql metadata load fails (when file exists)
2223
2237
  - Database state rolled back on any failure
@@ -2255,8 +2269,9 @@ See docs/half_orm_dev.md for complete documentation.
2255
2269
  # Handle error: check schema.sql exists, verify permissions
2256
2270
 
2257
2271
  Notes:
2258
- - Silences psql output using stdout=subprocess.DEVNULL
2259
- - Uses Model.ping() for reconnection after restoration
2272
+ - Uses DROP SCHEMA CASCADE - no superuser or CREATEDB privilege required
2273
+ - Works on cloud databases (AWS RDS, Azure Database, etc.)
2274
+ - Uses Model.reconnect(reload=True) to refresh metadata cache
2260
2275
  - Supports both schema.sql file and schema.sql -> schema-X.Y.Z.sql symlink
2261
2276
  - Metadata file is optional (backward compatibility with older schemas)
2262
2277
  - All PostgreSQL commands use repository connection configuration
@@ -2272,26 +2287,10 @@ See docs/half_orm_dev.md for complete documentation.
2272
2287
  )
2273
2288
 
2274
2289
  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
2290
+ # 2. Drop all schemas (no superuser privileges needed)
2291
+ self._reset_database_schemas()
2293
2292
 
2294
- # 5. Load schema from model/schema.sql
2293
+ # 3. Load schema from model/schema.sql
2295
2294
  try:
2296
2295
  self.database.execute_pg_command(
2297
2296
  'psql', '-d', self.name, '-f', str(schema_path)
@@ -2299,7 +2298,7 @@ See docs/half_orm_dev.md for complete documentation.
2299
2298
  except Exception as e:
2300
2299
  raise RepoError(f"Failed to load schema from {schema_path.name}: {e}") from e
2301
2300
 
2302
- # 5b. Load metadata from model/metadata-X.Y.Z.sql (if exists)
2301
+ # 4. Load metadata from model/metadata-X.Y.Z.sql (if exists)
2303
2302
  metadata_path = self._deduce_metadata_path(schema_path)
2304
2303
 
2305
2304
  if metadata_path and metadata_path.exists():
@@ -2315,8 +2314,8 @@ See docs/half_orm_dev.md for complete documentation.
2315
2314
  ) from e
2316
2315
  # else: metadata file doesn't exist, continue without error (backward compatibility)
2317
2316
 
2318
- # 6. Reconnect Model to restored database
2319
- self.model.ping()
2317
+ # 5. Reload half_orm metadata cache
2318
+ self.model.reconnect(reload=True)
2320
2319
 
2321
2320
  except RepoError:
2322
2321
  # Re-raise RepoError as-is
@@ -0,0 +1 @@
1
+ 0.17.3-a3
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: half_orm_dev
3
- Version: 0.17.3a1
3
+ Version: 0.17.3a3
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
@@ -1 +0,0 @@
1
- 0.17.3-a1
File without changes
File without changes