Files
shopdb-flask/migrations/versions/7d32_displayrole_kiosk_vocabulary.py
cproudlock 20a95013ad contract 0.18.0: one name per display role, the kiosk's own
Core called the roles dashboard / lobby / partskiosk. The kiosks call them
Dashboard / Lobby / 3DPrintRoom, which are the literal contents of
C:\Enrollment\display-type.txt, read by the GE-Enforce dispatcher to pick a
target. Two vocabularies for three kiosks, each with its own copy of the same
route map.

That is not cosmetic. A display reporting its own type sends what its file
says, so it could report a role core would not accept, and core could store
'partskiosk', a value no dispatcher would ever match. The enforcement report
column would have shown one vocabulary from the device and the other from the
DashboardDefault fallback, in the same column.

The machine's file wins, because that is what a person edits. DISPLAY_ROLE_PATHS
takes the kiosk spelling and the display scope now uses that dict rather than
holding a second one, so the two cannot drift again. normalize_display_role
resolves any casing and the retired 'partskiosk' forward; the dispatcher already
matched its map case-insensitively and the server now agrees with it.

Nothing is turned away over a capital: the API accepts any spelling and stores
the canonical one, displaypath resolves through the normalizer so rows written
before this keep working, and the settings dropdown canonicalises on open so an
old value does not render as a blank select.

A reported subtype is normalised on the way in, but an UNRECOGNISED one is kept
verbatim. That is a kiosk with a typo in its file or a role nobody declared, and
both are worth seeing in the fleet table rather than blanked or guessed at.

Contract bumped for the added names. DashboardDefault is finally listed in
__all__ too - 0.17.0 put it on the surface and never exported it.
2026-08-13 09:28:26 -04:00

68 lines
2.3 KiB
Python

"""Move dashboarddefaults.displayrole onto the kiosk's own role vocabulary
Core named the roles dashboard / lobby / partskiosk. The kiosks name them
Dashboard / Lobby / 3DPrintRoom - the literal values a person types into
C:\\Enrollment\\display-type.txt, which the GE-Enforce dispatcher reads to pick
a target. Two vocabularies meant a display could report a role core could not
store, and core could store 'partskiosk', a value no kiosk would ever match.
The machine's own file wins, so the stored values move to it. 'partskiosk'
becomes '3DPrintRoom'; the other two are a case change only. Anything else is
left alone - an unrecognised value is somebody's data, not ours to guess at.
Idempotent and reversible: matching is case-insensitive, so a re-run is a no-op
rather than a second rewrite, and downgrade puts the old spellings back.
Revision ID: 7d32_displayrole_kiosk_vocabulary
Revises: 7d31_dashboarddefault_fqdn
Create Date: 2026-08-13
"""
from alembic import op
import sqlalchemy as sa
revision = '7d32_displayrole_kiosk_vocabulary'
down_revision = '7d31_dashboarddefault_fqdn'
branch_labels = None
depends_on = None
# old spelling -> new spelling
FORWARD = {
'dashboard': 'Dashboard',
'lobby': 'Lobby',
'partskiosk': '3DPrintRoom',
}
BACKWARD = {new: old for old, new in FORWARD.items()}
def _rewrite(mapping, newdefault):
connection = op.get_bind()
inspector = sa.inspect(connection)
if 'dashboarddefaults' not in inspector.get_table_names():
return
columns = {col['name'] for col in inspector.get_columns('dashboarddefaults')}
if 'displayrole' not in columns:
return
for source, target in mapping.items():
connection.execute(
sa.text('UPDATE dashboarddefaults SET displayrole = :target'
' WHERE LOWER(displayrole) = :source'),
{'target': target, 'source': source.lower()})
# 7d28 created the column with server_default='dashboard'; keep the default
# spelled the same way as the values.
op.alter_column('dashboarddefaults', 'displayrole',
existing_type=sa.String(length=20),
existing_nullable=False,
server_default=newdefault)
def upgrade():
_rewrite(FORWARD, 'Dashboard')
def downgrade():
_rewrite(BACKWARD, 'dashboard')