Add the printedparts plugin: 3D-printed parts storefront and kiosk
Catalog with photos and append-only print-file revisions, a stock ledger attributing every take/restock/adjust to a badge-resolved employee, a touch kiosk (scan bin, scan badge, keypad quantity) with a deliberately open decrement-only take endpoint, 1x0.5in CODE128 bin labels, low-stock email alerts to selected users, roles, or addresses, and stock/consumption/by-person reports with a cache-vs-ledger reconcile. Ships disabled; enable per site. Contract 0.13.0 adds the mailer and the User/Role models to the plugin surface.
This commit is contained in:
14
plugins/printedparts/migrations/env.py
Normal file
14
plugins/printedparts/migrations/env.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""Alembic environment for the printedparts plugin migration chain.
|
||||
|
||||
Delegates to the shared runner in shopdb.plugins.alembic_template, which
|
||||
filters the metadata to this plugin's tables and drives Alembic against the
|
||||
per-plugin version table alembic_version_printedparts (ADR-008). This plugin
|
||||
is NEW (post-cutover): its 0001 baseline really CREATES its tables.
|
||||
"""
|
||||
import os
|
||||
|
||||
os.environ['PLUGIN_NAME'] = 'printedparts'
|
||||
|
||||
from shopdb.plugins.alembic_template import run_migrations # noqa: E402
|
||||
|
||||
run_migrations()
|
||||
24
plugins/printedparts/migrations/script.py.mako
Normal file
24
plugins/printedparts/migrations/script.py.mako
Normal file
@@ -0,0 +1,24 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade():
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade():
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,71 @@
|
||||
"""printedparts plugin baseline (real create).
|
||||
|
||||
Post-ADR-008 plugin: this per-plugin chain is the sole authoritative creator
|
||||
of printeditems and printeditemtransactions - the core chain never knew them.
|
||||
Runs from `flask plugin install printedparts` (and `flask plugin upgrade-all`)
|
||||
after `flask db upgrade` builds the core schema.
|
||||
|
||||
Both tables are self-contained (the only FK is transactions -> items inside
|
||||
the plugin), so the shared create_plugin_tables helper would work here; the
|
||||
ops are written out explicitly anyway to match the measuringtools exemplar
|
||||
and keep the baseline reviewable.
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'printedparts0001baseline'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'printeditems',
|
||||
sa.Column('printeditemid', sa.Integer(), nullable=False),
|
||||
sa.Column('itemcode', sa.String(length=20), nullable=True),
|
||||
sa.Column('itemname', sa.String(length=120), nullable=False),
|
||||
sa.Column('itemdescription', sa.String(length=500), nullable=True),
|
||||
sa.Column('imageurl', sa.String(length=255), nullable=True),
|
||||
sa.Column('quantityonhand', sa.Integer(), nullable=False),
|
||||
sa.Column('lowstockthreshold', sa.Integer(), nullable=False),
|
||||
sa.Column('binlocation', sa.String(length=100), nullable=True),
|
||||
sa.Column('printnotes', 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.PrimaryKeyConstraint('printeditemid'),
|
||||
sa.UniqueConstraint('itemcode'),
|
||||
)
|
||||
op.create_index('ix_printeditems_itemcode', 'printeditems', ['itemcode'])
|
||||
|
||||
op.create_table(
|
||||
'printeditemtransactions',
|
||||
sa.Column('transactionid', sa.Integer(), nullable=False),
|
||||
sa.Column('printeditemid', sa.Integer(), nullable=False),
|
||||
sa.Column('transactiontype', sa.String(length=10), nullable=False),
|
||||
sa.Column('quantitychange', sa.Integer(), nullable=False),
|
||||
sa.Column('employeesso', sa.String(length=20), nullable=False),
|
||||
sa.Column('employeename', sa.String(length=120), nullable=True),
|
||||
sa.Column('reason', sa.String(length=255), nullable=True),
|
||||
sa.Column('transactiondate', sa.DateTime(), nullable=False),
|
||||
sa.Column('createddate', sa.DateTime(), nullable=False),
|
||||
sa.Column('modifieddate', sa.DateTime(), nullable=False),
|
||||
sa.Column('isactive', sa.Boolean(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['printeditemid'], ['printeditems.printeditemid'],
|
||||
ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('transactionid'),
|
||||
)
|
||||
op.create_index('ix_printeditemtransactions_printeditemid',
|
||||
'printeditemtransactions', ['printeditemid'])
|
||||
op.create_index('ix_printeditemtransactions_employeesso',
|
||||
'printeditemtransactions', ['employeesso'])
|
||||
op.create_index('ix_printeditemtransactions_transactiondate',
|
||||
'printeditemtransactions', ['transactiondate'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('printeditemtransactions')
|
||||
op.drop_table('printeditems')
|
||||
@@ -0,0 +1,43 @@
|
||||
"""Add printeditemfiles: append-only print-file revisions per item.
|
||||
|
||||
The plugin's first incremental migration on top of its 0001 baseline -
|
||||
the ADR-008 payoff: the plugin evolves its own schema without touching
|
||||
the core chain. Applied by `flask plugin upgrade-all`.
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'printedparts0002files'
|
||||
down_revision = 'printedparts0001baseline'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'printeditemfiles',
|
||||
sa.Column('fileid', sa.Integer(), nullable=False),
|
||||
sa.Column('printeditemid', sa.Integer(), nullable=False),
|
||||
sa.Column('revision', sa.Integer(), nullable=False),
|
||||
sa.Column('filename', sa.String(length=255), nullable=False),
|
||||
sa.Column('storedfilename', sa.String(length=191), nullable=False),
|
||||
sa.Column('filesize', sa.Integer(), nullable=False),
|
||||
sa.Column('uploadnote', sa.String(length=255), nullable=True),
|
||||
sa.Column('uploadedby', sa.String(length=80), nullable=False),
|
||||
sa.Column('createddate', sa.DateTime(), nullable=False),
|
||||
sa.Column('modifieddate', sa.DateTime(), nullable=False),
|
||||
sa.Column('isactive', sa.Boolean(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['printeditemid'],
|
||||
['printeditems.printeditemid'],
|
||||
ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('fileid'),
|
||||
sa.UniqueConstraint('storedfilename'),
|
||||
)
|
||||
op.create_index('ix_printeditemfiles_printeditemid',
|
||||
'printeditemfiles', ['printeditemid'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('printeditemfiles')
|
||||
Reference in New Issue
Block a user