From 119d3dbf9b06e775777fb4ff4d7245b384a92c26 Mon Sep 17 00:00:00 2001 From: wyattb Date: Thu, 28 Nov 2024 12:48:00 -0500 Subject: [PATCH 1/3] #250 - notes can be NULL + added to PublicRun --- angular-client/src/utils/types.utils.ts | 1 + .../migrations/2024-11-10-031516_create_all/down.sql | 10 +++++++--- .../migrations/2024-11-10-031516_create_all/up.sql | 2 +- scylla-server/src/models.rs | 2 +- scylla-server/src/schema.rs | 8 ++++++-- scylla-server/src/services/run_service.rs | 4 ++-- scylla-server/src/transformers/run_transformer.rs | 2 ++ 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/angular-client/src/utils/types.utils.ts b/angular-client/src/utils/types.utils.ts index a8f54665..8c36c5e8 100644 --- a/angular-client/src/utils/types.utils.ts +++ b/angular-client/src/utils/types.utils.ts @@ -36,6 +36,7 @@ export type Run = { locationName: string; driverName: string; time: Date; + notes: string; }; export type Coordinate = { diff --git a/scylla-server/migrations/2024-11-10-031516_create_all/down.sql b/scylla-server/migrations/2024-11-10-031516_create_all/down.sql index 92b734d9..151b2412 100644 --- a/scylla-server/migrations/2024-11-10-031516_create_all/down.sql +++ b/scylla-server/migrations/2024-11-10-031516_create_all/down.sql @@ -1,4 +1,8 @@ --- This file should undo anything in `up.sql` -DROP TABLE "run"; +-- Drop Foreign Keys +ALTER TABLE "data" DROP CONSTRAINT "data_runId_fkey"; +ALTER TABLE "data" DROP CONSTRAINT "data_dataTypeName_fkey"; + +-- Drop Tables DROP TABLE "data"; -DROP TABLE "dataType"; \ No newline at end of file +DROP TABLE "dataType"; +DROP TABLE "run"; diff --git a/scylla-server/migrations/2024-11-10-031516_create_all/up.sql b/scylla-server/migrations/2024-11-10-031516_create_all/up.sql index 9ad478bf..86134396 100644 --- a/scylla-server/migrations/2024-11-10-031516_create_all/up.sql +++ b/scylla-server/migrations/2024-11-10-031516_create_all/up.sql @@ -5,7 +5,7 @@ CREATE TABLE "run" ( "latitude" DOUBLE PRECISION, "longitude" DOUBLE PRECISION, "driverName" TEXT, - "notes" TEXT NOT NULL, + "notes" TEXT, "time" TIMESTAMPTZ NOT NULL, CONSTRAINT "run_pkey" PRIMARY KEY ("id") diff --git a/scylla-server/src/models.rs b/scylla-server/src/models.rs index 03990555..8a1591fa 100644 --- a/scylla-server/src/models.rs +++ b/scylla-server/src/models.rs @@ -33,6 +33,6 @@ pub struct Run { pub latitude: Option, pub longitude: Option, pub driverName: Option, - pub notes: String, + pub notes: Option, pub time: DateTime, } diff --git a/scylla-server/src/schema.rs b/scylla-server/src/schema.rs index 52414e46..0a89af66 100644 --- a/scylla-server/src/schema.rs +++ b/scylla-server/src/schema.rs @@ -25,7 +25,7 @@ diesel::table! { latitude -> Nullable, longitude -> Nullable, driverName -> Nullable, - notes -> Text, + notes -> Nullable, time -> Timestamptz, } } @@ -33,4 +33,8 @@ diesel::table! { diesel::joinable!(data -> dataType (dataTypeName)); diesel::joinable!(data -> run (runId)); -diesel::allow_tables_to_appear_in_same_query!(data, dataType, run,); +diesel::allow_tables_to_appear_in_same_query!( + data, + dataType, + run, +); diff --git a/scylla-server/src/services/run_service.rs b/scylla-server/src/services/run_service.rs index 1c2e0d11..f12d3205 100644 --- a/scylla-server/src/services/run_service.rs +++ b/scylla-server/src/services/run_service.rs @@ -29,7 +29,7 @@ pub async fn create_run( timestamp: DateTime, ) -> Result { diesel::insert_into(run) - .values((time.eq(timestamp), notes.eq("A"))) + .values(time.eq(timestamp)) .get_result(db) } @@ -44,7 +44,7 @@ pub async fn create_run_with_id( run_id: i32, ) -> Result { diesel::insert_into(run) - .values((time.eq(timestamp), id.eq(run_id), notes.eq("A"))) + .values((time.eq(timestamp), id.eq(run_id))) .get_result(db) } diff --git a/scylla-server/src/transformers/run_transformer.rs b/scylla-server/src/transformers/run_transformer.rs index 5540c1a5..3b99bb93 100644 --- a/scylla-server/src/transformers/run_transformer.rs +++ b/scylla-server/src/transformers/run_transformer.rs @@ -10,6 +10,7 @@ pub struct PublicRun { pub driver_name: String, #[serde(rename = "time")] pub time_ms: i64, + pub notes: String, } impl From for PublicRun { @@ -19,6 +20,7 @@ impl From for PublicRun { location_name: value.locationName.unwrap_or_default(), driver_name: value.driverName.clone().unwrap_or_default(), time_ms: value.time.timestamp_millis(), + notes: value.notes.unwrap_or_default(), } } } From 553fbce9087e9bfadc4938ae8d4554967366b3b9 Mon Sep 17 00:00:00 2001 From: wyattb Date: Thu, 28 Nov 2024 13:09:41 -0500 Subject: [PATCH 2/3] #250 - fixed fmt --- scylla-server/src/schema.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scylla-server/src/schema.rs b/scylla-server/src/schema.rs index 0a89af66..1154d378 100644 --- a/scylla-server/src/schema.rs +++ b/scylla-server/src/schema.rs @@ -33,8 +33,4 @@ diesel::table! { diesel::joinable!(data -> dataType (dataTypeName)); diesel::joinable!(data -> run (runId)); -diesel::allow_tables_to_appear_in_same_query!( - data, - dataType, - run, -); +diesel::allow_tables_to_appear_in_same_query!(data, dataType, run,); From dac42336a6715fda3d0e00100e277a7ed1da3e03 Mon Sep 17 00:00:00 2001 From: wyattb Date: Thu, 5 Dec 2024 19:50:47 -0500 Subject: [PATCH 3/3] #250 - text field now has a default --- scylla-server/migrations/2024-11-10-031516_create_all/up.sql | 2 +- scylla-server/src/models.rs | 2 +- scylla-server/src/schema.rs | 2 +- scylla-server/src/transformers/run_transformer.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scylla-server/migrations/2024-11-10-031516_create_all/up.sql b/scylla-server/migrations/2024-11-10-031516_create_all/up.sql index 86134396..71d46db7 100644 --- a/scylla-server/migrations/2024-11-10-031516_create_all/up.sql +++ b/scylla-server/migrations/2024-11-10-031516_create_all/up.sql @@ -5,7 +5,7 @@ CREATE TABLE "run" ( "latitude" DOUBLE PRECISION, "longitude" DOUBLE PRECISION, "driverName" TEXT, - "notes" TEXT, + "notes" TEXT DEFAULT '', "time" TIMESTAMPTZ NOT NULL, CONSTRAINT "run_pkey" PRIMARY KEY ("id") diff --git a/scylla-server/src/models.rs b/scylla-server/src/models.rs index 8a1591fa..03990555 100644 --- a/scylla-server/src/models.rs +++ b/scylla-server/src/models.rs @@ -33,6 +33,6 @@ pub struct Run { pub latitude: Option, pub longitude: Option, pub driverName: Option, - pub notes: Option, + pub notes: String, pub time: DateTime, } diff --git a/scylla-server/src/schema.rs b/scylla-server/src/schema.rs index 1154d378..52414e46 100644 --- a/scylla-server/src/schema.rs +++ b/scylla-server/src/schema.rs @@ -25,7 +25,7 @@ diesel::table! { latitude -> Nullable, longitude -> Nullable, driverName -> Nullable, - notes -> Nullable, + notes -> Text, time -> Timestamptz, } } diff --git a/scylla-server/src/transformers/run_transformer.rs b/scylla-server/src/transformers/run_transformer.rs index 3b99bb93..bd7676d1 100644 --- a/scylla-server/src/transformers/run_transformer.rs +++ b/scylla-server/src/transformers/run_transformer.rs @@ -20,7 +20,7 @@ impl From for PublicRun { location_name: value.locationName.unwrap_or_default(), driver_name: value.driverName.clone().unwrap_or_default(), time_ms: value.time.timestamp_millis(), - notes: value.notes.unwrap_or_default(), + notes: value.notes, } } }