- Notifications
You must be signed in to change notification settings - Fork 0
fix(migrations): validate history comments, retention, and document foreign keys#2187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BigSimmo
merged 8 commits into
main
from
claude/migration-history-drift-allowlist-37444cAug 20, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8dd014d
feat(db): Phase 6.2 — validation guards + allowlist for the fifteen n…
BigSimmo aceb66f
docs(db): Phase 6.2 completion evidence, board, drift-detection live …
BigSimmo 750052d
docs(ledger): review record for the Phase 6.2 guard branch (PR #2185)
BigSimmo 8ec93b3
fix(db): validate cron retention job details, fk confkey, and dynamic…
BigSimmo 65c589b
Merge remote-tracking branch 'origin/main' into claude/migration-hist…
BigSimmo 596c90e
Merge branch 'main' into claude/migration-history-drift-allowlist-37444c
BigSimmo eb82d6c
fix(migrations): remove conflict marker from document foreign key val…
BigSimmo ae49016
Merge branch 'main' into claude/migration-history-drift-allowlist-37444c
BigSimmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1 ...ords/6a3785a84afec6df46b90f552bb0b3bcb3555d1c1b80156ecbf1c4ce17a2d357.record.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| | 2026-08-19 | claude/migration-history-drift-allowlist-37444c | aceb66fc936821397175aead919a47b54ee455ad | Phase 6.2 (#Q5JHBJ): six validation guard migrations 20260819110000-110500 + fifteen migration_history allowlist entries; guard test predicate refinement; forensics/board/drift-doc; production+staging applied in the authorised window; PR #2185 | Drift zero on production (live-drift 32251326536 compare step: No unexpected schema drift, all 20 history rows allowed) and staging; chain replay 210/210 CHAIN == MANIFEST; seven mutants raise; production dry-runs green and a mutant fails there; job red only on the Phase 0 Align-migration-history step (PGRST106) queued as its own P2 | verify:pr-local exit 0 (682 files / 7398 tests passed, failed none); vitest schema set 113/113; check:migration-role; check:drift --self-test; local whole-chain Docker replay + compareDriftSnapshots; production guard dry-runs + mutant; staging md5-matched Phase 2 apply + offline drift comparison | |
13 changes: 9 additions & 4 deletions
13 supabase/migrations/20260819110100_validate_history_comments_and_retention.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14 supabase/migrations/20260819110200_validate_history_document_foreign_keys.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -64,16 +64,96 @@ function stripSql(sql: string): string { | ||
| } | ||
| /** | ||
| * Executable SQL only: comments and single-quoted string literals removed. A | ||
| * validation guard pins the canonical `create index … on …` text of the objects | ||
| * it proves as a string literal (the 20260804110240 pattern), which is data, not | ||
| * a statement — the create-index check must not mistake it for a build. | ||
| * Executable SQL only: comments and single-quoted string literals removed, except | ||
| * when passed dynamically to EXECUTE. A validation guard pins the canonical | ||
| * `create index … on …` text of the objects it proves as a data literal (the | ||
| * 20260804110240 pattern), which must not be mistaken for a build; but dynamic | ||
| * EXECUTE of CREATE INDEX statements must still be caught. | ||
| */ | ||
| function executableSql(sql: string): string { | ||
| return stripSql(sql).replace(/'(?:[^']|'')*'/g, "''"); | ||
| const stripped = stripSql(sql); | ||
| let out = ""; | ||
| let inExecute = false; | ||
| let i = 0; | ||
| while (i < stripped.length) { | ||
| // Check for string literal | ||
| if (stripped[i] === "'") { | ||
| let literal = ""; | ||
| i++; // skip opening quote | ||
| while (i < stripped.length) { | ||
| if (stripped[i] === "'") { | ||
| if (stripped[i + 1] === "'") { | ||
| literal += "'"; | ||
| i += 2; | ||
| } else { | ||
| i++; // skip closing quote | ||
| break; | ||
| } | ||
| } else { | ||
| literal += stripped[i]; | ||
| i++; | ||
| } | ||
| } | ||
| if (inExecute) { | ||
| out += " " + literal + " "; | ||
| } else { | ||
| out += "''"; | ||
| } | ||
| continue; | ||
| } | ||
| // Check for dollar-quoted string opening $tag$ | ||
| if (stripped[i] === "$") { | ||
| const match = stripped.slice(i).match(/^\$[a-zA-Z0-9_]*\$/); | ||
| if (match) { | ||
| const tag = match[0]; | ||
| inExecute = false; | ||
| out += tag; | ||
| i += tag.length; | ||
| continue; | ||
| } | ||
| } | ||
| // Check for dynamic EXECUTE keyword (excluding GRANT/REVOKE EXECUTE and EXECUTE FUNCTION/PROCEDURE) | ||
| const rest = stripped.slice(i); | ||
| const executeMatch = rest.match(/^execute\b(?!\s+(?:function|procedure)\b)/i); | ||
| if (executeMatch) { | ||
| const prefix = stripped.slice(Math.max(0, i - 15), i); | ||
| if (!/\b(?:grant|revoke)\s+$/i.test(prefix)) { | ||
| inExecute = true; | ||
| } | ||
| out += rest.slice(0, executeMatch[0].length); | ||
| i += executeMatch[0].length; | ||
| continue; | ||
| } | ||
| // If inside EXECUTE, check for clause terminators or string concatenation | ||
| if (inExecute) { | ||
| if (rest.match(/^\|\|/)) { | ||
| out += " "; | ||
| i += 2; | ||
| continue; | ||
| } | ||
| const termMatch = rest.match(/^(?:into\b|using\b|;|end\b)/i); | ||
| if (termMatch) { | ||
| inExecute = false; | ||
| out += rest.slice(0, termMatch[0].length); | ||
| i += termMatch[0].length; | ||
| continue; | ||
| } | ||
BigSimmo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| out += stripped[i]; | ||
| i++; | ||
| } | ||
| return out; | ||
| } | ||
| const CREATE_INDEX_STATEMENT = /create\s+(?:unique\s+)?index\s+(?:concurrently\s+)?(?:if\s+not\s+exists\s+)?[a-z_]/i; | ||
| const CREATE_INDEX_STATEMENT = | ||
| /create\s+(?:unique\s+)?index\s+(?:concurrently\s+)?(?:if\s+not\s+exists\s+)?(?:[a-z0-9_%"]|\$)/i; | ||
BigSimmo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| describe("migration-history probe and guard-migration contract", () => { | ||
| it("the v2 snapshot migration exists and check:drift knows its name", () => { | ||
| @@ -159,6 +239,21 @@ describe("migration-history probe and guard-migration contract", () => { | ||
| expect(executableSql(`${reference}\ncreate index if not exists oops_idx on public.documents(id);`)).toMatch( | ||
| CREATE_INDEX_STATEMENT, | ||
| ); | ||
| expect( | ||
| executableSql( | ||
| `${reference}\ndo $$ begin execute 'create index if not exists oops_idx on public.documents(id);'; end $$;`, | ||
| ), | ||
| ).toMatch(CREATE_INDEX_STATEMENT); | ||
| expect( | ||
| executableSql( | ||
| `${reference}\ndo $$ begin execute format('create index %I on public.documents(id)', 'oops_idx'); end $$;`, | ||
| ), | ||
| ).toMatch(CREATE_INDEX_STATEMENT); | ||
| expect( | ||
| executableSql( | ||
| `${reference}\ndo $$ begin execute 'create ' || 'unique index concurrently if not exists oops_idx on public.documents(id);'; end $$;`, | ||
| ), | ||
| ).toMatch(CREATE_INDEX_STATEMENT); | ||
| }); | ||
| it("no pre-contract class is used for a version at or after the contract date", () => { | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.