// The module's migration is its own file and exactly `schemaStatements()` over its three entities // (decision AT-D20: the entity definitions are the one source of a column). The module ships the // Postgres profile; the Convex binding is provided for the integration owner and has no SQL. import { readFileSync } from "node:fs" import { schemaStatements } from "@conusai-kit/data-kysely" import { describe, expect, it } from "vitest" import { KNOWLEDGE_ENTITIES, knowledgeModule } from "../index.js" /** The statements for these tables alone: `schemaStatements` leads with the kernel's own two. */ function tablesOf(entities: Parameters[0]): string { const kernel = schemaStatements([]).length return `${schemaStatements(entities) .slice(kernel) .map((statement) => `${statement};`) .join("\n\n")}\n` } describe("the migration of the knowledge module", () => { it("is its own file, exactly its three tables", async () => { await expect( `-- SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0\n${tablesOf(KNOWLEDGE_ENTITIES)}`, ).toMatchFileSnapshot("../migrations/0001_knowledge.sql") }) it("is declared by the manifest, so the migrate job finds it, and every table is row-level secured", () => { expect(knowledgeModule.migrations).toEqual({ postgres: "migrations" }) expect(knowledgeModule.profiles).toEqual(["postgres"]) const sql = readFileSync(new URL("../migrations/0001_knowledge.sql", import.meta.url), "utf8") for (const table of ["knowledge_collection", "knowledge_document", "knowledge_config"]) { expect(sql).toContain(`create table "${table}"`) expect(sql).toContain(`alter table "${table}" force row level security`) } }) })