"""Add azuredeviceid to computers (Entra/Azure device-group imports). The core chain created computers WITHOUT an azuredeviceid column. This plugin revision adds it so BOTH fresh installs (core chain builds the table, then this adds the column) and existing installs get it. Guarded/idempotent: skips when the table is absent (plugin disabled) or the column already exists (e.g. a test DB built by db.create_all() from the model). Revision ID: computers0002azureid Revises: computers0001anchor """ from alembic import op import sqlalchemy as sa revision = 'computers0002azureid' down_revision = 'computers0001anchor' branch_labels = None depends_on = None def upgrade(): bind = op.get_bind() insp = sa.inspect(bind) if 'computers' not in insp.get_table_names(): return cols = {c['name'] for c in insp.get_columns('computers')} if 'azuredeviceid' not in cols: op.add_column('computers', sa.Column('azuredeviceid', sa.String(length=64), nullable=True)) def downgrade(): bind = op.get_bind() insp = sa.inspect(bind) if 'computers' not in insp.get_table_names(): return cols = {c['name'] for c in insp.get_columns('computers')} if 'azuredeviceid' in cols: op.drop_column('computers', 'azuredeviceid')