From b691e26b66f949dc042fcdc72eaf23e66453cbe0 Mon Sep 17 00:00:00 2001 From: itang06 Date: Tue, 10 Mar 2026 00:07:29 -0700 Subject: [PATCH 1/3] added migration to update time_labels with start/end timestamp and color column --- backend/migrations/20260310120000_update_time_labels.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 backend/migrations/20260310120000_update_time_labels.sql diff --git a/backend/migrations/20260310120000_update_time_labels.sql b/backend/migrations/20260310120000_update_time_labels.sql new file mode 100644 index 0000000..ce7bc0f --- /dev/null +++ b/backend/migrations/20260310120000_update_time_labels.sql @@ -0,0 +1,4 @@ +ALTER TABLE time_labels RENAME COLUMN timestamp TO start_timestamp; +ALTER TABLE time_labels ADD COLUMN end_timestamp TIMESTAMPTZ; +ALTER TABLE time_labels ADD COLUMN color TEXT NOT NULL DEFAULT ''; +ALTER TABLE time_labels ALTER COLUMN color DROP DEFAULT; From 626d8b0ccf83bff76b8cf49f33c2e98c25575660 Mon Sep 17 00:00:00 2001 From: itang06 Date: Tue, 10 Mar 2026 00:11:43 -0700 Subject: [PATCH 2/3] updated timelabel and newtimelabel structs to include start/end timestamp and color fields --- backend/shared-logic/src/models.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/shared-logic/src/models.rs b/backend/shared-logic/src/models.rs index 92c51b5..b91c289 100644 --- a/backend/shared-logic/src/models.rs +++ b/backend/shared-logic/src/models.rs @@ -54,16 +54,20 @@ pub struct FrontendState { pub struct TimeLabel { pub id: i32, pub session_id: i32, - pub timestamp: DateTime, + pub start_timestamp: DateTime, + pub end_timestamp: Option>, pub label: String, + pub color: String, } // Struct for a time label coming INTO the API from the frontend // No id (auto-generated) or session_id (comes from URL path) #[derive(Debug, Serialize, Deserialize)] pub struct NewTimeLabel { - pub timestamp: DateTime, + pub start_timestamp: DateTime, + pub end_timestamp: Option>, pub label: String, + pub color: String, } // Struct for a row of EEG data coming OUT of the DB From cf0b500287f656fc6dc2a850e4e65d3e3c06885c Mon Sep 17 00:00:00 2001 From: itang06 Date: Tue, 10 Mar 2026 00:16:09 -0700 Subject: [PATCH 3/3] updated insert_time_labels and get_time_labels_by_range db functions for new time_labels schema --- backend/shared-logic/src/db.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/shared-logic/src/db.rs b/backend/shared-logic/src/db.rs index 285ecf8..b90ae15 100644 --- a/backend/shared-logic/src/db.rs +++ b/backend/shared-logic/src/db.rs @@ -372,13 +372,15 @@ pub async fn insert_time_labels(client: &DbClient, session_id: i32, labels: Vec< } let mut query_builder = sqlx::QueryBuilder::new( - "INSERT INTO time_labels (session_id, timestamp, label) " + "INSERT INTO time_labels (session_id, start_timestamp, end_timestamp, label, color) " ); query_builder.push_values(labels.iter(), |mut b, label| { b.push_bind(session_id) - .push_bind(label.timestamp) - .push_bind(&label.label); + .push_bind(label.start_timestamp) + .push_bind(label.end_timestamp) + .push_bind(&label.label) + .push_bind(&label.color); }); query_builder.build().execute(&**client).await?; @@ -416,7 +418,7 @@ pub async fn get_time_labels_by_range(client: &DbClient, session_id: i32, start: let labels = sqlx::query_as!( TimeLabel, - "SELECT id, session_id, timestamp, label FROM time_labels WHERE session_id = $1 AND timestamp >= $2 AND timestamp <= $3 ORDER BY timestamp", + "SELECT id, session_id, start_timestamp, end_timestamp, label, color FROM time_labels WHERE session_id = $1 AND start_timestamp >= $2 AND start_timestamp <= $3 ORDER BY start_timestamp", session_id, start, end,