Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: point the skipped-events warning at a new destination
Re-running the migration into the same destination fails with
"UNIQUE constraint failed: sessions..." because the session rows are
already there, so telling the operator to just re-run sends them into
an error. The test now covers that advice end to end: a second run into
a fresh destination recovers the skipped row, and re-running into the
used one exits.
  • Loading branch information
feiiiiii5 committed Sep 28, 2026
commit c220ea0824cc9479e4ca0ccd2a0cad6dfdd3875f
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ def migrate(source_db_url: str, dest_db_path: str) -> None:
# is the number that survived, not the number the source held.
logger.warning(
"Skipped %d event(s) that could not be migrated: %s. They are still"
" in the source database; re-run the migration once the cause is"
" fixed.",
" in the source database; once the cause is fixed, re-run the"
" migration into a new, empty destination (the session rows are"
" already in this one).",
len(skipped_event_ids),
", ".join(skipped_event_ids),
)
Expand Down
23 changes: 23 additions & 0 deletions tests/unittests/sessions/migration/test_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,26 @@ def to_event(self):
assert "Migrated 1 events." in caplog.text
assert "Migrated 2 events." not in caplog.text
assert "event2" in caplog.text
# Re-running into the same destination fails on the sessions UNIQUE
# constraint, so the advice has to point at a fresh one.
assert "new, empty destination" in caplog.text

# And that advice is what actually works: with the cause fixed, a second run
# into a new destination gets both rows.
caplog.clear()
dest_db_path2 = tmp_path / "dest_sqlite2.db"
with caplog.at_level(logging.INFO):
mfss.migrate(source_db_url, str(dest_db_path2))
dest_conn2 = sqlite3.connect(dest_db_path2)
try:
migrated_ids2 = [
row[0] for row in dest_conn2.execute("SELECT id FROM events").fetchall()
]
finally:
dest_conn2.close()
assert sorted(migrated_ids2) == ["event1", "event2"]
assert "Skipped" not in caplog.text

# The same destination cannot be reused, which is why the warning says so.
with pytest.raises(SystemExit):
mfss.migrate(source_db_url, str(dest_db_path2))
Loading