"""Add algorithm column and widen public_key_b64 to Text on musehub_auth_keys. Quantum-readiness migration: the auth key table now carries an algorithm identifier so Ed25519 and future post-quantum algorithms (ML-DSA-65 / FIPS 204) can coexist. The public_key_b64 column is widened from VARCHAR(64) to TEXT because ML-DSA-65 public keys are 1952 bytes → ~2604 base64 chars. All existing rows default to "ed25519" — no data migration required. Revision ID: 0008 Revises: 0007 """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision = "0008" down_revision = "0007" branch_labels = None depends_on = None def upgrade() -> None: # Add algorithm column with "ed25519" as the default for existing rows op.add_column( "musehub_auth_keys", sa.Column( "algorithm", sa.String(32), nullable=False, server_default="ed25519", ), ) # Widen public_key_b64 from VARCHAR(64) to TEXT for post-quantum keys op.alter_column( "musehub_auth_keys", "public_key_b64", type_=sa.Text(), existing_nullable=False, ) op.create_index( "ix_musehub_auth_keys_algorithm", "musehub_auth_keys", ["algorithm"], ) def downgrade() -> None: op.drop_index("ix_musehub_auth_keys_algorithm", table_name="musehub_auth_keys") op.alter_column( "musehub_auth_keys", "public_key_b64", type_=sa.String(64), existing_nullable=False, ) op.drop_column("musehub_auth_keys", "algorithm")