MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / validateForeignKey

Function validateForeignKey

packages/core/fumadb/src/schema/validate.ts:19–39  ·  view source on GitHub ↗
(key: ForeignKey)

Source from the content-addressed store, hash-verified

17 const tables = Object.values(schema.tables);
18
19 function validateForeignKey(key: ForeignKey) {
20 if (
21 key.table === key.referencedTable &&
22 (key.onUpdate !== "RESTRICT" || key.onDelete !== "RESTRICT")
23 ) {
24 throw new Error(
25 `[${key.name}] Due to the limitations of MSSQL & Prisma MongoDB, you cannot specify other foreign key actions than "RESTRICT" for self-referencing foreign keys.`
26 );
27 }
28
29 for (const col of key.columns) {
30 if (
31 !col.isNullable &&
32 (key.onUpdate === "SET NULL" || key.onDelete === "SET NULL")
33 ) {
34 throw new Error(
35 `[${key.name}] You are using "SET NULL" as foreign key action, but some columns are non-nullable.`
36 );
37 }
38 }
39 }
40
41 function isCompositeColumnsUnique(table: AnyTable, columns: AnyColumn[]) {
42 if (columns.length === 1 && columns[0] instanceof IdColumn) return true;

Callers 1

validateSchemaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected