Skip to content

Commit c07b81c

Browse files
committed
feat: add new migration
1 parent f0f174c commit c07b81c

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""add three tables
2+
3+
Revision ID: 80580dd7587b
4+
Revises: 1a31ce608336
5+
Create Date: 2024-12-05 16:24:28.872367
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlmodel.sql.sqltypes
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '80580dd7587b'
15+
down_revision = '1a31ce608336'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.create_table('todo',
23+
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
24+
sa.Column('desc', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
25+
sa.Column('id', sa.Uuid(), nullable=False),
26+
sa.Column('user_id', sa.Uuid(), nullable=False),
27+
sa.Column('status', sqlmodel.sql.sqltypes.AutoString(length=20), nullable=False),
28+
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
29+
sa.PrimaryKeyConstraint('id')
30+
)
31+
op.create_table('subtodo',
32+
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
33+
sa.Column('desc', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
34+
sa.Column('id', sa.Uuid(), nullable=False),
35+
sa.Column('todo_id', sa.Uuid(), nullable=False),
36+
sa.Column('status', sqlmodel.sql.sqltypes.AutoString(length=20), nullable=False),
37+
sa.ForeignKeyConstraint(['todo_id'], ['todo.id'], ondelete='CASCADE'),
38+
sa.PrimaryKeyConstraint('id')
39+
)
40+
# ### end Alembic commands ###
41+
42+
43+
def downgrade():
44+
# ### commands auto generated by Alembic - please adjust! ###
45+
op.drop_table('subtodo')
46+
op.drop_table('todo')
47+
# ### end Alembic commands ###

backend/app/models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,27 @@ class TokenPayload(SQLModel):
112112
class NewPassword(SQLModel):
113113
token: str
114114
new_password: str = Field(min_length=8, max_length=40)
115+
116+
class TodoBase(SQLModel):
117+
title: str = Field(min_length=1, max_length=255)
118+
desc: str | None = Field(default=None, max_length=255)
119+
120+
# Table Todo
121+
class Todo(TodoBase, table=True):
122+
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
123+
title: str = Field(max_length=255)
124+
desc: str | None = Field(default=None, max_length=255)
125+
user_id: uuid.UUID = Field(
126+
foreign_key="user.id", nullable=False, ondelete="CASCADE"
127+
)
128+
status: str = Field(max_length=20)
129+
130+
# Table SubTodo
131+
class SubTodo(TodoBase, table=True):
132+
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
133+
title: str = Field(max_length=255)
134+
desc: str | None = Field(default=None, max_length=255)
135+
todo_id: uuid.UUID = Field(
136+
foreign_key="todo.id", nullable=False, ondelete="CASCADE"
137+
)
138+
status: str = Field(max_length=20)

0 commit comments

Comments
 (0)