Skip to content
Merged
Changes from all commits
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
22 changes: 22 additions & 0 deletions tests/supabase-schema.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,6 +50,10 @@ const auditLogsServiceRolePolicyMigration = readFileSync(
new URL("../supabase/migrations/20260630090000_audit_logs_service_role_policy.sql", import.meta.url),
"utf8",
).replace(/\s+/g, " ");
const preserveLegacyArtifactCommitMigration = readFileSync(
new URL("../supabase/migrations/20260702000000_commit_generation_preserve_legacy_artifacts.sql", import.meta.url),
"utf8",
).replace(/\s+/g, " ");

function extractTextChunkFunction(sql: string) {
const start = sql.indexOf("function public.match_document_chunks_text");
Expand DownExpand Up@@ -166,6 +170,24 @@ describe("Supabase schema Data API grants", () => {
expect(atomicReindexMigration).toContain("atomic reindex patch did not match match_document_index_units_hybrid");
});

it("preserves NULL-generation artifacts until replacements exist", () => {
for (const sql of [schema, preserveLegacyArtifactCommitMigration]) {
expect(sql).toContain(
"index_generation_id is null and exists ( select 1 from public.document_chunks replacement",
);
expect(sql).toContain(
"nullif(metadata->>'index_generation_id', '') is null and exists ( select 1 from public.document_images replacement",
);
expect(sql).toContain("from public.document_chunks replacement");
expect(sql).toContain("from public.document_images replacement");
expect(sql).toContain("from public.document_table_facts replacement");
expect(sql).toContain("from public.document_embedding_fields replacement");
expect(sql).toContain("from public.document_index_units replacement");
expect(sql).toContain("from public.document_memory_cards replacement");
expect(sql).toContain("from public.document_sections replacement");
Comment on lines +183 to +187

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Assert the NULL-generation guard for every artifact table

The test claims to guard all artifact deletes, but after document_images these assertions only prove that a same-table replacement subquery exists somewhere in the SQL. A schema regression that changes, for example, document_memory_cards back to an unconditional nullif(metadata->>'index_generation_id', '') is null delete would still pass as long as the from public.document_memory_cards replacement text remains, so the destructive drift this test is meant to catch can slip through. Please assert the full is null and exists (...) guard per table, or isolate each delete block before checking it.

Useful? React with 👍 / 👎.

}
});

it("can identify and clean abandoned staged reindex generations", () => {
for (const sql of [schema, abandonedReindexRecoveryMigration]) {
expect(sql).toContain("create or replace function public.cleanup_abandoned_document_index_generations");
Expand Down
Loading