53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
"""printers: printersupplyalerts table (toner alert crossing state).
|
|
|
|
Stores the last tier alerted per (printer, supply) so the poller fires once
|
|
on a downward crossing and re-arms after a refill. Idempotent create.
|
|
"""
|
|
from alembic import op
|
|
|
|
from shopdb.plugins.alembic_template import (
|
|
create_index_if_missing,
|
|
create_table_if_missing,
|
|
)
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'printers0002supplyalerts'
|
|
down_revision = 'printers0001anchor'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
if 'printersupplyalerts' in inspector.get_table_names():
|
|
return
|
|
create_table_if_missing(
|
|
'printersupplyalerts',
|
|
sa.Column('printersupplyalertid', sa.Integer(), primary_key=True),
|
|
sa.Column('printerid', sa.Integer(), nullable=False),
|
|
sa.Column('supplykey', sa.String(length=64), nullable=False),
|
|
sa.Column('lasttier', sa.String(length=16), nullable=False,
|
|
server_default='ok'),
|
|
sa.Column('createddate', sa.DateTime(), nullable=False),
|
|
sa.Column('modifieddate', sa.DateTime(), nullable=False),
|
|
sa.Column('isactive', sa.Boolean(), nullable=False,
|
|
server_default=sa.true()),
|
|
sa.ForeignKeyConstraint(['printerid'], ['printers.printerid'],
|
|
ondelete='CASCADE'),
|
|
sa.UniqueConstraint('printerid', 'supplykey',
|
|
name='uq_printersupplyalert_printer_key'),
|
|
)
|
|
create_index_if_missing('ix_printersupplyalerts_printerid',
|
|
'printersupplyalerts', ['printerid'])
|
|
|
|
|
|
def downgrade():
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
if 'printersupplyalerts' not in inspector.get_table_names():
|
|
return
|
|
op.drop_table('printersupplyalerts')
|