42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""Create todos table
|
|
|
|
Revision ID: 001
|
|
Revises:
|
|
Create Date: 2023-12-18
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '001'
|
|
down_revision: Union[str, None] = None
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create todos table
|
|
op.create_table(
|
|
'todos',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('title', sa.String(), nullable=False),
|
|
sa.Column('description', sa.String(), nullable=True),
|
|
sa.Column('completed', sa.Boolean(), default=False),
|
|
sa.Column('created_at', sa.DateTime(), default=sa.func.current_timestamp()),
|
|
sa.Column('updated_at', sa.DateTime(), default=sa.func.current_timestamp(), onupdate=sa.func.current_timestamp()),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
# Create index on title
|
|
op.create_index(op.f('ix_todos_id'), 'todos', ['id'], unique=False)
|
|
op.create_index(op.f('ix_todos_title'), 'todos', ['title'], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Drop todos table
|
|
op.drop_index(op.f('ix_todos_title'), table_name='todos')
|
|
op.drop_index(op.f('ix_todos_id'), table_name='todos')
|
|
op.drop_table('todos') |