9fefe289a7
Add migration version check before running alembic upgrade to prevent multiple uvicorn workers from running migrations simultaneously. - Check current vs head revision before running migrations - Skip migration if already at latest version - Log current and head revision for debugging
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
"""add user_configs table
|
|
|
|
Revision ID: 0003
|
|
Revises: 0002
|
|
Create Date: 2025-05-18
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '0003_user_configs'
|
|
down_revision: Union[str, None] = '0002_refresh_tokens'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
'user_configs',
|
|
sa.Column('id', sa.UUID(), nullable=False),
|
|
sa.Column('user_id', sa.UUID(), nullable=False),
|
|
sa.Column('config', sa.JSON(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('user_id')
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table('user_configs')
|