"""Add ApiKey table Revision ID: 2ea570019b8f Revises: 4af13678b83c Create Date: 2025-05-03 18:56:32.989446 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = '2ea570019b8f' down_revision: Union[str, None] = '4af13678b83c' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: """Upgrade schema.""" # ### commands auto generated by Alembic - adjusted ### op.create_table('api_keys', sa.Column('id', sa.UUID(), nullable=False), sa.Column('user_id', sa.UUID(), nullable=False), sa.Column('name', sa.String(), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('key_prefix', sa.String(length=8), nullable=False), sa.Column('hashed_key', sa.String(), nullable=False), sa.Column('scopes', postgresql.ARRAY(sa.String()), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=False), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), sa.Column('last_used_at', sa.DateTime(timezone=True), nullable=True), sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_api_keys_user_id_users_id')), sa.PrimaryKeyConstraint('id', name=op.f('pk_api_keys')) ) with op.batch_alter_table('api_keys', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_api_keys_hashed_key'), ['hashed_key'], unique=False) batch_op.create_index(batch_op.f('ix_api_keys_key_prefix'), ['key_prefix'], unique=True) batch_op.create_index(batch_op.f('ix_api_keys_user_id'), ['user_id'], unique=False) # Removed incorrect drop/alter table commands for other tables # ### end Alembic commands ### def downgrade() -> None: """Downgrade schema.""" # ### commands auto generated by Alembic - adjusted ### with op.batch_alter_table('api_keys', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_api_keys_user_id')) batch_op.drop_index(batch_op.f('ix_api_keys_key_prefix')) batch_op.drop_index(batch_op.f('ix_api_keys_hashed_key')) op.drop_table('api_keys') # Removed incorrect create/alter table commands for other tables # ### end Alembic commands ###