"""instance identity — the id lineage a backup carries Revision ID: 0127 Revises: 0126 Create Date: 2026-11-05 One row naming this database's id lineage. Every full backup carries it, a restore into a fresh instance adopts it (the restore keeps the original ids), and rolling a live instance back requires the backup's to match, so a backup's ids never land on unrelated rows. Made here with a random value, so every instance has one before its first account exists. """ import sqlalchemy as sa from alembic import op revision = "0127" down_revision = "0126" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "instance_identity", sa.Column("id", sa.Integer(), primary_key=True), sa.Column("instance_id", sa.Text(), nullable=False), sa.Column( "created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now(), ), sa.CheckConstraint("id = 1", name="ck_instance_identity_single_row"), ) op.execute( "INSERT INTO instance_identity (id, instance_id) VALUES (1, gen_random_uuid()::text)" ) def downgrade() -> None: op.drop_table("instance_identity")