half-orm-dev 0.17.3a1__py3-none-any.whl → 0.17.3a3__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 +12 -14
- half_orm_dev/repo.py +36 -37
- half_orm_dev/version.txt +1 -1
- {half_orm_dev-0.17.3a1.dist-info → half_orm_dev-0.17.3a3.dist-info}/METADATA +1 -1
- {half_orm_dev-0.17.3a1.dist-info → half_orm_dev-0.17.3a3.dist-info}/RECORD +9 -9
- {half_orm_dev-0.17.3a1.dist-info → half_orm_dev-0.17.3a3.dist-info}/WHEEL +0 -0
- {half_orm_dev-0.17.3a1.dist-info → half_orm_dev-0.17.3a3.dist-info}/licenses/AUTHORS +0 -0
- {half_orm_dev-0.17.3a1.dist-info → half_orm_dev-0.17.3a3.dist-info}/licenses/LICENSE +0 -0
- {half_orm_dev-0.17.3a1.dist-info → half_orm_dev-0.17.3a3.dist-info}/top_level.txt +0 -0
half_orm_dev/database.py
CHANGED
|
@@ -1362,25 +1362,23 @@ class Database:
|
|
|
1362
1362
|
pass
|
|
1363
1363
|
"""
|
|
1364
1364
|
try:
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
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
|
-
#
|
|
1372
|
-
#
|
|
1373
|
-
|
|
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
|
-
#
|
|
1376
|
-
|
|
1377
|
-
|
|
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
|
|
1386
|
-
)
|
|
1383
|
+
f"Ensure database connection is available."
|
|
1384
|
+
)
|
half_orm_dev/repo.py
CHANGED
|
@@ -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
|
|
2194
|
-
|
|
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.
|
|
2200
|
-
3.
|
|
2201
|
-
4.
|
|
2202
|
-
5.
|
|
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
|
|
2207
|
-
|
|
2208
|
-
|
|
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
|
|
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
|
-
-
|
|
2259
|
-
-
|
|
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.
|
|
2276
|
-
self.
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
2319
|
-
self.model.
|
|
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
|
half_orm_dev/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.17.3-
|
|
1
|
+
0.17.3-a3
|
|
@@ -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=
|
|
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=
|
|
12
|
+
half_orm_dev/repo.py,sha256=8kSVkwzZKF7M1670W6LaEHBEEksPnpWVc2DgkPNArTk,95162
|
|
13
13
|
half_orm_dev/utils.py,sha256=M3yViUFfsO7Cp9MYSoUSkCZ6R9w_4jW45UDZUOT8FhI,1493
|
|
14
|
-
half_orm_dev/version.txt,sha256=
|
|
14
|
+
half_orm_dev/version.txt,sha256=qSTZZdC6gl8-QFnsqAQnUROit9rkCseU80g_PaaaDsI,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.
|
|
54
|
-
half_orm_dev-0.17.
|
|
55
|
-
half_orm_dev-0.17.
|
|
56
|
-
half_orm_dev-0.17.
|
|
57
|
-
half_orm_dev-0.17.
|
|
58
|
-
half_orm_dev-0.17.
|
|
53
|
+
half_orm_dev-0.17.3a3.dist-info/licenses/AUTHORS,sha256=eWxqzRdLOt2gX0FMQj_wui03Od3jdlwa8xNe9tl84g0,113
|
|
54
|
+
half_orm_dev-0.17.3a3.dist-info/licenses/LICENSE,sha256=ufhxlSi6mttkGQTsGWrEoB3WA_fCPJ6-k07GSVBgyPw,644
|
|
55
|
+
half_orm_dev-0.17.3a3.dist-info/METADATA,sha256=KC90Vyh3C-aYWkfZnhnikmoUDm-r0Ld_55F_EGwSsu8,41866
|
|
56
|
+
half_orm_dev-0.17.3a3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
57
|
+
half_orm_dev-0.17.3a3.dist-info/top_level.txt,sha256=M5hEsWfn5Kw0HL-VnNmS6Jw-3cwRyjims5a8cr18eTM,13
|
|
58
|
+
half_orm_dev-0.17.3a3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|