fix(db): add migration to backfill room_messages.created_at on old schemas#5
Open
fix(db): add migration to backfill room_messages.created_at on old schemas#5
Conversation
…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>
3e30ba0 to
c1b34a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_aton existing databases that were created before this column was addedTest plan
created_atis populated for old rows