Skip to content

Let the server start again by deleting a dropped chat's rows before the chat - #1490

Merged
dylanplayer merged 1 commit into
mainfrom
fix-harnessless-chat-migration
Nov 26, 2026
Merged

dylanplayer merged 1 commit into
mainfrom
fix-harnessless-chat-migration

Conversation

@dylanplayer

Copy link
Copy Markdown
Member

Migration 115 (#1479) deleted empty harnessless chats while foreign keys were off, so nothing cascaded. Their session_state and session_events rows were left pointing at missing chats, the foreign key check after the migrations failed, and the server could not start on any machine that had such a chat. The migration rolled back each time, so no data was lost.

The migration now deletes every row that references a dropped chat (and the plugin event deliveries under its subscriptions) before deleting the chat. The test seeds those rows on the dropped chat and fails on the old migration with the same error. Verified against a copy of a real affected database: it migrates to 115 with no foreign key violations.

🤖 Generated with Claude Code

…he chat

Migration 115 (#1479) deleted empty harnessless chats while foreign keys
were off, so nothing cascaded. Their session_state and session_events rows
were left pointing at missing chats, the foreign key check after the
migrations failed, and the server could not start on any machine that had
such a chat.

The migration now deletes every row that references a dropped chat (and the
plugin event deliveries under its subscriptions) before deleting the chat.
The test seeds those rows on the dropped chat, and fails on the old
migration with the same error the machines hit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dylanplayer
dylanplayer merged commit 4142dd0 into main Nov 26, 2026
@dylanplayer
dylanplayer deleted the fix-harnessless-chat-migration branch November 26, 2026 04:59
dylanplayer added a commit that referenced this pull request Nov 26, 2026
…g to start (#1494)

* Let migrations apply the schema's own delete rules instead of refusing to start

Migrations run with foreign keys off, so a migration that deletes a parent row
skips the schema's ON DELETE rules and leaves children pointing at nothing.
The runner then refused to start the server (#1479, patched by hand in #1490).

After the migrations, the runner now resolves every row pragma
foreign_key_check reports by that foreign key's own rule: cascade deletes the
row (repeating until nothing new is orphaned), set null and set default reset
the columns. Only orphans on a key with no rule (or restrict) still refuse to
start. It runs inside the migration transaction, touches only reported rows,
does one check and nothing else when nothing is orphaned, and logs what it
resolved after the commit.

A new test seeds linked rows into every table, derived from the schema, before
every migration from the first to the latest, then opens the database through
the real runner. It fails on the old runner with #1479's migration 115.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Plan each fixture row once per round and give the chain test a hang guard

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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