Skip to content

Commit

Permalink
feat: add new migration
Browse files Browse the repository at this point in the history
  • Loading branch information
hippobach committed Dec 5, 2024
1 parent f0f174c commit c07b81c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
47 changes: 47 additions & 0 deletions backend/app/alembic/versions/80580dd7587b_add_three_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""add three tables
Revision ID: 80580dd7587b
Revises: 1a31ce608336
Create Date: 2024-12-05 16:24:28.872367
"""
from alembic import op
import sqlalchemy as sa
import sqlmodel.sql.sqltypes


# revision identifiers, used by Alembic.
revision = '80580dd7587b'
down_revision = '1a31ce608336'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('todo',
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
sa.Column('desc', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('user_id', sa.Uuid(), nullable=False),
sa.Column('status', sqlmodel.sql.sqltypes.AutoString(length=20), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('subtodo',
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
sa.Column('desc', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('todo_id', sa.Uuid(), nullable=False),
sa.Column('status', sqlmodel.sql.sqltypes.AutoString(length=20), nullable=False),
sa.ForeignKeyConstraint(['todo_id'], ['todo.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('subtodo')
op.drop_table('todo')
# ### end Alembic commands ###
24 changes: 24 additions & 0 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,27 @@ class TokenPayload(SQLModel):
class NewPassword(SQLModel):
token: str
new_password: str = Field(min_length=8, max_length=40)

class TodoBase(SQLModel):
title: str = Field(min_length=1, max_length=255)
desc: str | None = Field(default=None, max_length=255)

# Table Todo
class Todo(TodoBase, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
title: str = Field(max_length=255)
desc: str | None = Field(default=None, max_length=255)
user_id: uuid.UUID = Field(
foreign_key="user.id", nullable=False, ondelete="CASCADE"
)
status: str = Field(max_length=20)

# Table SubTodo
class SubTodo(TodoBase, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
title: str = Field(max_length=255)
desc: str | None = Field(default=None, max_length=255)
todo_id: uuid.UUID = Field(
foreign_key="todo.id", nullable=False, ondelete="CASCADE"
)
status: str = Field(max_length=20)

0 comments on commit c07b81c

Please sign in to comment.