Database regeneration: plan and verify
Plans, builds and verifies a NEW Firebird database from the field repository's schema-8 facts and a source database -- never writes an existing database.
regen-plan writes a reviewable plan directory (DDL in gbak order, load map, report, plan hash) with data-losing changes BLOCKED until selected by id; regen-verify compares schema facts, procedural objects, rows, content digests, sequences and key indices; --for-swap checks the backup rule and prints the swap card. regen-build (1.65) executes a reviewed plan into a NEW local file: one read-only snapshot of the source, a journal per step, an INCOMPLETE marker and --discard for a failed build, then regen-verify; ARRAY columns are refused.
How to run it
drag-lint repo regen-plan (--repo <file> | --project <project file>) [--source "<connection>"] [--seed-dir <folder of TABLE.csv>] [--select <id,...|all>] --output <plan dir> [--json]
Full flag list: repo in the CLI reference.
drag-lint repo regen-verify --plan-dir <plan dir> --source "<connection>" --target "<connection>" [--for-swap [--backup-manifest <file>]] [--json]
Full flag list: repo in the CLI reference.
drag-lint repo regen-build --plan-dir <plan dir> --target "<connection of a NEW local file>" [--source "<connection>"] [--seed-dir <folder of TABLE.csv>] [--apply | --discard] [--json]
Full flag list: repo in the CLI reference.
Flags
| Flag | Argument | Meaning | Default |
|---|---|---|---|
--repo | <file> | ||
--project | <project file> | ||
--source | "<connection>" | ||
--seed-dir | <folder of TABLE.csv> | ||
--select | <id,...|all> | ||
--output | <plan dir> | ||
--json | |||
--plan-dir | <plan dir> | ||
--source | "<connection>" | ||
--target | "<connection>" | ||
--for-swap | |||
--backup-manifest | <file> | ||
--json | |||
--plan-dir | <plan dir> | ||
--target | "<connection of a NEW local file>" | ||
--source | "<connection>" | ||
--seed-dir | <folder of TABLE.csv> | ||
--apply | |||
--discard | |||
--json |
Where to click
No IDE surface: this feature runs from the CLI (see How to run it).
Details
Status: internal (accepted, not advertised). repo regen-build (the data pump) came in 1.65; it stays internal until the owner has read a rehearsal log.
Spec: SPEC-db-regeneration.md (lane folder lanes\v164\RG-A, recovered 2026-12-02; errata E1-E7 at its top).
What it is
Regeneration builds a NEW Firebird database from the field repository's schema facts (schema 8), the procedural objects and the data of a source database: tables without constraints, data, then keys / computed columns / checks / foreign keys / indices, generators, procedural objects, grants, comments -- the gbak order. It never changes an existing database. 1.64 ships the two read-only halves:
| Verb | Reads | Writes | Exit |
|---|---|---|---|
repo regen-plan | the repository (read only); with --source, the source database in read-only SNAPSHOT transactions | the plan directory given by --output | 0 planned, 1 BLOCKED changes present, 2 refused |
repo regen-verify | the plan directory; source and target databases, read only | nothing | 0 equal under the plan, 1 findings, 2 refused / error |
regen-plan
drag-lint repo regen-plan (--repo F | --project P) [--source "Database=..."] [--seed-dir D] [--select ids|all]
--output <plan dir> [--json]
- Needs a schema-8 repository whose facts were captured (
repo refresh-schema; DL_METAschema_facts_version = 8). - Change ids:
add-table:T,drop-table:T,add-column:T.C,drop-column:T.C,widen-column:T.C,change-column:T.C,alter-column:T.C;object:<key>lines list differing domains / sequences / constraints / indices (they follow the repository and are never blocked). - BLOCKED (data loss, spec 5.3): dropping a table with data or a stored column, a type change that is not a
widening, NOT NULL on a nullable column, a new NOT NULL column without default.
all(the default) never selects a BLOCKED change; it needs its own id in--select. An unselected change keeps the source shape. - Plan directory:
00-database.sql(options as comments),10-domains,20-tables(stored columns only),25-generators,30-load.json,40-keys,45-computed,50-checks,55-fks,57-indices,60-generators(formula only),70-procedural,80-grants,90-comments,report.txt,schema.facts(the target's canonical facts, what verify compares),plan.json(inputs, changes, steps and the PLAN HASH over every other file). 7-bit ASCII, CRLF, deterministic: the same inputs give the same bytes. - External tables are left out (reported); a foreign key onto a table or key the target lacks is left out (reported).
- A plan directory that holds
journal.txt(a build started from it) is never overwritten.
regen-verify
drag-lint repo regen-verify --plan-dir <plan dir> --source "Database=..." --target "Database=..."
[--for-swap [--backup-manifest <db-backups.json>]] [--json]
Checks (spec 6): the target's schema facts equal schema.facts; procedural objects, active flags, positions and
dependencies equal the source's; every table loaded from the source has the same row count and content digest
(SHA-256 per row over the columns both store, NULL marked, BLOBs hashed; per table in key order, sorted for a table
without a key); a table that starts empty holds no row; every sequence is at least the source's value; no key index
is inactive. An edited plan directory (plan hash mismatch) is refused.
--for-swap also requires a verified backup of the source newer than the source file's last write (the repo backup
manifest, default %LOCALAPPDATA%\drag-lint\db-backups.json) and then prints the owner's swap card (shutdown, two
renames, online, rollback). drag-lint runs none of those steps.
regen-build (1.65)
drag-lint repo regen-build --plan-dir <plan dir> --target "Database=<NEW local file>;User_Name=..;Password=.."
[--source "<connection>"] [--seed-dir <folder of TABLE.csv>] [--apply | --discard] [--json]
Executes a reviewed plan directory into a NEW local Firebird database. Without --apply it is a dry run: it checks the
plan hash, the source (same file as the plan's, schema unchanged since the plan) and the target, and lists the steps,
the load map and the BLOCKED count; nothing is written.
With --apply: dropped-column CSVs (<plan>\dropped\TABLE.COLUMN.csv) first, then create the file (page size and default
character set of the source), 10-domains / 20-tables / 25-generators (one transaction per file), the load (ONE read-only
SNAPSHOT of the source for every table, one commit per table; seed tables from their CSV), 40-keys / 45-computed /
50-checks / 55-fks / 57-indices (statement by statement), sequences and identity columns to the source values,
70-procedural / 80-grants / 90-comments (compiled under the character set the source's PSQL depends on), index
statistics, then regen-verify. Rows move through IRegenRowSource / IRegenRowSink (the seam the 1.67 data modules
replace); the Firebird sink executes one prepared insert per row (a FireDAC Array DML batch re-encoded a VARCHAR NONE).
Refused (exit 2, nothing written): an edited or stale plan directory; a --source other than the plan's or one whose
schema changed; a target that exists, is the source, names a server / share / relative path, or carries OpenMode /
CreateDatabase / DropDatabase; seed tables without --seed-dir; ARRAY columns (the repository has no dimensions).
Journal (<plan>\journal.txt): START, DROPPED, CREATED, STEP, LOAD, PSQL, BUILT, VERIFIED / FAILED, DISCARDED. A failed
build leaves the target with RDB$DESCRIPTION = "drag-lint regen-build INCOMPLETE plan <hash>"; --discard deletes a
target only when the journal says this plan created it and nothing discarded it since. Exit: 0 built and verified,
1 verify findings (dry run: BLOCKED changes in the plan), 2 refused or failed.
Constraint names Firebird made up (INTEG_n) are not replayed and not compared as facts (the new database numbers its
own); their fact key is table, kind and columns (a CHECK: its source).
Rehearsal: a copy of the Firebird 4 sample database employee.fdb.
Tests
tests\autotest\run_fieldrepo_regen_plan.ps1-- RegenPlanTests: files, determinism, hash, change ids, BLOCKED, selection, load map, repository round trip, plan directory (pure, no Firebird).tests\autotest\run_fieldrepo_regen_verify.ps1-- RegenVerifyTests: the pure comparison; live on embedded Firebird 4: source -> plan -> a target built from the plan files -> verify 0 findings; positive controls (changed row, dropped index, dropped trigger, lower generator, duplicate row in a keyless table) each FOUND; the CLI verbs end to end.tests\autotest\run_v165_RG_B.ps1-- regen-build (tests\fieldrepo\regen\build\RegenBuildTests.dpr): pure plan reader, pump, refusals, journal; live build on embedded FB4 with exact row counts, two positive controls, --discard, drop-column, seed, ARRAY refusal, INTEG_n, charset.