72 lines
2.9 KiB
Python
72 lines
2.9 KiB
Python
"""initial migration
|
|
|
|
Revision ID: 1_initial_migration
|
|
Revises:
|
|
Create Date: 2023-10-24 10:00:00.000000
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '1_initial_migration'
|
|
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 user table
|
|
op.create_table(
|
|
'user',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('full_name', sa.String(), nullable=True),
|
|
sa.Column('hashed_password', sa.String(), nullable=False),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True, default=True),
|
|
sa.Column('is_superuser', sa.Boolean(), nullable=True, default=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
|
|
op.create_index(op.f('ix_user_id'), 'user', ['id'], unique=False)
|
|
|
|
# Create task table with TaskStatus and TaskPriority enums
|
|
op.create_table(
|
|
'task',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('title', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('status', sa.Enum('todo', 'in_progress', 'done', name='taskstatus'), nullable=False, default='todo'),
|
|
sa.Column('priority', sa.Enum('low', 'medium', 'high', name='taskpriority'), nullable=False, default='medium'),
|
|
sa.Column('due_date', sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column('owner_id', sa.Integer(), nullable=False),
|
|
sa.Column('assigned_to_id', sa.Integer(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
|
|
sa.ForeignKeyConstraint(['assigned_to_id'], ['user.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_task_id'), 'task', ['id'], unique=False)
|
|
op.create_index(op.f('ix_task_title'), 'task', ['title'], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Drop task table
|
|
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 enums
|
|
op.execute('DROP TYPE IF EXISTS taskstatus')
|
|
op.execute('DROP TYPE IF EXISTS taskpriority')
|
|
|
|
# Drop user table
|
|
op.drop_index(op.f('ix_user_id'), table_name='user')
|
|
op.drop_index(op.f('ix_user_email'), table_name='user')
|
|
op.drop_table('user') |