48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
"""Add task table
|
|
|
|
Revision ID: 002
|
|
Revises: 001
|
|
Create Date: 2023-10-23
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '002'
|
|
down_revision = '001'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Create task table
|
|
op.create_table(
|
|
'task',
|
|
sa.Column('id', sa.String(36), primary_key=True, index=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.Column('title', sa.String(200), index=True, nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('due_date', sa.DateTime(), nullable=True),
|
|
sa.Column('status', sa.Enum('todo', 'in_progress', 'completed', 'cancelled', name='taskstatus'), nullable=False, default='todo'),
|
|
sa.Column('priority', sa.Enum('low', 'medium', 'high', name='taskpriority'), nullable=False, default='medium'),
|
|
sa.Column('completed_at', sa.DateTime(), nullable=True),
|
|
)
|
|
op.create_index(op.f('ix_task_id'), 'task', ['id'], unique=False)
|
|
op.create_index(op.f('ix_task_title'), 'task', ['title'], unique=False)
|
|
op.create_index(op.f('ix_task_status'), 'task', ['status'], unique=False)
|
|
op.create_index(op.f('ix_task_priority'), 'task', ['priority'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_task_priority'), table_name='task')
|
|
op.drop_index(op.f('ix_task_status'), table_name='task')
|
|
op.drop_index(op.f('ix_task_title'), table_name='task')
|
|
op.drop_index(op.f('ix_task_id'), table_name='task')
|
|
op.drop_table('task')
|
|
|
|
# Drop the enum types
|
|
op.execute('DROP TYPE IF EXISTS taskstatus;')
|
|
op.execute('DROP TYPE IF EXISTS taskpriority;') |