Skip to content

Commit

Permalink
WIP: Separate out tasks and benchmarks, add migration to move due_dat…
Browse files Browse the repository at this point in the history
…e and trial_count to benchmarks
  • Loading branch information
canjalal committed Jan 17, 2025
1 parent fe82ce4 commit 9dd7b5f
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 148 deletions.
26 changes: 25 additions & 1 deletion src/backend/db/migrations/5_trial_data_belongs_to_benchmark.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,40 @@
ALTER TABLE trial_data
ADD COLUMN benchmark_id uuid REFERENCES benchmark(benchmark_id);

-- Step 1a: Add due_date and trial_count to benchmark

ALTER TABLE benchmark
ADD COLUMN due_date TIMESTAMPTZ;

ALTER TABLE benchmark
ADD COLUMN trial_count INTEGER;

-- 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 2a: Copy due_date and trial_count from tasks for existing records
-- Taking the first result of tasks that matches the right benchmark_id

UPDATE benchmark
SET due_date = task.due_date, trial_count = task.trial_count
FROM task
WHERE task.benchmark_id = benchmark.benchmark_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;
DROP COLUMN task_id;

-- Step 4a: Remove due_date, and trial_count from task

ALTER TABLE task
DROP COLUMN due_date;

ALTER TABLE task
DROP COLUMN trial_count;
Loading

0 comments on commit 9dd7b5f

Please sign in to comment.