
Features: - User authentication with JWT tokens - Task and project CRUD operations - Task filtering and organization generated with BackendIM... (backend.im)
84 lines
3.5 KiB
Python
84 lines
3.5 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 001_initial_migration
|
|
Revises:
|
|
Create Date: 2023-05-12 00:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '001_initial_migration'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create users table
|
|
op.create_table(
|
|
'users',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('username', 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=False, default=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('username'),
|
|
sa.UniqueConstraint('email')
|
|
)
|
|
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
|
|
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
|
|
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
|
|
|
# Create projects table
|
|
op.create_table(
|
|
'projects',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
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()),
|
|
sa.Column('owner_id', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_projects_id'), 'projects', ['id'], unique=False)
|
|
op.create_index(op.f('ix_projects_name'), 'projects', ['name'], unique=False)
|
|
|
|
# Create tasks table
|
|
op.create_table(
|
|
'tasks',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('title', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('priority', sa.Enum('LOW', 'MEDIUM', 'HIGH', name='taskpriority'), nullable=False, default='MEDIUM'),
|
|
sa.Column('status', sa.Enum('TODO', 'IN_PROGRESS', 'DONE', name='taskstatus'), nullable=False, default='TODO'),
|
|
sa.Column('due_date', sa.DateTime(), nullable=True),
|
|
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()),
|
|
sa.Column('owner_id', sa.Integer(), nullable=False),
|
|
sa.Column('project_id', sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
|
|
sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_tasks_id'), 'tasks', ['id'], unique=False)
|
|
op.create_index(op.f('ix_tasks_title'), 'tasks', ['title'], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f('ix_tasks_title'), table_name='tasks')
|
|
op.drop_index(op.f('ix_tasks_id'), table_name='tasks')
|
|
op.drop_table('tasks')
|
|
|
|
op.drop_index(op.f('ix_projects_name'), table_name='projects')
|
|
op.drop_index(op.f('ix_projects_id'), table_name='projects')
|
|
op.drop_table('projects')
|
|
|
|
op.drop_index(op.f('ix_users_email'), table_name='users')
|
|
op.drop_index(op.f('ix_users_username'), table_name='users')
|
|
op.drop_index(op.f('ix_users_id'), table_name='users')
|
|
op.drop_table('users') |