diff --git a/alembic/env.py b/alembic/env.py index bec8c62..7f0fbd1 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -3,6 +3,15 @@ from __future__ import annotations import asyncio + +# F19 (Astra P1): deterministic full-model discovery for Alembic. +# `from app.models import *` only loads CORE models (48 tables in a fresh +# process). Contact and ~80 other tables physically live in plugins +# (e.g. app.plugins.builtins.contacts.models) — the lazy package +# __getattr__ never fires for wildcard imports. Without the plugin models +# the metadata sort fails (contact_merge_history → contacts FK) and +# `alembic check` compares against an incomplete schema. +import importlib from logging.config import fileConfig from sqlalchemy import pool @@ -13,6 +22,15 @@ from alembic import context from app.config import get_settings from app.core.db import Base from app.models import * # noqa: F401,F403 +from app.plugins.registry import get_registry + +_registry = get_registry() +_registry.discover_builtins() +for _plugin_name in _registry.list_discovered(): + try: + importlib.import_module(f"app.plugins.builtins.{_plugin_name}.models") + except ImportError: + pass # plugin has no models module config = context.config if config.config_file_name is not None: