@prisma-next/target-postgres 0.4.1 → 0.5.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codec-ids-CojIXVf9.mjs +29 -0
- package/dist/codec-ids-CojIXVf9.mjs.map +1 -0
- package/dist/codec-ids.d.mts +28 -0
- package/dist/codec-ids.d.mts.map +1 -0
- package/dist/codec-ids.mjs +3 -0
- package/dist/codec-types.d.mts +42 -0
- package/dist/codec-types.d.mts.map +1 -0
- package/dist/codec-types.mjs +3 -0
- package/dist/codecs-BoahtY_Q.mjs +385 -0
- package/dist/codecs-BoahtY_Q.mjs.map +1 -0
- package/dist/codecs-D-F2KJqt.d.mts +299 -0
- package/dist/codecs-D-F2KJqt.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -0
- package/dist/codecs.mjs +3 -0
- package/dist/control.d.mts +1 -1
- package/dist/control.mjs +9 -1982
- package/dist/control.mjs.map +1 -1
- package/dist/data-transform-CxFRBIUp.d.mts +32 -0
- package/dist/data-transform-CxFRBIUp.d.mts.map +1 -0
- package/dist/data-transform-VfEGzXWt.mjs +39 -0
- package/dist/data-transform-VfEGzXWt.mjs.map +1 -0
- package/dist/data-transform.d.mts +2 -0
- package/dist/data-transform.mjs +3 -0
- package/dist/default-normalizer-DNOpRoOF.mjs +131 -0
- package/dist/default-normalizer-DNOpRoOF.mjs.map +1 -0
- package/dist/default-normalizer.d.mts +19 -0
- package/dist/default-normalizer.d.mts.map +1 -0
- package/dist/default-normalizer.mjs +3 -0
- package/dist/{descriptor-meta-DkvCmY98.mjs → descriptor-meta-BVoVtyp-.mjs} +1 -1
- package/dist/{descriptor-meta-DkvCmY98.mjs.map → descriptor-meta-BVoVtyp-.mjs.map} +1 -1
- package/dist/errors-AFvEPZ1R.mjs +34 -0
- package/dist/errors-AFvEPZ1R.mjs.map +1 -0
- package/dist/errors.d.mts +27 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +3 -0
- package/dist/issue-planner-CFjB0_oO.mjs +879 -0
- package/dist/issue-planner-CFjB0_oO.mjs.map +1 -0
- package/dist/issue-planner.d.mts +85 -0
- package/dist/issue-planner.d.mts.map +1 -0
- package/dist/issue-planner.mjs +3 -0
- package/dist/migration.d.mts +5 -79
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +6 -428
- package/dist/migration.mjs.map +1 -1
- package/dist/native-type-normalizer-CInai_oY.mjs +38 -0
- package/dist/native-type-normalizer-CInai_oY.mjs.map +1 -0
- package/dist/native-type-normalizer.d.mts +18 -0
- package/dist/native-type-normalizer.d.mts.map +1 -0
- package/dist/native-type-normalizer.mjs +3 -0
- package/dist/op-factory-call-BKlruaiC.mjs +605 -0
- package/dist/op-factory-call-BKlruaiC.mjs.map +1 -0
- package/dist/op-factory-call-C3bWXKSP.d.mts +304 -0
- package/dist/op-factory-call-C3bWXKSP.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +3 -0
- package/dist/op-factory-call.mjs +3 -0
- package/dist/pack.d.mts +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-CLUvVhUN.mjs +98 -0
- package/dist/planner-CLUvVhUN.mjs.map +1 -0
- package/dist/planner-ddl-builders-Dxvw1LHw.mjs +132 -0
- package/dist/planner-ddl-builders-Dxvw1LHw.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +22 -0
- package/dist/planner-ddl-builders.d.mts.map +1 -0
- package/dist/planner-ddl-builders.mjs +3 -0
- package/dist/planner-identity-values-Dju-o5GF.mjs +91 -0
- package/dist/planner-identity-values-Dju-o5GF.mjs.map +1 -0
- package/dist/planner-identity-values.d.mts +20 -0
- package/dist/planner-identity-values.d.mts.map +1 -0
- package/dist/planner-identity-values.mjs +3 -0
- package/dist/planner-produced-postgres-migration-CRRTno6Z.d.mts +20 -0
- package/dist/planner-produced-postgres-migration-CRRTno6Z.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration-DSSPq8QS.mjs +33 -0
- package/dist/planner-produced-postgres-migration-DSSPq8QS.mjs.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +5 -0
- package/dist/planner-produced-postgres-migration.mjs +3 -0
- package/dist/planner-schema-lookup-B7lkypwn.mjs +29 -0
- package/dist/planner-schema-lookup-B7lkypwn.mjs.map +1 -0
- package/dist/planner-schema-lookup.d.mts +22 -0
- package/dist/planner-schema-lookup.d.mts.map +1 -0
- package/dist/planner-schema-lookup.mjs +3 -0
- package/dist/planner-sql-checks-7jkgm9TX.mjs +241 -0
- package/dist/planner-sql-checks-7jkgm9TX.mjs.map +1 -0
- package/dist/planner-sql-checks.d.mts +55 -0
- package/dist/planner-sql-checks.d.mts.map +1 -0
- package/dist/planner-sql-checks.mjs +3 -0
- package/dist/{planner-target-details-MXb3oeul.d.mts → planner-target-details-DH-azLu-.d.mts} +1 -1
- package/dist/{planner-target-details-MXb3oeul.d.mts.map → planner-target-details-DH-azLu-.d.mts.map} +1 -1
- package/dist/planner-target-details.d.mts +2 -0
- package/dist/planner-target-details.mjs +1 -0
- package/dist/planner.d.mts +68 -0
- package/dist/planner.d.mts.map +1 -0
- package/dist/planner.mjs +4 -0
- package/dist/postgres-migration-BjA3Zmts.d.mts +50 -0
- package/dist/postgres-migration-BjA3Zmts.d.mts.map +1 -0
- package/dist/postgres-migration-qtmtbONe.mjs +52 -0
- package/dist/postgres-migration-qtmtbONe.mjs.map +1 -0
- package/dist/render-ops-D6_DHdOK.mjs +8 -0
- package/dist/render-ops-D6_DHdOK.mjs.map +1 -0
- package/dist/render-ops.d.mts +11 -0
- package/dist/render-ops.d.mts.map +1 -0
- package/dist/render-ops.mjs +3 -0
- package/dist/render-typescript-1rF_SB4g.mjs +85 -0
- package/dist/render-typescript-1rF_SB4g.mjs.map +1 -0
- package/dist/render-typescript.d.mts +15 -0
- package/dist/render-typescript.d.mts.map +1 -0
- package/dist/render-typescript.mjs +3 -0
- package/dist/runtime.d.mts +15 -3
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +10 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/shared-Bxkt8pNO.d.mts +41 -0
- package/dist/shared-Bxkt8pNO.d.mts.map +1 -0
- package/dist/sql-utils-r-Lw535w.mjs +76 -0
- package/dist/sql-utils-r-Lw535w.mjs.map +1 -0
- package/dist/sql-utils.d.mts +59 -0
- package/dist/sql-utils.d.mts.map +1 -0
- package/dist/sql-utils.mjs +3 -0
- package/dist/statement-builders-BPnmt6wx.mjs +116 -0
- package/dist/statement-builders-BPnmt6wx.mjs.map +1 -0
- package/dist/statement-builders.d.mts +23 -0
- package/dist/statement-builders.d.mts.map +1 -0
- package/dist/statement-builders.mjs +3 -0
- package/dist/tables-BmdW_FWO.mjs +477 -0
- package/dist/tables-BmdW_FWO.mjs.map +1 -0
- package/dist/types-ClK03Ojd.d.mts +10 -0
- package/dist/types-ClK03Ojd.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +37 -20
- package/src/core/codec-ids.ts +30 -0
- package/src/core/codecs.ts +645 -0
- package/src/core/default-normalizer.ts +131 -0
- package/src/core/descriptor-meta.ts +1 -1
- package/src/core/errors.ts +33 -0
- package/src/core/json-schema-type-expression.ts +131 -0
- package/src/core/migrations/op-factory-call.ts +1 -5
- package/src/core/migrations/operations/columns.ts +1 -1
- package/src/core/migrations/operations/constraints.ts +1 -1
- package/src/core/migrations/operations/data-transform.ts +27 -21
- package/src/core/migrations/operations/dependencies.ts +1 -1
- package/src/core/migrations/operations/enums.ts +1 -1
- package/src/core/migrations/operations/indexes.ts +1 -1
- package/src/core/migrations/operations/shared.ts +1 -1
- package/src/core/migrations/operations/tables.ts +1 -1
- package/src/core/migrations/planner-ddl-builders.ts +1 -1
- package/src/core/migrations/planner-recipes.ts +1 -1
- package/src/core/migrations/planner-sql-checks.ts +1 -1
- package/src/core/migrations/planner.ts +2 -4
- package/src/core/migrations/postgres-migration.ts +54 -1
- package/src/core/migrations/render-typescript.ts +22 -12
- package/src/core/migrations/runner.ts +2 -4
- package/src/core/native-type-normalizer.ts +49 -0
- package/src/core/sql-utils.ts +104 -0
- package/src/exports/codec-ids.ts +1 -0
- package/src/exports/codec-types.ts +51 -0
- package/src/exports/codecs.ts +2 -0
- package/src/exports/data-transform.ts +1 -0
- package/src/exports/default-normalizer.ts +1 -0
- package/src/exports/errors.ts +1 -0
- package/src/exports/issue-planner.ts +1 -0
- package/src/exports/migration.ts +6 -0
- package/src/exports/native-type-normalizer.ts +1 -0
- package/src/exports/op-factory-call.ts +25 -0
- package/src/exports/planner-ddl-builders.ts +8 -0
- package/src/exports/planner-identity-values.ts +1 -0
- package/src/exports/planner-produced-postgres-migration.ts +1 -0
- package/src/exports/planner-schema-lookup.ts +6 -0
- package/src/exports/planner-sql-checks.ts +11 -0
- package/src/exports/planner-target-details.ts +1 -0
- package/src/exports/planner.ts +1 -0
- package/src/exports/render-ops.ts +1 -0
- package/src/exports/render-typescript.ts +1 -0
- package/src/exports/runtime.ts +19 -4
- package/src/exports/sql-utils.ts +7 -0
- package/src/exports/statement-builders.ts +7 -0
- package/src/exports/types.ts +1 -0
- package/dist/postgres-migration-BsHJHV9O.mjs +0 -2793
- package/dist/postgres-migration-BsHJHV9O.mjs.map +0 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
2
|
+
|
|
3
|
+
//#region src/core/migrations/planner-identity-values.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the identity value (monoid neutral element) as a SQL literal for a column's type.
|
|
6
|
+
* Checks codec hooks first (extensions can provide type-specific identity values),
|
|
7
|
+
* then falls back to the built-in map.
|
|
8
|
+
*/
|
|
9
|
+
function resolveIdentityValue(column, codecHooks, storageTypes = {}) {
|
|
10
|
+
const referencedType = column.typeRef ? storageTypes[column.typeRef] : void 0;
|
|
11
|
+
const codecId = referencedType?.codecId ?? column.codecId;
|
|
12
|
+
const nativeType = referencedType?.nativeType ?? column.nativeType;
|
|
13
|
+
const typeParams = referencedType?.typeParams ?? column.typeParams;
|
|
14
|
+
if (codecId) {
|
|
15
|
+
const hookDefault = codecHooks.get(codecId)?.resolveIdentityValue?.({
|
|
16
|
+
nativeType,
|
|
17
|
+
codecId,
|
|
18
|
+
...ifDefined("typeParams", typeParams)
|
|
19
|
+
});
|
|
20
|
+
if (hookDefault !== void 0) return hookDefault;
|
|
21
|
+
}
|
|
22
|
+
return buildBuiltinIdentityValue(nativeType, typeParams);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns the built-in identity value (monoid neutral element) as a SQL literal for the given
|
|
26
|
+
* PostgreSQL native type — e.g. 0 for integers, '' for text, false for booleans.
|
|
27
|
+
*
|
|
28
|
+
* This is the planner's fallback when no codec hook provides a type-specific identity value.
|
|
29
|
+
*
|
|
30
|
+
* Returns null for unrecognized types (for example enums and extension-owned types without a
|
|
31
|
+
* hook), which causes the planner to fall back to the empty-table precheck.
|
|
32
|
+
*
|
|
33
|
+
* @internal Exported for testing only.
|
|
34
|
+
*/
|
|
35
|
+
function buildBuiltinIdentityValue(nativeType, typeParams) {
|
|
36
|
+
const normalizedNativeType = normalizeIdentityValueNativeType(nativeType);
|
|
37
|
+
if (normalizedNativeType.endsWith("[]")) return "'{}'";
|
|
38
|
+
switch (normalizedNativeType) {
|
|
39
|
+
case "text":
|
|
40
|
+
case "character":
|
|
41
|
+
case "bpchar":
|
|
42
|
+
case "character varying":
|
|
43
|
+
case "varchar": return "''";
|
|
44
|
+
case "int2":
|
|
45
|
+
case "int4":
|
|
46
|
+
case "int8":
|
|
47
|
+
case "integer":
|
|
48
|
+
case "bigint":
|
|
49
|
+
case "smallint":
|
|
50
|
+
case "float4":
|
|
51
|
+
case "float8":
|
|
52
|
+
case "real":
|
|
53
|
+
case "double precision":
|
|
54
|
+
case "numeric":
|
|
55
|
+
case "decimal": return "0";
|
|
56
|
+
case "bool":
|
|
57
|
+
case "boolean": return "false";
|
|
58
|
+
case "uuid": return "'00000000-0000-0000-0000-000000000000'";
|
|
59
|
+
case "json": return "'{}'::json";
|
|
60
|
+
case "jsonb": return "'{}'::jsonb";
|
|
61
|
+
case "date":
|
|
62
|
+
case "timestamp":
|
|
63
|
+
case "timestamptz":
|
|
64
|
+
case "timestamp with time zone":
|
|
65
|
+
case "timestamp without time zone": return "'epoch'";
|
|
66
|
+
case "time":
|
|
67
|
+
case "time without time zone": return "'00:00:00'";
|
|
68
|
+
case "timetz":
|
|
69
|
+
case "time with time zone": return "'00:00:00+00'";
|
|
70
|
+
case "interval": return "'0'";
|
|
71
|
+
case "bytea": return "''::bytea";
|
|
72
|
+
case "tsvector": return "''::tsvector";
|
|
73
|
+
case "bit": return buildBitIdentityValue(typeParams);
|
|
74
|
+
case "bit varying":
|
|
75
|
+
case "varbit": return "B''";
|
|
76
|
+
default: return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function normalizeIdentityValueNativeType(nativeType) {
|
|
80
|
+
return nativeType.trim().toLowerCase().replace(/\s+/g, " ");
|
|
81
|
+
}
|
|
82
|
+
function buildBitIdentityValue(typeParams) {
|
|
83
|
+
const length = typeParams?.["length"];
|
|
84
|
+
if (length === void 0) return "B'0'";
|
|
85
|
+
if (typeof length !== "number" || !Number.isInteger(length) || length <= 0) return null;
|
|
86
|
+
return `B'${"0".repeat(length)}'`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { resolveIdentityValue as n, buildBuiltinIdentityValue as t };
|
|
91
|
+
//# sourceMappingURL=planner-identity-values-Dju-o5GF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-identity-values-Dju-o5GF.mjs","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\n/**\n * Resolves the identity value (monoid neutral element) as a SQL literal for a column's type.\n * Checks codec hooks first (extensions can provide type-specific identity values),\n * then falls back to the built-in map.\n */\nexport function resolveIdentityValue(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance> = {},\n): string | null {\n const referencedType = column.typeRef ? storageTypes[column.typeRef] : undefined;\n const codecId = referencedType?.codecId ?? column.codecId;\n const nativeType = referencedType?.nativeType ?? column.nativeType;\n const typeParams = referencedType?.typeParams ?? column.typeParams;\n\n if (codecId) {\n const hookDefault = codecHooks.get(codecId)?.resolveIdentityValue?.({\n nativeType,\n codecId,\n ...ifDefined('typeParams', typeParams),\n });\n if (hookDefault !== undefined) {\n return hookDefault;\n }\n }\n\n return buildBuiltinIdentityValue(nativeType, typeParams);\n}\n\n/**\n * Returns the built-in identity value (monoid neutral element) as a SQL literal for the given\n * PostgreSQL native type — e.g. 0 for integers, '' for text, false for booleans.\n *\n * This is the planner's fallback when no codec hook provides a type-specific identity value.\n *\n * Returns null for unrecognized types (for example enums and extension-owned types without a\n * hook), which causes the planner to fall back to the empty-table precheck.\n *\n * @internal Exported for testing only.\n */\nexport function buildBuiltinIdentityValue(\n nativeType: string,\n typeParams?: Record<string, unknown>,\n): string | null {\n const normalizedNativeType = normalizeIdentityValueNativeType(nativeType);\n\n if (normalizedNativeType.endsWith('[]')) {\n return \"'{}'\";\n }\n\n switch (normalizedNativeType) {\n case 'text':\n case 'character':\n case 'bpchar':\n case 'character varying':\n case 'varchar':\n return \"''\";\n\n case 'int2':\n case 'int4':\n case 'int8':\n case 'integer':\n case 'bigint':\n case 'smallint':\n case 'float4':\n case 'float8':\n case 'real':\n case 'double precision':\n case 'numeric':\n case 'decimal':\n return '0';\n\n case 'bool':\n case 'boolean':\n return 'false';\n\n case 'uuid':\n return \"'00000000-0000-0000-0000-000000000000'\";\n\n case 'json':\n return \"'{}'::json\";\n case 'jsonb':\n return \"'{}'::jsonb\";\n\n case 'date':\n case 'timestamp':\n case 'timestamptz':\n case 'timestamp with time zone':\n case 'timestamp without time zone':\n return \"'epoch'\";\n\n case 'time':\n case 'time without time zone':\n return \"'00:00:00'\";\n case 'timetz':\n case 'time with time zone':\n return \"'00:00:00+00'\";\n\n case 'interval':\n return \"'0'\";\n\n case 'bytea':\n return \"''::bytea\";\n case 'tsvector':\n return \"''::tsvector\";\n\n case 'bit':\n return buildBitIdentityValue(typeParams);\n case 'bit varying':\n case 'varbit':\n return \"B''\";\n\n default:\n return null;\n }\n}\n\nfunction normalizeIdentityValueNativeType(nativeType: string): string {\n return nativeType.trim().toLowerCase().replace(/\\s+/g, ' ');\n}\n\nfunction buildBitIdentityValue(typeParams?: Record<string, unknown>): string | null {\n const length = typeParams?.['length'];\n if (length === undefined) {\n return \"B'0'\";\n }\n if (typeof length !== 'number' || !Number.isInteger(length) || length <= 0) {\n return null;\n }\n return `B'${'0'.repeat(length)}'`;\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,qBACd,QACA,YACA,eAAoD,EAAE,EACvC;CACf,MAAM,iBAAiB,OAAO,UAAU,aAAa,OAAO,WAAW;CACvE,MAAM,UAAU,gBAAgB,WAAW,OAAO;CAClD,MAAM,aAAa,gBAAgB,cAAc,OAAO;CACxD,MAAM,aAAa,gBAAgB,cAAc,OAAO;AAExD,KAAI,SAAS;EACX,MAAM,cAAc,WAAW,IAAI,QAAQ,EAAE,uBAAuB;GAClE;GACA;GACA,GAAG,UAAU,cAAc,WAAW;GACvC,CAAC;AACF,MAAI,gBAAgB,OAClB,QAAO;;AAIX,QAAO,0BAA0B,YAAY,WAAW;;;;;;;;;;;;;AAc1D,SAAgB,0BACd,YACA,YACe;CACf,MAAM,uBAAuB,iCAAiC,WAAW;AAEzE,KAAI,qBAAqB,SAAS,KAAK,CACrC,QAAO;AAGT,SAAQ,sBAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,UACH,QAAO;EAET,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,UACH,QAAO;EAET,KAAK;EACL,KAAK,UACH,QAAO;EAET,KAAK,OACH,QAAO;EAET,KAAK,OACH,QAAO;EACT,KAAK,QACH,QAAO;EAET,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,8BACH,QAAO;EAET,KAAK;EACL,KAAK,yBACH,QAAO;EACT,KAAK;EACL,KAAK,sBACH,QAAO;EAET,KAAK,WACH,QAAO;EAET,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EAET,KAAK,MACH,QAAO,sBAAsB,WAAW;EAC1C,KAAK;EACL,KAAK,SACH,QAAO;EAET,QACE,QAAO;;;AAIb,SAAS,iCAAiC,YAA4B;AACpE,QAAO,WAAW,MAAM,CAAC,aAAa,CAAC,QAAQ,QAAQ,IAAI;;AAG7D,SAAS,sBAAsB,YAAqD;CAClF,MAAM,SAAS,aAAa;AAC5B,KAAI,WAAW,OACb,QAAO;AAET,KAAI,OAAO,WAAW,YAAY,CAAC,OAAO,UAAU,OAAO,IAAI,UAAU,EACvE,QAAO;AAET,QAAO,KAAK,IAAI,OAAO,OAAO,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CodecControlHooks } from "@prisma-next/family-sql/control";
|
|
2
|
+
import { StorageColumn, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
3
|
+
|
|
4
|
+
//#region src/core/migrations/planner-identity-values.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the built-in identity value (monoid neutral element) as a SQL literal for the given
|
|
8
|
+
* PostgreSQL native type — e.g. 0 for integers, '' for text, false for booleans.
|
|
9
|
+
*
|
|
10
|
+
* This is the planner's fallback when no codec hook provides a type-specific identity value.
|
|
11
|
+
*
|
|
12
|
+
* Returns null for unrecognized types (for example enums and extension-owned types without a
|
|
13
|
+
* hook), which causes the planner to fall back to the empty-table precheck.
|
|
14
|
+
*
|
|
15
|
+
* @internal Exported for testing only.
|
|
16
|
+
*/
|
|
17
|
+
declare function buildBuiltinIdentityValue(nativeType: string, typeParams?: Record<string, unknown>): string | null;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { buildBuiltinIdentityValue };
|
|
20
|
+
//# sourceMappingURL=planner-identity-values.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-identity-values.d.mts","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;iBA4CgB,yBAAA,kCAED"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { t as PostgresPlanTargetDetails } from "./planner-target-details-DH-azLu-.mjs";
|
|
2
|
+
import { b as PostgresOpFactoryCall } from "./op-factory-call-C3bWXKSP.mjs";
|
|
3
|
+
import { t as PostgresMigration } from "./postgres-migration-BjA3Zmts.mjs";
|
|
4
|
+
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
5
|
+
import { MigrationPlanWithAuthoringSurface } from "@prisma-next/framework-components/control";
|
|
6
|
+
import { MigrationMeta } from "@prisma-next/migration-tools/migration";
|
|
7
|
+
|
|
8
|
+
//#region src/core/migrations/planner-produced-postgres-migration.d.ts
|
|
9
|
+
|
|
10
|
+
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
11
|
+
declare class TypeScriptRenderablePostgresMigration extends PostgresMigration implements MigrationPlanWithAuthoringSurface {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(calls: readonly PostgresOpFactoryCall[], meta: MigrationMeta);
|
|
14
|
+
get operations(): readonly Op[];
|
|
15
|
+
describe(): MigrationMeta;
|
|
16
|
+
renderTypeScript(): string;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { TypeScriptRenderablePostgresMigration as t };
|
|
20
|
+
//# sourceMappingURL=planner-produced-postgres-migration-CRRTno6Z.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-produced-postgres-migration-CRRTno6Z.d.mts","names":[],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAmCK,EAAA,GAAK,0BAA0B;cAEvB,qCAAA,SACH,iBAAA,YACG;;8BAKiB,+BAA+B;6BAMvB;cAIf"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as PostgresMigration } from "./postgres-migration-qtmtbONe.mjs";
|
|
2
|
+
import { t as renderOps } from "./render-ops-D6_DHdOK.mjs";
|
|
3
|
+
import { t as renderCallsToTypeScript } from "./render-typescript-1rF_SB4g.mjs";
|
|
4
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
5
|
+
|
|
6
|
+
//#region src/core/migrations/planner-produced-postgres-migration.ts
|
|
7
|
+
var TypeScriptRenderablePostgresMigration = class extends PostgresMigration {
|
|
8
|
+
#calls;
|
|
9
|
+
#meta;
|
|
10
|
+
constructor(calls, meta) {
|
|
11
|
+
super();
|
|
12
|
+
this.#calls = calls;
|
|
13
|
+
this.#meta = meta;
|
|
14
|
+
}
|
|
15
|
+
get operations() {
|
|
16
|
+
return renderOps(this.#calls);
|
|
17
|
+
}
|
|
18
|
+
describe() {
|
|
19
|
+
return this.#meta;
|
|
20
|
+
}
|
|
21
|
+
renderTypeScript() {
|
|
22
|
+
return renderCallsToTypeScript(this.#calls, {
|
|
23
|
+
from: this.#meta.from,
|
|
24
|
+
to: this.#meta.to,
|
|
25
|
+
...ifDefined("kind", this.#meta.kind),
|
|
26
|
+
...ifDefined("labels", this.#meta.labels)
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { TypeScriptRenderablePostgresMigration as t };
|
|
33
|
+
//# sourceMappingURL=planner-produced-postgres-migration-DSSPq8QS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-produced-postgres-migration-DSSPq8QS.mjs","names":["#calls","#meta"],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":["/**\n * Planner-produced Postgres migration.\n *\n * Returned by `PostgresMigrationPlanner.plan(...)` and `emptyMigration(...)`.\n * Holds the migration IR (`PostgresOpFactoryCall[]`) alongside\n * `MigrationMeta` and exposes both the runtime-ops view (`get operations`)\n * and the TypeScript authoring view (`renderTypeScript()`). Satisfies\n * `MigrationPlanWithAuthoringSurface` so the CLI can uniformly serialize any\n * planner result back to `migration.ts`.\n *\n * Extends the family-level `SqlMigration` alias rather than the target-local\n * migration base directly — mirrors Mongo's `PlannerProducedMongoMigration`\n * shape and keeps CLI wiring one step removed from target internals.\n *\n * Placeholder-bearing plans: `renderTypeScript()` always succeeds and embeds\n * `() => placeholder(\"slot\")` at each stub. `operations`, in contrast, is\n * _not safe to enumerate_ on a stub-bearing plan — `DataTransformCall.toOp()`\n * throws `PN-MIG-2001` because a planner-stubbed closure cannot be lowered\n * to a runtime op. Callers that know a plan may carry stubs must render to\n * `migration.ts`, let the user fill the slots, and re-load the edited\n * migration before enumerating ops. The walk-schema planner does not emit\n * `DataTransformCall`s today, so this asymmetry is invisible until the\n * issue-planner integration lands in Phase 2.\n */\n\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { MigrationPlanWithAuthoringSurface } from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\nimport { PostgresMigration } from './postgres-migration';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\nexport class TypeScriptRenderablePostgresMigration\n extends PostgresMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly PostgresOpFactoryCall[];\n readonly #meta: MigrationMeta;\n\n constructor(calls: readonly PostgresOpFactoryCall[], meta: MigrationMeta) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n }\n\n override get operations(): readonly Op[] {\n return renderOps(this.#calls);\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, {\n from: this.#meta.from,\n to: this.#meta.to,\n ...ifDefined('kind', this.#meta.kind),\n ...ifDefined('labels', this.#meta.labels),\n });\n }\n}\n"],"mappings":";;;;;;AAqCA,IAAa,wCAAb,cACU,kBAEV;CACE,CAASA;CACT,CAASC;CAET,YAAY,OAAyC,MAAqB;AACxE,SAAO;AACP,QAAKD,QAAS;AACd,QAAKC,OAAQ;;CAGf,IAAa,aAA4B;AACvC,SAAO,UAAU,MAAKD,MAAO;;CAG/B,AAAS,WAA0B;AACjC,SAAO,MAAKC;;CAGd,mBAA2B;AACzB,SAAO,wBAAwB,MAAKD,OAAQ;GAC1C,MAAM,MAAKC,KAAM;GACjB,IAAI,MAAKA,KAAM;GACf,GAAG,UAAU,QAAQ,MAAKA,KAAM,KAAK;GACrC,GAAG,UAAU,UAAU,MAAKA,KAAM,OAAO;GAC1C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "./shared-Bxkt8pNO.mjs";
|
|
2
|
+
import "./op-factory-call-C3bWXKSP.mjs";
|
|
3
|
+
import "./postgres-migration-BjA3Zmts.mjs";
|
|
4
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-CRRTno6Z.mjs";
|
|
5
|
+
export { TypeScriptRenderablePostgresMigration };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/core/migrations/planner-schema-lookup.ts
|
|
2
|
+
function buildSchemaLookupMap(schema) {
|
|
3
|
+
const map = /* @__PURE__ */ new Map();
|
|
4
|
+
for (const [tableName, table] of Object.entries(schema.tables)) map.set(tableName, buildSchemaTableLookup(table));
|
|
5
|
+
return map;
|
|
6
|
+
}
|
|
7
|
+
function buildSchemaTableLookup(table) {
|
|
8
|
+
return {
|
|
9
|
+
uniqueKeys: new Set(table.uniques.map((u) => u.columns.join(","))),
|
|
10
|
+
indexKeys: new Set(table.indexes.map((i) => i.columns.join(","))),
|
|
11
|
+
uniqueIndexKeys: new Set(table.indexes.filter((i) => i.unique).map((i) => i.columns.join(","))),
|
|
12
|
+
fkKeys: new Set(table.foreignKeys.map((fk) => `${fk.columns.join(",")}|${fk.referencedTable}|${fk.referencedColumns.join(",")}`))
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function hasUniqueConstraint(lookup, columns) {
|
|
16
|
+
const key = columns.join(",");
|
|
17
|
+
return lookup.uniqueKeys.has(key) || lookup.uniqueIndexKeys.has(key);
|
|
18
|
+
}
|
|
19
|
+
function hasIndex(lookup, columns) {
|
|
20
|
+
const key = columns.join(",");
|
|
21
|
+
return lookup.indexKeys.has(key) || lookup.uniqueKeys.has(key);
|
|
22
|
+
}
|
|
23
|
+
function hasForeignKey(lookup, fk) {
|
|
24
|
+
return lookup.fkKeys.has(`${fk.columns.join(",")}|${fk.references.table}|${fk.references.columns.join(",")}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { hasUniqueConstraint as i, hasForeignKey as n, hasIndex as r, buildSchemaLookupMap as t };
|
|
29
|
+
//# sourceMappingURL=planner-schema-lookup-B7lkypwn.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-schema-lookup-B7lkypwn.mjs","names":[],"sources":["../src/core/migrations/planner-schema-lookup.ts"],"sourcesContent":["import type { ForeignKey } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\n\n/**\n * Pre-computed lookup sets for a schema table's constraints.\n * Converts O(n*m) linear scans to O(1) Set lookups per constraint check.\n */\nexport interface SchemaTableLookup {\n readonly uniqueKeys: Set<string>;\n readonly indexKeys: Set<string>;\n readonly uniqueIndexKeys: Set<string>;\n readonly fkKeys: Set<string>;\n}\n\nexport function buildSchemaLookupMap(schema: SqlSchemaIR): ReadonlyMap<string, SchemaTableLookup> {\n const map = new Map<string, SchemaTableLookup>();\n for (const [tableName, table] of Object.entries(schema.tables)) {\n map.set(tableName, buildSchemaTableLookup(table));\n }\n return map;\n}\n\nfunction buildSchemaTableLookup(table: SqlSchemaIR['tables'][string]): SchemaTableLookup {\n const uniqueKeys = new Set(table.uniques.map((u) => u.columns.join(',')));\n const indexKeys = new Set(table.indexes.map((i) => i.columns.join(',')));\n const uniqueIndexKeys = new Set(\n table.indexes.filter((i) => i.unique).map((i) => i.columns.join(',')),\n );\n const fkKeys = new Set(\n table.foreignKeys.map(\n (fk) => `${fk.columns.join(',')}|${fk.referencedTable}|${fk.referencedColumns.join(',')}`,\n ),\n );\n return { uniqueKeys, indexKeys, uniqueIndexKeys, fkKeys };\n}\n\nexport function hasUniqueConstraint(\n lookup: SchemaTableLookup,\n columns: readonly string[],\n): boolean {\n const key = columns.join(',');\n return lookup.uniqueKeys.has(key) || lookup.uniqueIndexKeys.has(key);\n}\n\nexport function hasIndex(lookup: SchemaTableLookup, columns: readonly string[]): boolean {\n const key = columns.join(',');\n return lookup.indexKeys.has(key) || lookup.uniqueKeys.has(key);\n}\n\nexport function hasForeignKey(lookup: SchemaTableLookup, fk: ForeignKey): boolean {\n return lookup.fkKeys.has(\n `${fk.columns.join(',')}|${fk.references.table}|${fk.references.columns.join(',')}`,\n );\n}\n"],"mappings":";AAcA,SAAgB,qBAAqB,QAA6D;CAChG,MAAM,sBAAM,IAAI,KAAgC;AAChD,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,OAAO,OAAO,CAC5D,KAAI,IAAI,WAAW,uBAAuB,MAAM,CAAC;AAEnD,QAAO;;AAGT,SAAS,uBAAuB,OAAyD;AAWvF,QAAO;EAAE,YAVU,IAAI,IAAI,MAAM,QAAQ,KAAK,MAAM,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC;EAUpD,WATH,IAAI,IAAI,MAAM,QAAQ,KAAK,MAAM,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC;EASxC,iBARR,IAAI,IAC1B,MAAM,QAAQ,QAAQ,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,EAAE,QAAQ,KAAK,IAAI,CAAC,CACtE;EAMgD,QALlC,IAAI,IACjB,MAAM,YAAY,KACf,OAAO,GAAG,GAAG,QAAQ,KAAK,IAAI,CAAC,GAAG,GAAG,gBAAgB,GAAG,GAAG,kBAAkB,KAAK,IAAI,GACxF,CACF;EACwD;;AAG3D,SAAgB,oBACd,QACA,SACS;CACT,MAAM,MAAM,QAAQ,KAAK,IAAI;AAC7B,QAAO,OAAO,WAAW,IAAI,IAAI,IAAI,OAAO,gBAAgB,IAAI,IAAI;;AAGtE,SAAgB,SAAS,QAA2B,SAAqC;CACvF,MAAM,MAAM,QAAQ,KAAK,IAAI;AAC7B,QAAO,OAAO,UAAU,IAAI,IAAI,IAAI,OAAO,WAAW,IAAI,IAAI;;AAGhE,SAAgB,cAAc,QAA2B,IAAyB;AAChF,QAAO,OAAO,OAAO,IACnB,GAAG,GAAG,QAAQ,KAAK,IAAI,CAAC,GAAG,GAAG,WAAW,MAAM,GAAG,GAAG,WAAW,QAAQ,KAAK,IAAI,GAClF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ForeignKey } from "@prisma-next/sql-contract/types";
|
|
2
|
+
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
3
|
+
|
|
4
|
+
//#region src/core/migrations/planner-schema-lookup.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Pre-computed lookup sets for a schema table's constraints.
|
|
8
|
+
* Converts O(n*m) linear scans to O(1) Set lookups per constraint check.
|
|
9
|
+
*/
|
|
10
|
+
interface SchemaTableLookup {
|
|
11
|
+
readonly uniqueKeys: Set<string>;
|
|
12
|
+
readonly indexKeys: Set<string>;
|
|
13
|
+
readonly uniqueIndexKeys: Set<string>;
|
|
14
|
+
readonly fkKeys: Set<string>;
|
|
15
|
+
}
|
|
16
|
+
declare function buildSchemaLookupMap(schema: SqlSchemaIR): ReadonlyMap<string, SchemaTableLookup>;
|
|
17
|
+
declare function hasUniqueConstraint(lookup: SchemaTableLookup, columns: readonly string[]): boolean;
|
|
18
|
+
declare function hasIndex(lookup: SchemaTableLookup, columns: readonly string[]): boolean;
|
|
19
|
+
declare function hasForeignKey(lookup: SchemaTableLookup, fk: ForeignKey): boolean;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { buildSchemaLookupMap, hasForeignKey, hasIndex, hasUniqueConstraint };
|
|
22
|
+
//# sourceMappingURL=planner-schema-lookup.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-schema-lookup.d.mts","names":[],"sources":["../src/core/migrations/planner-schema-lookup.ts"],"sourcesContent":[],"mappings":";;;;;;;AAOA;;AAEsB,UAFL,iBAAA,CAEK;EACM,SAAA,UAAA,EAFL,GAEK,CAAA,MAAA,CAAA;EACT,SAAA,SAAA,EAFG,GAEH,CAAA,MAAA,CAAA;EAAG,SAAA,eAAA,EADM,GACN,CAAA,MAAA,CAAA;EAGN,SAAA,MAAA,EAHG,GAGH,CAAA,MAAoB,CAAA;;AAA2C,iBAA/D,oBAAA,CAA+D,MAAA,EAAlC,WAAkC,CAAA,EAApB,WAAoB,CAAA,MAAA,EAAA,iBAAA,CAAA;AAApB,iBAsB3C,mBAAA,CAtB2C,MAAA,EAuBjD,iBAvBiD,EAAA,OAAA,EAAA,SAAA,MAAA,EAAA,CAAA,EAAA,OAAA;AAAW,iBA8BtD,QAAA,CA9BsD,MAAA,EA8BrC,iBA9BqC,EAAA,OAAA,EAAA,SAAA,MAAA,EAAA,CAAA,EAAA,OAAA;AAsBtD,iBAaA,aAAA,CAZN,MAAA,EAY4B,iBAZX,EAAA,EAAA,EAYkC,UAZlC,CAAA,EAAA,OAAA"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-r-Lw535w.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/migrations/planner-type-resolution.ts
|
|
4
|
+
function resolveColumnTypeMetadata(column, storageTypes) {
|
|
5
|
+
if (!column.typeRef) return column;
|
|
6
|
+
const referencedType = storageTypes[column.typeRef];
|
|
7
|
+
if (!referencedType) return column;
|
|
8
|
+
return {
|
|
9
|
+
codecId: referencedType.codecId,
|
|
10
|
+
nativeType: referencedType.nativeType,
|
|
11
|
+
typeParams: referencedType.typeParams
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/core/migrations/planner-sql-checks.ts
|
|
17
|
+
function qualifyTableName(schema, table) {
|
|
18
|
+
return `${quoteIdentifier(schema)}.${quoteIdentifier(table)}`;
|
|
19
|
+
}
|
|
20
|
+
function toRegclassLiteral(schema, name) {
|
|
21
|
+
return `'${escapeLiteral(`${quoteIdentifier(schema)}.${quoteIdentifier(name)}`)}'`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* When `table` is omitted the check matches by name + schema across all tables.
|
|
25
|
+
* Pass `table` to scope the check to a single table (prevents false matches on
|
|
26
|
+
* identically-named constraints in different tables).
|
|
27
|
+
*/
|
|
28
|
+
function constraintExistsCheck({ constraintName, schema, table, exists = true }) {
|
|
29
|
+
const existsClause = exists ? "EXISTS" : "NOT EXISTS";
|
|
30
|
+
const tableFilter = table ? `AND c.conrelid = to_regclass(${toRegclassLiteral(schema, table)})` : "";
|
|
31
|
+
return `SELECT ${existsClause} (
|
|
32
|
+
SELECT 1 FROM pg_constraint c
|
|
33
|
+
JOIN pg_namespace n ON c.connamespace = n.oid
|
|
34
|
+
WHERE c.conname = '${escapeLiteral(constraintName)}'
|
|
35
|
+
AND n.nspname = '${escapeLiteral(schema)}'
|
|
36
|
+
${tableFilter}
|
|
37
|
+
)`;
|
|
38
|
+
}
|
|
39
|
+
function columnExistsCheck({ schema, table, column, exists = true }) {
|
|
40
|
+
return `SELECT ${exists ? "" : "NOT "}EXISTS (
|
|
41
|
+
SELECT 1
|
|
42
|
+
FROM information_schema.columns
|
|
43
|
+
WHERE table_schema = '${escapeLiteral(schema)}'
|
|
44
|
+
AND table_name = '${escapeLiteral(table)}'
|
|
45
|
+
AND column_name = '${escapeLiteral(column)}'
|
|
46
|
+
)`;
|
|
47
|
+
}
|
|
48
|
+
function columnNullabilityCheck({ schema, table, column, nullable }) {
|
|
49
|
+
const expected = nullable ? "YES" : "NO";
|
|
50
|
+
return `SELECT EXISTS (
|
|
51
|
+
SELECT 1
|
|
52
|
+
FROM information_schema.columns
|
|
53
|
+
WHERE table_schema = '${escapeLiteral(schema)}'
|
|
54
|
+
AND table_name = '${escapeLiteral(table)}'
|
|
55
|
+
AND column_name = '${escapeLiteral(column)}'
|
|
56
|
+
AND is_nullable = '${expected}'
|
|
57
|
+
)`;
|
|
58
|
+
}
|
|
59
|
+
function tableIsEmptyCheck(qualifiedTableName) {
|
|
60
|
+
return `SELECT NOT EXISTS (SELECT 1 FROM ${qualifiedTableName} LIMIT 1)`;
|
|
61
|
+
}
|
|
62
|
+
function columnHasNoDefaultCheck(opts) {
|
|
63
|
+
return `SELECT NOT EXISTS (
|
|
64
|
+
SELECT 1
|
|
65
|
+
FROM information_schema.columns
|
|
66
|
+
WHERE table_schema = '${escapeLiteral(opts.schema)}'
|
|
67
|
+
AND table_name = '${escapeLiteral(opts.table)}'
|
|
68
|
+
AND column_name = '${escapeLiteral(opts.column)}'
|
|
69
|
+
AND column_default IS NOT NULL
|
|
70
|
+
)`;
|
|
71
|
+
}
|
|
72
|
+
const FORMAT_TYPE_DISPLAY = new Map([
|
|
73
|
+
["int2", "smallint"],
|
|
74
|
+
["int4", "integer"],
|
|
75
|
+
["int8", "bigint"],
|
|
76
|
+
["float4", "real"],
|
|
77
|
+
["float8", "double precision"],
|
|
78
|
+
["bool", "boolean"],
|
|
79
|
+
["timestamp", "timestamp without time zone"],
|
|
80
|
+
["timestamptz", "timestamp with time zone"],
|
|
81
|
+
["time", "time without time zone"],
|
|
82
|
+
["timetz", "time with time zone"]
|
|
83
|
+
]);
|
|
84
|
+
const UNQUOTED_POSTGRES_IDENTIFIER_PATTERN = /^[a-z_][a-z0-9_$]*$/;
|
|
85
|
+
const POSTGRES_RESERVED_IDENTIFIER_WORDS = new Set([
|
|
86
|
+
"all",
|
|
87
|
+
"analyse",
|
|
88
|
+
"analyze",
|
|
89
|
+
"and",
|
|
90
|
+
"any",
|
|
91
|
+
"array",
|
|
92
|
+
"as",
|
|
93
|
+
"asc",
|
|
94
|
+
"asymmetric",
|
|
95
|
+
"authorization",
|
|
96
|
+
"between",
|
|
97
|
+
"binary",
|
|
98
|
+
"both",
|
|
99
|
+
"case",
|
|
100
|
+
"cast",
|
|
101
|
+
"check",
|
|
102
|
+
"collate",
|
|
103
|
+
"column",
|
|
104
|
+
"constraint",
|
|
105
|
+
"create",
|
|
106
|
+
"current_catalog",
|
|
107
|
+
"current_date",
|
|
108
|
+
"current_role",
|
|
109
|
+
"current_time",
|
|
110
|
+
"current_timestamp",
|
|
111
|
+
"current_user",
|
|
112
|
+
"default",
|
|
113
|
+
"deferrable",
|
|
114
|
+
"desc",
|
|
115
|
+
"distinct",
|
|
116
|
+
"do",
|
|
117
|
+
"else",
|
|
118
|
+
"end",
|
|
119
|
+
"except",
|
|
120
|
+
"false",
|
|
121
|
+
"fetch",
|
|
122
|
+
"for",
|
|
123
|
+
"foreign",
|
|
124
|
+
"freeze",
|
|
125
|
+
"from",
|
|
126
|
+
"full",
|
|
127
|
+
"grant",
|
|
128
|
+
"group",
|
|
129
|
+
"having",
|
|
130
|
+
"ilike",
|
|
131
|
+
"in",
|
|
132
|
+
"initially",
|
|
133
|
+
"inner",
|
|
134
|
+
"intersect",
|
|
135
|
+
"into",
|
|
136
|
+
"is",
|
|
137
|
+
"isnull",
|
|
138
|
+
"join",
|
|
139
|
+
"lateral",
|
|
140
|
+
"leading",
|
|
141
|
+
"left",
|
|
142
|
+
"like",
|
|
143
|
+
"limit",
|
|
144
|
+
"localtime",
|
|
145
|
+
"localtimestamp",
|
|
146
|
+
"natural",
|
|
147
|
+
"not",
|
|
148
|
+
"notnull",
|
|
149
|
+
"null",
|
|
150
|
+
"offset",
|
|
151
|
+
"on",
|
|
152
|
+
"only",
|
|
153
|
+
"or",
|
|
154
|
+
"order",
|
|
155
|
+
"outer",
|
|
156
|
+
"overlaps",
|
|
157
|
+
"placing",
|
|
158
|
+
"primary",
|
|
159
|
+
"references",
|
|
160
|
+
"right",
|
|
161
|
+
"select",
|
|
162
|
+
"session_user",
|
|
163
|
+
"similar",
|
|
164
|
+
"some",
|
|
165
|
+
"symmetric",
|
|
166
|
+
"table",
|
|
167
|
+
"then",
|
|
168
|
+
"to",
|
|
169
|
+
"trailing",
|
|
170
|
+
"true",
|
|
171
|
+
"union",
|
|
172
|
+
"unique",
|
|
173
|
+
"user",
|
|
174
|
+
"using",
|
|
175
|
+
"variadic",
|
|
176
|
+
"verbose",
|
|
177
|
+
"when",
|
|
178
|
+
"where",
|
|
179
|
+
"window",
|
|
180
|
+
"with"
|
|
181
|
+
]);
|
|
182
|
+
function formatUserDefinedTypeName(identifier) {
|
|
183
|
+
if (UNQUOTED_POSTGRES_IDENTIFIER_PATTERN.test(identifier) && !POSTGRES_RESERVED_IDENTIFIER_WORDS.has(identifier)) return identifier;
|
|
184
|
+
return quoteIdentifier(identifier);
|
|
185
|
+
}
|
|
186
|
+
function buildExpectedFormatType(column, codecHooks, storageTypes = {}) {
|
|
187
|
+
const resolved = resolveColumnTypeMetadata(column, storageTypes);
|
|
188
|
+
if (resolved.typeParams && resolved.codecId) {
|
|
189
|
+
const hooks = codecHooks.get(resolved.codecId);
|
|
190
|
+
if (hooks?.expandNativeType) return hooks.expandNativeType({
|
|
191
|
+
nativeType: resolved.nativeType,
|
|
192
|
+
codecId: resolved.codecId,
|
|
193
|
+
typeParams: resolved.typeParams
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (column.typeRef) return formatUserDefinedTypeName(resolved.nativeType);
|
|
197
|
+
return FORMAT_TYPE_DISPLAY.get(resolved.nativeType) ?? resolved.nativeType;
|
|
198
|
+
}
|
|
199
|
+
function columnTypeCheck({ schema, table, column, expectedType }) {
|
|
200
|
+
return `SELECT EXISTS (
|
|
201
|
+
SELECT 1
|
|
202
|
+
FROM pg_attribute a
|
|
203
|
+
JOIN pg_class c ON c.oid = a.attrelid
|
|
204
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
205
|
+
WHERE n.nspname = '${escapeLiteral(schema)}'
|
|
206
|
+
AND c.relname = '${escapeLiteral(table)}'
|
|
207
|
+
AND a.attname = '${escapeLiteral(column)}'
|
|
208
|
+
AND format_type(a.atttypid, a.atttypmod) = '${escapeLiteral(expectedType)}'
|
|
209
|
+
AND NOT a.attisdropped
|
|
210
|
+
)`;
|
|
211
|
+
}
|
|
212
|
+
function columnDefaultExistsCheck({ schema, table, column, exists = true }) {
|
|
213
|
+
const nullCheck = exists ? "IS NOT NULL" : "IS NULL";
|
|
214
|
+
return `SELECT EXISTS (
|
|
215
|
+
SELECT 1
|
|
216
|
+
FROM information_schema.columns
|
|
217
|
+
WHERE table_schema = '${escapeLiteral(schema)}'
|
|
218
|
+
AND table_name = '${escapeLiteral(table)}'
|
|
219
|
+
AND column_name = '${escapeLiteral(column)}'
|
|
220
|
+
AND column_default ${nullCheck}
|
|
221
|
+
)`;
|
|
222
|
+
}
|
|
223
|
+
function tableHasPrimaryKeyCheck(schema, table, exists, constraintName) {
|
|
224
|
+
const comparison = exists ? "" : "NOT ";
|
|
225
|
+
const constraintFilter = constraintName ? `AND c2.relname = '${escapeLiteral(constraintName)}'` : "";
|
|
226
|
+
return `SELECT ${comparison}EXISTS (
|
|
227
|
+
SELECT 1
|
|
228
|
+
FROM pg_index i
|
|
229
|
+
JOIN pg_class c ON c.oid = i.indrelid
|
|
230
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
231
|
+
LEFT JOIN pg_class c2 ON c2.oid = i.indexrelid
|
|
232
|
+
WHERE n.nspname = '${escapeLiteral(schema)}'
|
|
233
|
+
AND c.relname = '${escapeLiteral(table)}'
|
|
234
|
+
AND i.indisprimary
|
|
235
|
+
${constraintFilter}
|
|
236
|
+
)`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
//#endregion
|
|
240
|
+
export { columnNullabilityCheck as a, qualifyTableName as c, toRegclassLiteral as d, resolveColumnTypeMetadata as f, columnHasNoDefaultCheck as i, tableHasPrimaryKeyCheck as l, columnDefaultExistsCheck as n, columnTypeCheck as o, columnExistsCheck as r, constraintExistsCheck as s, buildExpectedFormatType as t, tableIsEmptyCheck as u };
|
|
241
|
+
//# sourceMappingURL=planner-sql-checks-7jkgm9TX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-sql-checks-7jkgm9TX.mjs","names":["FORMAT_TYPE_DISPLAY: ReadonlyMap<string, string>"],"sources":["../src/core/migrations/planner-type-resolution.ts","../src/core/migrations/planner-sql-checks.ts"],"sourcesContent":["import type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';\n\nexport type ResolvedColumnTypeMetadata = Pick<\n StorageColumn,\n 'nativeType' | 'codecId' | 'typeParams'\n>;\n\nexport function resolveColumnTypeMetadata(\n column: StorageColumn,\n storageTypes: Record<string, StorageTypeInstance>,\n): ResolvedColumnTypeMetadata {\n if (!column.typeRef) {\n return column;\n }\n\n const referencedType = storageTypes[column.typeRef];\n if (!referencedType) {\n return column;\n }\n\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n typeParams: referencedType.typeParams,\n };\n}\n","import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\nexport function qualifyTableName(schema: string, table: string): string {\n return `${quoteIdentifier(schema)}.${quoteIdentifier(table)}`;\n}\n\nexport function toRegclassLiteral(schema: string, name: string): string {\n const regclass = `${quoteIdentifier(schema)}.${quoteIdentifier(name)}`;\n return `'${escapeLiteral(regclass)}'`;\n}\n\n/**\n * When `table` is omitted the check matches by name + schema across all tables.\n * Pass `table` to scope the check to a single table (prevents false matches on\n * identically-named constraints in different tables).\n */\nexport function constraintExistsCheck({\n constraintName,\n schema,\n table,\n exists = true,\n}: {\n constraintName: string;\n schema: string;\n table?: string;\n exists?: boolean;\n}): string {\n const existsClause = exists ? 'EXISTS' : 'NOT EXISTS';\n const tableFilter = table\n ? `AND c.conrelid = to_regclass(${toRegclassLiteral(schema, table)})`\n : '';\n return `SELECT ${existsClause} (\n SELECT 1 FROM pg_constraint c\n JOIN pg_namespace n ON c.connamespace = n.oid\n WHERE c.conname = '${escapeLiteral(constraintName)}'\n AND n.nspname = '${escapeLiteral(schema)}'\n ${tableFilter}\n)`;\n}\n\nexport function columnExistsCheck({\n schema,\n table,\n column,\n exists = true,\n}: {\n schema: string;\n table: string;\n column: string;\n exists?: boolean;\n}): string {\n const existsClause = exists ? '' : 'NOT ';\n return `SELECT ${existsClause}EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = '${escapeLiteral(schema)}'\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n)`;\n}\n\nexport function columnNullabilityCheck({\n schema,\n table,\n column,\n nullable,\n}: {\n schema: string;\n table: string;\n column: string;\n nullable: boolean;\n}): string {\n const expected = nullable ? 'YES' : 'NO';\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = '${escapeLiteral(schema)}'\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n AND is_nullable = '${expected}'\n)`;\n}\n\nexport function tableIsEmptyCheck(qualifiedTableName: string): string {\n return `SELECT NOT EXISTS (SELECT 1 FROM ${qualifiedTableName} LIMIT 1)`;\n}\n\nexport function columnHasNoDefaultCheck(opts: {\n schema: string;\n table: string;\n column: string;\n}): string {\n return `SELECT NOT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = '${escapeLiteral(opts.schema)}'\n AND table_name = '${escapeLiteral(opts.table)}'\n AND column_name = '${escapeLiteral(opts.column)}'\n AND column_default IS NOT NULL\n)`;\n}\n\nconst FORMAT_TYPE_DISPLAY: ReadonlyMap<string, string> = new Map([\n ['int2', 'smallint'],\n ['int4', 'integer'],\n ['int8', 'bigint'],\n ['float4', 'real'],\n ['float8', 'double precision'],\n ['bool', 'boolean'],\n ['timestamp', 'timestamp without time zone'],\n ['timestamptz', 'timestamp with time zone'],\n ['time', 'time without time zone'],\n ['timetz', 'time with time zone'],\n]);\n\nconst UNQUOTED_POSTGRES_IDENTIFIER_PATTERN = /^[a-z_][a-z0-9_$]*$/;\n\nconst POSTGRES_RESERVED_IDENTIFIER_WORDS = new Set([\n 'all',\n 'analyse',\n 'analyze',\n 'and',\n 'any',\n 'array',\n 'as',\n 'asc',\n 'asymmetric',\n 'authorization',\n 'between',\n 'binary',\n 'both',\n 'case',\n 'cast',\n 'check',\n 'collate',\n 'column',\n 'constraint',\n 'create',\n 'current_catalog',\n 'current_date',\n 'current_role',\n 'current_time',\n 'current_timestamp',\n 'current_user',\n 'default',\n 'deferrable',\n 'desc',\n 'distinct',\n 'do',\n 'else',\n 'end',\n 'except',\n 'false',\n 'fetch',\n 'for',\n 'foreign',\n 'freeze',\n 'from',\n 'full',\n 'grant',\n 'group',\n 'having',\n 'ilike',\n 'in',\n 'initially',\n 'inner',\n 'intersect',\n 'into',\n 'is',\n 'isnull',\n 'join',\n 'lateral',\n 'leading',\n 'left',\n 'like',\n 'limit',\n 'localtime',\n 'localtimestamp',\n 'natural',\n 'not',\n 'notnull',\n 'null',\n 'offset',\n 'on',\n 'only',\n 'or',\n 'order',\n 'outer',\n 'overlaps',\n 'placing',\n 'primary',\n 'references',\n 'right',\n 'select',\n 'session_user',\n 'similar',\n 'some',\n 'symmetric',\n 'table',\n 'then',\n 'to',\n 'trailing',\n 'true',\n 'union',\n 'unique',\n 'user',\n 'using',\n 'variadic',\n 'verbose',\n 'when',\n 'where',\n 'window',\n 'with',\n]);\n\nfunction formatUserDefinedTypeName(identifier: string): string {\n if (\n UNQUOTED_POSTGRES_IDENTIFIER_PATTERN.test(identifier) &&\n !POSTGRES_RESERVED_IDENTIFIER_WORDS.has(identifier)\n ) {\n return identifier;\n }\n\n return quoteIdentifier(identifier);\n}\n\nexport function buildExpectedFormatType(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance> = {},\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n\n if (resolved.typeParams && resolved.codecId) {\n const hooks = codecHooks.get(resolved.codecId);\n if (hooks?.expandNativeType) {\n return hooks.expandNativeType({\n nativeType: resolved.nativeType,\n codecId: resolved.codecId,\n typeParams: resolved.typeParams,\n });\n }\n }\n\n if (column.typeRef) {\n return formatUserDefinedTypeName(resolved.nativeType);\n }\n\n return FORMAT_TYPE_DISPLAY.get(resolved.nativeType) ?? resolved.nativeType;\n}\n\nexport function columnTypeCheck({\n schema,\n table,\n column,\n expectedType,\n}: {\n schema: string;\n table: string;\n column: string;\n expectedType: string;\n}): string {\n return `SELECT EXISTS (\n SELECT 1\n FROM pg_attribute a\n JOIN pg_class c ON c.oid = a.attrelid\n JOIN pg_namespace n ON n.oid = c.relnamespace\n WHERE n.nspname = '${escapeLiteral(schema)}'\n AND c.relname = '${escapeLiteral(table)}'\n AND a.attname = '${escapeLiteral(column)}'\n AND format_type(a.atttypid, a.atttypmod) = '${escapeLiteral(expectedType)}'\n AND NOT a.attisdropped\n)`;\n}\n\nexport function columnDefaultExistsCheck({\n schema,\n table,\n column,\n exists = true,\n}: {\n schema: string;\n table: string;\n column: string;\n exists?: boolean;\n}): string {\n const nullCheck = exists ? 'IS NOT NULL' : 'IS NULL';\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = '${escapeLiteral(schema)}'\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n AND column_default ${nullCheck}\n)`;\n}\n\nexport function tableHasPrimaryKeyCheck(\n schema: string,\n table: string,\n exists: boolean,\n constraintName?: string,\n): string {\n const comparison = exists ? '' : 'NOT ';\n const constraintFilter = constraintName\n ? `AND c2.relname = '${escapeLiteral(constraintName)}'`\n : '';\n return `SELECT ${comparison}EXISTS (\n SELECT 1\n FROM pg_index i\n JOIN pg_class c ON c.oid = i.indrelid\n JOIN pg_namespace n ON n.oid = c.relnamespace\n LEFT JOIN pg_class c2 ON c2.oid = i.indexrelid\n WHERE n.nspname = '${escapeLiteral(schema)}'\n AND c.relname = '${escapeLiteral(table)}'\n AND i.indisprimary\n ${constraintFilter}\n)`;\n}\n"],"mappings":";;;AAOA,SAAgB,0BACd,QACA,cAC4B;AAC5B,KAAI,CAAC,OAAO,QACV,QAAO;CAGT,MAAM,iBAAiB,aAAa,OAAO;AAC3C,KAAI,CAAC,eACH,QAAO;AAGT,QAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;EAC3B,YAAY,eAAe;EAC5B;;;;;ACnBH,SAAgB,iBAAiB,QAAgB,OAAuB;AACtE,QAAO,GAAG,gBAAgB,OAAO,CAAC,GAAG,gBAAgB,MAAM;;AAG7D,SAAgB,kBAAkB,QAAgB,MAAsB;AAEtE,QAAO,IAAI,cADM,GAAG,gBAAgB,OAAO,CAAC,GAAG,gBAAgB,KAAK,GAClC,CAAC;;;;;;;AAQrC,SAAgB,sBAAsB,EACpC,gBACA,QACA,OACA,SAAS,QAMA;CACT,MAAM,eAAe,SAAS,WAAW;CACzC,MAAM,cAAc,QAChB,gCAAgC,kBAAkB,QAAQ,MAAM,CAAC,KACjE;AACJ,QAAO,UAAU,aAAa;;;uBAGT,cAAc,eAAe,CAAC;qBAChC,cAAc,OAAO,CAAC;IACvC,YAAY;;;AAIhB,SAAgB,kBAAkB,EAChC,QACA,OACA,QACA,SAAS,QAMA;AAET,QAAO,UADc,SAAS,KAAK,OACL;;;0BAGN,cAAc,OAAO,CAAC;wBACxB,cAAc,MAAM,CAAC;yBACpB,cAAc,OAAO,CAAC;;;AAI/C,SAAgB,uBAAuB,EACrC,QACA,OACA,QACA,YAMS;CACT,MAAM,WAAW,WAAW,QAAQ;AACpC,QAAO;;;0BAGiB,cAAc,OAAO,CAAC;wBACxB,cAAc,MAAM,CAAC;yBACpB,cAAc,OAAO,CAAC;yBACtB,SAAS;;;AAIlC,SAAgB,kBAAkB,oBAAoC;AACpE,QAAO,oCAAoC,mBAAmB;;AAGhE,SAAgB,wBAAwB,MAI7B;AACT,QAAO;;;0BAGiB,cAAc,KAAK,OAAO,CAAC;wBAC7B,cAAc,KAAK,MAAM,CAAC;yBACzB,cAAc,KAAK,OAAO,CAAC;;;;AAKpD,MAAMA,sBAAmD,IAAI,IAAI;CAC/D,CAAC,QAAQ,WAAW;CACpB,CAAC,QAAQ,UAAU;CACnB,CAAC,QAAQ,SAAS;CAClB,CAAC,UAAU,OAAO;CAClB,CAAC,UAAU,mBAAmB;CAC9B,CAAC,QAAQ,UAAU;CACnB,CAAC,aAAa,8BAA8B;CAC5C,CAAC,eAAe,2BAA2B;CAC3C,CAAC,QAAQ,yBAAyB;CAClC,CAAC,UAAU,sBAAsB;CAClC,CAAC;AAEF,MAAM,uCAAuC;AAE7C,MAAM,qCAAqC,IAAI,IAAI;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,0BAA0B,YAA4B;AAC7D,KACE,qCAAqC,KAAK,WAAW,IACrD,CAAC,mCAAmC,IAAI,WAAW,CAEnD,QAAO;AAGT,QAAO,gBAAgB,WAAW;;AAGpC,SAAgB,wBACd,QACA,YACA,eAAoD,EAAE,EAC9C;CACR,MAAM,WAAW,0BAA0B,QAAQ,aAAa;AAEhE,KAAI,SAAS,cAAc,SAAS,SAAS;EAC3C,MAAM,QAAQ,WAAW,IAAI,SAAS,QAAQ;AAC9C,MAAI,OAAO,iBACT,QAAO,MAAM,iBAAiB;GAC5B,YAAY,SAAS;GACrB,SAAS,SAAS;GAClB,YAAY,SAAS;GACtB,CAAC;;AAIN,KAAI,OAAO,QACT,QAAO,0BAA0B,SAAS,WAAW;AAGvD,QAAO,oBAAoB,IAAI,SAAS,WAAW,IAAI,SAAS;;AAGlE,SAAgB,gBAAgB,EAC9B,QACA,OACA,QACA,gBAMS;AACT,QAAO;;;;;uBAKc,cAAc,OAAO,CAAC;uBACtB,cAAc,MAAM,CAAC;uBACrB,cAAc,OAAO,CAAC;kDACK,cAAc,aAAa,CAAC;;;;AAK9E,SAAgB,yBAAyB,EACvC,QACA,OACA,QACA,SAAS,QAMA;CACT,MAAM,YAAY,SAAS,gBAAgB;AAC3C,QAAO;;;0BAGiB,cAAc,OAAO,CAAC;wBACxB,cAAc,MAAM,CAAC;yBACpB,cAAc,OAAO,CAAC;yBACtB,UAAU;;;AAInC,SAAgB,wBACd,QACA,OACA,QACA,gBACQ;CACR,MAAM,aAAa,SAAS,KAAK;CACjC,MAAM,mBAAmB,iBACrB,qBAAqB,cAAc,eAAe,CAAC,KACnD;AACJ,QAAO,UAAU,WAAW;;;;;;uBAMP,cAAc,OAAO,CAAC;uBACtB,cAAc,MAAM,CAAC;;MAEtC,iBAAiB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CodecControlHooks } from "@prisma-next/family-sql/control";
|
|
2
|
+
import { StorageColumn, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
3
|
+
|
|
4
|
+
//#region src/core/migrations/planner-sql-checks.d.ts
|
|
5
|
+
declare function qualifyTableName(schema: string, table: string): string;
|
|
6
|
+
declare function toRegclassLiteral(schema: string, name: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* When `table` is omitted the check matches by name + schema across all tables.
|
|
9
|
+
* Pass `table` to scope the check to a single table (prevents false matches on
|
|
10
|
+
* identically-named constraints in different tables).
|
|
11
|
+
*/
|
|
12
|
+
declare function constraintExistsCheck({
|
|
13
|
+
constraintName,
|
|
14
|
+
schema,
|
|
15
|
+
table,
|
|
16
|
+
exists
|
|
17
|
+
}: {
|
|
18
|
+
constraintName: string;
|
|
19
|
+
schema: string;
|
|
20
|
+
table?: string;
|
|
21
|
+
exists?: boolean;
|
|
22
|
+
}): string;
|
|
23
|
+
declare function columnExistsCheck({
|
|
24
|
+
schema,
|
|
25
|
+
table,
|
|
26
|
+
column,
|
|
27
|
+
exists
|
|
28
|
+
}: {
|
|
29
|
+
schema: string;
|
|
30
|
+
table: string;
|
|
31
|
+
column: string;
|
|
32
|
+
exists?: boolean;
|
|
33
|
+
}): string;
|
|
34
|
+
declare function columnNullabilityCheck({
|
|
35
|
+
schema,
|
|
36
|
+
table,
|
|
37
|
+
column,
|
|
38
|
+
nullable
|
|
39
|
+
}: {
|
|
40
|
+
schema: string;
|
|
41
|
+
table: string;
|
|
42
|
+
column: string;
|
|
43
|
+
nullable: boolean;
|
|
44
|
+
}): string;
|
|
45
|
+
declare function tableIsEmptyCheck(qualifiedTableName: string): string;
|
|
46
|
+
declare function columnHasNoDefaultCheck(opts: {
|
|
47
|
+
schema: string;
|
|
48
|
+
table: string;
|
|
49
|
+
column: string;
|
|
50
|
+
}): string;
|
|
51
|
+
declare function buildExpectedFormatType(column: StorageColumn, codecHooks: Map<string, CodecControlHooks>, storageTypes?: Record<string, StorageTypeInstance>): string;
|
|
52
|
+
declare function tableHasPrimaryKeyCheck(schema: string, table: string, exists: boolean, constraintName?: string): string;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { buildExpectedFormatType, columnExistsCheck, columnHasNoDefaultCheck, columnNullabilityCheck, constraintExistsCheck, qualifyTableName, tableHasPrimaryKeyCheck, tableIsEmptyCheck, toRegclassLiteral };
|
|
55
|
+
//# sourceMappingURL=planner-sql-checks.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-sql-checks.d.mts","names":[],"sources":["../src/core/migrations/planner-sql-checks.ts"],"sourcesContent":[],"mappings":";;;;iBAKgB,gBAAA;iBAIA,iBAAA;AAJhB;AAIA;AAUA;;;AAGE,iBAHc,qBAAA,CAGd;EAAA,cAAA;EAAA,MAAA;EAAA,KAAA;EAAA;CAAA,EAAA;EACA,cAAA,EAAA,MAAA;EAAa,MAAA,EAAA,MAAA;EAoBC,KAAA,CAAA,EAAA,MAAA;EACd,MAAA,CAAA,EAAA,OAAA;CACA,CAAA,EAAA,MAAA;AACA,iBAHc,iBAAA,CAGd;EAAA,MAAA;EAAA,KAAA;EAAA,MAAA;EAAA;CAAA,EAAA;EACA,MAAA,EAAA,MAAA;EAAa,KAAA,EAAA,MAAA;EAiBC,MAAA,EAAA,MAAA;EACd,MAAA,CAAA,EAAA,OAAA;CACA,CAAA,EAAA,MAAA;AACA,iBAHc,sBAAA,CAGd;EAAA,MAAA;EAAA,KAAA;EAAA,MAAA;EAAA;AAkKF,CAlKE,EAAA;EACA,MAAA,EAAA,MAAA;EAAQ,KAAA,EAAA,MAAA;EAkBM,MAAA,EAAA,MAAA;EAIA,QAAA,EAAA,OAAA;AA2IhB,CAAA,CAAA,EAAgB,MAAA;AACN,iBAhJM,iBAAA,CAgJN,kBAAA,EAAA,MAAA,CAAA,EAAA,MAAA;AACgB,iBA7IV,uBAAA,CA6IU,IAAA,EAAA;EAAZ,MAAA,EAAA,MAAA;EACiB,KAAA,EAAA,MAAA;EAAf,MAAA,EAAA,MAAA;CAAM,CAAA,EAAA,MAAA;AAoEN,iBAvEA,uBAAA,CAuEuB,MAAA,EAtE7B,aAsE6B,EAAA,UAAA,EArEzB,GAqEyB,CAAA,MAAA,EArEb,iBAqEa,CAAA,EAAA,YAAA,CAAA,EApEvB,MAoEuB,CAAA,MAAA,EApER,mBAoEQ,CAAA,CAAA,EAAA,MAAA;iBAAvB,uBAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as columnNullabilityCheck, c as qualifyTableName, d as toRegclassLiteral, i as columnHasNoDefaultCheck, l as tableHasPrimaryKeyCheck, r as columnExistsCheck, s as constraintExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-7jkgm9TX.mjs";
|
|
2
|
+
|
|
3
|
+
export { buildExpectedFormatType, columnExistsCheck, columnHasNoDefaultCheck, columnNullabilityCheck, constraintExistsCheck, qualifyTableName, tableHasPrimaryKeyCheck, tableIsEmptyCheck, toRegclassLiteral };
|
package/dist/{planner-target-details-MXb3oeul.d.mts.map → planner-target-details-DH-azLu-.d.mts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner-target-details-
|
|
1
|
+
{"version":3,"file":"planner-target-details-DH-azLu-.d.mts","names":[],"sources":["../src/core/migrations/planner-target-details.ts"],"sourcesContent":[],"mappings":";KAEY,cAAA;AAAA,UAUK,yBAAA,CAVS;EAUT,SAAA,MAAA,EAAA,MAAA;uBAEM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|