From f7ced4b7801e7fecc699d9d03f4072929a1fad74 Mon Sep 17 00:00:00 2001 From: Akulij Date: Tue, 8 Apr 2025 00:42:21 +0900 Subject: [PATCH] use timezoned timestamp in event date --- migrations/2025-04-07-153426_event_timestamptz/down.sql | 2 ++ migrations/2025-04-07-153426_event_timestamptz/up.sql | 2 ++ src/db/models.rs | 4 +++- src/db/schema.rs | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 migrations/2025-04-07-153426_event_timestamptz/down.sql create mode 100644 migrations/2025-04-07-153426_event_timestamptz/up.sql diff --git a/migrations/2025-04-07-153426_event_timestamptz/down.sql b/migrations/2025-04-07-153426_event_timestamptz/down.sql new file mode 100644 index 0000000..1d1ef23 --- /dev/null +++ b/migrations/2025-04-07-153426_event_timestamptz/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE events +ALTER COLUMN time TYPE TIMESTAMP; diff --git a/migrations/2025-04-07-153426_event_timestamptz/up.sql b/migrations/2025-04-07-153426_event_timestamptz/up.sql new file mode 100644 index 0000000..39e11de --- /dev/null +++ b/migrations/2025-04-07-153426_event_timestamptz/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE events +ALTER COLUMN time TYPE TIMESTAMPTZ; diff --git a/src/db/models.rs b/src/db/models.rs index c3c0272..4f71cab 100644 --- a/src/db/models.rs +++ b/src/db/models.rs @@ -6,12 +6,14 @@ use crate::db::schema::*; use chrono::NaiveDateTime; +use chrono::DateTime; +use chrono::offset::Utc; use diesel::prelude::*; #[derive(Queryable, Debug, Identifiable)] #[diesel(table_name = events)] pub struct Event { pub id: i32, - pub time: NaiveDateTime, + pub time: DateTime, } #[derive(Queryable, Debug, Identifiable)] diff --git a/src/db/schema.rs b/src/db/schema.rs index 05e50ed..2c8e625 100644 --- a/src/db/schema.rs +++ b/src/db/schema.rs @@ -3,7 +3,7 @@ diesel::table! { events (id) { id -> Int4, - time -> Timestamp, + time -> Timestamptz, } }