Consolidate bundled plugin schema into the core migration chain

The core chain already owns and reproduces the full bundled schema (deploys run
`flask db upgrade` only). The per-plugin Alembic baselines duplicated those
tables, so `flask plugin upgrade-all` would conflict - a footgun. Remove the 6
bundled plugin migration dirs; the per-plugin Alembic helpers
(alembic_template, PluginMigrationRunner) remain for external/filesystem
plugins. upgrade-all now cleanly no-ops for bundled plugins.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-06-26 14:48:07 -04:00
parent 919e0b8600
commit 4f1638bda0
28 changed files with 7 additions and 662 deletions

View File

@@ -1,11 +1,10 @@
"""Per-plugin Alembic chain wiring tests.
"""Plugin table-ownership tests.
Pins the bundled-plugin migration setup so a future refactor that breaks
the scaffolding fails fast with a clear test rather than a confusing
runtime error on a fresh deploy.
Bundled plugin schema is owned by the core migration chain (deploys run
`flask db upgrade` only, which reproduces the full schema). The per-plugin
Alembic helpers remain for external/filesystem plugins; these tests pin the
PLUGIN_TABLE_OWNERS registry those helpers consume.
"""
from pathlib import Path
import pytest
from shopdb.plugins.alembic_template import (
@@ -20,29 +19,16 @@ BUNDLED_PLUGINS = ('computers', 'equipment', 'network', 'notifications', 'printe
@pytest.mark.parametrize('plugin', BUNDLED_PLUGINS)
def test_bundled_plugin_has_table_owner_entry(plugin):
"""Every bundled plugin appears in PLUGIN_TABLE_OWNERS with at least
one table; otherwise its baseline migration would be a no-op."""
one table, documenting which tables it contributes to the schema."""
assert plugin in PLUGIN_TABLE_OWNERS
assert len(PLUGIN_TABLE_OWNERS[plugin]) > 0
@pytest.mark.parametrize('plugin', BUNDLED_PLUGINS)
def test_bundled_plugin_has_migrations_dir(plugin):
"""Each bundled plugin has the on-disk Alembic scaffolding."""
root = Path(__file__).resolve().parent.parent / 'plugins' / plugin / 'migrations'
assert (root / 'env.py').is_file(), f"{plugin}/migrations/env.py missing"
assert (root / 'alembic.ini').is_file(), f"{plugin}/migrations/alembic.ini missing"
assert (root / 'script.py.mako').is_file(), f"{plugin}/migrations/script.py.mako missing"
versions = root / 'versions'
assert versions.is_dir(), f"{plugin}/migrations/versions missing"
baseline = versions / '0001_baseline.py'
assert baseline.is_file(), f"{plugin}/migrations/versions/0001_baseline.py missing"
@pytest.mark.parametrize('plugin', BUNDLED_PLUGINS)
def test_plugin_metadata_has_all_owned_tables(plugin, app):
"""The MetaData filtered to a plugin's owned tables actually contains
every table named in PLUGIN_TABLE_OWNERS. Catches drift between the
template's table list and what the models declare."""
registry and what the models declare."""
with app.app_context():
md = _get_plugin_metadata(plugin)
owned = set(PLUGIN_TABLE_OWNERS[plugin])