simple-module-core 0.0.44__tar.gz → 0.0.46__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.
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/PKG-INFO +1 -1
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/pyproject.toml +1 -1
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/__main__.py +13 -4
- simple_module_core-0.0.46/simple_module_core/_entry_point_errors.py +25 -0
- simple_module_core-0.0.46/simple_module_core/_migration_doctor.py +56 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/deprecation.py +1 -1
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_expression_index.py +60 -9
- simple_module_core-0.0.46/simple_module_core/diagnostics/_migration.py +96 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/discovery.py +7 -3
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/dotenv.py +23 -0
- simple_module_core-0.0.46/tests/test_core_discovery_stale_sys_path.py +64 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_diagnostics.py +19 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_expression_index_diagnostics.py +36 -0
- simple_module_core-0.0.44/simple_module_core/diagnostics/_migration.py +0 -45
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/.gitignore +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/LICENSE +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/README.md +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/__init__.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/_data_doctor.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/_i18n_flatten.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/_i18n_translator.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/_permission_grants.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/_request_hooks.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/activity_feed.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/app_state.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/audit_links.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/body_limits.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/correlation.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/cors.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/csp.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/data_compatibility.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/datetimes.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/design_packs.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/__init__.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_coupling.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_css.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_db_extensions.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_dependencies.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_durable_names.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_heavy_task_imports.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_i18n.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_inertia_api.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_js_workspace.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_module.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_pages.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_runner.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_spa_mount.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_tenancy.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_types.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/durable_events.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/environments.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/events.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/exceptions.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/feature_flags.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/health.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/i18n.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/i18n_overrides.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/invalidation.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/invalidation_refresh.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/leases.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/mail.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/menu.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/module.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/module_meta.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/module_settings.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/path_rules.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/permission_denied.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/permissions.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/public_routes.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/py.typed +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/rate_limit.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/redirect_safety.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/resources.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/secret_fields.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/services.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/settings_base.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/settings_hydrate.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/setup_steps.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/singleflight.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/spa_mount.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/stored_settings.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/tenancy.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/tenant_events.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/user_directory.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/user_events.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/versioning.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_audit_links.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_auth_provider_selection.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_app_state.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_data_compatibility_doctor.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_datetimes.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_inline_delivery_context.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_invalidation_refresh.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_leases.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_lifecycle_docs.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_mail_resolution.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_module_settings.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_settings_source_cache.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_singleflight.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_user_directory.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_csp_registry.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_css_diagnostics.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_css_scanner.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_db_extensions_diagnostics.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_deprecation_helper.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_design_packs.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_diagnostics_tenancy.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_discovery.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_discovery_missing_deps.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_doctor_cli_overrides.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_dotenv.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_durable_events.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_environments.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_events.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_events_inline.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_feature_flags.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_feature_flags_decorator.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_health_registry.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_heavy_task_imports_diagnostics.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_i18n.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_i18n_diagnostics.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_i18n_overrides.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_invalidation.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_invalidation_handlers.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_menu.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_module_base.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_module_diagnostics.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_path_rule_registries.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_permission_sources.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_permissions.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_permissions_admin_principal.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_public_routes.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_public_routes_rate_precedence.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_redirect_safety.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_services.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_settings_base.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_sm003_page_render.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_sm009_dynamic_coupling.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_sm034_durable_names.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_tenant_exists.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_tenant_roles.py +0 -0
- {simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_versioning.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: simple_module_core
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.46
|
|
4
4
|
Summary: Module-system primitives for the simple_module framework — ModuleBase, discovery, diagnostics, events
|
|
5
5
|
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
|
|
6
6
|
Project-URL: Repository, https://github.com/antosubash/simple_module_python
|
|
@@ -25,6 +25,7 @@ import sys
|
|
|
25
25
|
from pathlib import Path
|
|
26
26
|
|
|
27
27
|
from simple_module_core._data_doctor import data_compatibility_diagnostics
|
|
28
|
+
from simple_module_core._migration_doctor import migration_diagnostics
|
|
28
29
|
from simple_module_core.diagnostics import (
|
|
29
30
|
Diagnostic,
|
|
30
31
|
DiagnosticLevel,
|
|
@@ -39,7 +40,7 @@ from simple_module_core.discovery import (
|
|
|
39
40
|
select_auth_provider,
|
|
40
41
|
topological_sort,
|
|
41
42
|
)
|
|
42
|
-
from simple_module_core.dotenv import find_env_file, parse_dotenv
|
|
43
|
+
from simple_module_core.dotenv import absolutize_sqlite_url, find_env_file, parse_dotenv
|
|
43
44
|
from simple_module_core.exceptions import InvalidModuleError
|
|
44
45
|
|
|
45
46
|
|
|
@@ -77,8 +78,13 @@ def _load_i18n_settings_from_env() -> tuple[list[str] | None, str]:
|
|
|
77
78
|
|
|
78
79
|
|
|
79
80
|
def _database_url() -> str:
|
|
80
|
-
"""``SM_DATABASE_URL``, defaulting like ``Settings.database_url``.
|
|
81
|
-
|
|
81
|
+
"""``SM_DATABASE_URL``, defaulting and anchored like ``Settings.database_url``.
|
|
82
|
+
|
|
83
|
+
A relative SQLite path is resolved against the project root, as the app
|
|
84
|
+
resolves it, so doctor run from ``host/`` reads the app's database.
|
|
85
|
+
"""
|
|
86
|
+
url = os.environ.get("SM_DATABASE_URL", "sqlite+aiosqlite:///./app.db")
|
|
87
|
+
return absolutize_sqlite_url(url, anchor=find_env_file().parent)
|
|
82
88
|
|
|
83
89
|
|
|
84
90
|
def _database_dialect() -> str:
|
|
@@ -92,7 +98,9 @@ def _database_dialect() -> str:
|
|
|
92
98
|
|
|
93
99
|
|
|
94
100
|
def _hosting_locales() -> Path | None:
|
|
95
|
-
"""The framework's own ``hosting`` catalog
|
|
101
|
+
"""The framework's own ``hosting`` catalog, found without importing it.
|
|
102
|
+
|
|
103
|
+
It holds the setup wizard's and the admin overview's strings.
|
|
96
104
|
|
|
97
105
|
The running app's ``build_i18n_registry`` always adds it, so doctor must
|
|
98
106
|
too, or every ``hosting.*`` host override reads as unknown (SM027). Core
|
|
@@ -188,6 +196,7 @@ def main() -> int:
|
|
|
188
196
|
database_dialect=_database_dialect(),
|
|
189
197
|
)
|
|
190
198
|
diagnostics.extend(override_findings)
|
|
199
|
+
diagnostics.extend(migration_diagnostics(modules, _database_url(), find_env_file().parent))
|
|
191
200
|
diagnostics.extend(data_compatibility_diagnostics(modules, _database_url()))
|
|
192
201
|
# A missing dependency only warns at a dev boot, but production refuses
|
|
193
202
|
# to start with it (GH #501), so doctor reports it as what it will be.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Telling an unimportable module entry point apart from a broken module."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def own_package_missing(ep, exc: BaseException) -> bool:
|
|
7
|
+
"""Whether the entry point's own package, not a dependency, is unimportable.
|
|
8
|
+
|
|
9
|
+
A package installed after this process started looks like that: the entry
|
|
10
|
+
point is listed (metadata is read fresh) but ``sys.path`` was fixed at
|
|
11
|
+
start-up, so an editable install's ``.pth`` entry is not on it (GH #915).
|
|
12
|
+
"""
|
|
13
|
+
if not isinstance(exc, ModuleNotFoundError) or not exc.name:
|
|
14
|
+
return False
|
|
15
|
+
target = getattr(ep, "module", "") or ""
|
|
16
|
+
return target == exc.name or target.startswith(f"{exc.name}.")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def stale_path_message(ep, exc: BaseException) -> str:
|
|
20
|
+
missing = getattr(exc, "name", None)
|
|
21
|
+
return (
|
|
22
|
+
f"Module entry point '{ep.name}' is installed but {missing!r} cannot be imported "
|
|
23
|
+
"in this process. If it was added after the server started (smpy add, uv sync), "
|
|
24
|
+
"restart the server (`make dev`): a reload keeps the old import path"
|
|
25
|
+
)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Doctor's migration checks (SM010, SM011) against ``SM_DATABASE_URL`` (#895)."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import importlib.util
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from simple_module_core.diagnostics import Diagnostic, DiagnosticLevel
|
|
9
|
+
from simple_module_core.diagnostics._migration import MigrationDiagnostics, module_table_names
|
|
10
|
+
from simple_module_core.module import ModuleBase
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _alembic_ini(project_root: Path) -> Path | None:
|
|
14
|
+
"""``alembic.ini`` at the project root, else ``host/alembic.ini``, as the CLI resolves it."""
|
|
15
|
+
for candidate in (project_root / "alembic.ini", project_root / "host" / "alembic.ini"):
|
|
16
|
+
if candidate.is_file():
|
|
17
|
+
return candidate
|
|
18
|
+
return None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def migration_diagnostics(
|
|
22
|
+
modules: Sequence[ModuleBase], database_url: str, project_root: Path
|
|
23
|
+
) -> list[Diagnostic]:
|
|
24
|
+
# Core-only installations have neither Alembic nor a database runtime.
|
|
25
|
+
if importlib.util.find_spec("simple_module_db") is None:
|
|
26
|
+
return []
|
|
27
|
+
ini = _alembic_ini(project_root)
|
|
28
|
+
if ini is None:
|
|
29
|
+
return []
|
|
30
|
+
from simple_module_db.migration_state import read_migration_state
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
state = asyncio.run(read_migration_state(database_url, ini))
|
|
34
|
+
except Exception:
|
|
35
|
+
# Unreachable is a warning, as for SM033: doctor also runs where no
|
|
36
|
+
# database is up. A revision file that fails to import lands here too.
|
|
37
|
+
# The error text can carry credentials, so it is not shown.
|
|
38
|
+
return [
|
|
39
|
+
Diagnostic(
|
|
40
|
+
level=DiagnosticLevel.WARNING,
|
|
41
|
+
code="SM010",
|
|
42
|
+
message="Could not read the migration state (database or Alembic revisions); "
|
|
43
|
+
"SM010 and SM011 were not checked",
|
|
44
|
+
module_name="migrations",
|
|
45
|
+
suggestion="Check SM_DATABASE_URL and that the database is running, and that "
|
|
46
|
+
"the revisions load (`make migration-history`).",
|
|
47
|
+
)
|
|
48
|
+
]
|
|
49
|
+
if state is None:
|
|
50
|
+
return []
|
|
51
|
+
checks = MigrationDiagnostics()
|
|
52
|
+
behind = checks.check_heads(state.current, state.heads)
|
|
53
|
+
if behind:
|
|
54
|
+
# Behind head, a missing table may simply be in a pending revision.
|
|
55
|
+
return behind
|
|
56
|
+
return checks.check_table_coverage(module_table_names(modules), set(state.tables))
|
|
@@ -14,7 +14,9 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
import importlib
|
|
16
16
|
import logging
|
|
17
|
+
import re
|
|
17
18
|
from collections.abc import Iterable
|
|
19
|
+
from pathlib import Path
|
|
18
20
|
from typing import TYPE_CHECKING, Any
|
|
19
21
|
|
|
20
22
|
from simple_module_core.diagnostics._types import Diagnostic, DiagnosticLevel
|
|
@@ -25,13 +27,37 @@ if TYPE_CHECKING:
|
|
|
25
27
|
logger = logging.getLogger(__name__)
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
_ORDERING_MODIFIERS = frozenset({"asc_op", "desc_op", "nulls_first_op", "nulls_last_op"})
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def unwrap_ordering(expr: Any) -> Any:
|
|
34
|
+
"""``expr`` without its ``desc()``/``asc()``/``nulls_first()``/``nulls_last()`` wrappers."""
|
|
35
|
+
while getattr(getattr(expr, "modifier", None), "__name__", None) in _ORDERING_MODIFIERS:
|
|
36
|
+
expr = expr.element
|
|
37
|
+
return expr
|
|
38
|
+
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
def _is_column(expr: Any) -> bool:
|
|
41
|
+
"""A column, possibly wrapped in ``desc()``/``asc()``/``nulls_last()``.
|
|
42
|
+
|
|
43
|
+
SQLite reflects ``created_at DESC`` as the column ``created_at`` and Alembic
|
|
44
|
+
compares it as one (GH #869), so an ordering keeps an element a column. A
|
|
45
|
+
plain ``Column`` is attached to its table; ``sa.column("x")`` is a named,
|
|
46
|
+
non-literal column; ``text()``, ``literal_column()``, a function or a bare
|
|
47
|
+
string label are expressions.
|
|
33
48
|
"""
|
|
34
|
-
|
|
49
|
+
expr = unwrap_ordering(expr)
|
|
50
|
+
if hasattr(expr, "element"):
|
|
51
|
+
# Still wraps something once the ordering is gone: a label over an
|
|
52
|
+
# arbitrary expression (``lower(email).label("x")``) or ``sa.desc("col")``'s
|
|
53
|
+
# bare-string label. A column wraps nothing.
|
|
54
|
+
return False
|
|
55
|
+
return getattr(expr, "table", None) is not None or getattr(expr, "is_literal", None) is False
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def index_is_expression_based(index: Any) -> bool:
|
|
59
|
+
"""True when any element of ``index`` is an expression rather than a plain column."""
|
|
60
|
+
return not all(_is_column(expr) for expr in index.expressions)
|
|
35
61
|
|
|
36
62
|
|
|
37
63
|
def find_expression_indexes(tables: Iterable[Any]) -> list[tuple[str, str]]:
|
|
@@ -70,6 +96,32 @@ def module_all_tables(mod: ModuleBase) -> list[Any]:
|
|
|
70
96
|
return list(seen.values())
|
|
71
97
|
|
|
72
98
|
|
|
99
|
+
_ROUNDTRIP_TARGET = re.compile(r"^migrations-roundtrip-pg:", re.MULTILINE)
|
|
100
|
+
_DOCS_URL = "https://docs.py.simplemodule.dev/module-authoring"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def expression_index_advice(root: Path | None = None) -> str:
|
|
104
|
+
"""How to verify expression indexes, in terms of what this project has.
|
|
105
|
+
|
|
106
|
+
The framework repository has a Postgres round-trip make target; an app made
|
|
107
|
+
by ``smpy new`` does not, so pointing it there sends users nowhere (GH #917).
|
|
108
|
+
``root`` defaults to the working directory, where make, alembic and doctor run.
|
|
109
|
+
"""
|
|
110
|
+
try:
|
|
111
|
+
makefile = (root or Path.cwd()) / "Makefile"
|
|
112
|
+
has_target = _ROUNDTRIP_TARGET.search(makefile.read_text(encoding="utf-8")) is not None
|
|
113
|
+
except OSError:
|
|
114
|
+
has_target = False
|
|
115
|
+
if has_target:
|
|
116
|
+
return "verify them on PostgreSQL with `make migrations-roundtrip-pg`"
|
|
117
|
+
return (
|
|
118
|
+
"verify them on PostgreSQL: point `SM_DATABASE_URL` at a PostgreSQL database, "
|
|
119
|
+
"run `make migrate`, then `alembic check` with the app's alembic.ini "
|
|
120
|
+
"(`uv run alembic -c host/alembic.ini check` in a `smpy new` app), which "
|
|
121
|
+
f"reports a missing index. See {_DOCS_URL}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
73
125
|
def check_expression_indexes_unverifiable(
|
|
74
126
|
tables: Iterable[Any], dialect: str | None, module_name: str
|
|
75
127
|
) -> list[Diagnostic]:
|
|
@@ -90,17 +142,16 @@ def check_expression_indexes_unverifiable(
|
|
|
90
142
|
f"about them"
|
|
91
143
|
),
|
|
92
144
|
module_name=module_name,
|
|
93
|
-
suggestion=(
|
|
94
|
-
"Add them to a revision by hand and verify on Postgres: "
|
|
95
|
-
"`make migrations-roundtrip-pg`"
|
|
96
|
-
),
|
|
145
|
+
suggestion=f"Add them to a revision by hand and {expression_index_advice()}",
|
|
97
146
|
)
|
|
98
147
|
]
|
|
99
148
|
|
|
100
149
|
|
|
101
150
|
__all__ = [
|
|
102
151
|
"check_expression_indexes_unverifiable",
|
|
152
|
+
"expression_index_advice",
|
|
103
153
|
"find_expression_indexes",
|
|
104
154
|
"index_is_expression_based",
|
|
105
155
|
"module_all_tables",
|
|
156
|
+
"unwrap_ordering",
|
|
106
157
|
]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Alembic migration-state diagnostics (SM010, SM011)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable, Set
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from simple_module_core.diagnostics._expression_index import module_all_tables
|
|
9
|
+
from simple_module_core.diagnostics._types import Diagnostic, DiagnosticLevel
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from simple_module_core.module import ModuleBase
|
|
13
|
+
|
|
14
|
+
_CODE_BEHIND = "SM010"
|
|
15
|
+
_MODULE_NAME = "migrations"
|
|
16
|
+
_SUGGEST_MIGRATE = "Run: make migrate"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def module_table_names(modules: Iterable[ModuleBase]) -> set[str]:
|
|
20
|
+
"""Names of the tables declared in each module's ``models`` (the set SM026 checks)."""
|
|
21
|
+
return {table.name for mod in modules for table in module_all_tables(mod)}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class MigrationDiagnostics:
|
|
25
|
+
"""Validates database migration state."""
|
|
26
|
+
|
|
27
|
+
def check_heads(self, current: Set[str], heads: Set[str]) -> list[Diagnostic]:
|
|
28
|
+
"""SM010 for a database missing any head; the boot check's ``heads - current`` rule.
|
|
29
|
+
|
|
30
|
+
A never-migrated database is a WARNING: a production boot sends it to
|
|
31
|
+
``/setup`` rather than refusing it. One behind on any branch is an ERROR,
|
|
32
|
+
because a production boot refuses it.
|
|
33
|
+
"""
|
|
34
|
+
missing = heads - current
|
|
35
|
+
if not missing:
|
|
36
|
+
return []
|
|
37
|
+
if not current:
|
|
38
|
+
return [
|
|
39
|
+
Diagnostic(
|
|
40
|
+
level=DiagnosticLevel.WARNING,
|
|
41
|
+
code=_CODE_BEHIND,
|
|
42
|
+
message="Database has never been migrated (no alembic_version)",
|
|
43
|
+
module_name=_MODULE_NAME,
|
|
44
|
+
suggestion=_SUGGEST_MIGRATE,
|
|
45
|
+
)
|
|
46
|
+
]
|
|
47
|
+
return [
|
|
48
|
+
Diagnostic(
|
|
49
|
+
level=DiagnosticLevel.ERROR,
|
|
50
|
+
code=_CODE_BEHIND,
|
|
51
|
+
message=(
|
|
52
|
+
f"Database is behind: missing heads {', '.join(map(repr, sorted(missing)))}"
|
|
53
|
+
),
|
|
54
|
+
module_name=_MODULE_NAME,
|
|
55
|
+
suggestion=_SUGGEST_MIGRATE,
|
|
56
|
+
)
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
def check_revision_mismatch(
|
|
60
|
+
self,
|
|
61
|
+
current_revision: str | None,
|
|
62
|
+
head_revision: str | None,
|
|
63
|
+
) -> list[Diagnostic]:
|
|
64
|
+
"""SM010: Error if database is not at the migration head."""
|
|
65
|
+
if current_revision == head_revision:
|
|
66
|
+
return []
|
|
67
|
+
return [
|
|
68
|
+
Diagnostic(
|
|
69
|
+
level=DiagnosticLevel.ERROR,
|
|
70
|
+
code=_CODE_BEHIND,
|
|
71
|
+
message=(f"Database at revision {current_revision!r}, expected {head_revision!r}"),
|
|
72
|
+
module_name=_MODULE_NAME,
|
|
73
|
+
suggestion=_SUGGEST_MIGRATE,
|
|
74
|
+
)
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
def check_table_coverage(
|
|
78
|
+
self,
|
|
79
|
+
module_tables: set[str],
|
|
80
|
+
migrated_tables: set[str],
|
|
81
|
+
) -> list[Diagnostic]:
|
|
82
|
+
"""SM011: Warning for module tables a database at every head does not have."""
|
|
83
|
+
missing = module_tables - migrated_tables
|
|
84
|
+
return [
|
|
85
|
+
Diagnostic(
|
|
86
|
+
level=DiagnosticLevel.WARNING,
|
|
87
|
+
code="SM011",
|
|
88
|
+
message=(
|
|
89
|
+
f"Table '{table}' is declared in models but missing from the migrated "
|
|
90
|
+
"database, so no migration creates it"
|
|
91
|
+
),
|
|
92
|
+
module_name=_MODULE_NAME,
|
|
93
|
+
suggestion=f'Run: make migration msg="add {table}"',
|
|
94
|
+
)
|
|
95
|
+
for table in sorted(missing)
|
|
96
|
+
]
|
|
@@ -6,6 +6,7 @@ import logging
|
|
|
6
6
|
from collections.abc import Sequence
|
|
7
7
|
from importlib.metadata import entry_points
|
|
8
8
|
|
|
9
|
+
from simple_module_core._entry_point_errors import own_package_missing, stale_path_message
|
|
9
10
|
from simple_module_core.dotenv import env_str, load_dotenv_into_environ
|
|
10
11
|
from simple_module_core.exceptions import (
|
|
11
12
|
CircularDependencyError,
|
|
@@ -63,10 +64,10 @@ def discover_modules(
|
|
|
63
64
|
# Imported here to avoid a circular import at module load time.
|
|
64
65
|
from simple_module_core.versioning import check_framework_compatibility
|
|
65
66
|
|
|
66
|
-
def fail(msg: str, exc: BaseException | None = None) -> None:
|
|
67
|
+
def fail(msg: str, exc: BaseException | None = None, *, with_traceback: bool = True) -> None:
|
|
67
68
|
if strict:
|
|
68
69
|
raise InvalidModuleError(msg) from exc
|
|
69
|
-
if exc is not None:
|
|
70
|
+
if exc is not None and with_traceback:
|
|
70
71
|
logger.exception("%s — skipping", msg)
|
|
71
72
|
else:
|
|
72
73
|
logger.error("%s — skipping", msg)
|
|
@@ -79,7 +80,10 @@ def discover_modules(
|
|
|
79
80
|
try:
|
|
80
81
|
module_cls = ep.load()
|
|
81
82
|
except Exception as exc:
|
|
82
|
-
|
|
83
|
+
if own_package_missing(ep, exc):
|
|
84
|
+
fail(stale_path_message(ep, exc), exc, with_traceback=False)
|
|
85
|
+
else:
|
|
86
|
+
fail(f"Failed to load module entry point '{ep.name}': {exc}", exc)
|
|
83
87
|
continue
|
|
84
88
|
|
|
85
89
|
try:
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"""Minimal ``.env`` parser + env-var helpers — dependency-free.
|
|
2
2
|
|
|
3
|
+
Also holds ``absolutize_sqlite_url``, which anchors a relative SQLite
|
|
4
|
+
``SM_DATABASE_URL`` at the project root for both the app and the doctor CLI.
|
|
5
|
+
|
|
3
6
|
Used in places that can't or shouldn't pull in ``pydantic-settings`` (the
|
|
4
7
|
diagnostics CLI runs before the host package is imported; the users-module
|
|
5
8
|
bootstrap runs after settings are constructed and needs to read values that
|
|
@@ -139,3 +142,23 @@ def env_bool(name: str, default: bool = False) -> bool:
|
|
|
139
142
|
if raw in BOOL_LITERALS_FALSE:
|
|
140
143
|
return False
|
|
141
144
|
return default
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def absolutize_sqlite_url(url: str, *, anchor: Path) -> str:
|
|
148
|
+
"""Rewrite a relative sqlite path to an absolute one under ``anchor``.
|
|
149
|
+
|
|
150
|
+
``sqlite+aiosqlite:///./host/app.db`` means "relative to the project
|
|
151
|
+
root" by convention, but SQLAlchemy resolves it against the process cwd
|
|
152
|
+
— correct in the web process (which chdirs) and silently wrong in every
|
|
153
|
+
CLI run from a subdirectory. Absolute paths (``:////...``), ``:memory:``,
|
|
154
|
+
SQLite URI-mode paths (``file:...?uri=true``), and non-sqlite URLs pass
|
|
155
|
+
through untouched.
|
|
156
|
+
"""
|
|
157
|
+
if not url.startswith("sqlite"):
|
|
158
|
+
return url
|
|
159
|
+
scheme, sep, rest = url.partition(":///")
|
|
160
|
+
if not sep or not rest or rest.startswith(("/", ":memory:", "file:")):
|
|
161
|
+
return url
|
|
162
|
+
path_part, query_sep, query = rest.partition("?")
|
|
163
|
+
resolved = (anchor / path_part).resolve()
|
|
164
|
+
return f"{scheme}:///{resolved}{query_sep}{query}"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""A module installed after the process started reports "restart", not a crash.
|
|
2
|
+
|
|
3
|
+
GH #915: with ``make dev`` running, ``smpy add`` installs a module as an
|
|
4
|
+
editable package. uvicorn's reloader keeps the ``sys.path`` it started with,
|
|
5
|
+
so the new entry point is listed but its package cannot be imported until a
|
|
6
|
+
restart. Discovery used to log ``No module named 'notes.module'`` with a
|
|
7
|
+
traceback, which reads as a broken module.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import logging
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
import simple_module_core.discovery as discovery_mod
|
|
16
|
+
from simple_module_core.discovery import InvalidModuleError, discover_modules
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class _EntryPoint:
|
|
20
|
+
def __init__(self, name: str, module: str, exc: Exception) -> None:
|
|
21
|
+
self.name = name
|
|
22
|
+
self.module = module
|
|
23
|
+
self._exc = exc
|
|
24
|
+
|
|
25
|
+
def load(self):
|
|
26
|
+
raise self._exc
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _missing(name: str) -> ModuleNotFoundError:
|
|
30
|
+
return ModuleNotFoundError(f"No module named {name!r}", name=name)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.parametrize("missing", ["notes", "notes.module"])
|
|
34
|
+
def test_unimportable_own_package_says_restart(monkeypatch, caplog, missing) -> None:
|
|
35
|
+
ep = _EntryPoint("notes", "notes.module", _missing(missing))
|
|
36
|
+
monkeypatch.setattr(discovery_mod, "entry_points", lambda group: [ep])
|
|
37
|
+
|
|
38
|
+
with caplog.at_level(logging.ERROR, logger="simple_module_core.discovery"):
|
|
39
|
+
assert discover_modules(strict=False) == []
|
|
40
|
+
|
|
41
|
+
(record,) = [r for r in caplog.records if "notes" in r.getMessage()]
|
|
42
|
+
assert "restart" in record.getMessage()
|
|
43
|
+
assert record.exc_info is None # no traceback: the module is not broken
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_strict_mode_still_refuses(monkeypatch) -> None:
|
|
47
|
+
ep = _EntryPoint("notes", "notes.module", _missing("notes.module"))
|
|
48
|
+
monkeypatch.setattr(discovery_mod, "entry_points", lambda group: [ep])
|
|
49
|
+
|
|
50
|
+
with pytest.raises(InvalidModuleError, match="restart"):
|
|
51
|
+
discover_modules(strict=True)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_a_missing_third_party_import_is_still_a_failure(monkeypatch, caplog) -> None:
|
|
55
|
+
"""The module's own code importing something absent is a real bug."""
|
|
56
|
+
ep = _EntryPoint("notes", "notes.module", _missing("somelib"))
|
|
57
|
+
monkeypatch.setattr(discovery_mod, "entry_points", lambda group: [ep])
|
|
58
|
+
|
|
59
|
+
with caplog.at_level(logging.ERROR, logger="simple_module_core.discovery"):
|
|
60
|
+
discover_modules(strict=False)
|
|
61
|
+
|
|
62
|
+
(record,) = [r for r in caplog.records if "notes" in r.getMessage()]
|
|
63
|
+
assert "restart" not in record.getMessage()
|
|
64
|
+
assert record.exc_info is not None
|
|
@@ -52,6 +52,25 @@ class TestMigrationDiagnostics:
|
|
|
52
52
|
)
|
|
53
53
|
assert len(results) == 0
|
|
54
54
|
|
|
55
|
+
def test_check_heads_at_every_head(self):
|
|
56
|
+
assert MigrationDiagnostics().check_heads({"a", "b"}, {"a", "b"}) == []
|
|
57
|
+
|
|
58
|
+
def test_check_heads_never_migrated_warns(self):
|
|
59
|
+
(finding,) = MigrationDiagnostics().check_heads(set(), {"a", "b"})
|
|
60
|
+
assert finding.code == "SM010"
|
|
61
|
+
assert finding.level == DiagnosticLevel.WARNING
|
|
62
|
+
assert "make migrate" in finding.suggestion
|
|
63
|
+
|
|
64
|
+
def test_check_heads_behind_names_the_missing_heads(self):
|
|
65
|
+
(finding,) = MigrationDiagnostics().check_heads({"a", "old"}, {"a", "b", "c"})
|
|
66
|
+
assert finding.code == "SM010"
|
|
67
|
+
assert finding.level == DiagnosticLevel.ERROR
|
|
68
|
+
assert "missing heads 'b', 'c'" in finding.message
|
|
69
|
+
|
|
70
|
+
def test_check_heads_extra_revision_is_not_behind(self):
|
|
71
|
+
# Same rule as the boot check: only heads the database lacks count.
|
|
72
|
+
assert MigrationDiagnostics().check_heads({"a", "b", "extra"}, {"a", "b"}) == []
|
|
73
|
+
|
|
55
74
|
|
|
56
75
|
class TestPrintDiagnostics:
|
|
57
76
|
async def test_writes_to_stderr(self, capsys):
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_expression_index_diagnostics.py
RENAMED
|
@@ -84,3 +84,39 @@ def test_module_without_models_is_skipped():
|
|
|
84
84
|
meta = ModuleMeta(name="NoModels")
|
|
85
85
|
|
|
86
86
|
assert module_all_tables(NoModels()) == []
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_a_descending_column_is_a_column_not_an_expression():
|
|
90
|
+
"""SQLite reflects ``created_at DESC`` as a column and Alembic compares it (GH #869)."""
|
|
91
|
+
md = sa.MetaData()
|
|
92
|
+
table = sa.Table(
|
|
93
|
+
"t",
|
|
94
|
+
md,
|
|
95
|
+
sa.Column("id", sa.Integer, primary_key=True),
|
|
96
|
+
sa.Column("created_at", sa.DateTime),
|
|
97
|
+
sa.Index("ix_t_named", "id", sa.desc(sa.column("created_at"))),
|
|
98
|
+
)
|
|
99
|
+
sa.Index("ix_t_bound", table.c.created_at.desc().nulls_last())
|
|
100
|
+
assert find_expression_indexes([table]) == []
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_text_ordering_and_literal_columns_still_count_as_expressions():
|
|
104
|
+
md = sa.MetaData()
|
|
105
|
+
table = sa.Table(
|
|
106
|
+
"t",
|
|
107
|
+
md,
|
|
108
|
+
sa.Column("id", sa.Integer, primary_key=True),
|
|
109
|
+
sa.Column("created_at", sa.DateTime),
|
|
110
|
+
sa.Index("ix_t_text", "id", sa.text("created_at DESC")),
|
|
111
|
+
sa.Index("ix_t_label", "id", sa.desc("created_at")),
|
|
112
|
+
sa.Index("ix_t_literal", sa.desc(sa.literal_column("created_at"))),
|
|
113
|
+
)
|
|
114
|
+
sa.Index("ix_t_labelled_func", sa.func.lower(table.c.id).label("x"))
|
|
115
|
+
sa.Index("ix_t_cast", sa.cast(table.c.created_at, sa.String).desc())
|
|
116
|
+
assert find_expression_indexes([table]) == [
|
|
117
|
+
("t", "ix_t_cast"),
|
|
118
|
+
("t", "ix_t_label"),
|
|
119
|
+
("t", "ix_t_labelled_func"),
|
|
120
|
+
("t", "ix_t_literal"),
|
|
121
|
+
("t", "ix_t_text"),
|
|
122
|
+
]
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"""Alembic migration-state diagnostics (SM010, SM011)."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from simple_module_core.diagnostics._types import Diagnostic, DiagnosticLevel
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class MigrationDiagnostics:
|
|
9
|
-
"""Validates database migration state."""
|
|
10
|
-
|
|
11
|
-
def check_revision_mismatch(
|
|
12
|
-
self,
|
|
13
|
-
current_revision: str | None,
|
|
14
|
-
head_revision: str | None,
|
|
15
|
-
) -> list[Diagnostic]:
|
|
16
|
-
"""SM010: Error if database is not at the migration head."""
|
|
17
|
-
if current_revision == head_revision:
|
|
18
|
-
return []
|
|
19
|
-
return [
|
|
20
|
-
Diagnostic(
|
|
21
|
-
level=DiagnosticLevel.ERROR,
|
|
22
|
-
code="SM010",
|
|
23
|
-
message=(f"Database at revision {current_revision!r}, expected {head_revision!r}"),
|
|
24
|
-
module_name="migrations",
|
|
25
|
-
suggestion="Run: make migrate",
|
|
26
|
-
)
|
|
27
|
-
]
|
|
28
|
-
|
|
29
|
-
def check_table_coverage(
|
|
30
|
-
self,
|
|
31
|
-
module_tables: set[str],
|
|
32
|
-
migrated_tables: set[str],
|
|
33
|
-
) -> list[Diagnostic]:
|
|
34
|
-
"""SM011: Warning if module tables are missing from migration history."""
|
|
35
|
-
missing = module_tables - migrated_tables
|
|
36
|
-
return [
|
|
37
|
-
Diagnostic(
|
|
38
|
-
level=DiagnosticLevel.WARNING,
|
|
39
|
-
code="SM011",
|
|
40
|
-
message=f"Table '{table}' declared in models but not found in migration history",
|
|
41
|
-
module_name="migrations",
|
|
42
|
-
suggestion=f'Run: make migration msg="add {table}"',
|
|
43
|
-
)
|
|
44
|
-
for table in sorted(missing)
|
|
45
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/_i18n_translator.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/_permission_grants.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/_request_hooks.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/data_compatibility.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/__init__.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_coupling.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_css.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_i18n.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_module.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_pages.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_runner.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_spa_mount.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_tenancy.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/diagnostics/_types.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/durable_events.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/i18n_overrides.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/invalidation_refresh.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/module_settings.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/permission_denied.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/redirect_safety.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/settings_hydrate.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/stored_settings.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/simple_module_core/user_directory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_auth_provider_selection.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_data_compatibility_doctor.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_inline_delivery_context.py
RENAMED
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_invalidation_refresh.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_core_settings_source_cache.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_db_extensions_diagnostics.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_discovery_missing_deps.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_feature_flags_decorator.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_heavy_task_imports_diagnostics.py
RENAMED
|
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
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_permissions_admin_principal.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_public_routes_rate_precedence.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_core-0.0.44 → simple_module_core-0.0.46}/tests/test_sm009_dynamic_coupling.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|