
- Set up project structure with FastAPI - Implement SQLAlchemy models for User and Task - Create Alembic migrations - Implement authentication with JWT - Add CRUD operations for tasks - Add task filtering and prioritization - Configure health check endpoint - Update README with project documentation
76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 01_initial
|
|
Revises:
|
|
Create Date: 2023-07-16 00:00:00.000000
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
import enum
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '01_initial'
|
|
down_revision: Union[str, None] = None
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
# Create Enum types
|
|
class TaskStatusEnum(enum.Enum):
|
|
TODO = "todo"
|
|
IN_PROGRESS = "in_progress"
|
|
DONE = "done"
|
|
|
|
|
|
class TaskPriorityEnum(enum.Enum):
|
|
LOW = "low"
|
|
MEDIUM = "medium"
|
|
HIGH = "high"
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create user table
|
|
op.create_table(
|
|
'user',
|
|
sa.Column('id', sa.String(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('hashed_password', sa.String(), nullable=False),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), 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
|
|
op.create_table(
|
|
'task',
|
|
sa.Column('id', sa.String(), 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),
|
|
sa.Column('priority', sa.Enum('low', 'medium', 'high', name='taskpriority'), nullable=False),
|
|
sa.Column('due_date', sa.DateTime(), nullable=True),
|
|
sa.Column('completed_at', sa.DateTime(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('owner_id', sa.String(), nullable=False),
|
|
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ondelete='CASCADE'),
|
|
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:
|
|
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')
|
|
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') |