todoapp-kcnfku/migrations/versions/0001_create_todo_table.py
Automated Action 5fbf8c4171 Create simple Todo app with FastAPI and SQLite
- Setup project structure with FastAPI
- Create Todo model and database schemas
- Implement CRUD operations for Todo items
- Create API endpoints for Todo operations
- Add health check endpoint
- Configure Alembic for database migrations
- Add detailed documentation in README.md
2025-05-27 16:58:01 +00:00

51 lines
1.5 KiB
Python

"""create todo table
Revision ID: 0001
Revises:
Create Date: 2023-10-30
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '0001'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# Create enum type for todo priority
priority_enum = sa.Enum('low', 'medium', 'high', name='todopriority')
priority_enum.create(op.get_bind(), checkfirst=True)
# Create todos table
op.create_table(
'todo',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('description', sa.String(length=1000), nullable=True),
sa.Column('priority', priority_enum, nullable=False, default='medium'),
sa.Column('completed', sa.Boolean(), nullable=False, default=False),
sa.Column('created_at', sa.DateTime(), nullable=False, server_default=sa.func.now()),
sa.Column('updated_at', sa.DateTime(), nullable=False, server_default=sa.func.now(), onupdate=sa.func.now()),
sa.PrimaryKeyConstraint('id')
)
# Create indexes
op.create_index(op.f('ix_todo_id'), 'todo', ['id'], unique=False)
op.create_index(op.f('ix_todo_title'), 'todo', ['title'], unique=False)
def downgrade() -> None:
# Drop indexes
op.drop_index(op.f('ix_todo_title'), table_name='todo')
op.drop_index(op.f('ix_todo_id'), table_name='todo')
# Drop table
op.drop_table('todo')
# Drop enum type
sa.Enum(name='todopriority').drop(op.get_bind(), checkfirst=True)