Add the measuringtools plugin (ADR-005) and the plugin-system tutorial
Gage-lab instruments as Asset extensions: measuringtooltypes (color-coded lookup) + measuringtools (calibration interval/dates, provider, notes) with calibration status derived at read time (overdue / due soon / current / unknown), never stored. Full CRUD API with permission-gated writes, types management with in-use guard, calibration report, nav/reports/config-schema hooks, and a complete frontend (list/detail/form, types settings page, calibration report page, gated routes per ADR-009). First plugin whose migration chain really creates tables post-cutover (ADR-008), and the working example for docs/PLUGIN-GUIDE.md - a 12-section walkthrough of building a plugin on this framework, linked from PLUGIN-QUICKSTART and PLUGINS. Verified: full suite 323 passing, live E2E on all four pages, fresh scratch-MySQL migration dry-run green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
"""measuringtools plugin baseline (real create).
|
||||
|
||||
This plugin was built AFTER the ADR-008 ownership cutover, so unlike the ten
|
||||
bundled plugins whose 0001 is a stamp-only no-op anchor, this baseline actually
|
||||
CREATES the plugin's tables. The core Alembic chain never knew about
|
||||
measuringtooltypes / measuringtools, so this per-plugin chain is their sole
|
||||
authoritative creator. It runs from `flask plugin install measuringtools`
|
||||
(and `flask plugin upgrade-all`) after `flask db upgrade` builds the core schema.
|
||||
|
||||
Note on create_plugin_tables: the shared helper in
|
||||
shopdb.plugins.alembic_template builds a per-plugin MetaData filtered to only the
|
||||
plugin's own tables, which means a foreign key to a core table (assets) cannot
|
||||
be resolved at CreateTable-compile time (NoReferencedTableError). Since these
|
||||
tables reference assets.assetid, the baseline emits explicit Alembic ops (the
|
||||
same shape Alembic autogenerate produces) instead. Tables inherit the
|
||||
connection's default charset, so on a utf8mb4 database they are utf8mb4, matching
|
||||
how the core chain creates its tables.
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'measuringtools0001baseline'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'measuringtooltypes',
|
||||
sa.Column('measuringtooltypeid', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=100), nullable=False),
|
||||
sa.Column('description', sa.Text(), nullable=True),
|
||||
sa.Column('color', sa.String(length=20), nullable=True),
|
||||
sa.Column('createddate', sa.DateTime(), nullable=False),
|
||||
sa.Column('modifieddate', sa.DateTime(), nullable=False),
|
||||
sa.Column('isactive', sa.Boolean(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('measuringtooltypeid'),
|
||||
sa.UniqueConstraint('name'),
|
||||
)
|
||||
op.create_table(
|
||||
'measuringtools',
|
||||
sa.Column('measuringtoolid', sa.Integer(), nullable=False),
|
||||
sa.Column('assetid', sa.Integer(), nullable=False),
|
||||
sa.Column('measuringtooltypeid', sa.Integer(), nullable=True),
|
||||
sa.Column('calibrationintervaldays', sa.Integer(), nullable=True),
|
||||
sa.Column('lastcalibrationdate', sa.Date(), nullable=True),
|
||||
sa.Column('nextcalibrationdate', sa.Date(), nullable=True),
|
||||
sa.Column('calibrationprovider', sa.String(length=150), nullable=True),
|
||||
sa.Column('notes', sa.Text(), nullable=True),
|
||||
sa.Column('createddate', sa.DateTime(), nullable=False),
|
||||
sa.Column('modifieddate', sa.DateTime(), nullable=False),
|
||||
sa.Column('isactive', sa.Boolean(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['assetid'], ['assets.assetid'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['measuringtooltypeid'],
|
||||
['measuringtooltypes.measuringtooltypeid']),
|
||||
sa.PrimaryKeyConstraint('measuringtoolid'),
|
||||
sa.UniqueConstraint('assetid'),
|
||||
)
|
||||
op.create_index('idx_measuringtool_type', 'measuringtools',
|
||||
['measuringtooltypeid'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index('idx_measuringtool_type', table_name='measuringtools')
|
||||
op.drop_table('measuringtools')
|
||||
op.drop_table('measuringtooltypes')
|
||||
Reference in New Issue
Block a user