Skip to content

fix(db): add migration to backfill room_messages.created_at on old schemas#5

Open
tjdownes wants to merge 1 commit intodevfrom
fix/room-server-db-migration
Open

fix(db): add migration to backfill room_messages.created_at on old schemas#5
tjdownes wants to merge 1 commit intodevfrom
fix/room-server-db-migration

Conversation

@tjdownes
Copy link
Copy Markdown
Owner

@tjdownes tjdownes commented May 1, 2026

Summary

The problem was that created_at was added to the CREATE TABLE room_messages statement at some point, but existing databases never got the column because SQLite's CREATE TABLE IF NOT EXISTS is a no-op on tables that already exist. So every INSERT INTO room_messages on an older database was failing with:

OperationalError: table room_messages has no column named created_at

Insert_room_message() would return None, add_post() would return False, and messages would silently not be stored. The tricky part is that it was invisible to the sender - the companion app still showed "Delivered" because the ACK goes out before add_post() is called, so you'd think messages were getting through when they weren't.

This PR adds migration to backfill room_messages.created_at on existing databases that were created before this column was added

Test plan

  • Apply to an existing database, verify created_at is populated for old rows

…hemas

Databases created before created_at was added to the CREATE TABLE statement
are missing the column.  SQLite's CREATE TABLE IF NOT EXISTS is a no-op on
existing tables so the column is never added automatically.  Every subsequent
INSERT INTO room_messages fails with:

  OperationalError: table room_messages has no column named created_at

This causes insert_room_message() to return None, add_post() to return False,
and the web API to surface "Failed to add message (rate limit or validation
error)".  The companion still shows "Delivered ✓" because the ACK is sent
before add_post() is called — storage failure and delivery acknowledgement are
fully decoupled.

Migration 10 runs PRAGMA table_info(room_messages), detects the missing column,
and issues ALTER TABLE … ADD COLUMN created_at REAL NOT NULL DEFAULT 0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tjdownes tjdownes force-pushed the fix/room-server-db-migration branch from 3e30ba0 to c1b34a4 Compare May 1, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant