Skip to content

Commit

Permalink
WIP: Start work moving trial data to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
canjalal committed Jan 10, 2025
1 parent f25a333 commit 75c84fc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
17 changes: 17 additions & 0 deletions src/backend/db/migrations/5_trial_data_belongs_to_benchmark.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Step 1: Add new benchmark_id column to trial_data
ALTER TABLE trial_data
ADD COLUMN benchmark_id uuid REFERENCES benchmark(benchmark_id);

-- Step 2: Copy benchmark_id from tasks for existing records
UPDATE trial_data
SET benchmark_id = task.benchmark_id
FROM task
WHERE trial_data.task_id = task.task_id;

-- Step 3: Make benchmark_id required
ALTER TABLE trial_data
ALTER COLUMN benchmark_id SET NOT NULL;

-- Step 4: Remove task_id column
ALTER TABLE trial_data
DROP COLUMN task_id;
16 changes: 6 additions & 10 deletions src/backend/routers/iep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ export const iep = router({
.mutation(async (req) => {
const { userId } = req.ctx.auth;

const { task_id, success, unsuccess, notes } = req.input;
const { benchmark_id, success, unsuccess, notes } = req.input;

Check failure on line 261 in src/backend/routers/iep.ts

View workflow job for this annotation

GitHub Actions / type-check

Property 'benchmark_id' does not exist on type '{ success: number; task_id: string; notes: string; unsuccess: number; }'.

const result = await req.ctx.db
.insertInto("trial_data")
.values({
task_id,
benchmark_id,

Check failure on line 266 in src/backend/routers/iep.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe assignment of an error typed value

Check failure on line 266 in src/backend/routers/iep.ts

View workflow job for this annotation

GitHub Actions / type-check

Object literal may only specify known properties, and 'benchmark_id' does not exist in type 'InsertExpression<KyselySchema, "trial_data">'.
created_by_user_id: userId,
success,
unsuccess,
Expand Down Expand Up @@ -393,21 +393,19 @@ export const iep = router({
getBenchmarkAndTrialData: hasPara
.input(
z.object({
task_id: z.string(),
benchmark_id: z.string(),
})
)
.query(async (req) => {
const { task_id } = req.input;
const { benchmark_id } = req.input;

const result = await req.ctx.db
.selectFrom("benchmark")
.innerJoin("task", "benchmark.benchmark_id", "task.benchmark_id")
.innerJoin("goal", "benchmark.goal_id", "goal.goal_id")
.innerJoin("iep", "goal.iep_id", "iep.iep_id")
.innerJoin("student", "iep.student_id", "student.student_id")
.where("task.task_id", "=", task_id)
.select((eb) => [
"task.task_id",
"benchmark.benchmark_id",
"student.first_name",
"student.last_name",
"goal.category",
Expand All @@ -416,9 +414,6 @@ export const iep = router({
"benchmark.frequency",
"benchmark.number_of_trials",
"benchmark.benchmark_id",
"task.due_date",
"task.seen",
"task.trial_count",
jsonArrayFrom(
eb
.selectFrom("trial_data")
Expand Down Expand Up @@ -449,6 +444,7 @@ export const iep = router({
.orderBy("trial_data.created_at")
).as("trials"),
])
.where("benchmark.benchmark_id", "=", benchmark_id)
.executeTakeFirstOrThrow();

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/benchmarks/[benchmark_id]/review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ReviewPage = () => {
const { benchmark_id } = router.query;
const { data: task, isLoading } = trpc.iep.getBenchmarkAndTrialData.useQuery(
{
task_id: benchmark_id as string,
benchmark_id: benchmark_id as string,
},
{
enabled: Boolean(benchmark_id),
Expand Down

0 comments on commit 75c84fc

Please sign in to comment.