Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/db-user/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl std::ops::Deref for UserDatabase {
}

// Append only. Do not reorder.
const MIGRATIONS: [&str; 27] = [
const MIGRATIONS: [&str; 28] = [
include_str!("./calendars_migration.sql"),
include_str!("./configs_migration.sql"),
include_str!("./events_migration.sql"),
Expand Down Expand Up @@ -170,6 +170,7 @@ const MIGRATIONS: [&str; 27] = [
include_str!("./templates_migration_1.sql"),
include_str!("./chat_conversations_migration.sql"),
include_str!("./chat_messages_v2_migration.sql"),
include_str!("./templates_migration_2.sql"),
];

pub async fn migrate(db: &UserDatabase) -> Result<(), crate::Error> {
Expand Down
4 changes: 4 additions & 0 deletions crates/db-user/src/templates_migration_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE templates
ADD COLUMN created_at TEXT NOT NULL DEFAULT (
strftime('%Y-%m-%dT%H:%M:%SZ', 'now')
);
1 change: 1 addition & 0 deletions crates/db-user/src/templates_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ mod tests {
context_option: Some(
r#"{"type":"tags","selections":["Meeting","Project A"]}"#.to_string(),
),
created_at: Template::default_created_at(),
})
.await
.unwrap();
Expand Down
7 changes: 7 additions & 0 deletions crates/db-user/src/templates_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ user_common_derives! {
pub sections: Vec<TemplateSection>,
pub tags: Vec<String>,
pub context_option: Option<String>,
#[serde(default = "Template::default_created_at")]
pub created_at: String,
}
}

Expand All @@ -20,6 +22,10 @@ user_common_derives! {
}

impl Template {
pub fn default_created_at() -> String {
chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
}

pub fn from_row(row: &libsql::Row) -> Result<Self, serde::de::value::Error> {
Ok(Self {
id: row.get(0).expect("id"),
Expand All @@ -35,6 +41,7 @@ impl Template {
.map(|s| serde_json::from_str(s).unwrap())
.unwrap_or_default(),
context_option: row.get(6).ok(),
created_at: row.get(7).unwrap_or_else(|_| Self::default_created_at()),
})
}
}