Skip to content

Commit

Permalink
Updated the inserting of events into the DB (#162)
Browse files Browse the repository at this point in the history
* SQL update

* made event task_id unique
  • Loading branch information
S3JER authored May 8, 2024
1 parent 45e196b commit 6466ca6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend/migrations/0002_create_events_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ CREATE TABLE Events(
id INTEGER PRIMARY KEY NOT NULL,
task_id INTEGER NOT NULL
REFERENCES Tasks(id) ON DELETE CASCADE,
start_time DATETIME NOT NULL
start_time DATETIME NOT NULL,
UNIQUE(task_id)
);
2 changes: 1 addition & 1 deletion backend/src/scheduling/background_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async fn run_algorithm(pool: &SqlitePool, algorithm: &mut impl SchedulerAlgorith
for event in events {
sqlx::query!(
r#"
INSERT INTO Events (task_id, start_time)
INSERT OR REPLACE INTO Events (task_id, start_time)
VALUES ((SELECT id FROM Tasks WHERE id == ? LIMIT 1), ?)
"#,
event.task_id,
Expand Down

0 comments on commit 6466ca6

Please sign in to comment.