@prisma-next/target-postgres 0.5.0-dev.9 → 0.5.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 → codec-ids-C5qzBqus.mjs} +4 -4
- package/dist/{codec-ids-CojIXVf9.mjs.map → codec-ids-C5qzBqus.mjs.map} +1 -1
- package/dist/codec-ids-CplrEfmx.d.mts +29 -0
- package/dist/codec-ids-CplrEfmx.d.mts.map +1 -0
- package/dist/codec-ids.d.mts +2 -28
- package/dist/codec-ids.mjs +2 -3
- package/dist/codec-types-lrsb3N07.d.mts +79 -0
- package/dist/codec-types-lrsb3N07.d.mts.map +1 -0
- package/dist/codec-types.d.mts +2 -42
- package/dist/codec-types.mjs +1 -3
- package/dist/codecs-Cue97Xqf.d.mts +558 -0
- package/dist/codecs-Cue97Xqf.d.mts.map +1 -0
- package/dist/codecs.d.mts +13 -2
- package/dist/codecs.d.mts.map +1 -0
- package/dist/codecs.mjs +738 -2
- package/dist/codecs.mjs.map +1 -0
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +132 -96
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-VfEGzXWt.mjs → data-transform-DKWXdHuZ.mjs} +25 -7
- package/dist/data-transform-DKWXdHuZ.mjs.map +1 -0
- package/dist/data-transform-bIeAcZIJ.d.mts +38 -0
- package/dist/data-transform-bIeAcZIJ.d.mts.map +1 -0
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +2 -3
- package/dist/{default-normalizer-DNOpRoOF.mjs → default-normalizer-C8XyZj85.mjs} +2 -2
- package/dist/{default-normalizer-DNOpRoOF.mjs.map → default-normalizer-C8XyZj85.mjs.map} +1 -1
- package/dist/default-normalizer.d.mts +0 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +2 -3
- package/dist/descriptor-meta-Dde_BS3K.mjs +99 -0
- package/dist/descriptor-meta-Dde_BS3K.mjs.map +1 -0
- package/dist/{errors-AFvEPZ1R.mjs → errors-Chm2bKcS.mjs} +2 -3
- package/dist/{errors-AFvEPZ1R.mjs.map → errors-Chm2bKcS.mjs.map} +1 -1
- package/dist/errors.d.mts +0 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +2 -3
- package/dist/{issue-planner-CFjB0_oO.mjs → issue-planner-DQ6WJkad.mjs} +24 -91
- package/dist/issue-planner-DQ6WJkad.mjs.map +1 -0
- package/dist/issue-planner.d.mts +4 -7
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +2 -3
- package/dist/migration.d.mts +29 -5
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +5 -6
- package/dist/migration.mjs.map +1 -1
- package/dist/{native-type-normalizer-CInai_oY.mjs → native-type-normalizer-Cry4QoLf.mjs} +2 -2
- package/dist/native-type-normalizer-Cry4QoLf.mjs.map +1 -0
- package/dist/native-type-normalizer.d.mts.map +1 -1
- package/dist/native-type-normalizer.mjs +2 -3
- package/dist/{op-factory-call-BKlruaiC.mjs → op-factory-call-DeaFxa8_.mjs} +27 -10
- package/dist/op-factory-call-DeaFxa8_.mjs.map +1 -0
- package/dist/{op-factory-call-C3bWXKSP.d.mts → op-factory-call-UFpUPJL6.d.mts} +11 -8
- package/dist/op-factory-call-UFpUPJL6.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +1 -2
- package/dist/op-factory-call.mjs +2 -3
- package/dist/pack.d.mts +28 -9
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +2 -3
- package/dist/{planner-CLUvVhUN.mjs → planner-CYtKhLYa.mjs} +22 -16
- package/dist/planner-CYtKhLYa.mjs.map +1 -0
- package/dist/{planner-ddl-builders-Dxvw1LHw.mjs → planner-ddl-builders-CLB7Umhh.mjs} +4 -5
- package/dist/planner-ddl-builders-CLB7Umhh.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +1 -1
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +2 -3
- package/dist/{planner-identity-values-Dju-o5GF.mjs → planner-identity-values-DTx0gePL.mjs} +2 -3
- package/dist/{planner-identity-values-Dju-o5GF.mjs.map → planner-identity-values-DTx0gePL.mjs.map} +1 -1
- package/dist/planner-identity-values.d.mts +0 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +2 -3
- package/dist/{planner-produced-postgres-migration-CRRTno6Z.d.mts → planner-produced-postgres-migration-CjxWIVgh.d.mts} +11 -7
- package/dist/planner-produced-postgres-migration-CjxWIVgh.d.mts.map +1 -0
- package/dist/{planner-produced-postgres-migration-DSSPq8QS.mjs → planner-produced-postgres-migration-DphktB2N.mjs} +16 -8
- package/dist/planner-produced-postgres-migration-DphktB2N.mjs.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +1 -4
- package/dist/planner-produced-postgres-migration.mjs +2 -3
- package/dist/{planner-schema-lookup-B7lkypwn.mjs → planner-schema-lookup-B1ags8ys.mjs} +2 -2
- package/dist/{planner-schema-lookup-B7lkypwn.mjs.map → planner-schema-lookup-B1ags8ys.mjs.map} +1 -1
- package/dist/planner-schema-lookup.d.mts +0 -1
- package/dist/planner-schema-lookup.d.mts.map +1 -1
- package/dist/planner-schema-lookup.mjs +2 -3
- package/dist/{planner-sql-checks-7jkgm9TX.mjs → planner-sql-checks-DwZvGlV4.mjs} +3 -5
- package/dist/planner-sql-checks-DwZvGlV4.mjs.map +1 -0
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +2 -3
- package/dist/{planner-target-details-DH-azLu-.d.mts → planner-target-details-bVVcanWh.d.mts} +1 -1
- package/dist/planner-target-details-bVVcanWh.d.mts.map +1 -0
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner-target-details.mjs +1 -1
- package/dist/planner.d.mts +21 -12
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +2 -4
- package/dist/{postgres-migration-qtmtbONe.mjs → postgres-migration-Bkv140RW.mjs} +4 -5
- package/dist/postgres-migration-Bkv140RW.mjs.map +1 -0
- package/dist/{postgres-migration-BjA3Zmts.d.mts → postgres-migration-UkcHfZAA.d.mts} +6 -6
- package/dist/postgres-migration-UkcHfZAA.d.mts.map +1 -0
- package/dist/render-ops--1nnfNus.mjs +23 -0
- package/dist/render-ops--1nnfNus.mjs.map +1 -0
- package/dist/render-ops.d.mts +3 -4
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +2 -3
- package/dist/{render-typescript-1rF_SB4g.mjs → render-typescript-D3doH-vX.mjs} +2 -14
- package/dist/render-typescript-D3doH-vX.mjs.map +1 -0
- package/dist/render-typescript.d.mts +3 -6
- package/dist/render-typescript.d.mts.map +1 -1
- package/dist/render-typescript.mjs +2 -3
- package/dist/runtime.d.mts +5 -9
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +7 -14
- package/dist/runtime.mjs.map +1 -1
- package/dist/{shared-Bxkt8pNO.d.mts → shared-MpwjwAjM.d.mts} +2 -2
- package/dist/shared-MpwjwAjM.d.mts.map +1 -0
- package/dist/{sql-utils-r-Lw535w.mjs → sql-utils-CggjWNij.mjs} +4 -2
- package/dist/sql-utils-CggjWNij.mjs.map +1 -0
- package/dist/sql-utils.d.mts.map +1 -1
- package/dist/sql-utils.mjs +2 -3
- package/dist/{statement-builders-BPnmt6wx.mjs → statement-builders-BT889jV0.mjs} +28 -13
- package/dist/statement-builders-BT889jV0.mjs.map +1 -0
- package/dist/statement-builders.d.mts +31 -3
- package/dist/statement-builders.d.mts.map +1 -1
- package/dist/statement-builders.mjs +2 -3
- package/dist/{tables-BmdW_FWO.mjs → tables-DgYIXjUt.mjs} +53 -14
- package/dist/tables-DgYIXjUt.mjs.map +1 -0
- package/dist/{types-ClK03Ojd.d.mts → types-CTqpysRY.d.mts} +1 -1
- package/dist/types-CTqpysRY.d.mts.map +1 -0
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +1 -1
- package/package.json +21 -19
- package/src/core/authoring.ts +5 -11
- package/src/core/codec-helpers.ts +135 -0
- package/src/core/codec-ids.ts +1 -0
- package/src/core/codec-type-map.ts +81 -0
- package/src/core/codecs.ts +941 -547
- package/src/core/descriptor-meta.ts +1 -1
- package/src/core/migrations/issue-planner.ts +23 -35
- package/src/core/migrations/op-factory-call.ts +26 -5
- package/src/core/migrations/operations/data-transform.ts +86 -21
- package/src/core/migrations/operations/dependencies.ts +52 -0
- package/src/core/migrations/operations/indexes.ts +27 -2
- package/src/core/migrations/planner-produced-postgres-migration.ts +17 -5
- package/src/core/migrations/planner-strategies.ts +4 -86
- package/src/core/migrations/planner.ts +62 -20
- package/src/core/migrations/postgres-migration.ts +3 -6
- package/src/core/migrations/render-ops.ts +26 -3
- package/src/core/migrations/render-typescript.ts +5 -9
- package/src/core/migrations/runner.ts +172 -151
- package/src/core/migrations/statement-builders.ts +49 -10
- package/src/core/registry.ts +11 -0
- package/src/exports/codec-types.ts +4 -13
- package/src/exports/codecs.ts +49 -2
- package/src/exports/control.ts +0 -1
- package/src/exports/migration.ts +5 -1
- package/src/exports/runtime.ts +6 -11
- package/src/exports/statement-builders.ts +2 -1
- package/dist/codec-ids.d.mts.map +0 -1
- package/dist/codec-types.d.mts.map +0 -1
- package/dist/codecs-BQEm9_oo.d.mts +0 -319
- package/dist/codecs-BQEm9_oo.d.mts.map +0 -1
- package/dist/codecs-BoahtY_Q.mjs +0 -385
- package/dist/codecs-BoahtY_Q.mjs.map +0 -1
- package/dist/data-transform-CxFRBIUp.d.mts +0 -32
- package/dist/data-transform-CxFRBIUp.d.mts.map +0 -1
- package/dist/data-transform-VfEGzXWt.mjs.map +0 -1
- package/dist/descriptor-meta-BVoVtyp-.mjs +0 -120
- package/dist/descriptor-meta-BVoVtyp-.mjs.map +0 -1
- package/dist/issue-planner-CFjB0_oO.mjs.map +0 -1
- package/dist/native-type-normalizer-CInai_oY.mjs.map +0 -1
- package/dist/op-factory-call-BKlruaiC.mjs.map +0 -1
- package/dist/op-factory-call-C3bWXKSP.d.mts.map +0 -1
- package/dist/planner-CLUvVhUN.mjs.map +0 -1
- package/dist/planner-ddl-builders-Dxvw1LHw.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-CRRTno6Z.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-DSSPq8QS.mjs.map +0 -1
- package/dist/planner-sql-checks-7jkgm9TX.mjs.map +0 -1
- package/dist/planner-target-details-DH-azLu-.d.mts.map +0 -1
- package/dist/postgres-migration-BjA3Zmts.d.mts.map +0 -1
- package/dist/postgres-migration-qtmtbONe.mjs.map +0 -1
- package/dist/render-ops-D6_DHdOK.mjs +0 -8
- package/dist/render-ops-D6_DHdOK.mjs.map +0 -1
- package/dist/render-typescript-1rF_SB4g.mjs.map +0 -1
- package/dist/shared-Bxkt8pNO.d.mts.map +0 -1
- package/dist/sql-utils-r-Lw535w.mjs.map +0 -1
- package/dist/statement-builders-BPnmt6wx.mjs.map +0 -1
- package/dist/tables-BmdW_FWO.mjs.map +0 -1
- package/dist/types-ClK03Ojd.d.mts.map +0 -1
- package/src/core/json-schema-type-expression.ts +0 -131
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PostgresPlanTargetDetails } from "./planner-target-details-
|
|
1
|
+
import { t as PostgresPlanTargetDetails } from "./planner-target-details-bVVcanWh.mjs";
|
|
2
2
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { ReferentialAction } from "@prisma-next/sql-contract/types";
|
|
4
4
|
|
|
@@ -38,4 +38,4 @@ interface ForeignKeySpec {
|
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
40
|
export { ForeignKeySpec as n, Op as r, ColumnSpec as t };
|
|
41
|
-
//# sourceMappingURL=shared-
|
|
41
|
+
//# sourceMappingURL=shared-MpwjwAjM.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-MpwjwAjM.d.mts","names":[],"sources":["../src/core/migrations/operations/shared.ts"],"mappings":";;;;;KAMY,EAAA,GAAK,yBAAA,CAA0B,yBAAA;;AAA3C;;;;;AAcA;;;;;;UAAiB,UAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA;EAAA,SACA,QAAA;AAAA;;;;;UAOM,cAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA;IAAA,SACE,KAAA;IAAA,SACA,OAAA;EAAA;EAAA,SAEF,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;AAAA"}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* home that both adapters can depend on without crossing planes.
|
|
12
12
|
*/
|
|
13
13
|
var SqlEscapeError = class extends Error {
|
|
14
|
+
value;
|
|
15
|
+
kind;
|
|
14
16
|
constructor(message, value, kind) {
|
|
15
17
|
super(message);
|
|
16
18
|
this.value = value;
|
|
@@ -70,7 +72,7 @@ function qualifyName(schemaName, objectName) {
|
|
|
70
72
|
function validateEnumValueLength(value, enumTypeName) {
|
|
71
73
|
if (value.length > MAX_IDENTIFIER_LENGTH) throw new SqlEscapeError(`Enum value "${value.slice(0, 20)}..." for type "${enumTypeName}" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character label limit`, value, "literal");
|
|
72
74
|
}
|
|
73
|
-
|
|
74
75
|
//#endregion
|
|
75
76
|
export { validateEnumValueLength as a, quoteIdentifier as i, escapeLiteral as n, qualifyName as r, SqlEscapeError as t };
|
|
76
|
-
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=sql-utils-CggjWNij.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-utils-CggjWNij.mjs","names":[],"sources":["../src/core/sql-utils.ts"],"sourcesContent":["/**\n * Shared SQL utility functions for the Postgres target.\n *\n * These functions handle safe SQL identifier and literal escaping\n * with security validations to prevent injection and encoding issues.\n *\n * They live in `target-postgres` because both the control adapter (used at\n * emit time) and the runtime adapter (used at execute time) need the same\n * escaping/validation behavior, and the target package is the natural shared\n * home that both adapters can depend on without crossing planes.\n */\n\nexport class SqlEscapeError extends Error {\n constructor(\n message: string,\n public readonly value: string,\n public readonly kind: 'identifier' | 'literal',\n ) {\n super(message);\n this.name = 'SqlEscapeError';\n }\n}\n\nconst MAX_IDENTIFIER_LENGTH = 63;\n\n/**\n * Validates and quotes a PostgreSQL identifier (table, column, type, schema names).\n *\n * Security validations:\n * - Rejects null bytes which could cause truncation or unexpected behavior\n * - Rejects empty identifiers\n * - Warns on identifiers exceeding PostgreSQL's 63-character limit\n *\n * @throws {SqlEscapeError} If the identifier contains null bytes or is empty\n */\nexport function quoteIdentifier(identifier: string): string {\n if (identifier.length === 0) {\n throw new SqlEscapeError('Identifier cannot be empty', identifier, 'identifier');\n }\n if (identifier.includes('\\0')) {\n throw new SqlEscapeError(\n 'Identifier cannot contain null bytes',\n identifier.replace(/\\0/g, '\\\\0'),\n 'identifier',\n );\n }\n if (identifier.length > MAX_IDENTIFIER_LENGTH) {\n console.warn(\n `Identifier \"${identifier.slice(0, 20)}...\" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character limit and will be truncated`,\n );\n }\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\n/**\n * Escapes a string literal for safe use in SQL statements.\n *\n * Security validations:\n * - Rejects null bytes which could cause truncation or unexpected behavior\n *\n * Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).\n * Backslashes are treated as literal characters, not escape sequences.\n *\n * @throws {SqlEscapeError} If the value contains null bytes\n */\nexport function escapeLiteral(value: string): string {\n if (value.includes('\\0')) {\n throw new SqlEscapeError(\n 'Literal value cannot contain null bytes',\n value.replace(/\\0/g, '\\\\0'),\n 'literal',\n );\n }\n return value.replace(/'/g, \"''\");\n}\n\n/**\n * Builds a qualified name (schema.object) with proper quoting.\n */\nexport function qualifyName(schemaName: string, objectName: string): string {\n return `${quoteIdentifier(schemaName)}.${quoteIdentifier(objectName)}`;\n}\n\n/**\n * Validates that an enum value doesn't exceed PostgreSQL's label length limit.\n *\n * PostgreSQL enum labels have a maximum length of NAMEDATALEN-1 (63 bytes by default).\n * Unlike identifiers, enum labels that exceed this limit cause an error rather than\n * silent truncation.\n *\n * @param value - The enum value to validate\n * @param enumTypeName - Name of the enum type (for error messages)\n * @throws {SqlEscapeError} If the value exceeds the maximum length\n */\nexport function validateEnumValueLength(value: string, enumTypeName: string): void {\n if (value.length > MAX_IDENTIFIER_LENGTH) {\n throw new SqlEscapeError(\n `Enum value \"${value.slice(0, 20)}...\" for type \"${enumTypeName}\" exceeds PostgreSQL's ` +\n `${MAX_IDENTIFIER_LENGTH}-character label limit`,\n value,\n 'literal',\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,MAAM;CAGtB;CACA;CAHlB,YACE,SACA,OACA,MACA;EACA,MAAM,QAAQ;EAHE,KAAA,QAAA;EACA,KAAA,OAAA;EAGhB,KAAK,OAAO;;;AAIhB,MAAM,wBAAwB;;;;;;;;;;;AAY9B,SAAgB,gBAAgB,YAA4B;CAC1D,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,eAAe,8BAA8B,YAAY,aAAa;CAElF,IAAI,WAAW,SAAS,KAAK,EAC3B,MAAM,IAAI,eACR,wCACA,WAAW,QAAQ,OAAO,MAAM,EAChC,aACD;CAEH,IAAI,WAAW,SAAS,uBACtB,QAAQ,KACN,eAAe,WAAW,MAAM,GAAG,GAAG,CAAC,4BAA4B,sBAAsB,wCAC1F;CAEH,OAAO,IAAI,WAAW,QAAQ,MAAM,OAAK,CAAC;;;;;;;;;;;;;AAc5C,SAAgB,cAAc,OAAuB;CACnD,IAAI,MAAM,SAAS,KAAK,EACtB,MAAM,IAAI,eACR,2CACA,MAAM,QAAQ,OAAO,MAAM,EAC3B,UACD;CAEH,OAAO,MAAM,QAAQ,MAAM,KAAK;;;;;AAMlC,SAAgB,YAAY,YAAoB,YAA4B;CAC1E,OAAO,GAAG,gBAAgB,WAAW,CAAC,GAAG,gBAAgB,WAAW;;;;;;;;;;;;;AActE,SAAgB,wBAAwB,OAAe,cAA4B;CACjF,IAAI,MAAM,SAAS,uBACjB,MAAM,IAAI,eACR,eAAe,MAAM,MAAM,GAAG,GAAG,CAAC,iBAAiB,aAAa,yBAC3D,sBAAsB,yBAC3B,OACA,UACD"}
|
package/dist/sql-utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-utils.d.mts","names":[],"sources":["../src/core/sql-utils.ts"],"
|
|
1
|
+
{"version":3,"file":"sql-utils.d.mts","names":[],"sources":["../src/core/sql-utils.ts"],"mappings":";;AAYA;;;;;;;;;;cAAa,cAAA,SAAuB,KAAA;EAAA,SAGhB,KAAA;EAAA,SACA,IAAA;cAFhB,OAAA,UACgB,KAAA,UACA,IAAA;AAAA;;;;AAiDpB;;;;;AAcA;;iBA5CgB,eAAA,CAAgB,UAAA;;;AA2DhC;;;;;;;;;iBA7BgB,aAAA,CAAc,KAAA;;;;iBAcd,WAAA,CAAY,UAAA,UAAoB,UAAA;;;;;;;;;;;;iBAehC,uBAAA,CAAwB,KAAA,UAAe,YAAA"}
|
package/dist/sql-utils.mjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { a as validateEnumValueLength, i as quoteIdentifier, n as escapeLiteral, r as qualifyName, t as SqlEscapeError } from "./sql-utils-
|
|
2
|
-
|
|
3
|
-
export { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier, validateEnumValueLength };
|
|
1
|
+
import { a as validateEnumValueLength, i as quoteIdentifier, n as escapeLiteral, r as qualifyName, t as SqlEscapeError } from "./sql-utils-CggjWNij.mjs";
|
|
2
|
+
export { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier, validateEnumValueLength };
|
|
@@ -1,18 +1,29 @@
|
|
|
1
|
+
import { APP_SPACE_ID as APP_SPACE_ID$1 } from "@prisma-next/framework-components/control";
|
|
1
2
|
//#region src/core/migrations/statement-builders.ts
|
|
2
3
|
const ensurePrismaContractSchemaStatement = {
|
|
3
4
|
sql: "create schema if not exists prisma_contract",
|
|
4
5
|
params: []
|
|
5
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Schema for `prisma_contract.marker`. The `space text` primary key
|
|
9
|
+
* supports one row per loaded contract space (`'app'`,
|
|
10
|
+
* `'<extension-id>'`, …); on a brand-new database `CREATE TABLE IF NOT
|
|
11
|
+
* EXISTS` produces this shape directly. The migration runner detects
|
|
12
|
+
* pre-1.0 single-row markers (no `space` column) at boot and fails with
|
|
13
|
+
* a structured `LEGACY_MARKER_SHAPE` error rather than auto-migrating —
|
|
14
|
+
* see `specs/framework-mechanism.spec.md § 2`.
|
|
15
|
+
*/
|
|
6
16
|
const ensureMarkerTableStatement = {
|
|
7
17
|
sql: `create table if not exists prisma_contract.marker (
|
|
8
|
-
|
|
18
|
+
space text not null primary key default '${APP_SPACE_ID$1}',
|
|
9
19
|
core_hash text not null,
|
|
10
20
|
profile_hash text not null,
|
|
11
21
|
contract_json jsonb,
|
|
12
22
|
canonical_version int,
|
|
13
23
|
updated_at timestamptz not null default now(),
|
|
14
24
|
app_tag text,
|
|
15
|
-
meta jsonb not null default '{}'
|
|
25
|
+
meta jsonb not null default '{}',
|
|
26
|
+
invariants text[] not null default '{}'
|
|
16
27
|
)`,
|
|
17
28
|
params: []
|
|
18
29
|
};
|
|
@@ -30,27 +41,29 @@ const ensureLedgerTableStatement = {
|
|
|
30
41
|
)`,
|
|
31
42
|
params: []
|
|
32
43
|
};
|
|
33
|
-
function
|
|
44
|
+
function buildMergeMarkerStatements(input) {
|
|
34
45
|
const params = [
|
|
35
|
-
|
|
46
|
+
input.space,
|
|
36
47
|
input.storageHash,
|
|
37
48
|
input.profileHash,
|
|
38
49
|
jsonParam(input.contractJson),
|
|
39
50
|
input.canonicalVersion ?? null,
|
|
40
51
|
input.appTag ?? null,
|
|
41
|
-
jsonParam(input.meta ?? {})
|
|
52
|
+
jsonParam(input.meta ?? {}),
|
|
53
|
+
input.invariants
|
|
42
54
|
];
|
|
43
55
|
return {
|
|
44
56
|
insert: {
|
|
45
57
|
sql: `insert into prisma_contract.marker (
|
|
46
|
-
|
|
58
|
+
space,
|
|
47
59
|
core_hash,
|
|
48
60
|
profile_hash,
|
|
49
61
|
contract_json,
|
|
50
62
|
canonical_version,
|
|
51
63
|
updated_at,
|
|
52
64
|
app_tag,
|
|
53
|
-
meta
|
|
65
|
+
meta,
|
|
66
|
+
invariants
|
|
54
67
|
) values (
|
|
55
68
|
$1,
|
|
56
69
|
$2,
|
|
@@ -59,7 +72,8 @@ function buildWriteMarkerStatements(input) {
|
|
|
59
72
|
$5,
|
|
60
73
|
now(),
|
|
61
74
|
$6,
|
|
62
|
-
$7::jsonb
|
|
75
|
+
$7::jsonb,
|
|
76
|
+
$8::text[]
|
|
63
77
|
)`,
|
|
64
78
|
params
|
|
65
79
|
},
|
|
@@ -71,8 +85,9 @@ function buildWriteMarkerStatements(input) {
|
|
|
71
85
|
canonical_version = $5,
|
|
72
86
|
updated_at = now(),
|
|
73
87
|
app_tag = $6,
|
|
74
|
-
meta = $7::jsonb
|
|
75
|
-
|
|
88
|
+
meta = $7::jsonb,
|
|
89
|
+
invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)
|
|
90
|
+
where space = $1`,
|
|
76
91
|
params
|
|
77
92
|
}
|
|
78
93
|
};
|
|
@@ -110,7 +125,7 @@ function buildLedgerInsertStatement(input) {
|
|
|
110
125
|
function jsonParam(value) {
|
|
111
126
|
return JSON.stringify(value ?? null);
|
|
112
127
|
}
|
|
113
|
-
|
|
114
128
|
//#endregion
|
|
115
|
-
export {
|
|
116
|
-
|
|
129
|
+
export { ensureMarkerTableStatement as a, ensureLedgerTableStatement as i, buildLedgerInsertStatement as n, ensurePrismaContractSchemaStatement as o, buildMergeMarkerStatements as r, APP_SPACE_ID$1 as t };
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=statement-builders-BT889jV0.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statement-builders-BT889jV0.mjs","names":["APP_SPACE_ID"],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":["import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\n\nexport { APP_SPACE_ID };\n\nexport interface SqlStatement {\n readonly sql: string;\n readonly params: readonly unknown[];\n}\n\nexport const ensurePrismaContractSchemaStatement: SqlStatement = {\n sql: 'create schema if not exists prisma_contract',\n params: [],\n};\n\n/**\n * Schema for `prisma_contract.marker`. The `space text` primary key\n * supports one row per loaded contract space (`'app'`,\n * `'<extension-id>'`, …); on a brand-new database `CREATE TABLE IF NOT\n * EXISTS` produces this shape directly. The migration runner detects\n * pre-1.0 single-row markers (no `space` column) at boot and fails with\n * a structured `LEGACY_MARKER_SHAPE` error rather than auto-migrating —\n * see `specs/framework-mechanism.spec.md § 2`.\n */\nexport const ensureMarkerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.marker (\n space text not null primary key default '${APP_SPACE_ID}',\n core_hash text not null,\n profile_hash text not null,\n contract_json jsonb,\n canonical_version int,\n updated_at timestamptz not null default now(),\n app_tag text,\n meta jsonb not null default '{}',\n invariants text[] not null default '{}'\n )`,\n params: [],\n};\n\nexport const ensureLedgerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.ledger (\n id bigserial primary key,\n created_at timestamptz not null default now(),\n origin_core_hash text,\n origin_profile_hash text,\n destination_core_hash text not null,\n destination_profile_hash text,\n contract_json_before jsonb,\n contract_json_after jsonb,\n operations jsonb not null\n )`,\n params: [],\n};\n\nexport interface MergeMarkerInput {\n /**\n * Logical space identifier for this marker row. Required at every\n * call site so the type system surfaces every place that needs to\n * thread the value (rather than letting an `?? APP_SPACE_ID`\n * fall-through silently collapse multi-space markers onto the\n * `'app'` row). App-plan callers pass {@link APP_SPACE_ID}\n * (`'app'`); per-extension callers (planner / runner / verifier\n * extensions over contract spaces) pass the extension's space id.\n */\n readonly space: string;\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson?: unknown;\n readonly canonicalVersion?: number | null;\n readonly appTag?: string | null;\n readonly meta?: Record<string, unknown>;\n /**\n * Invariants to merge into `marker.invariants`. INSERT writes them as\n * the initial value (callers are expected to pass a sorted, deduped\n * array). UPDATE merges them with the existing column server-side via\n * a single atomic SQL expression.\n */\n readonly invariants: readonly string[];\n}\n\nexport function buildMergeMarkerStatements(input: MergeMarkerInput): {\n readonly insert: SqlStatement;\n readonly update: SqlStatement;\n} {\n const params: readonly unknown[] = [\n input.space,\n input.storageHash,\n input.profileHash,\n jsonParam(input.contractJson),\n input.canonicalVersion ?? null,\n input.appTag ?? null,\n jsonParam(input.meta ?? {}),\n input.invariants,\n ];\n\n return {\n insert: {\n sql: `insert into prisma_contract.marker (\n space,\n core_hash,\n profile_hash,\n contract_json,\n canonical_version,\n updated_at,\n app_tag,\n meta,\n invariants\n ) values (\n $1,\n $2,\n $3,\n $4::jsonb,\n $5,\n now(),\n $6,\n $7::jsonb,\n $8::text[]\n )`,\n params,\n },\n update: {\n // `invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)`\n // reads the current column value under the UPDATE's row lock, unions\n // with the incoming array, dedupes, and sorts ascending — single\n // statement, atomic, no read-then-write window.\n sql: `update prisma_contract.marker set\n core_hash = $2,\n profile_hash = $3,\n contract_json = $4::jsonb,\n canonical_version = $5,\n updated_at = now(),\n app_tag = $6,\n meta = $7::jsonb,\n invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)\n where space = $1`,\n params,\n },\n };\n}\n\nexport interface LedgerInsertInput {\n readonly originStorageHash?: string | null;\n readonly originProfileHash?: string | null;\n readonly destinationStorageHash: string;\n readonly destinationProfileHash?: string | null;\n readonly contractJsonBefore?: unknown;\n readonly contractJsonAfter?: unknown;\n readonly operations: unknown;\n}\n\nexport function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {\n return {\n sql: `insert into prisma_contract.ledger (\n origin_core_hash,\n origin_profile_hash,\n destination_core_hash,\n destination_profile_hash,\n contract_json_before,\n contract_json_after,\n operations\n ) values (\n $1,\n $2,\n $3,\n $4,\n $5::jsonb,\n $6::jsonb,\n $7::jsonb\n )`,\n params: [\n input.originStorageHash ?? null,\n input.originProfileHash ?? null,\n input.destinationStorageHash,\n input.destinationProfileHash ?? null,\n jsonParam(input.contractJsonBefore),\n jsonParam(input.contractJsonAfter),\n jsonParam(input.operations),\n ],\n };\n}\n\nfunction jsonParam(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n"],"mappings":";;AASA,MAAa,sCAAoD;CAC/D,KAAK;CACL,QAAQ,EAAE;CACX;;;;;;;;;;AAWD,MAAa,6BAA2C;CACtD,KAAK;+CACwCA,eAAa;;;;;;;;;;CAU1D,QAAQ,EAAE;CACX;AAED,MAAa,6BAA2C;CACtD,KAAK;;;;;;;;;;;CAWL,QAAQ,EAAE;CACX;AA4BD,SAAgB,2BAA2B,OAGzC;CACA,MAAM,SAA6B;EACjC,MAAM;EACN,MAAM;EACN,MAAM;EACN,UAAU,MAAM,aAAa;EAC7B,MAAM,oBAAoB;EAC1B,MAAM,UAAU;EAChB,UAAU,MAAM,QAAQ,EAAE,CAAC;EAC3B,MAAM;EACP;CAED,OAAO;EACL,QAAQ;GACN,KAAK;;;;;;;;;;;;;;;;;;;;;GAqBL;GACD;EACD,QAAQ;GAKN,KAAK;;;;;;;;;;GAUL;GACD;EACF;;AAaH,SAAgB,2BAA2B,OAAwC;CACjF,OAAO;EACL,KAAK;;;;;;;;;;;;;;;;;EAiBL,QAAQ;GACN,MAAM,qBAAqB;GAC3B,MAAM,qBAAqB;GAC3B,MAAM;GACN,MAAM,0BAA0B;GAChC,UAAU,MAAM,mBAAmB;GACnC,UAAU,MAAM,kBAAkB;GAClC,UAAU,MAAM,WAAW;GAC5B;EACF;;AAGH,SAAS,UAAU,OAAwB;CACzC,OAAO,KAAK,UAAU,SAAS,KAAK"}
|
|
@@ -1,23 +1,51 @@
|
|
|
1
|
+
import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
2
|
+
|
|
1
3
|
//#region src/core/migrations/statement-builders.d.ts
|
|
2
4
|
interface SqlStatement {
|
|
3
5
|
readonly sql: string;
|
|
4
6
|
readonly params: readonly unknown[];
|
|
5
7
|
}
|
|
6
8
|
declare const ensurePrismaContractSchemaStatement: SqlStatement;
|
|
9
|
+
/**
|
|
10
|
+
* Schema for `prisma_contract.marker`. The `space text` primary key
|
|
11
|
+
* supports one row per loaded contract space (`'app'`,
|
|
12
|
+
* `'<extension-id>'`, …); on a brand-new database `CREATE TABLE IF NOT
|
|
13
|
+
* EXISTS` produces this shape directly. The migration runner detects
|
|
14
|
+
* pre-1.0 single-row markers (no `space` column) at boot and fails with
|
|
15
|
+
* a structured `LEGACY_MARKER_SHAPE` error rather than auto-migrating —
|
|
16
|
+
* see `specs/framework-mechanism.spec.md § 2`.
|
|
17
|
+
*/
|
|
7
18
|
declare const ensureMarkerTableStatement: SqlStatement;
|
|
8
19
|
declare const ensureLedgerTableStatement: SqlStatement;
|
|
9
|
-
interface
|
|
20
|
+
interface MergeMarkerInput {
|
|
21
|
+
/**
|
|
22
|
+
* Logical space identifier for this marker row. Required at every
|
|
23
|
+
* call site so the type system surfaces every place that needs to
|
|
24
|
+
* thread the value (rather than letting an `?? APP_SPACE_ID`
|
|
25
|
+
* fall-through silently collapse multi-space markers onto the
|
|
26
|
+
* `'app'` row). App-plan callers pass {@link APP_SPACE_ID}
|
|
27
|
+
* (`'app'`); per-extension callers (planner / runner / verifier
|
|
28
|
+
* extensions over contract spaces) pass the extension's space id.
|
|
29
|
+
*/
|
|
30
|
+
readonly space: string;
|
|
10
31
|
readonly storageHash: string;
|
|
11
32
|
readonly profileHash: string;
|
|
12
33
|
readonly contractJson?: unknown;
|
|
13
34
|
readonly canonicalVersion?: number | null;
|
|
14
35
|
readonly appTag?: string | null;
|
|
15
36
|
readonly meta?: Record<string, unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Invariants to merge into `marker.invariants`. INSERT writes them as
|
|
39
|
+
* the initial value (callers are expected to pass a sorted, deduped
|
|
40
|
+
* array). UPDATE merges them with the existing column server-side via
|
|
41
|
+
* a single atomic SQL expression.
|
|
42
|
+
*/
|
|
43
|
+
readonly invariants: readonly string[];
|
|
16
44
|
}
|
|
17
|
-
declare function
|
|
45
|
+
declare function buildMergeMarkerStatements(input: MergeMarkerInput): {
|
|
18
46
|
readonly insert: SqlStatement;
|
|
19
47
|
readonly update: SqlStatement;
|
|
20
48
|
};
|
|
21
49
|
//#endregion
|
|
22
|
-
export { type SqlStatement,
|
|
50
|
+
export { APP_SPACE_ID, type SqlStatement, buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
|
|
23
51
|
//# sourceMappingURL=statement-builders.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statement-builders.d.mts","names":[],"sources":["../src/core/migrations/statement-builders.ts"],"
|
|
1
|
+
{"version":3,"file":"statement-builders.d.mts","names":[],"sources":["../src/core/migrations/statement-builders.ts"],"mappings":";;;UAIiB,YAAA;EAAA,SACN,GAAA;EAAA,SACA,MAAA;AAAA;AAAA,cAGE,mCAAA,EAAqC,YAAA;;AAAlD;;;;;AAcA;;;cAAa,0BAAA,EAA4B,YAAA;AAAA,cAe5B,0BAAA,EAA4B,YAAA;AAAA,UAexB,gBAAA;EAFhB;;;;AAED;;;;;EAFC,SAYU,KAAA;EAAA,SACA,WAAA;EAAA,SACA,WAAA;EAAA,SACA,YAAA;EAAA,SACA,gBAAA;EAAA,SACA,MAAA;EAAA,SACA,IAAA,GAAO,MAAA;EAOP;;;AAGX;;;EAHW,SAAA,UAAA;AAAA;AAAA,iBAGK,0BAAA,CAA2B,KAAA,EAAO,gBAAA;EAAA,SACvC,MAAA,EAAQ,YAAA;EAAA,SACR,MAAA,EAAQ,YAAA;AAAA"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
export { buildWriteMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
|
|
1
|
+
import { a as ensureMarkerTableStatement, i as ensureLedgerTableStatement, o as ensurePrismaContractSchemaStatement, r as buildMergeMarkerStatements, t as APP_SPACE_ID } from "./statement-builders-BT889jV0.mjs";
|
|
2
|
+
export { APP_SPACE_ID, buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { i as quoteIdentifier, n as escapeLiteral, r as qualifyName } from "./sql-utils-
|
|
2
|
-
import { a as columnNullabilityCheck, c as qualifyTableName, d as toRegclassLiteral, n as columnDefaultExistsCheck, o as columnTypeCheck, r as columnExistsCheck, s as constraintExistsCheck } from "./planner-sql-checks-
|
|
1
|
+
import { i as quoteIdentifier, n as escapeLiteral, r as qualifyName } from "./sql-utils-CggjWNij.mjs";
|
|
2
|
+
import { a as columnNullabilityCheck, c as qualifyTableName, d as toRegclassLiteral, n as columnDefaultExistsCheck, o as columnTypeCheck, r as columnExistsCheck, s as constraintExistsCheck } from "./planner-sql-checks-DwZvGlV4.mjs";
|
|
3
3
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
4
|
-
|
|
5
4
|
//#region src/core/migrations/operations/shared.ts
|
|
6
5
|
function step(description, sql) {
|
|
7
6
|
return {
|
|
@@ -28,7 +27,6 @@ function renderColumnDefinition(column) {
|
|
|
28
27
|
column.nullable ? "" : "NOT NULL"
|
|
29
28
|
].filter(Boolean).join(" ");
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
//#endregion
|
|
33
31
|
//#region src/core/migrations/operations/columns.ts
|
|
34
32
|
function addColumn(schemaName, tableName, column) {
|
|
@@ -203,7 +201,6 @@ function dropDefault(schemaName, tableName, columnName) {
|
|
|
203
201
|
}))]
|
|
204
202
|
};
|
|
205
203
|
}
|
|
206
|
-
|
|
207
204
|
//#endregion
|
|
208
205
|
//#region src/core/migrations/operations/constraints.ts
|
|
209
206
|
const REFERENTIAL_ACTION_SQL = {
|
|
@@ -322,7 +319,6 @@ function dropConstraint(schemaName, tableName, constraintName, kind = "unique")
|
|
|
322
319
|
}))]
|
|
323
320
|
};
|
|
324
321
|
}
|
|
325
|
-
|
|
326
322
|
//#endregion
|
|
327
323
|
//#region src/core/migrations/operations/dependencies.ts
|
|
328
324
|
function createExtension(extensionName) {
|
|
@@ -336,6 +332,40 @@ function createExtension(extensionName) {
|
|
|
336
332
|
postcheck: []
|
|
337
333
|
};
|
|
338
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Install a Postgres extension as the baseline op for an extension-pack
|
|
337
|
+
* contract space. Layered on top of {@link createExtension}: stamps an
|
|
338
|
+
* `invariantId` (required so the per-space marker records the install),
|
|
339
|
+
* scopes the op `id` under a caller-chosen namespace (e.g. `pgvector.`),
|
|
340
|
+
* and emits pre- and postcheck SQL probing `pg_extension`. The richer
|
|
341
|
+
* shape lets the runner's idempotency probe skip the install on re-run
|
|
342
|
+
* (postcheck-pre-satisfied) without firing the precheck.
|
|
343
|
+
*
|
|
344
|
+
* Use this for hand-rolled baseline migrations in contract-space
|
|
345
|
+
* extension packages (e.g. `extension-pgvector`, `extension-paradedb`);
|
|
346
|
+
* use the bare {@link createExtension} for planner-emitted ops where the
|
|
347
|
+
* caller already controls idempotency through the surrounding plan.
|
|
348
|
+
*/
|
|
349
|
+
function installExtension(options) {
|
|
350
|
+
const { extensionName, invariantId, id } = options;
|
|
351
|
+
return {
|
|
352
|
+
id,
|
|
353
|
+
label: options.label ?? `Enable extension "${extensionName}"`,
|
|
354
|
+
operationClass: "additive",
|
|
355
|
+
invariantId,
|
|
356
|
+
target: {
|
|
357
|
+
id: "postgres",
|
|
358
|
+
details: {
|
|
359
|
+
schema: "public",
|
|
360
|
+
objectType: "dependency",
|
|
361
|
+
name: extensionName
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
precheck: [step(`verify extension "${extensionName}" is not already enabled`, `SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = '${extensionName}')`)],
|
|
365
|
+
execute: [step(`create extension "${extensionName}"`, `CREATE EXTENSION IF NOT EXISTS ${extensionName}`)],
|
|
366
|
+
postcheck: [step(`confirm extension "${extensionName}" is enabled`, `SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = '${extensionName}')`)]
|
|
367
|
+
};
|
|
368
|
+
}
|
|
339
369
|
function createSchema(schemaName) {
|
|
340
370
|
return {
|
|
341
371
|
id: `schema.${schemaName}`,
|
|
@@ -347,7 +377,6 @@ function createSchema(schemaName) {
|
|
|
347
377
|
postcheck: []
|
|
348
378
|
};
|
|
349
379
|
}
|
|
350
|
-
|
|
351
380
|
//#endregion
|
|
352
381
|
//#region src/core/migrations/operations/enums.ts
|
|
353
382
|
function enumTypeExistsCheck(schemaName, nativeType, exists = true) {
|
|
@@ -412,19 +441,30 @@ function renameType(schemaName, fromName, toName) {
|
|
|
412
441
|
postcheck: [step(`verify type "${toName}" exists`, enumTypeExistsCheck(schemaName, toName))]
|
|
413
442
|
};
|
|
414
443
|
}
|
|
415
|
-
|
|
416
444
|
//#endregion
|
|
417
445
|
//#region src/core/migrations/operations/indexes.ts
|
|
418
|
-
function
|
|
446
|
+
function renderIndexOptionValue(key, value) {
|
|
447
|
+
if (typeof value === "string") return `'${escapeLiteral(value)}'`;
|
|
448
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
449
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
450
|
+
throw new Error(`Index option "${key}" must be a string, finite number, or boolean; got ${typeof value}`);
|
|
451
|
+
}
|
|
452
|
+
function renderIndexOptions(options) {
|
|
453
|
+
return Object.entries(options).map(([key, value]) => `${quoteIdentifier(key)} = ${renderIndexOptionValue(key, value)}`).join(", ");
|
|
454
|
+
}
|
|
455
|
+
function createIndex(schemaName, tableName, indexName, columns, extras) {
|
|
419
456
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
420
457
|
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
458
|
+
const using = extras?.type ? ` USING ${quoteIdentifier(extras.type)}` : "";
|
|
459
|
+
const options = extras?.options;
|
|
460
|
+
const withClause = options && Object.keys(options).length > 0 ? ` WITH (${renderIndexOptions(options)})` : "";
|
|
421
461
|
return {
|
|
422
462
|
id: `index.${tableName}.${indexName}`,
|
|
423
463
|
label: `Create index "${indexName}" on "${tableName}"`,
|
|
424
464
|
operationClass: "additive",
|
|
425
465
|
target: targetDetails("index", indexName, schemaName, tableName),
|
|
426
466
|
precheck: [step(`ensure index "${indexName}" does not exist`, `SELECT to_regclass(${toRegclassLiteral(schemaName, indexName)}) IS NULL`)],
|
|
427
|
-
execute: [step(`create index "${indexName}"`, `CREATE INDEX ${quoteIdentifier(indexName)} ON ${qualified} (${columnList})`)],
|
|
467
|
+
execute: [step(`create index "${indexName}"`, `CREATE INDEX ${quoteIdentifier(indexName)} ON ${qualified}${using} (${columnList})${withClause}`)],
|
|
428
468
|
postcheck: [step(`verify index "${indexName}" exists`, `SELECT to_regclass(${toRegclassLiteral(schemaName, indexName)}) IS NOT NULL`)]
|
|
429
469
|
};
|
|
430
470
|
}
|
|
@@ -439,7 +479,6 @@ function dropIndex(schemaName, tableName, indexName) {
|
|
|
439
479
|
postcheck: [step(`verify index "${indexName}" does not exist`, `SELECT to_regclass(${toRegclassLiteral(schemaName, indexName)}) IS NULL`)]
|
|
440
480
|
};
|
|
441
481
|
}
|
|
442
|
-
|
|
443
482
|
//#endregion
|
|
444
483
|
//#region src/core/migrations/operations/tables.ts
|
|
445
484
|
function createTable(schemaName, tableName, columns, primaryKey) {
|
|
@@ -471,7 +510,7 @@ function dropTable(schemaName, tableName) {
|
|
|
471
510
|
postcheck: [step(`verify table "${tableName}" does not exist`, `SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NULL`)]
|
|
472
511
|
};
|
|
473
512
|
}
|
|
474
|
-
|
|
475
513
|
//#endregion
|
|
476
|
-
export {
|
|
477
|
-
|
|
514
|
+
export { setNotNull as S, alterColumnType as _, addEnumValues as a, dropNotNull as b, renameType as c, installExtension as d, addForeignKey as f, addColumn as g, dropConstraint as h, dropIndex as i, createExtension as l, addUnique as m, dropTable as n, createEnumType as o, addPrimaryKey as p, createIndex as r, dropEnumType as s, createTable as t, createSchema as u, dropColumn as v, setDefault as x, dropDefault as y };
|
|
515
|
+
|
|
516
|
+
//# sourceMappingURL=tables-DgYIXjUt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables-DgYIXjUt.mjs","names":[],"sources":["../src/core/migrations/operations/shared.ts","../src/core/migrations/operations/columns.ts","../src/core/migrations/operations/constraints.ts","../src/core/migrations/operations/dependencies.ts","../src/core/migrations/operations/enums.ts","../src/core/migrations/operations/indexes.ts","../src/core/migrations/operations/tables.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { quoteIdentifier } from '../../sql-utils';\nimport type { OperationClass, PostgresPlanTargetDetails } from '../planner-target-details';\n\nexport type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\n/**\n * Literal-args shape for a column definition consumed by `createTable` and\n * `addColumn`. Fully materialized: codec expansion and default rendering have\n * already happened in the wrapper.\n *\n * - `typeSql` is the column's DDL type string (e.g. `\"integer\"`, `\"SERIAL\"`,\n * `\"varchar(100)\"`), already produced by `buildColumnTypeSql` in the\n * call-factory wrapper.\n * - `defaultSql` is the full `DEFAULT …` clause (e.g. `\"DEFAULT 42\"`) or an\n * empty string when the column has no default, matching\n * `buildColumnDefaultSql`'s output.\n */\nexport interface ColumnSpec {\n readonly name: string;\n readonly typeSql: string;\n readonly defaultSql: string;\n readonly nullable: boolean;\n}\n\n/**\n * Literal-args shape for a foreign key definition. The referenced table is\n * assumed to live in the same schema as the constrained table.\n */\nexport interface ForeignKeySpec {\n readonly name: string;\n readonly columns: readonly string[];\n readonly references: {\n readonly table: string;\n readonly columns: readonly string[];\n };\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n}\n\nexport function step(description: string, sql: string) {\n return { description, sql };\n}\n\nexport function targetDetails(\n objectType: OperationClass,\n name: string,\n schema: string,\n table?: string,\n): { readonly id: 'postgres'; readonly details: PostgresPlanTargetDetails } {\n return {\n id: 'postgres',\n details: { schema, objectType, name, ...ifDefined('table', table) },\n };\n}\n\nexport function renderColumnDefinition(column: ColumnSpec): string {\n const parts = [\n quoteIdentifier(column.name),\n column.typeSql,\n column.defaultSql,\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n}\n","import { quoteIdentifier } from '../../sql-utils';\nimport {\n columnDefaultExistsCheck,\n columnExistsCheck,\n columnNullabilityCheck,\n columnTypeCheck,\n qualifyTableName,\n} from '../planner-sql-checks';\nimport { type ColumnSpec, type Op, step, targetDetails } from './shared';\n\nexport function addColumn(schemaName: string, tableName: string, column: ColumnSpec): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n const parts = [\n `ALTER TABLE ${qualified}`,\n `ADD COLUMN ${quoteIdentifier(column.name)} ${column.typeSql}`,\n column.defaultSql,\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n const addSql = parts.join(' ');\n\n return {\n id: `column.${tableName}.${column.name}`,\n label: `Add column \"${column.name}\" to \"${tableName}\"`,\n operationClass: 'additive',\n target: targetDetails('column', column.name, schemaName, tableName),\n precheck: [\n step(\n `ensure column \"${column.name}\" is missing`,\n columnExistsCheck({\n schema: schemaName,\n table: tableName,\n column: column.name,\n exists: false,\n }),\n ),\n ],\n execute: [step(`add column \"${column.name}\"`, addSql)],\n postcheck: [\n step(\n `verify column \"${column.name}\" exists`,\n columnExistsCheck({ schema: schemaName, table: tableName, column: column.name }),\n ),\n ],\n };\n}\n\nexport function dropColumn(schemaName: string, tableName: string, columnName: string): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n return {\n id: `dropColumn.${tableName}.${columnName}`,\n label: `Drop column \"${columnName}\" from \"${tableName}\"`,\n operationClass: 'destructive',\n target: targetDetails('column', columnName, schemaName, tableName),\n precheck: [\n step(\n `ensure column \"${columnName}\" exists`,\n columnExistsCheck({ schema: schemaName, table: tableName, column: columnName }),\n ),\n ],\n execute: [\n step(\n `drop column \"${columnName}\"`,\n `ALTER TABLE ${qualified} DROP COLUMN ${quoteIdentifier(columnName)}`,\n ),\n ],\n postcheck: [\n step(\n `verify column \"${columnName}\" does not exist`,\n columnExistsCheck({\n schema: schemaName,\n table: tableName,\n column: columnName,\n exists: false,\n }),\n ),\n ],\n };\n}\n\n/**\n * `qualifiedTargetType` is the new column type as it appears in the\n * `ALTER COLUMN TYPE` clause (schema-qualified for user-defined types, raw\n * native name for built-ins). `formatTypeExpected` is the unqualified\n * `format_type` form used in the postcheck. `rawTargetTypeForLabel` is the\n * string appearing in the human-readable label (typically `toType` when\n * explicit, else the column's native type).\n */\nexport function alterColumnType(\n schemaName: string,\n tableName: string,\n columnName: string,\n options: {\n readonly qualifiedTargetType: string;\n readonly formatTypeExpected: string;\n readonly rawTargetTypeForLabel: string;\n readonly using?: string;\n },\n): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n const usingClause = options.using\n ? ` USING ${options.using}`\n : ` USING ${quoteIdentifier(columnName)}::${options.qualifiedTargetType}`;\n return {\n id: `alterType.${tableName}.${columnName}`,\n label: `Alter type of \"${tableName}\".\"${columnName}\" to ${options.rawTargetTypeForLabel}`,\n operationClass: 'destructive',\n target: targetDetails('column', columnName, schemaName, tableName),\n precheck: [\n step(\n `ensure column \"${columnName}\" exists`,\n columnExistsCheck({ schema: schemaName, table: tableName, column: columnName }),\n ),\n ],\n execute: [\n step(\n `alter type of \"${columnName}\"`,\n `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} TYPE ${options.qualifiedTargetType}${usingClause}`,\n ),\n ],\n postcheck: [\n step(\n `verify column \"${columnName}\" has type \"${options.formatTypeExpected}\"`,\n columnTypeCheck({\n schema: schemaName,\n table: tableName,\n column: columnName,\n expectedType: options.formatTypeExpected,\n }),\n ),\n ],\n meta: { warning: 'TABLE_REWRITE' },\n };\n}\n\nexport function setNotNull(schemaName: string, tableName: string, columnName: string): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n return {\n id: `alterNullability.setNotNull.${tableName}.${columnName}`,\n label: `Set NOT NULL on \"${tableName}\".\"${columnName}\"`,\n operationClass: 'destructive',\n target: targetDetails('column', columnName, schemaName, tableName),\n precheck: [\n step(\n `ensure column \"${columnName}\" exists`,\n columnExistsCheck({ schema: schemaName, table: tableName, column: columnName }),\n ),\n step(\n `ensure no NULL values in \"${columnName}\"`,\n `SELECT NOT EXISTS (SELECT 1 FROM ${qualified} WHERE ${quoteIdentifier(columnName)} IS NULL)`,\n ),\n ],\n execute: [\n step(\n `set NOT NULL on \"${columnName}\"`,\n `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} SET NOT NULL`,\n ),\n ],\n postcheck: [\n step(\n `verify column \"${columnName}\" is NOT NULL`,\n columnNullabilityCheck({\n schema: schemaName,\n table: tableName,\n column: columnName,\n nullable: false,\n }),\n ),\n ],\n };\n}\n\nexport function dropNotNull(schemaName: string, tableName: string, columnName: string): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n return {\n id: `alterNullability.dropNotNull.${tableName}.${columnName}`,\n label: `Drop NOT NULL on \"${tableName}\".\"${columnName}\"`,\n operationClass: 'widening',\n target: targetDetails('column', columnName, schemaName, tableName),\n precheck: [\n step(\n `ensure column \"${columnName}\" exists`,\n columnExistsCheck({ schema: schemaName, table: tableName, column: columnName }),\n ),\n ],\n execute: [\n step(\n `drop NOT NULL on \"${columnName}\"`,\n `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP NOT NULL`,\n ),\n ],\n postcheck: [\n step(\n `verify column \"${columnName}\" is nullable`,\n columnNullabilityCheck({\n schema: schemaName,\n table: tableName,\n column: columnName,\n nullable: true,\n }),\n ),\n ],\n };\n}\n\n/**\n * `defaultSql` is the full `DEFAULT …` clause as produced by\n * `buildColumnDefaultSql` — e.g. `\"DEFAULT 42\"`,\n * `\"DEFAULT (CURRENT_TIMESTAMP)\"`, or `\"DEFAULT nextval('seq'::regclass)\"`.\n *\n * `operationClass` defaults to `'additive'` (setting a default on a column\n * that currently has none). The reconciliation planner passes `'widening'`\n * when the column already has a different default — policy enforcement\n * treats that as a widening change rather than an additive one.\n */\nexport function setDefault(\n schemaName: string,\n tableName: string,\n columnName: string,\n defaultSql: string,\n operationClass: 'additive' | 'widening' = 'additive',\n): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n return {\n id: `setDefault.${tableName}.${columnName}`,\n label: `Set default on \"${tableName}\".\"${columnName}\"`,\n operationClass,\n target: targetDetails('column', columnName, schemaName, tableName),\n precheck: [\n step(\n `ensure column \"${columnName}\" exists`,\n columnExistsCheck({ schema: schemaName, table: tableName, column: columnName }),\n ),\n ],\n execute: [\n step(\n `set default on \"${columnName}\"`,\n `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} SET ${defaultSql}`,\n ),\n ],\n postcheck: [\n step(\n `verify column \"${columnName}\" has a default`,\n columnDefaultExistsCheck({\n schema: schemaName,\n table: tableName,\n column: columnName,\n exists: true,\n }),\n ),\n ],\n };\n}\n\nexport function dropDefault(schemaName: string, tableName: string, columnName: string): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n return {\n id: `dropDefault.${tableName}.${columnName}`,\n label: `Drop default on \"${tableName}\".\"${columnName}\"`,\n operationClass: 'destructive',\n target: targetDetails('column', columnName, schemaName, tableName),\n precheck: [\n step(\n `ensure column \"${columnName}\" exists`,\n columnExistsCheck({ schema: schemaName, table: tableName, column: columnName }),\n ),\n ],\n execute: [\n step(\n `drop default on \"${columnName}\"`,\n `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP DEFAULT`,\n ),\n ],\n postcheck: [\n step(\n `verify column \"${columnName}\" has no default`,\n columnDefaultExistsCheck({\n schema: schemaName,\n table: tableName,\n column: columnName,\n exists: false,\n }),\n ),\n ],\n };\n}\n","import type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport { quoteIdentifier } from '../../sql-utils';\nimport { constraintExistsCheck, qualifyTableName } from '../planner-sql-checks';\nimport { type ForeignKeySpec, type Op, step, targetDetails } from './shared';\n\nconst REFERENTIAL_ACTION_SQL: Record<ReferentialAction, string> = {\n noAction: 'NO ACTION',\n restrict: 'RESTRICT',\n cascade: 'CASCADE',\n setNull: 'SET NULL',\n setDefault: 'SET DEFAULT',\n};\n\nfunction renderForeignKeySql(schemaName: string, tableName: string, fk: ForeignKeySpec): string {\n let sql = `ALTER TABLE ${qualifyTableName(schemaName, tableName)}\nADD CONSTRAINT ${quoteIdentifier(fk.name)}\nFOREIGN KEY (${fk.columns.map(quoteIdentifier).join(', ')})\nREFERENCES ${qualifyTableName(schemaName, fk.references.table)} (${fk.references.columns\n .map(quoteIdentifier)\n .join(', ')})`;\n\n if (fk.onDelete !== undefined) {\n const action = REFERENTIAL_ACTION_SQL[fk.onDelete];\n if (!action) {\n throw new Error(`Unknown referential action for onDelete: ${String(fk.onDelete)}`);\n }\n sql += `\\nON DELETE ${action}`;\n }\n if (fk.onUpdate !== undefined) {\n const action = REFERENTIAL_ACTION_SQL[fk.onUpdate];\n if (!action) {\n throw new Error(`Unknown referential action for onUpdate: ${String(fk.onUpdate)}`);\n }\n sql += `\\nON UPDATE ${action}`;\n }\n return sql;\n}\n\nexport function addPrimaryKey(\n schemaName: string,\n tableName: string,\n constraintName: string,\n columns: readonly string[],\n): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n const columnList = columns.map(quoteIdentifier).join(', ');\n return {\n id: `primaryKey.${tableName}.${constraintName}`,\n label: `Add primary key on \"${tableName}\"`,\n operationClass: 'additive',\n target: targetDetails('primaryKey', constraintName, schemaName, tableName),\n precheck: [\n step(\n `ensure primary key \"${constraintName}\" does not exist`,\n constraintExistsCheck({\n constraintName,\n schema: schemaName,\n table: tableName,\n exists: false,\n }),\n ),\n ],\n execute: [\n step(\n `add primary key \"${constraintName}\"`,\n `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} PRIMARY KEY (${columnList})`,\n ),\n ],\n postcheck: [\n step(\n `verify primary key \"${constraintName}\" exists`,\n constraintExistsCheck({ constraintName, schema: schemaName, table: tableName }),\n ),\n ],\n };\n}\n\nexport function addUnique(\n schemaName: string,\n tableName: string,\n constraintName: string,\n columns: readonly string[],\n): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n const columnList = columns.map(quoteIdentifier).join(', ');\n return {\n id: `unique.${tableName}.${constraintName}`,\n label: `Add unique constraint on \"${tableName}\" (${columns.join(', ')})`,\n operationClass: 'additive',\n target: targetDetails('unique', constraintName, schemaName, tableName),\n precheck: [\n step(\n `ensure constraint \"${constraintName}\" does not exist`,\n constraintExistsCheck({\n constraintName,\n schema: schemaName,\n table: tableName,\n exists: false,\n }),\n ),\n ],\n execute: [\n step(\n `add unique constraint \"${constraintName}\"`,\n `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} UNIQUE (${columnList})`,\n ),\n ],\n postcheck: [\n step(\n `verify constraint \"${constraintName}\" exists`,\n constraintExistsCheck({ constraintName, schema: schemaName, table: tableName }),\n ),\n ],\n };\n}\n\nexport function addForeignKey(schemaName: string, tableName: string, fk: ForeignKeySpec): Op {\n return {\n id: `foreignKey.${tableName}.${fk.name}`,\n label: `Add foreign key \"${fk.name}\" on \"${tableName}\"`,\n operationClass: 'additive',\n target: targetDetails('foreignKey', fk.name, schemaName, tableName),\n precheck: [\n step(\n `ensure FK \"${fk.name}\" does not exist`,\n constraintExistsCheck({\n constraintName: fk.name,\n schema: schemaName,\n table: tableName,\n exists: false,\n }),\n ),\n ],\n execute: [step(`add FK \"${fk.name}\"`, renderForeignKeySql(schemaName, tableName, fk))],\n postcheck: [\n step(\n `verify FK \"${fk.name}\" exists`,\n constraintExistsCheck({\n constraintName: fk.name,\n schema: schemaName,\n table: tableName,\n }),\n ),\n ],\n };\n}\n\n/**\n * `kind` feeds the operation's `target.details.objectType`. Descriptor-flow\n * does not carry kind information in its drop-constraint descriptor, so the\n * default is `'unique'`. The reconciliation planner passes the correct kind\n * (`'foreignKey'`, `'primaryKey'`, or `'unique'`) based on the `SchemaIssue`\n * that produced the drop.\n */\nexport function dropConstraint(\n schemaName: string,\n tableName: string,\n constraintName: string,\n kind: 'foreignKey' | 'unique' | 'primaryKey' = 'unique',\n): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n return {\n id: `dropConstraint.${tableName}.${constraintName}`,\n label: `Drop constraint \"${constraintName}\" on \"${tableName}\"`,\n operationClass: 'destructive',\n target: targetDetails(kind, constraintName, schemaName, tableName),\n precheck: [\n step(\n `ensure constraint \"${constraintName}\" exists`,\n constraintExistsCheck({ constraintName, schema: schemaName, table: tableName }),\n ),\n ],\n execute: [\n step(\n `drop constraint \"${constraintName}\"`,\n `ALTER TABLE ${qualified} DROP CONSTRAINT ${quoteIdentifier(constraintName)}`,\n ),\n ],\n postcheck: [\n step(\n `verify constraint \"${constraintName}\" does not exist`,\n constraintExistsCheck({\n constraintName,\n schema: schemaName,\n table: tableName,\n exists: false,\n }),\n ),\n ],\n };\n}\n","import { quoteIdentifier } from '../../sql-utils';\nimport { type Op, step } from './shared';\n\nexport function createExtension(extensionName: string): Op {\n return {\n id: `extension.${extensionName}`,\n label: `Create extension \"${extensionName}\"`,\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [],\n execute: [\n step(\n `Create extension \"${extensionName}\"`,\n `CREATE EXTENSION IF NOT EXISTS ${quoteIdentifier(extensionName)}`,\n ),\n ],\n postcheck: [],\n };\n}\n\n/**\n * Install a Postgres extension as the baseline op for an extension-pack\n * contract space. Layered on top of {@link createExtension}: stamps an\n * `invariantId` (required so the per-space marker records the install),\n * scopes the op `id` under a caller-chosen namespace (e.g. `pgvector.`),\n * and emits pre- and postcheck SQL probing `pg_extension`. The richer\n * shape lets the runner's idempotency probe skip the install on re-run\n * (postcheck-pre-satisfied) without firing the precheck.\n *\n * Use this for hand-rolled baseline migrations in contract-space\n * extension packages (e.g. `extension-pgvector`, `extension-paradedb`);\n * use the bare {@link createExtension} for planner-emitted ops where the\n * caller already controls idempotency through the surrounding plan.\n */\nexport function installExtension(options: {\n readonly extensionName: string;\n readonly invariantId: string;\n readonly id: string;\n readonly label?: string;\n}): Op {\n const { extensionName, invariantId, id } = options;\n const label = options.label ?? `Enable extension \"${extensionName}\"`;\n return {\n id,\n label,\n operationClass: 'additive',\n invariantId,\n target: {\n id: 'postgres',\n details: { schema: 'public', objectType: 'dependency', name: extensionName },\n },\n precheck: [\n step(\n `verify extension \"${extensionName}\" is not already enabled`,\n `SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = '${extensionName}')`,\n ),\n ],\n execute: [\n step(\n `create extension \"${extensionName}\"`,\n `CREATE EXTENSION IF NOT EXISTS ${extensionName}`,\n ),\n ],\n postcheck: [\n step(\n `confirm extension \"${extensionName}\" is enabled`,\n `SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = '${extensionName}')`,\n ),\n ],\n };\n}\n\nexport function createSchema(schemaName: string): Op {\n return {\n id: `schema.${schemaName}`,\n label: `Create schema \"${schemaName}\"`,\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [],\n execute: [\n step(\n `Create schema \"${schemaName}\"`,\n `CREATE SCHEMA IF NOT EXISTS ${quoteIdentifier(schemaName)}`,\n ),\n ],\n postcheck: [],\n };\n}\n","import { escapeLiteral, qualifyName, quoteIdentifier } from '../../sql-utils';\nimport { type Op, step, targetDetails } from './shared';\n\nfunction enumTypeExistsCheck(schemaName: string, nativeType: string, exists = true): string {\n const clause = exists ? 'EXISTS' : 'NOT EXISTS';\n return `SELECT ${clause} (\n SELECT 1\n FROM pg_type t\n JOIN pg_namespace n ON t.typnamespace = n.oid\n WHERE n.nspname = '${escapeLiteral(schemaName)}'\n AND t.typname = '${escapeLiteral(nativeType)}'\n)`;\n}\n\nexport function createEnumType(\n schemaName: string,\n typeName: string,\n values: readonly string[],\n): Op {\n const qualifiedType = qualifyName(schemaName, typeName);\n const literalValues = values.map((v) => `'${escapeLiteral(v)}'`).join(', ');\n return {\n id: `type.${typeName}`,\n label: `Create enum type \"${typeName}\"`,\n operationClass: 'additive',\n target: targetDetails('type', typeName, schemaName),\n precheck: [\n step(\n `ensure type \"${typeName}\" does not exist`,\n enumTypeExistsCheck(schemaName, typeName, false),\n ),\n ],\n execute: [\n step(\n `create enum type \"${typeName}\"`,\n `CREATE TYPE ${qualifiedType} AS ENUM (${literalValues})`,\n ),\n ],\n postcheck: [\n step(`verify type \"${typeName}\" exists`, enumTypeExistsCheck(schemaName, typeName)),\n ],\n };\n}\n\n/**\n * `typeName` is the contract-facing type name (used for id/label).\n * `nativeType` is the Postgres type name to mutate (may differ for external types).\n */\nexport function addEnumValues(\n schemaName: string,\n typeName: string,\n nativeType: string,\n values: readonly string[],\n): Op {\n const qualifiedType = qualifyName(schemaName, nativeType);\n return {\n id: `type.${typeName}.addValues`,\n label: `Add values to enum type \"${typeName}\": ${values.join(', ')}`,\n operationClass: 'additive',\n target: targetDetails('type', typeName, schemaName),\n precheck: [\n step(`ensure type \"${nativeType}\" exists`, enumTypeExistsCheck(schemaName, nativeType)),\n ],\n execute: values.map((value) =>\n step(\n `add value '${value}' to enum \"${nativeType}\"`,\n `ALTER TYPE ${qualifiedType} ADD VALUE '${escapeLiteral(value)}'`,\n ),\n ),\n postcheck: [\n step(`verify type \"${nativeType}\" exists`, enumTypeExistsCheck(schemaName, nativeType)),\n ],\n };\n}\n\nexport function dropEnumType(schemaName: string, typeName: string): Op {\n const qualified = qualifyName(schemaName, typeName);\n return {\n id: `type.${typeName}.drop`,\n label: `Drop enum type \"${typeName}\"`,\n operationClass: 'destructive',\n target: targetDetails('type', typeName, schemaName),\n precheck: [step(`ensure type \"${typeName}\" exists`, enumTypeExistsCheck(schemaName, typeName))],\n execute: [step(`drop enum type \"${typeName}\"`, `DROP TYPE ${qualified}`)],\n postcheck: [\n step(`verify type \"${typeName}\" removed`, enumTypeExistsCheck(schemaName, typeName, false)),\n ],\n };\n}\n\nexport function renameType(schemaName: string, fromName: string, toName: string): Op {\n const qualifiedFrom = qualifyName(schemaName, fromName);\n return {\n id: `type.${fromName}.rename`,\n label: `Rename type \"${fromName}\" to \"${toName}\"`,\n operationClass: 'destructive',\n target: targetDetails('type', fromName, schemaName),\n precheck: [\n step(`ensure type \"${fromName}\" exists`, enumTypeExistsCheck(schemaName, fromName)),\n step(\n `ensure type \"${toName}\" does not already exist`,\n enumTypeExistsCheck(schemaName, toName, false),\n ),\n ],\n execute: [\n step(\n `rename type \"${fromName}\" to \"${toName}\"`,\n `ALTER TYPE ${qualifiedFrom} RENAME TO ${quoteIdentifier(toName)}`,\n ),\n ],\n postcheck: [step(`verify type \"${toName}\" exists`, enumTypeExistsCheck(schemaName, toName))],\n };\n}\n","import { escapeLiteral, quoteIdentifier } from '../../sql-utils';\nimport { qualifyTableName, toRegclassLiteral } from '../planner-sql-checks';\nimport { type Op, step, targetDetails } from './shared';\n\nexport interface CreateIndexExtras {\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n}\n\nfunction renderIndexOptionValue(key: string, value: unknown): string {\n if (typeof value === 'string') return `'${escapeLiteral(value)}'`;\n if (typeof value === 'number' && Number.isFinite(value)) return String(value);\n if (typeof value === 'boolean') return value ? 'true' : 'false';\n throw new Error(\n `Index option \"${key}\" must be a string, finite number, or boolean; got ${typeof value}`,\n );\n}\n\nfunction renderIndexOptions(options: Record<string, unknown>): string {\n return Object.entries(options)\n .map(([key, value]) => `${quoteIdentifier(key)} = ${renderIndexOptionValue(key, value)}`)\n .join(', ');\n}\n\nexport function createIndex(\n schemaName: string,\n tableName: string,\n indexName: string,\n columns: readonly string[],\n extras?: CreateIndexExtras,\n): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n const columnList = columns.map(quoteIdentifier).join(', ');\n const using = extras?.type ? ` USING ${quoteIdentifier(extras.type)}` : '';\n const options = extras?.options;\n const withClause =\n options && Object.keys(options).length > 0 ? ` WITH (${renderIndexOptions(options)})` : '';\n return {\n id: `index.${tableName}.${indexName}`,\n label: `Create index \"${indexName}\" on \"${tableName}\"`,\n operationClass: 'additive',\n target: targetDetails('index', indexName, schemaName, tableName),\n precheck: [\n step(\n `ensure index \"${indexName}\" does not exist`,\n `SELECT to_regclass(${toRegclassLiteral(schemaName, indexName)}) IS NULL`,\n ),\n ],\n execute: [\n step(\n `create index \"${indexName}\"`,\n `CREATE INDEX ${quoteIdentifier(indexName)} ON ${qualified}${using} (${columnList})${withClause}`,\n ),\n ],\n postcheck: [\n step(\n `verify index \"${indexName}\" exists`,\n `SELECT to_regclass(${toRegclassLiteral(schemaName, indexName)}) IS NOT NULL`,\n ),\n ],\n };\n}\n\nexport function dropIndex(schemaName: string, tableName: string, indexName: string): Op {\n return {\n id: `dropIndex.${tableName}.${indexName}`,\n label: `Drop index \"${indexName}\"`,\n operationClass: 'destructive',\n target: targetDetails('index', indexName, schemaName, tableName),\n precheck: [\n step(\n `ensure index \"${indexName}\" exists`,\n `SELECT to_regclass(${toRegclassLiteral(schemaName, indexName)}) IS NOT NULL`,\n ),\n ],\n execute: [\n step(`drop index \"${indexName}\"`, `DROP INDEX ${qualifyTableName(schemaName, indexName)}`),\n ],\n postcheck: [\n step(\n `verify index \"${indexName}\" does not exist`,\n `SELECT to_regclass(${toRegclassLiteral(schemaName, indexName)}) IS NULL`,\n ),\n ],\n };\n}\n","import { quoteIdentifier } from '../../sql-utils';\nimport { qualifyTableName, toRegclassLiteral } from '../planner-sql-checks';\nimport { type ColumnSpec, type Op, renderColumnDefinition, step, targetDetails } from './shared';\n\nexport function createTable(\n schemaName: string,\n tableName: string,\n columns: ReadonlyArray<ColumnSpec>,\n primaryKey?: { readonly columns: readonly string[] },\n): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n const columnDefs = columns.map(renderColumnDefinition);\n const constraintDefs: string[] = [];\n if (primaryKey) {\n constraintDefs.push(`PRIMARY KEY (${primaryKey.columns.map(quoteIdentifier).join(', ')})`);\n }\n const allDefs = [...columnDefs, ...constraintDefs];\n const createSql = `CREATE TABLE ${qualified} (\\n ${allDefs.join(',\\n ')}\\n)`;\n\n return {\n id: `table.${tableName}`,\n label: `Create table \"${tableName}\"`,\n summary: `Creates table \"${tableName}\"`,\n operationClass: 'additive',\n target: targetDetails('table', tableName, schemaName),\n precheck: [\n step(\n `ensure table \"${tableName}\" does not exist`,\n `SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NULL`,\n ),\n ],\n execute: [step(`create table \"${tableName}\"`, createSql)],\n postcheck: [\n step(\n `verify table \"${tableName}\" exists`,\n `SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NOT NULL`,\n ),\n ],\n };\n}\n\nexport function dropTable(schemaName: string, tableName: string): Op {\n const qualified = qualifyTableName(schemaName, tableName);\n return {\n id: `dropTable.${tableName}`,\n label: `Drop table \"${tableName}\"`,\n operationClass: 'destructive',\n target: targetDetails('table', tableName, schemaName),\n precheck: [\n step(\n `ensure table \"${tableName}\" exists`,\n `SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NOT NULL`,\n ),\n ],\n execute: [step(`drop table \"${tableName}\"`, `DROP TABLE ${qualified}`)],\n postcheck: [\n step(\n `verify table \"${tableName}\" does not exist`,\n `SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NULL`,\n ),\n ],\n };\n}\n"],"mappings":";;;;AA0CA,SAAgB,KAAK,aAAqB,KAAa;CACrD,OAAO;EAAE;EAAa;EAAK;;AA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A;EAAA,SACW,IAAA;EAAA,SAA2B,IAAA;AAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as PostgresColumnDefault } from "./types-
|
|
1
|
+
import { t as PostgresColumnDefault } from "./types-CTqpysRY.mjs";
|
|
2
2
|
export { type PostgresColumnDefault };
|
package/dist/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"description": "Postgres target pack for Prisma Next",
|
|
7
8
|
"dependencies": {
|
|
8
|
-
"
|
|
9
|
+
"@standard-schema/spec": "^1.1.0",
|
|
10
|
+
"arktype": "^2.1.29",
|
|
9
11
|
"pathe": "^2.0.3",
|
|
10
|
-
"@prisma-next/cli": "0.5.
|
|
11
|
-
"@prisma-next/contract": "0.5.
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/
|
|
15
|
-
"@prisma-next/
|
|
16
|
-
"@prisma-next/
|
|
17
|
-
"@prisma-next/
|
|
18
|
-
"@prisma-next/sql-errors": "0.5.
|
|
19
|
-
"@prisma-next/sql-operations": "0.5.
|
|
20
|
-
"@prisma-next/sql-relational-core": "0.5.
|
|
21
|
-
"@prisma-next/
|
|
22
|
-
"@prisma-next/
|
|
12
|
+
"@prisma-next/cli": "0.5.1",
|
|
13
|
+
"@prisma-next/contract": "0.5.1",
|
|
14
|
+
"@prisma-next/framework-components": "0.5.1",
|
|
15
|
+
"@prisma-next/errors": "0.5.1",
|
|
16
|
+
"@prisma-next/family-sql": "0.5.1",
|
|
17
|
+
"@prisma-next/sql-contract": "0.5.1",
|
|
18
|
+
"@prisma-next/migration-tools": "0.5.1",
|
|
19
|
+
"@prisma-next/ts-render": "0.5.1",
|
|
20
|
+
"@prisma-next/sql-errors": "0.5.1",
|
|
21
|
+
"@prisma-next/sql-operations": "0.5.1",
|
|
22
|
+
"@prisma-next/sql-relational-core": "0.5.1",
|
|
23
|
+
"@prisma-next/utils": "0.5.1",
|
|
24
|
+
"@prisma-next/sql-schema-ir": "0.5.1"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
25
|
-
"tsdown": "0.
|
|
27
|
+
"tsdown": "0.22.0",
|
|
26
28
|
"typescript": "5.9.3",
|
|
27
|
-
"vitest": "4.
|
|
29
|
+
"vitest": "4.1.5",
|
|
30
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
28
31
|
"@prisma-next/tsconfig": "0.0.0",
|
|
29
|
-
"@prisma-next/tsdown": "0.0.0"
|
|
30
|
-
"@prisma-next/test-utils": "0.0.1"
|
|
32
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
31
33
|
},
|
|
32
34
|
"files": [
|
|
33
35
|
"dist",
|
package/src/core/authoring.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';
|
|
1
2
|
import type {
|
|
2
3
|
AuthoringFieldNamespace,
|
|
3
4
|
AuthoringTypeNamespace,
|
|
@@ -89,15 +90,8 @@ export const postgresAuthoringFieldPresets = {
|
|
|
89
90
|
nativeType: 'timestamptz',
|
|
90
91
|
},
|
|
91
92
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
nativeType: 'timestamptz',
|
|
97
|
-
default: {
|
|
98
|
-
kind: 'function',
|
|
99
|
-
expression: 'now()',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
93
|
+
temporal: temporalAuthoringPresets({
|
|
94
|
+
codecId: 'pg/timestamptz@1',
|
|
95
|
+
nativeType: 'timestamptz',
|
|
96
|
+
}),
|
|
103
97
|
} as const satisfies AuthoringFieldNamespace;
|