simple-web-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit dac53494b377b4768b4bd64106452561cc43c4c1
parent 0c1d430e4f5b840df5b392770cbfbb4feff875a7
Author: Silas Brack <silasbrack@gmail.com>
Date:   Sat, 13 Jun 2026 15:59:27 +0200

fix: set created_at in all INSERT statements

The epoch timestamp migration removed DEFAULT (datetime('now'))
from all tables but the INSERT statements weren't updated to
provide created_at explicitly. Fixes NOT NULL constraint failure
on session, comment, vote, and user creation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Diffstat:
Msrc/database.rs | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/database.rs b/src/database.rs @@ -531,9 +531,9 @@ impl Database { }; conn.execute( - "INSERT INTO comment (story_id, parent_id, path, depth, text, created_by) - VALUES (?1, ?2, ?3, ?4, ?5, ?6)", - params![story_id, parent_id, path, depth, text, user_id], + "INSERT INTO comment (story_id, parent_id, path, depth, text, created_by, created_at) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)", + params![story_id, parent_id, path, depth, text, user_id, now_epoch()], ).map_err(|e| AppError::Database(e.to_string()))?; let id = conn.last_insert_rowid(); @@ -580,8 +580,8 @@ impl Database { // Try to insert let result = conn.execute( - "INSERT INTO vote (user_id, target_type, target_id) VALUES (?1, ?2, ?3)", - params![user_id, target_type, target_id], + "INSERT INTO vote (user_id, target_type, target_id, created_at) VALUES (?1, ?2, ?3, ?4)", + params![user_id, target_type, target_id, now_epoch()], ); match result { @@ -761,8 +761,8 @@ impl Database { pub fn create_user(&self, email: &str, password_hash: &str, username: &str, verification_token: Option<&str>) -> Result<User, AppError> { let conn = self.write_conn()?; conn.execute( - "INSERT INTO user (email, password_hash, username, verification_token) VALUES (?1, ?2, ?3, ?4)", - params![email, password_hash, username, verification_token], + "INSERT INTO user (email, password_hash, username, verification_token, created_at) VALUES (?1, ?2, ?3, ?4, ?5)", + params![email, password_hash, username, verification_token, now_epoch()], ).map_err(|e| AppError::Database(e.to_string()))?; let id = conn.last_insert_rowid(); @@ -799,8 +799,8 @@ impl Database { let conn = self.write_conn()?; conn.execute( - "INSERT INTO session (token, user_id) VALUES (?1, ?2)", - params![token, user_id], + "INSERT INTO session (token, user_id, created_at) VALUES (?1, ?2, ?3)", + params![token, user_id, now_epoch()], ).map_err(|e| AppError::Database(e.to_string()))?; Ok(token)