WIP: fix(database): make v2->v3 chatlog migration deterministic and FK-safe #129

Draft
jabber.developer2 wants to merge 1 commits from fix/issue-128-migrate-v3-dedup into master
Collaborator

Closes #128.

_migrate_to_v3 deduped duplicate archive_id rows via a bare-column GROUP BY (arbitrary survivor — in practice the older row, dropping the latest) and copied rows with SELECT * (positional column binding).

This PR:

  • keeps MAX(id) per archive_id group ("latest insert wins") instead of GROUP BY's implementation-defined pick;
  • NULLs out replaces_db_id / replaced_by_db_id pointing at dropped rows, so no dangling XEP-0308 (LMC) links survive (the "Broken LMC reference" condition verify_integrity flags);
  • lists columns explicitly instead of SELECT *, with a schema-side note to keep the two in sync.

Only affects users upgrading from a v2 DB — already-v3 databases and live inserts are unchanged.

Verified with a local sqlite3 migration test (deterministic survivor, FK sweep, preserved valid FKs); kept local / out of CI as a one-shot migration check.

Closes #128. `_migrate_to_v3` deduped duplicate `archive_id` rows via a bare-column `GROUP BY` (arbitrary survivor — in practice the older row, dropping the latest) and copied rows with `SELECT *` (positional column binding). This PR: - keeps `MAX(id)` per `archive_id` group ("latest insert wins") instead of `GROUP BY`'s implementation-defined pick; - NULLs out `replaces_db_id` / `replaced_by_db_id` pointing at dropped rows, so no dangling XEP-0308 (LMC) links survive (the "Broken LMC reference" condition `verify_integrity` flags); - lists columns explicitly instead of `SELECT *`, with a schema-side note to keep the two in sync. Only affects users upgrading from a v2 DB — already-v3 databases and live inserts are unchanged. Verified with a local `sqlite3` migration test (deterministic survivor, FK sweep, preserved valid FKs); kept local / out of CI as a one-shot migration check.
jabber.developer2 added 1 commit 2026-05-27 11:23:27 +00:00
fix(database): make v2->v3 chatlog migration deterministic and FK-safe
All checks were successful
CI Code / Check spelling (pull_request) Successful in 18s
CI Code / Check coding style (pull_request) Successful in 34s
CI Code / Linux (debian) (pull_request) Successful in 4m45s
CI Code / Linux (ubuntu) (pull_request) Successful in 4m53s
CI Code / Code Coverage (pull_request) Successful in 6m57s
CI Code / Linux (arch) (pull_request) Successful in 10m19s
d9f1c25c7c
_migrate_to_v3 deduplicated duplicate archive_id rows with a bare-column
GROUP BY, which lets SQLite keep an arbitrary row per group (in practice the
older row, dropping the latest), and copied rows with SELECT *, which relies
on positional column matching between the v2 and v3 schemas.

- Keep MAX(id) per archive_id group ("latest insert wins") instead of
  GROUP BY's implementation-defined pick.
- Sweep replaces_db_id / replaced_by_db_id after dedupe, NULLing references
  to dropped rows so the migrated table carries no dangling XEP-0308 (LMC)
  links (the "Broken LMC reference" condition verify_integrity flags).
- List columns explicitly instead of SELECT * so the copy cannot mis-bind,
  and note at the schema that column changes must be mirrored here.

Refs #128
jabber.developer2 changed title from fix(database): make v2->v3 chatlog migration deterministic and FK-safe to WIP: fix(database): make v2->v3 chatlog migration deterministic and FK-safe 2026-05-27 11:23:30 +00:00
jabber.developer2 force-pushed fix/issue-128-migrate-v3-dedup from d9f1c25c7c to 25e9bc6e93 2026-06-19 08:43:24 +00:00 Compare
All checks were successful
CI Code / Check spelling (pull_request) Successful in 16s
Required
Details
CI Code / Check coding style (pull_request) Successful in 31s
Required
Details
CI Code / Code Coverage (pull_request) Successful in 3m12s
Required
Details
CI Code / Linux (debian) (pull_request) Successful in 4m40s
Required
Details
CI Code / Linux (arch) (pull_request) Successful in 6m54s
Required
Details
CI Code / Linux (ubuntu) (pull_request) Successful in 7m3s
Required
Details
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/issue-128-migrate-v3-dedup:fix/issue-128-migrate-v3-dedup
git checkout fix/issue-128-migrate-v3-dedup
Sign in to join this conversation.
No description provided.