fastapi-svelte-template/backend/todo/database/migrations/versions/7e5a8cabd3a4_create_todo_tables.py

37 lines
1.1 KiB
Python

"""create todo tables
Revision ID: 7e5a8cabd3a4
Revises: 335e07a98bc8
Create Date: 2023-05-12 21:59:26.867894
"""
from alembic import op
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Boolean
from sqlalchemy.sql.functions import now
# revision identifiers, used by Alembic.
revision = '7e5a8cabd3a4'
down_revision = '335e07a98bc8'
branch_labels = None
depends_on = down_revision
def upgrade() -> None:
op.create_table(
'todo_items',
Column('id', Integer, primary_key=True, autoincrement=True, index=True),
Column('title', String, nullable=False),
Column('description', String, nullable=False),
Column('done', Boolean, nullable=False, default=False, index=True),
Column('created', DateTime(timezone=True), nullable=False, server_default=now()),
Column('updated', DateTime(timezone=True), nullable=False, server_default=now(), onupdate=now()),
Column('finished', DateTime(timezone=True), nullable=True, default=None),
Column('user_id', Integer, ForeignKey('users.id', ondelete="CASCADE"), nullable=False),
)
def downgrade() -> None:
op.drop_table('todo_items')