From c095270d067d70fe980cab47db7eebeafcf4643d Mon Sep 17 00:00:00 2001 From: cproudlock Date: Fri, 26 Jun 2026 12:19:40 -0400 Subject: [PATCH] Make the core migration chain reproduce the full bundled schema Deploys run `flask db upgrade` (core chain) only. The core chain reproduced everything except modelsupplies + the computer make/model and installed-app version columns, which lived only in per-plugin migrations the deploy never runs. Migration 7c04 folds those into the core chain (idempotent). Verified: a fresh `flask db upgrade` on an empty database produces a schema identical to the live DB (zero table/column diffs). Also dropped two unused appversions audit columns (create_all drift) and the empty orphaned alembic_version_* plugin tracker tables so live matches a fresh deploy exactly. Co-Authored-By: Claude Opus 4.8 --- .../versions/7c04_fold_plugin_schema.py | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 migrations/versions/7c04_fold_plugin_schema.py diff --git a/migrations/versions/7c04_fold_plugin_schema.py b/migrations/versions/7c04_fold_plugin_schema.py new file mode 100644 index 0000000..d95bd04 --- /dev/null +++ b/migrations/versions/7c04_fold_plugin_schema.py @@ -0,0 +1,85 @@ +"""Fold remaining plugin schema into the core chain + +Deploys run `flask db upgrade` (core chain) only, so the core chain must +reproduce the full bundled schema. The core baseline already creates the +plugin tables as of baseline time; this adds the post-baseline additions that +previously lived only in per-plugin migrations (which deploys don't run): + + - modelsupplies (printer model -> toner/drum/waste part numbers) + - computers.vendorid + computers.modelnumberid (PC make/model) + - computerinstalledapps.installedversion (collector version string) + +Idempotent: skips anything already present, so it is a no-op on the live DB +(which already has these) and creates them on a fresh deploy. + +Revision ID: 7c04_fold_plugin_schema +Revises: 7c03_locationtypes +Create Date: 2026-06-26 + +""" +from alembic import op +import sqlalchemy as sa + + +revision = '7c04_fold_plugin_schema' +down_revision = '7c03_locationtypes' +branch_labels = None +depends_on = None + + +def upgrade(): + bind = op.get_bind() + insp = sa.inspect(bind) + tables = set(insp.get_table_names()) + + if 'modelsupplies' not in tables: + op.create_table( + 'modelsupplies', + sa.Column('modelsupplyid', sa.Integer(), primary_key=True), + sa.Column('modelnumberid', sa.Integer(), + sa.ForeignKey('models.modelnumberid'), nullable=False), + sa.Column('supplytype', sa.String(length=20), nullable=False, + server_default='toner'), + sa.Column('color', sa.String(length=20), nullable=False, + server_default='none'), + sa.Column('capacitytier', sa.String(length=20), nullable=False, + server_default='standard'), + sa.Column('partnumber', sa.String(length=50), nullable=False), + sa.Column('marketingname', sa.String(length=120), nullable=True), + sa.Column('pageyield', sa.Integer(), nullable=True), + sa.Column('notes', sa.Text(), nullable=True), + sa.Column('createddate', sa.DateTime(), nullable=True), + sa.Column('modifieddate', sa.DateTime(), nullable=True), + sa.Column('isactive', sa.Boolean(), nullable=True), + sa.UniqueConstraint('modelnumberid', 'partnumber', + name='uq_modelsupply_part'), + ) + op.create_index('idx_modelsupplies_modelnumberid', 'modelsupplies', + ['modelnumberid']) + + comp_cols = {c['name'] for c in insp.get_columns('computers')} + with op.batch_alter_table('computers') as batch_op: + if 'vendorid' not in comp_cols: + batch_op.add_column(sa.Column('vendorid', sa.Integer(), nullable=True)) + batch_op.create_foreign_key('fk_computers_vendor', 'vendors', + ['vendorid'], ['vendorid']) + if 'modelnumberid' not in comp_cols: + batch_op.add_column(sa.Column('modelnumberid', sa.Integer(), nullable=True)) + batch_op.create_foreign_key('fk_computers_model', 'models', + ['modelnumberid'], ['modelnumberid']) + + cia_cols = {c['name'] for c in insp.get_columns('computerinstalledapps')} + if 'installedversion' not in cia_cols: + op.add_column('computerinstalledapps', + sa.Column('installedversion', sa.String(length=100), + nullable=True)) + + +def downgrade(): + op.drop_table('modelsupplies') + with op.batch_alter_table('computers') as batch_op: + batch_op.drop_constraint('fk_computers_model', type_='foreignkey') + batch_op.drop_constraint('fk_computers_vendor', type_='foreignkey') + batch_op.drop_column('modelnumberid') + batch_op.drop_column('vendorid') + op.drop_column('computerinstalledapps', 'installedversion')