P0-fix: plugin migrations use migration engine (crm_migration) instead of API engine (crm_api)
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
- main.py: registry.initialize(get_migration_engine()) instead of get_engine() - main.py: plugin migrations run via get_migration_session_factory() not async_session() - registry.py: upgrade_plugin, install_plugin, uninstall_plugin all use migration session for DDL - db/__init__.py: get_migration_engine() raises RuntimeError if MIGRATION_DATABASE_URL missing (no fallback) - Fixes fresh-install failure: crm_api has no DDL rights, plugin migrations need crm_migration
This commit is contained in:
+18
-6
@@ -494,9 +494,13 @@ class PluginRegistry:
|
||||
f"Running migrations to update."
|
||||
)
|
||||
|
||||
# Re-run migrations to apply any new migration files
|
||||
# Re-run migrations to apply any new migration files — use migration engine (crm_migration) for DDL
|
||||
if plugin.manifest.migrations:
|
||||
await self.migration_runner.run_all_migrations(db, name, plugin.manifest.migrations)
|
||||
from app.core.db import get_migration_session_factory
|
||||
mig_factory = get_migration_session_factory()
|
||||
async with mig_factory() as mig_db:
|
||||
await self.migration_runner.run_all_migrations(mig_db, name, plugin.manifest.migrations)
|
||||
await mig_db.commit()
|
||||
|
||||
# Update DB version to match manifest
|
||||
record.version = manifest_version
|
||||
@@ -548,9 +552,13 @@ class PluginRegistry:
|
||||
# Check dependencies are installed
|
||||
await self._check_dependencies_installed(db, name)
|
||||
|
||||
# Run migrations
|
||||
# Run migrations — use migration engine (crm_migration) for DDL
|
||||
if plugin.manifest.migrations:
|
||||
await self.migration_runner.run_all_migrations(db, name, plugin.manifest.migrations)
|
||||
from app.core.db import get_migration_session_factory
|
||||
mig_factory = get_migration_session_factory()
|
||||
async with mig_factory() as mig_db:
|
||||
await self.migration_runner.run_all_migrations(mig_db, name, plugin.manifest.migrations)
|
||||
await mig_db.commit()
|
||||
|
||||
# Call on_install hook
|
||||
await plugin.on_install(db, self._container)
|
||||
@@ -741,10 +749,14 @@ class PluginRegistry:
|
||||
# Call on_uninstall hook
|
||||
await plugin.on_uninstall(db, self._container)
|
||||
|
||||
# Optionally drop plugin tables
|
||||
# Optionally drop plugin tables — use migration engine (crm_migration) for DDL
|
||||
dropped_tables: list[str] = []
|
||||
if remove_data:
|
||||
dropped_tables = await self.migration_runner.drop_plugin_tables(db, name)
|
||||
from app.core.db import get_migration_session_factory
|
||||
mig_factory = get_migration_session_factory()
|
||||
async with mig_factory() as mig_db:
|
||||
dropped_tables = await self.migration_runner.drop_plugin_tables(mig_db, name)
|
||||
await mig_db.commit()
|
||||
|
||||
# Remove DB record
|
||||
await db.delete(record)
|
||||
|
||||
Reference in New Issue
Block a user