7f97ba8e9b
Add if_not_exists=True to CREATE TABLE operations in migrations 0003 and 0004. This prevents DuplicateTableError when migrations are re-run on databases where tables were partially created.
37 lines
1.1 KiB
Python
37 lines
1.1 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'),
|
|
if_not_exists=True,
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table('user_configs')
|