Two rows now cover 41 of 44 printers. printerdrivers could only bind a driver to ONE modelnumberid, so the HP and Xerox universal drivers - which between them cover almost the whole floor - would have needed 21 near-duplicate rows pointing at the same package. That is a table nobody keeps true, and it is why 42 of 44 printers resolved no driver at all. printerdrivers gains vendorid, and resolution runs most-specific-first: the printer's model, then its vendor, then the pre-vendorid convention of matching the vendor word in the driver's name so a site that populated the table before the column existed does not silently lose every driver on upgrade. A row that names a vendor is never matched by its text, because a mis-set vendor resolving to the wrong package is worse than resolving to none. Six rows now resolve 44 of 44 printers at the reference site, and the DesignJet correctly takes its own driver over the HP universal one. Set-ShopdbPrinters.ps1 is the client half: ask for-host, create the queues that are missing, record the desired default. It NEVER removes a queue - a bad minute from the API must not take printers away from a working bay - and it never fetches a driver, because downloading 48 MB while somebody waits to print is the wrong moment. The common scope stages those. Apply-ShopdbDefaultPrinter.ps1 applies the default in the USER's context, which is the only context that can: SYSTEM cannot set a per-user default for somebody else. It also turns off "Let Windows manage my default printer", without which Windows silently overwrites the choice the next time anyone prints elsewhere - a fix that undoes itself within a day. VALIDATED ON WINDOWS 11 AGAINST A LIVE SHOPDB, not only by tests. Printers were assigned to a MACHINE; a PC controlling it, holding no rows of its own, created both queues bound to the right universal drivers, recorded the default and set it, and a second run changed nothing. The first attempt failed with "Relationship types are not seeded - run: flask seed reference-data", which is the deployment trap the plan predicted, caught by an explicit error rather than silently resolving nothing.
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
"""Give a printer driver a vendor, so one row can serve a whole make.
|
|
|
|
HP's and Xerox's universal drivers cover 41 of the reference site's 44 printers
|
|
between them, but a driver could only be bound to ONE modelnumberid - so covering
|
|
them meant 21 near-duplicate rows all pointing at the same package, a table
|
|
nobody would keep true. A driver with no model and a vendor now serves every
|
|
printer of that make, and a per-model row still wins where one genuinely differs
|
|
(a plotter, a card printer, a label printer).
|
|
|
|
Nullable and guarded: a re-run is a no-op, and existing rows keep working
|
|
unchanged because model matching is still tried first.
|
|
|
|
Revision ID: printers0004drivervendor
|
|
Revises: printers0003drivername
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision = 'printers0004drivervendor'
|
|
down_revision = 'printers0003drivername'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
columns = {column['name'] for column in inspector.get_columns('printerdrivers')}
|
|
if 'vendorid' not in columns:
|
|
op.add_column('printerdrivers', sa.Column('vendorid', sa.Integer(), nullable=True))
|
|
# No FK constraint: printerdrivers is a plugin table and vendors is core.
|
|
# ADR-008 keeps plugin chains from writing constraints across that line,
|
|
# and the resolver treats a vendor that no longer exists as no match.
|
|
op.create_index('idx_printerdriver_vendor', 'printerdrivers', ['vendorid'])
|
|
|
|
|
|
def downgrade():
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
columns = {column['name'] for column in inspector.get_columns('printerdrivers')}
|
|
if 'vendorid' in columns:
|
|
op.drop_index('idx_printerdriver_vendor', table_name='printerdrivers')
|
|
op.drop_column('printerdrivers', 'vendorid')
|