Skip to content

Preserve DNS rules and IDs across SQLite migration - #53

Open
compnew2006 wants to merge 1 commit into
UserJoo9:mainfrom
compnew2006:codex/qm-01-dns-migration
Open

compnew2006 wants to merge 1 commit into
UserJoo9:mainfrom
compnew2006:codex/qm-01-dns-migration

Conversation

@compnew2006

Copy link
Copy Markdown
Contributor

Problem

The DNS rules startup migration checked a STORED generated column with PRAGMA table_info, which omits generated columns. A current database looked like a legacy database on every restart. Rebuilding the table also reassigned DNS rule IDs. In a restart reproduction, a stored rule with ID 17 became ID 1. An interruption between the old migration's DDL and copy could leave a legacy table stranded.

Changes

  • Inspect the effective schema with table_xinfo so current databases bypass the migration.
  • Rebuild genuinely old tables in one transaction. Keep the newest rule from a legacy duplicate group, preserve every retained ID, and carry the AUTOINCREMENT high-water mark forward.
  • Identify residue from a past interrupted migration and stop with recovery guidance while leaving its rows intact.

Before and after

Scenario Before After
Restart with current DNS schema The migration can rebuild the table and renumber rules The schema check returns without rewriting DNS rules
Upgrade a genuinely legacy database Retained rules can get new IDs and previously allocated IDs can later be reused Deduplication keeps the newest rule and preserves retained and allocated identity history
The rebuild fails mid-copy DDL and the data copy can be separated by a commit The transaction rolls the DNS migration back

The change affects startup and upgrades of the DNS rules table. Fresh databases retain the existing schema. If migration residue already exists, recover or restore the original table from a verified backup before restarting. An older application binary can repeat the faulty migration, so keep a verified backup and avoid starting that binary against the upgraded database during rollback.

Verification

  • Reproduced unintended renumbering and sequence reuse before the fix.
  • Exercised restart on a current DB, upgrade with legacy duplicates, injected copy failure, and preservation of complete and partial legacy residue.
  • Migration and DNS-rule suites passed locally (48 passed, one skipped). Pyflakes and Git whitespace checks passed. All databases used for verification were temporary.

This branch has not been deployed

No deployments
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