lenapi 0.1.4.6__tar.gz → 0.1.4.8__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.
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/PKG-INFO +2 -2
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/README.md +1 -1
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/__init__.py +1 -1
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/cli.py +66 -73
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi.egg-info/PKG-INFO +2 -2
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/pyproject.toml +1 -1
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/LICENSE +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/admin.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/application.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/auth.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/authentication.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/authorization.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/background.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/concurrency.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/database.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/dependencies.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/docs_guard.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/logging.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/middleware.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/migration_render.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/model.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/models.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/mongodb.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/openapi.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/parameters.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/project.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/request.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/response.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/security.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/security_store.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/sentinels.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/service.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/throttling.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi/transaction.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi.egg-info/SOURCES.txt +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi.egg-info/dependency_links.txt +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi.egg-info/entry_points.txt +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi.egg-info/requires.txt +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi.egg-info/top_level.txt +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/lenapi_bootstrap.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/setup.cfg +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_admin_console.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_cli_settings_recovery.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_docs_guard.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_framework_features.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_media_upload.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_migration_render.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_mongodb.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_platform_services.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_project_isolation.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_security_patch.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_sentinels.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_throttle.py +0 -0
- {lenapi-0.1.4.6 → lenapi-0.1.4.8}/tests/test_user_model_extension.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lenapi
|
|
3
|
-
Version: 0.1.4.
|
|
3
|
+
Version: 0.1.4.8
|
|
4
4
|
Summary: A modern ASGI framework with Pydantic validation, sync and async database access, WebSockets, authentication, and integrated API documentation.
|
|
5
5
|
Author: Maekandex Communication Limitation
|
|
6
6
|
Author-email: "Ifeanyi M. Onovo" <ifeanyi@maekandex.com.ng>
|
|
@@ -2051,7 +2051,7 @@ python lenora.py migrate
|
|
|
2051
2051
|
python lenora.py showmigrations
|
|
2052
2052
|
```
|
|
2053
2053
|
|
|
2054
|
-
`repair-migrations`
|
|
2054
|
+
`repair-migrations` rebuilds SQL migration history from the live database schema and the current models. It removes this project's local revision files and Alembic version table, then generates and applies a fresh migration. Application tables and rows are preserved; existing tables or columns no longer represented by models are retained rather than dropped. Back up the database before running it. MongoDB has no Alembic history and does not support this repair command.
|
|
2055
2055
|
|
|
2056
2056
|
```bash
|
|
2057
2057
|
python lenora.py repair-migrations
|
|
@@ -1999,7 +1999,7 @@ python lenora.py migrate
|
|
|
1999
1999
|
python lenora.py showmigrations
|
|
2000
2000
|
```
|
|
2001
2001
|
|
|
2002
|
-
`repair-migrations`
|
|
2002
|
+
`repair-migrations` rebuilds SQL migration history from the live database schema and the current models. It removes this project's local revision files and Alembic version table, then generates and applies a fresh migration. Application tables and rows are preserved; existing tables or columns no longer represented by models are retained rather than dropped. Back up the database before running it. MongoDB has no Alembic history and does not support this repair command.
|
|
2003
2003
|
|
|
2004
2004
|
```bash
|
|
2005
2005
|
python lenora.py repair-migrations
|
|
@@ -473,9 +473,13 @@ def _main() -> None:
|
|
|
473
473
|
showmigrations = commands.add_parser("showmigrations", help="show local and applied database migration history")
|
|
474
474
|
showmigrations.add_argument("--app", default=DEFAULT_APP, help=f"ASGI app import string (default: {DEFAULT_APP})")
|
|
475
475
|
repair_migrations = commands.add_parser(
|
|
476
|
-
"repair-migrations", help="
|
|
476
|
+
"repair-migrations", help="rebuild migration history from the live schema and current models while preserving application data"
|
|
477
477
|
)
|
|
478
478
|
repair_migrations.add_argument("--app", default=DEFAULT_APP, help=f"ASGI app import string (default: {DEFAULT_APP})")
|
|
479
|
+
repair_migrations.add_argument(
|
|
480
|
+
"--message", "-m", default="repaired schema baseline",
|
|
481
|
+
help="description for the regenerated migration",
|
|
482
|
+
)
|
|
479
483
|
clear_migrations = commands.add_parser(
|
|
480
484
|
"clear_migrations", help="clear migration files and version history for an empty database only"
|
|
481
485
|
)
|
|
@@ -1028,7 +1032,7 @@ def test_http_endpoint_is_registered_and_documented(method, path):
|
|
|
1028
1032
|
|
|
1029
1033
|
engine = app.database.engine
|
|
1030
1034
|
revisions = Path.cwd() / "migrations" / "versions"
|
|
1031
|
-
if namespace and args.command
|
|
1035
|
+
if namespace and args.command not in {"delete_migrations", "repair-migrations"}:
|
|
1032
1036
|
# Never read or adopt the legacy global alembic_version table: it may
|
|
1033
1037
|
# belong to another project using the same database. Also refuse to
|
|
1034
1038
|
# replay a pre-namespace local chain into the shared database.
|
|
@@ -1096,7 +1100,22 @@ def test_http_endpoint_is_registered_and_documented(method, path):
|
|
|
1096
1100
|
name for name in inspector.get_view_names()
|
|
1097
1101
|
if namespace and name.startswith(f"{namespace}_")
|
|
1098
1102
|
}
|
|
1099
|
-
if args.command
|
|
1103
|
+
if args.command == "repair-migrations":
|
|
1104
|
+
# A repair rebases only migration metadata. Keep every application
|
|
1105
|
+
# table, view, and row; autogenerate a new revision against the live
|
|
1106
|
+
# schema below so the resulting migration contains only forward diffs.
|
|
1107
|
+
revisions.mkdir(parents=True, exist_ok=True)
|
|
1108
|
+
with engine.begin() as connection:
|
|
1109
|
+
if version_table in inspect(connection).get_table_names():
|
|
1110
|
+
quoted_version = connection.dialect.identifier_preparer.quote(version_table)
|
|
1111
|
+
connection.exec_driver_sql(f"DROP TABLE {quoted_version}")
|
|
1112
|
+
for path in revisions.glob("*.py"):
|
|
1113
|
+
if path.name != "__init__.py":
|
|
1114
|
+
path.unlink()
|
|
1115
|
+
logger.info(
|
|
1116
|
+
"Reset local migration revisions and the project Alembic version table; application data was preserved."
|
|
1117
|
+
)
|
|
1118
|
+
if args.command in {"migration", "migrate"}:
|
|
1100
1119
|
confirm_project_orphans(orphaned_tables | owned_views, "database tables/views")
|
|
1101
1120
|
if orphaned_tables or owned_views:
|
|
1102
1121
|
dialect = engine.dialect.name
|
|
@@ -1278,72 +1297,6 @@ def test_http_endpoint_is_registered_and_documented(method, path):
|
|
|
1278
1297
|
print("Database migration state: " + ", ".join(sorted(current_heads)))
|
|
1279
1298
|
return
|
|
1280
1299
|
|
|
1281
|
-
if args.command == "repair-migrations":
|
|
1282
|
-
script = ScriptDirectory.from_config(config)
|
|
1283
|
-
with engine.connect() as connection:
|
|
1284
|
-
table_names = set(inspect(connection).get_table_names())
|
|
1285
|
-
differences = compare_metadata(
|
|
1286
|
-
MigrationContext.configure(
|
|
1287
|
-
connection,
|
|
1288
|
-
opts={"compare_type": True, "include_object": include_migration_object,
|
|
1289
|
-
"version_table": version_table},
|
|
1290
|
-
),
|
|
1291
|
-
Model.metadata,
|
|
1292
|
-
)
|
|
1293
|
-
if differences:
|
|
1294
|
-
parser.error(
|
|
1295
|
-
"database schema does not match current models; refusing to change migration history. "
|
|
1296
|
-
"Restore the missing revision file or reconcile the schema first. "
|
|
1297
|
-
"If the database is empty, run python lenora.py migration instead."
|
|
1298
|
-
)
|
|
1299
|
-
local_revisions = [
|
|
1300
|
-
path for path in revisions.glob("*.py") if path.name != "__init__.py"
|
|
1301
|
-
]
|
|
1302
|
-
if not local_revisions:
|
|
1303
|
-
if not table_names:
|
|
1304
|
-
parser.error("database is empty; run python lenora.py migration to create the initial revision")
|
|
1305
|
-
from alembic.autogenerate import render_python_code
|
|
1306
|
-
from alembic.operations.ops import CreateIndexOp, CreateTableOp, UpgradeOps
|
|
1307
|
-
from alembic.util import rev_id
|
|
1308
|
-
|
|
1309
|
-
revision_id = rev_id()
|
|
1310
|
-
operations = []
|
|
1311
|
-
tables = list(Model.metadata.sorted_tables)
|
|
1312
|
-
for table in tables:
|
|
1313
|
-
operations.append(CreateTableOp.from_table(table))
|
|
1314
|
-
for table in tables:
|
|
1315
|
-
operations.extend(
|
|
1316
|
-
CreateIndexOp.from_index(index)
|
|
1317
|
-
for index in sorted(table.indexes, key=lambda index: index.name or "")
|
|
1318
|
-
)
|
|
1319
|
-
upgrade_code = render_python_code(UpgradeOps(ops=operations))
|
|
1320
|
-
downgrade_code = "\n".join(
|
|
1321
|
-
f" op.drop_table({table.name!r})" for table in reversed(tables)
|
|
1322
|
-
) or " pass"
|
|
1323
|
-
revisions.mkdir(parents=True, exist_ok=True)
|
|
1324
|
-
baseline = revisions / f"{revision_id}_baseline.py"
|
|
1325
|
-
baseline.write_text(
|
|
1326
|
-
'"""Baseline schema captured from the current model metadata.\n\n'
|
|
1327
|
-
f"Revision ID: {revision_id}\nRevises: None\n\n\n"
|
|
1328
|
-
'"""\nfrom alembic import op\nimport sqlalchemy as sa\n\n'
|
|
1329
|
-
f"revision = {revision_id!r}\ndown_revision = None\n"
|
|
1330
|
-
"branch_labels = None\ndepends_on = None\n\n\n"
|
|
1331
|
-
"def upgrade():\n"
|
|
1332
|
-
f"{upgrade_code}\n\n\n"
|
|
1333
|
-
"def downgrade():\n"
|
|
1334
|
-
f"{downgrade_code}\n",
|
|
1335
|
-
encoding="utf-8",
|
|
1336
|
-
)
|
|
1337
|
-
logger.info("Created baseline migration %s from current models.", baseline.name)
|
|
1338
|
-
head = revision_id
|
|
1339
|
-
else:
|
|
1340
|
-
head = script.get_current_head()
|
|
1341
|
-
if head is None:
|
|
1342
|
-
parser.error("no migration head found; inspect showmigrations and restore missing revision files")
|
|
1343
|
-
command.stamp(config, "head")
|
|
1344
|
-
logger.info("Migration history repaired to %s; schema and data were preserved.", head)
|
|
1345
|
-
return
|
|
1346
|
-
|
|
1347
1300
|
if args.command == "clear_migrations":
|
|
1348
1301
|
with engine.connect() as connection:
|
|
1349
1302
|
table_names = set(inspect(connection).get_table_names())
|
|
@@ -1354,7 +1307,7 @@ def test_http_endpoint_is_registered_and_documented(method, path):
|
|
|
1354
1307
|
if application_tables:
|
|
1355
1308
|
parser.error(
|
|
1356
1309
|
"refusing to clear migrations because the database contains application tables; "
|
|
1357
|
-
"use `python lenora.py repair-migrations`
|
|
1310
|
+
"use `python lenora.py repair-migrations` to rebuild migration history while preserving application tables and data"
|
|
1358
1311
|
)
|
|
1359
1312
|
if version_table in table_names:
|
|
1360
1313
|
with engine.begin() as connection:
|
|
@@ -1367,13 +1320,19 @@ def test_http_endpoint_is_registered_and_documented(method, path):
|
|
|
1367
1320
|
logger.info("Cleared migration files and database history; no application tables existed.")
|
|
1368
1321
|
return
|
|
1369
1322
|
|
|
1370
|
-
schema_generation = args.command in {"migration", "background-worker"}
|
|
1323
|
+
schema_generation = args.command in {"migration", "background-worker", "repair-migrations"}
|
|
1371
1324
|
if schema_generation:
|
|
1372
1325
|
existing_revisions = [
|
|
1373
1326
|
path for path in revisions.glob("*.py") if path.name != "__init__.py"
|
|
1374
1327
|
]
|
|
1375
1328
|
revisions_before_autogenerate = {path.resolve() for path in existing_revisions}
|
|
1376
|
-
|
|
1329
|
+
# Repair autogeneration must compare against the real database even
|
|
1330
|
+
# for SQLite. The normal initial-migration path uses an empty temporary
|
|
1331
|
+
# database to generate a create-all baseline, which would overwrite
|
|
1332
|
+
# the meaning of an existing schema during repair.
|
|
1333
|
+
config.attributes["lenapi_initial_revision"] = (
|
|
1334
|
+
not existing_revisions and args.command != "repair-migrations"
|
|
1335
|
+
)
|
|
1377
1336
|
|
|
1378
1337
|
script = ScriptDirectory.from_config(config)
|
|
1379
1338
|
|
|
@@ -1525,6 +1484,36 @@ def test_http_endpoint_is_registered_and_documented(method, path):
|
|
|
1525
1484
|
temporary_engine.dispose()
|
|
1526
1485
|
|
|
1527
1486
|
def skip_empty_revision(migration_context, revision, directives):
|
|
1487
|
+
if args.command == "repair-migrations":
|
|
1488
|
+
# Preserve existing database data: an autogenerate diff must
|
|
1489
|
+
# never remove a table or column simply because its model was
|
|
1490
|
+
# removed or renamed. Keep the remaining forward changes.
|
|
1491
|
+
from alembic.operations import ops
|
|
1492
|
+
|
|
1493
|
+
def keep_data_operations(container):
|
|
1494
|
+
kept = []
|
|
1495
|
+
for operation in container.ops:
|
|
1496
|
+
if isinstance(operation, (ops.DropTableOp, ops.DropColumnOp)):
|
|
1497
|
+
preserved_name = getattr(operation, "table_name", "table")
|
|
1498
|
+
if isinstance(operation, ops.DropColumnOp):
|
|
1499
|
+
preserved_name = f"{preserved_name}.{operation.column_name}"
|
|
1500
|
+
logger.warning(
|
|
1501
|
+
"Keeping existing database data in %s; model removal was not applied.",
|
|
1502
|
+
preserved_name,
|
|
1503
|
+
)
|
|
1504
|
+
continue
|
|
1505
|
+
nested = getattr(operation, "ops", None)
|
|
1506
|
+
if nested is not None:
|
|
1507
|
+
keep_data_operations(operation)
|
|
1508
|
+
kept.append(operation)
|
|
1509
|
+
container.ops = kept
|
|
1510
|
+
|
|
1511
|
+
for directive in directives or ():
|
|
1512
|
+
for upgrade_ops in directive.upgrade_ops_list:
|
|
1513
|
+
keep_data_operations(upgrade_ops)
|
|
1514
|
+
# Unlike an ordinary migration, an empty repair revision is
|
|
1515
|
+
# useful: it records the new baseline after a history reset.
|
|
1516
|
+
return
|
|
1528
1517
|
if directives and directives[0].upgrade_ops.is_empty():
|
|
1529
1518
|
directives.clear()
|
|
1530
1519
|
|
|
@@ -1643,7 +1632,11 @@ def test_http_endpoint_is_registered_and_documented(method, path):
|
|
|
1643
1632
|
name for name in table_names
|
|
1644
1633
|
if namespace and name.startswith(f"{namespace}_") and name != version_table
|
|
1645
1634
|
}
|
|
1646
|
-
if
|
|
1635
|
+
if (
|
|
1636
|
+
existing_tables
|
|
1637
|
+
and version_table not in table_names
|
|
1638
|
+
and args.command != "repair-migrations"
|
|
1639
|
+
):
|
|
1647
1640
|
differences = compare_metadata(
|
|
1648
1641
|
MigrationContext.configure(
|
|
1649
1642
|
connection,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lenapi
|
|
3
|
-
Version: 0.1.4.
|
|
3
|
+
Version: 0.1.4.8
|
|
4
4
|
Summary: A modern ASGI framework with Pydantic validation, sync and async database access, WebSockets, authentication, and integrated API documentation.
|
|
5
5
|
Author: Maekandex Communication Limitation
|
|
6
6
|
Author-email: "Ifeanyi M. Onovo" <ifeanyi@maekandex.com.ng>
|
|
@@ -2051,7 +2051,7 @@ python lenora.py migrate
|
|
|
2051
2051
|
python lenora.py showmigrations
|
|
2052
2052
|
```
|
|
2053
2053
|
|
|
2054
|
-
`repair-migrations`
|
|
2054
|
+
`repair-migrations` rebuilds SQL migration history from the live database schema and the current models. It removes this project's local revision files and Alembic version table, then generates and applies a fresh migration. Application tables and rows are preserved; existing tables or columns no longer represented by models are retained rather than dropped. Back up the database before running it. MongoDB has no Alembic history and does not support this repair command.
|
|
2055
2055
|
|
|
2056
2056
|
```bash
|
|
2057
2057
|
python lenora.py repair-migrations
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "lenapi"
|
|
7
|
-
version = "0.1.4.
|
|
7
|
+
version = "0.1.4.8"
|
|
8
8
|
description = "A modern ASGI framework with Pydantic validation, sync and async database access, WebSockets, authentication, and integrated API documentation."
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "Ifeanyi M. Onovo", email = "ifeanyi@maekandex.com.ng"},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|