Skip to content

Commit c44213c

Browse files
committed
fix: update database schema for path and step models
- Change step.id to use integer instead of UUID - Rename path.owner_id to creator_id - Add created_at and updated_at to path table - Add role_prompt, validation_prompt, and exposition_json to step table - Set default values for user.is_active and user.is_superuser
1 parent 37d90e9 commit c44213c

File tree

2 files changed

+76
-13
lines changed

2 files changed

+76
-13
lines changed

backend/app/alembic/versions/ea8d60701d49_add_path_and_step_models.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from alembic import op
1111
import sqlalchemy as sa
1212
import sqlmodel.sql.sqltypes
13+
from sqlalchemy.dialects import postgresql
1314

1415

1516
# revision identifiers, used by Alembic.
@@ -21,22 +22,39 @@
2122

2223
def upgrade() -> None:
2324
# ### commands auto generated by Alembic - please adjust! ###
25+
26+
# Modify the user table to set default values
27+
op.alter_column('user', 'is_active',
28+
existing_type=sa.BOOLEAN(),
29+
server_default=sa.true(),
30+
existing_nullable=False)
31+
op.alter_column('user', 'is_superuser',
32+
existing_type=sa.BOOLEAN(),
33+
server_default=sa.false(),
34+
existing_nullable=False)
35+
36+
# Create path table with correct columns
2437
op.create_table('path',
25-
sa.Column('id', sqlmodel.sql.sqltypes.GUID(), nullable=False),
26-
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
27-
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
28-
sa.Column('owner_id', sqlmodel.sql.sqltypes.GUID(), nullable=False),
29-
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ondelete='CASCADE'),
30-
sa.PrimaryKeyConstraint('id')
38+
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
39+
sa.Column('creator_id', postgresql.UUID(as_uuid=True), nullable=False),
40+
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
41+
sa.Column('path_summary', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
42+
sa.Column('created_at', sa.DateTime(), nullable=False),
43+
sa.Column('updated_at', sa.DateTime(), nullable=False),
44+
sa.ForeignKeyConstraint(['creator_id'], ['user.id'], ondelete='CASCADE'),
45+
sa.PrimaryKeyConstraint('id')
3146
)
47+
48+
# Create step table
3249
op.create_table('step',
33-
sa.Column('id', sqlmodel.sql.sqltypes.GUID(), nullable=False),
34-
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
35-
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
36-
sa.Column('path_id', sqlmodel.sql.sqltypes.GUID(), nullable=False),
37-
sa.Column('order', sa.Integer(), nullable=False),
38-
sa.ForeignKeyConstraint(['path_id'], ['path.id'], ondelete='CASCADE'),
39-
sa.PrimaryKeyConstraint('id')
50+
sa.Column('id', sa.Integer(), nullable=False),
51+
sa.Column('path_id', postgresql.UUID(as_uuid=True), nullable=False),
52+
sa.Column('number', sa.Integer(), nullable=False),
53+
sa.Column('role_prompt', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
54+
sa.Column('validation_prompt', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
55+
sa.Column('exposition_json', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
56+
sa.ForeignKeyConstraint(['path_id'], ['path.id'], ondelete='CASCADE'),
57+
sa.PrimaryKeyConstraint('id')
4058
)
4159
# ### end Alembic commands ###
4260

@@ -45,4 +63,14 @@ def downgrade() -> None:
4563
# ### commands auto generated by Alembic - please adjust! ###
4664
op.drop_table('step')
4765
op.drop_table('path')
66+
67+
# Remove default values from user table
68+
op.alter_column('user', 'is_active',
69+
existing_type=sa.BOOLEAN(),
70+
server_default=None,
71+
existing_nullable=False)
72+
op.alter_column('user', 'is_superuser',
73+
existing_type=sa.BOOLEAN(),
74+
server_default=None,
75+
existing_nullable=False)
4876
# ### end Alembic commands ###
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Flex, Spinner } from "@chakra-ui/react"
2+
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router"
3+
4+
import Sidebar from "../../components/Common/Sidebar"
5+
import UserMenu from "../../components/Common/UserMenu"
6+
import useAuth, { isLoggedIn } from "../../hooks/useAuth"
7+
8+
export const Route = createFileRoute("/_layout")({
9+
component: Layout,
10+
beforeLoad: async () => {
11+
if (!isLoggedIn()) {
12+
throw redirect({
13+
to: "/login",
14+
})
15+
}
16+
},
17+
})
18+
19+
function Layout() {
20+
const { isLoading } = useAuth()
21+
22+
return (
23+
<Flex maxW="large" h="auto" position="relative">
24+
<Sidebar />
25+
{isLoading ? (
26+
<Flex justify="center" align="center" height="100vh" width="full">
27+
<Spinner size="xl" color="ui.main" />
28+
</Flex>
29+
) : (
30+
<Outlet />
31+
)}
32+
<UserMenu />
33+
</Flex>
34+
)
35+
}

0 commit comments

Comments
 (0)