mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-07-25 11:32:30 -04:00
b432c08f8b
# Description of Changes Follow-up to #5288. Stacked on that branch; only the last commit is new. #5288 fixed `drop_table` to delete a dropped event table's `st_event_table` row, but databases which already dropped an event table on an unfixed version still carry an orphaned `st_event_table` row in their commitlogs and snapshots. This PR adds `fixup_delete_orphaned_st_event_table_rows` to `rebuild_state_after_replay`, following the existing `fixup_delete_duplicate_system_sequence_rows` pattern: after replay, delete any `st_event_table` row whose table id has no row in `st_table`. This heals affected databases on their next restart, with no migration or operator action required. The fixup is a no-op for databases without orphans, and skips cleanly when `st_event_table` does not exist yet (histories from before event tables were introduced, where `migrate_system_tables` creates it later). # API and ABI breaking changes None. # Expected complexity level and risk 1. Same shape as the existing system sequence fixup; runs once per database open over two small system tables. # Testing - [x] New unit test `test_fixup_deletes_orphaned_st_event_table_rows`: creates a real event table, replays an orphaned `st_event_table` row for a nonexistent table id (simulating a commitlog written by an unfixed version), runs the fixup, and asserts the orphan is deleted while the extant event table's row is preserved. - [x] Verified end-to-end against a data directory produced by stock 2.5.0 which dropped an event table (and was bricked by the replay bug): opened with a binary built from this branch, the database replays, the orphaned `st_event_table` row is gone, and user data is intact. --------- Co-authored-by: joshua-spacetime <josh@clockworklabs.io>