@prisma-next/target-postgres 0.12.0-dev.3 → 0.12.0-dev.31
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-DliyCWPY.d.mts → codec-ids-BEVQ-gO4.d.mts} +1 -1
- package/dist/{codec-ids-DliyCWPY.d.mts.map → codec-ids-BEVQ-gO4.d.mts.map} +1 -1
- package/dist/codec-ids.d.mts +1 -1
- package/dist/{codec-types-BF1DXTPs.d.mts → codec-types-ClVgENiR.d.mts} +2 -2
- package/dist/{codec-types-BF1DXTPs.d.mts.map → codec-types-ClVgENiR.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-DuP3d9Au.d.mts → codecs-BHrYhAZc.d.mts} +2 -2
- package/dist/{codecs-DuP3d9Au.d.mts.map → codecs-BHrYhAZc.d.mts.map} +1 -1
- package/dist/codecs.d.mts +1 -1
- package/dist/column-type-compatibility-Dzxz_CkP.mjs +11 -0
- package/dist/column-type-compatibility-Dzxz_CkP.mjs.map +1 -0
- package/dist/column-type-compatibility.d.mts +5 -0
- package/dist/column-type-compatibility.d.mts.map +1 -0
- package/dist/column-type-compatibility.mjs +2 -0
- package/dist/contract-free.d.mts +35 -0
- package/dist/contract-free.d.mts.map +1 -0
- package/dist/contract-free.mjs +97 -0
- package/dist/contract-free.mjs.map +1 -0
- package/dist/control.d.mts +1 -1
- package/dist/control.mjs +45 -25
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-CAPmAdxS.d.mts → data-transform-C1ZpoMCt.d.mts} +2 -2
- package/dist/{data-transform-CAPmAdxS.d.mts.map → data-transform-C1ZpoMCt.d.mts.map} +1 -1
- package/dist/{data-transform-CRkv2T_U.mjs → data-transform-DIYwbe4S.mjs} +1 -1
- package/dist/{data-transform-CRkv2T_U.mjs.map → data-transform-DIYwbe4S.mjs.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/ddl.d.mts +2 -0
- package/dist/ddl.mjs +2 -0
- package/dist/{default-normalizer-DaAhmzBV.mjs → default-normalizer-DFHtpCPH.mjs} +1 -1
- package/dist/{default-normalizer-DaAhmzBV.mjs.map → default-normalizer-DFHtpCPH.mjs.map} +1 -1
- package/dist/default-normalizer.mjs +1 -1
- package/dist/{descriptor-meta-Uu8QaClr.mjs → descriptor-meta-BqATo5Dz.mjs} +3 -2
- package/dist/descriptor-meta-BqATo5Dz.mjs.map +1 -0
- package/dist/{descriptor-meta-runtime-DMRX39kp.mjs → descriptor-meta-runtime-BBL7VdnR.mjs} +2 -2
- package/dist/{descriptor-meta-runtime-DMRX39kp.mjs.map → descriptor-meta-runtime-BBL7VdnR.mjs.map} +1 -1
- package/dist/{enum-planning-DRA9LaMU.mjs → enum-planning-DHQE3zSH.mjs} +0 -0
- package/dist/{enum-planning-DRA9LaMU.mjs.map → enum-planning-DHQE3zSH.mjs.map} +1 -1
- package/dist/enum-planning.d.mts +1 -1
- package/dist/enum-planning.mjs +1 -1
- package/dist/{errors-BbnITmAD.mjs → errors-De185dnO.mjs} +1 -1
- package/dist/{errors-BbnITmAD.mjs.map → errors-De185dnO.mjs.map} +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{issue-planner-BtaL6OfW.mjs → issue-planner-ttX4mOiF.mjs} +10 -10
- package/dist/{issue-planner-BtaL6OfW.mjs.map → issue-planner-ttX4mOiF.mjs.map} +1 -1
- package/dist/issue-planner.d.mts +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +3 -3
- package/dist/migration.mjs +3 -3
- package/dist/{native-type-normalizer-BNEQ9VDs.mjs → native-type-normalizer-BUUe8USD.mjs} +1 -1
- package/dist/{native-type-normalizer-BNEQ9VDs.mjs.map → native-type-normalizer-BUUe8USD.mjs.map} +1 -1
- package/dist/native-type-normalizer.mjs +1 -1
- package/dist/nodes-BS8vS8gv.d.mts +38 -0
- package/dist/nodes-BS8vS8gv.d.mts.map +1 -0
- package/dist/nodes-BYSqasmC.mjs +42 -0
- package/dist/nodes-BYSqasmC.mjs.map +1 -0
- package/dist/{op-factory-call-CDlImOF_.d.mts → op-factory-call-B9mYdDex.d.mts} +3 -3
- package/dist/{op-factory-call-CDlImOF_.d.mts.map → op-factory-call-B9mYdDex.d.mts.map} +1 -1
- package/dist/{op-factory-call-ewOd5q6L.mjs → op-factory-call-D8XePTfV.mjs} +2 -2
- package/dist/{op-factory-call-ewOd5q6L.mjs.map → op-factory-call-D8XePTfV.mjs.map} +1 -1
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +3 -2
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-ddl-builders-BNMfSE9r.mjs → planner-ddl-builders-BcRMeGgx.mjs} +3 -3
- package/dist/{planner-ddl-builders-BNMfSE9r.mjs.map → planner-ddl-builders-BcRMeGgx.mjs.map} +1 -1
- package/dist/planner-ddl-builders.d.mts +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-nhVj0hp-.mjs → planner-identity-values-DmwlJe_z.mjs} +1 -1
- package/dist/{planner-identity-values-nhVj0hp-.mjs.map → planner-identity-values-DmwlJe_z.mjs.map} +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-D_nsXbhl.mjs → planner-produced-postgres-migration-D6KXC2DH.mjs} +4 -4
- package/dist/{planner-produced-postgres-migration-D_nsXbhl.mjs.map → planner-produced-postgres-migration-D6KXC2DH.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-D02NOhVQ.d.mts → planner-produced-postgres-migration-RdjC7aUC.d.mts} +3 -3
- package/dist/{planner-produced-postgres-migration-D02NOhVQ.d.mts.map → planner-produced-postgres-migration-RdjC7aUC.d.mts.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-schema-lookup-CGxxYfnD.mjs → planner-schema-lookup-Bm4S3LvB.mjs} +1 -1
- package/dist/{planner-schema-lookup-CGxxYfnD.mjs.map → planner-schema-lookup-Bm4S3LvB.mjs.map} +1 -1
- package/dist/planner-schema-lookup.mjs +1 -1
- package/dist/{planner-sql-checks-CfEiTXoQ.mjs → planner-sql-checks-lxWZQCFz.mjs} +3 -3
- package/dist/{planner-sql-checks-CfEiTXoQ.mjs.map → planner-sql-checks-lxWZQCFz.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-target-details-a_wuOiYf.d.mts → planner-target-details-C1Ye0hb6.d.mts} +1 -1
- package/dist/{planner-target-details-a_wuOiYf.d.mts.map → planner-target-details-C1Ye0hb6.d.mts.map} +1 -1
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner-y-bVvDFR.mjs +342 -0
- package/dist/planner-y-bVvDFR.mjs.map +1 -0
- package/dist/planner.d.mts +3 -2
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-BnOboPWs.mjs → postgres-contract-serializer-BYpK6TkY.mjs} +3 -3
- package/dist/{postgres-contract-serializer-BnOboPWs.mjs.map → postgres-contract-serializer-BYpK6TkY.mjs.map} +1 -1
- package/dist/{postgres-enum-type-CSzsvXrO.d.mts → postgres-enum-type-Bl6THBPg.d.mts} +1 -1
- package/dist/{postgres-enum-type-CSzsvXrO.d.mts.map → postgres-enum-type-Bl6THBPg.d.mts.map} +1 -1
- package/dist/{postgres-enum-type-BMgyxNyy.mjs → postgres-enum-type-CaGZ2mfI.mjs} +1 -1
- package/dist/{postgres-enum-type-BMgyxNyy.mjs.map → postgres-enum-type-CaGZ2mfI.mjs.map} +1 -1
- package/dist/{postgres-migration-BatbEvU6.mjs → postgres-migration-BnDg_Nj0.mjs} +3 -3
- package/dist/{postgres-migration-BatbEvU6.mjs.map → postgres-migration-BnDg_Nj0.mjs.map} +1 -1
- package/dist/{postgres-migration-DRY8V-bQ.d.mts → postgres-migration-DLZtVVDM.d.mts} +3 -3
- package/dist/{postgres-migration-DRY8V-bQ.d.mts.map → postgres-migration-DLZtVVDM.d.mts.map} +1 -1
- package/dist/{postgres-schema-BxAuNFX0.mjs → postgres-schema-Dky_Jff8.mjs} +3 -3
- package/dist/{postgres-schema-BxAuNFX0.mjs.map → postgres-schema-Dky_Jff8.mjs.map} +1 -1
- package/dist/{render-ops-XhICjX_P.mjs → render-ops-BpU-Qv06.mjs} +1 -1
- package/dist/{render-ops-XhICjX_P.mjs.map → render-ops-BpU-Qv06.mjs.map} +1 -1
- package/dist/render-ops.d.mts +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/{render-typescript-K125n-RZ.mjs → render-typescript-D9O7aOS_.mjs} +1 -1
- package/dist/{render-typescript-K125n-RZ.mjs.map → render-typescript-D9O7aOS_.mjs.map} +1 -1
- package/dist/render-typescript.mjs +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/{shared-Do_a5ymU.d.mts → shared-wRIzOjdd.d.mts} +2 -2
- package/dist/{shared-Do_a5ymU.d.mts.map → shared-wRIzOjdd.d.mts.map} +1 -1
- package/dist/{sql-utils-CggjWNij.mjs → sql-utils-DR_F9aHR.mjs} +1 -1
- package/dist/{sql-utils-CggjWNij.mjs.map → sql-utils-DR_F9aHR.mjs.map} +1 -1
- package/dist/sql-utils.mjs +1 -1
- package/dist/{statement-builders-DVI5IVAa.mjs → statement-builders-Cd311EDF.mjs} +16 -4
- package/dist/statement-builders-Cd311EDF.mjs.map +1 -0
- package/dist/statement-builders.d.mts.map +1 -1
- package/dist/statement-builders.mjs +1 -1
- package/dist/{tables-DoA39Yqo.mjs → tables-Cuy4VIgu.mjs} +3 -3
- package/dist/{tables-DoA39Yqo.mjs.map → tables-Cuy4VIgu.mjs.map} +1 -1
- package/dist/{types-O40IcFV9.d.mts → types-DncetAjv.d.mts} +1 -1
- package/dist/types-DncetAjv.d.mts.map +1 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +2 -2
- package/package.json +20 -17
- package/src/contract-free/control-bootstrap.ts +55 -0
- package/src/contract-free/ddl.ts +32 -0
- package/src/core/column-type-compatibility.ts +13 -0
- package/src/core/ddl/nodes.ts +59 -0
- package/src/core/descriptor-meta.ts +1 -0
- package/src/core/migrations/control-policy.ts +235 -0
- package/src/core/migrations/planner.ts +57 -6
- package/src/core/migrations/runner.ts +66 -27
- package/src/core/migrations/statement-builders.ts +18 -3
- package/src/exports/column-type-compatibility.ts +1 -0
- package/src/exports/contract-free.ts +5 -0
- package/src/exports/ddl.ts +7 -0
- package/dist/descriptor-meta-Uu8QaClr.mjs.map +0 -1
- package/dist/planner-Bjz5pnLa.mjs +0 -177
- package/dist/planner-Bjz5pnLa.mjs.map +0 -1
- package/dist/statement-builders-DVI5IVAa.mjs.map +0 -1
- package/dist/types-O40IcFV9.d.mts.map +0 -1
package/dist/{planner-schema-lookup-CGxxYfnD.mjs.map → planner-schema-lookup-Bm4S3LvB.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner-schema-lookup-
|
|
1
|
+
{"version":3,"file":"planner-schema-lookup-Bm4S3LvB.mjs","names":[],"sources":["../src/core/migrations/planner-schema-lookup.ts"],"sourcesContent":["import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport 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<string>();\n for (const fk of table.foreignKeys) {\n // Keys are JSON-encoded tuples so identifiers containing any character\n // (including the column-list comma or pipe characters) cannot collide\n // across structurally-distinct FKs. Unqualified keys are 3-tuples\n // (cols, table, refCols); qualified keys are 4-tuples\n // (cols, schema, table, refCols) — the arity difference makes the two\n // key shapes fundamentally non-collidable.\n fkKeys.add(JSON.stringify([fk.columns, fk.referencedTable, fk.referencedColumns]));\n if (fk.referencedSchema !== undefined) {\n fkKeys.add(\n JSON.stringify([fk.columns, fk.referencedSchema, fk.referencedTable, fk.referencedColumns]),\n );\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 // Mirror the encoding produced by buildSchemaTableLookup exactly:\n // unqualified 3-tuple for unbound-namespace FKs, qualified 4-tuple for\n // bound-namespace FKs.\n if (fk.target.namespaceId === UNBOUND_NAMESPACE_ID) {\n return lookup.fkKeys.has(\n JSON.stringify([fk.source.columns, fk.target.tableName, fk.target.columns]),\n );\n }\n return lookup.fkKeys.has(\n JSON.stringify([\n fk.source.columns,\n fk.target.namespaceId,\n fk.target.t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B;CAIhF,IAAI,GAAG,OAAO,gBAAgB,sBAC5B,OAAO,OAAO,OAAO,IACnB,KAAK,UAAU;EAAC,GAAG,OAAO;EAAS,GAAG,OAAO;EAAW,GAAG,OAAO;CAAO,CAAC,CAC5E;CAEF,OAAO,OAAO,OAAO,IACnB,KAAK,UAAU;EACb,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;CACZ,CAAC,CACH;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as hasUniqueConstraint, n as hasForeignKey, r as hasIndex, t as buildSchemaLookupMap } from "./planner-schema-lookup-
|
|
1
|
+
import { i as hasUniqueConstraint, n as hasForeignKey, r as hasIndex, t as buildSchemaLookupMap } from "./planner-schema-lookup-Bm4S3LvB.mjs";
|
|
2
2
|
export { buildSchemaLookupMap, hasForeignKey, hasIndex, hasUniqueConstraint };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-
|
|
2
|
-
import { i as postgresCreateNamespace } from "./postgres-schema-
|
|
1
|
+
import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-DR_F9aHR.mjs";
|
|
2
|
+
import { i as postgresCreateNamespace } from "./postgres-schema-Dky_Jff8.mjs";
|
|
3
3
|
import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
4
4
|
//#region src/core/migrations/planner-type-resolution.ts
|
|
5
5
|
function resolveColumnTypeMetadata(column, storageTypes) {
|
|
@@ -258,4 +258,4 @@ function tableHasPrimaryKeyCheck(schema, table, exists, constraintName) {
|
|
|
258
258
|
//#endregion
|
|
259
259
|
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 };
|
|
260
260
|
|
|
261
|
-
//# sourceMappingURL=planner-sql-checks-
|
|
261
|
+
//# sourceMappingURL=planner-sql-checks-lxWZQCFz.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner-sql-checks-CfEiTXoQ.mjs","names":[],"sources":["../src/core/migrations/planner-type-resolution.ts","../src/core/migrations/planner-sql-checks.ts"],"sourcesContent":["import {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n type StorageColumn,\n type StorageTypeInstance,\n} 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: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>,\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 if (isPostgresEnumStorageEntry(referencedType)) {\n // Enum types are referenced by name (`quoteIdentifier(nativeType)`),\n // not via parameterised codec expansion. The structural shape\n // carries `codecId` as an enumerable property (mirroring the\n // codec-typed view); `typeParams` is intentionally omitted here so\n // `expandParameterizedTypeSql` does not try to look up a\n // (deliberately absent) `expandNativeType` hook for `pg/enum@*`.\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n };\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 {\n PostgresEnumStorageEntry,\n StorageColumn,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { postgresCreateNamespace } from '../postgres-schema';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\n/**\n * String-keyed entry points the migration ops use to render\n * schema-qualified DDL and catalog checks. The `schema` argument is\n * interpreted as a namespace coordinate: the framework `__unbound__`\n * sentinel resolves to the late-bound `PostgresUnboundSchema` singleton\n * (which elides the qualifier so `search_path` decides at runtime); any\n * other id materialises a `PostgresSchema(id)` whose qualifier is the\n * named schema. Helpers route through these `Namespace` concretions so\n * the unbound branch lives in the polymorphic override, not the call\n * site.\n */\nexport function qualifyTableName(schema: string, table: string): string {\n return postgresCreateNamespace({ id: schema }).qualifyTable(table);\n}\n\nexport function toRegclassLiteral(schema: string, name: string): string {\n return postgresCreateNamespace({ id: schema }).regclassLiteral(name);\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 namespace = postgresCreateNamespace({ id: schema });\n const existsClause = exists ? 'EXISTS' : 'NOT EXISTS';\n const tableFilter = table\n ? `AND c.conrelid = to_regclass(${namespace.regclassLiteral(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 = ${namespace.schemaSqlExpression()}\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 namespace = postgresCreateNamespace({ id: schema });\n const existsClause = exists ? '' : 'NOT ';\n return `SELECT ${existsClause}EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\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 namespace = postgresCreateNamespace({ id: schema });\n const expected = nullable ? 'YES' : 'NO';\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\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 const namespace = postgresCreateNamespace({ id: opts.schema });\n return `SELECT NOT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\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 | PostgresEnumStorageEntry> = {},\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 const namespace = postgresCreateNamespace({ id: schema });\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 = ${namespace.schemaSqlExpression()}\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 namespace = postgresCreateNamespace({ id: schema });\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 = ${namespace.schemaSqlExpression()}\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 namespace = postgresCreateNamespace({ id: schema });\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 = ${namespace.schemaSqlExpression()}\n AND c.relname = '${escapeLiteral(table)}'\n AND i.indisprimary\n ${constraintFilter}\n)`;\n}\n"],"mappings":";;;;AAYA,SAAgB,0BACd,QACA,cAC4B;CAC5B,IAAI,CAAC,OAAO,SACV,OAAO;CAGT,MAAM,iBAAiB,aAAa,OAAO;CAC3C,IAAI,CAAC,gBACH,OAAO;CAGT,IAAI,2BAA2B,cAAc,GAO3C,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;CAC7B;CAGF,OAAO;EACL,SA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AE;wBACjC,cAAc,KAAK,KAAK,EAAE;yBACzB,cAAc,KAAK,MAAM,EAAE;;;AAGpD;AAEA,MAAM,sBAAmD,IAAI,IAAI;CAC/D,CAAC,QAAQ,UAAU;CACnB,CAAC,QAAQ,SAAS;CAClB,CAAC,QAAQ,QAAQ;CACjB,CAAC,UAAU,MAAM;CACjB,CAAC,UAAU,kBAAkB;CAC7B,CAAC,QAAQ,SAAS;CAClB,CAAC,aAAa,6BAA6B;CAC3C,CAAC,eAAe,0BAA0B;CAC1C,CAAC,QAAQ,wBAAwB;CACjC,CAAC,UAAU,qBAAqB;AAClC,CAAC;AAED,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;AACF,CAAC;AAED,SAAS,0BAA0B,YAA4B;CAC7D,IACE,qCAAqC,KAAK,UAAU,KACpD,CAAC,mCAAmC,IAAI,UAAU,GAElD,OAAO;CAGT,OAAO,gBAAgB,UAAU;AACnC;AAEA,SAAgB,wBACd,QACA,YACA,eAA+E,CAAC,GACxE;CACR,MAAM,WAAW,0BAA0B,QAAQ,YAAY;CAE/D,IAAI,SAAS,cAAc,SAAS,SAAS;EAC3C,MAAM,QAAQ,WAAW,IAAI,SAAS,OAAO;EAC7C,IAAI,OAAO,kBACT,OAAO,MAAM,iBAAiB;GAC5B,YAAY,SAAS;GACrB,SAAS,SAAS;GAClB,YAAY,SAAS;EACvB,CAAC;CAEL;CAEA,IAAI,OAAO,SACT,OAAO,0BAA0B,SAAS,UAAU;CAGtD,OAAO,oBAAoB,IAAI,SAAS,UAAU,KAAK,SAAS;AAClE;AAEA,SAAgB,gBAAgB,EAC9B,QACA,OACA,QACA,gBAMS;CAET,OAAO;;;;;sBADW,wBAAwB,EAAE,IAAI,OAAO,CAM3B,EAAE,oBAAoB,EAAE;uBAC/B,cAAc,KAAK,EAAE;uBACrB,cAAc,MAAM,EAAE;kDACK,cAAc,YAAY,EAAE;;;AAG9E;AAEA,SAAgB,yBAAyB,EACvC,QACA,OACA,QACA,SAAS,QAMA;CACT,MAAM,YAAY,wBAAwB,EAAE,IAAI,OAAO,CAAC;CACxD,MAAM,YAAY,SAAS,gBAAgB;CAC3C,OAAO;;;yBAGgB,UAAU,oBAAoB,EAAE;wBACjC,cAAc,KAAK,EAAE;yBACpB,cAAc,MAAM,EAAE;yBACtB,UAAU;;AAEnC;AAEA,SAAgB,wBACd,QACA,OACA,QACA,gBACQ;CACR,MAAM,YAAY,wBAAwB,EAAE,IAAI,OAAO,CAAC;CACxD,MAAM,aAAa,SAAS,KAAK;CACjC,MAAM,mBAAmB,iBACrB,qBAAqB,cAAc,cAAc,EAAE,KACnD;CACJ,OAAO,UAAU,WAAW;;;;;;sBAMR,UAAU,oBAAoB,EAAE;uBAC/B,cAAc,KAAK,EAAE;;MAEtC,iBAAiB;;AAEvB"}
|
|
1
|
+
{"version":3,"file":"planner-sql-checks-lxWZQCFz.mjs","names":[],"sources":["../src/core/migrations/planner-type-resolution.ts","../src/core/migrations/planner-sql-checks.ts"],"sourcesContent":["import {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n type StorageColumn,\n type StorageTypeInstance,\n} 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: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>,\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 if (isPostgresEnumStorageEntry(referencedType)) {\n // Enum types are referenced by name (`quoteIdentifier(nativeType)`),\n // not via parameterised codec expansion. The structural shape\n // carries `codecId` as an enumerable property (mirroring the\n // codec-typed view); `typeParams` is intentionally omitted here so\n // `expandParameterizedTypeSql` does not try to look up a\n // (deliberately absent) `expandNativeType` hook for `pg/enum@*`.\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n };\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 {\n PostgresEnumStorageEntry,\n StorageColumn,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { postgresCreateNamespace } from '../postgres-schema';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\n/**\n * String-keyed entry points the migration ops use to render\n * schema-qualified DDL and catalog checks. The `schema` argument is\n * interpreted as a namespace coordinate: the framework `__unbound__`\n * sentinel resolves to the late-bound `PostgresUnboundSchema` singleton\n * (which elides the qualifier so `search_path` decides at runtime); any\n * other id materialises a `PostgresSchema(id)` whose qualifier is the\n * named schema. Helpers route through these `Namespace` concretions so\n * the unbound branch lives in the polymorphic override, not the call\n * site.\n */\nexport function qualifyTableName(schema: string, table: string): string {\n return postgresCreateNamespace({ id: schema }).qualifyTable(table);\n}\n\nexport function toRegclassLiteral(schema: string, name: string): string {\n return postgresCreateNamespace({ id: schema }).regclassLiteral(name);\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 namespace = postgresCreateNamespace({ id: schema });\n const existsClause = exists ? 'EXISTS' : 'NOT EXISTS';\n const tableFilter = table\n ? `AND c.conrelid = to_regclass(${namespace.regclassLiteral(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 = ${namespace.schemaSqlExpression()}\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 namespace = postgresCreateNamespace({ id: schema });\n const existsClause = exists ? '' : 'NOT ';\n return `SELECT ${existsClause}EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\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 namespace = postgresCreateNamespace({ id: schema });\n const expected = nullable ? 'YES' : 'NO';\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\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 const namespace = postgresCreateNamespace({ id: opts.schema });\n return `SELECT NOT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\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 | PostgresEnumStorageEntry> = {},\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 const namespace = postgresCreateNamespace({ id: schema });\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 = ${namespace.schemaSqlExpression()}\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 namespace = postgresCreateNamespace({ id: schema });\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 = ${namespace.schemaSqlExpression()}\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 namespace = postgresCreateNamespace({ id: schema });\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 = ${namespace.schemaSqlExpression()}\n AND c.relname = '${escapeLiteral(table)}'\n AND i.indisprimary\n ${constraintFilter}\n)`;\n}\n"],"mappings":";;;;AAYA,SAAgB,0BACd,QACA,cAC4B;CAC5B,IAAI,CAAC,OAAO,SACV,OAAO;CAGT,MAAM,iBAAiB,aAAa,OAAO;CAC3C,IAAI,CAAC,gBACH,OAAO;CAGT,IAAI,2BAA2B,cAAc,GAO3C,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;CAC7B;CAGF,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;EAC3B,YAAY,eAAe;CAC7B;AACF;;;;;;;;;;;;;;ACtBA,SAAgB,iBAAiB,QAAgB,OAAuB;CACtE,OAAO,wBAAwB,EAAE,IAAI,OAAO,CAAC,EAAE,aAAa,KAAK;AACnE;AAEA,SAAgB,kBAAkB,QAAgB,MAAsB;CACtE,OAAO,wBAAwB,EAAE,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI;AACrE;;;;;;AAOA,SAAgB,sBAAsB,EACpC,gBACA,QACA,OACA,SAAS,QAMA;CACT,MAAM,YAAY,wBAAwB,EAAE,IAAI,OAAO,CAAC;CACxD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;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;AACF,CAAC;AAED,SAAS,0BAA0B,YAA4B;CAC7D,IACE,qCAAqC,KAAK,UAAU,KACpD,CAAC,mCAAmC,IAAI,UAAU,GAElD,OAAO;CAGT,OAAO,gBAAgB,UAAU;AACnC;AAEA,SAAgB,wBACd,QACA,YACA,eAA+E,CAAC,GACxE;CACR,MAAM,WAAW,0BAA0B,QAAQ,YAAY;CAE/D,IAAI,SAAS,cAAc,SAAS,SAAS;EAC3C,MAAM,QAAQ,WAAW,IAAI,SAAS,OAAO;EAC7C,IAAI,OAAO,kBACT,OAAO,MAAM,iBAAiB;GAC5B,YAAY,SAAS;GACrB,SAAS,SAAS;GAClB,YAAY,SAAS;EACvB,CAAC;CAEL;CAEA,IAAI,OAAO,SACT,OAAO,0BAA0B,SAAS,UAAU;CAGtD,OAAO,oBAAoB,IAAI,SAAS,UAAU,KAAK,SAAS;AAClE;AAEA,SAAgB,gBAAgB,EAC9B,QACA,OACA,QACA,gBAMS;CAET,OAAO;;;;;sBADW,wBAAwB,EAAE,IAAI,OAAO,CAM3B,EAAE,oBAAoB,EAAE;uBAC/B,cAAc,KAAK,EAAE;uBACrB,cAAc,MAAM,EAAE;kDACK,cAAc,YAAY,EAAE;;;AAG9E;AAEA,SAAgB,yBAAyB,EACvC,QACA,OACA,QACA,SAAS,QAMA;CACT,MAAM,YAAY,wBAAwB,EAAE,IAAI,OAAO,CAAC;CACxD,MAAM,YAAY,SAAS,gBAAgB;CAC3C,OAAO;;;yBAGgB,UAAU,oBAAoB,EAAE;wBACjC,cAAc,KAAK,EAAE;yBACpB,cAAc,MAAM,EAAE;yBACtB,UAAU;;AAEnC;AAEA,SAAgB,wBACd,QACA,OACA,QACA,gBACQ;CACR,MAAM,YAAY,wBAAwB,EAAE,IAAI,OAAO,CAAC;CACxD,MAAM,aAAa,SAAS,KAAK;CACjC,MAAM,mBAAmB,iBACrB,qBAAqB,cAAc,cAAc,EAAE,KACnD;CACJ,OAAO,UAAU,WAAW;;;;;;sBAMR,UAAU,oBAAoB,EAAE;uBAC/B,cAAc,KAAK,EAAE;;MAEtC,iBAAiB;;AAEvB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
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-
|
|
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-lxWZQCFz.mjs";
|
|
2
2
|
export { buildExpectedFormatType, columnExistsCheck, columnHasNoDefaultCheck, columnNullabilityCheck, constraintExistsCheck, qualifyTableName, tableHasPrimaryKeyCheck, tableIsEmptyCheck, toRegclassLiteral };
|
package/dist/{planner-target-details-a_wuOiYf.d.mts.map → planner-target-details-C1Ye0hb6.d.mts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner-target-details-
|
|
1
|
+
{"version":3,"file":"planner-target-details-C1Ye0hb6.d.mts","names":[],"sources":["../src/core/migrations/planner-target-details.ts"],"mappings":";KAEY,cAAA;AAAA,UAUK,yBAAA;EAAA,SACN,MAAA;EAAA,SACA,UAAA,EAAY,cAAc;EAAA,SAC1B,IAAA;EAAA,SACA,KAAA;AAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as PostgresPlanTargetDetails } from "./planner-target-details-
|
|
1
|
+
import { t as PostgresPlanTargetDetails } from "./planner-target-details-C1Ye0hb6.mjs";
|
|
2
2
|
export { type PostgresPlanTargetDetails };
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { t as postgresColumnsCompatible } from "./column-type-compatibility-Dzxz_CkP.mjs";
|
|
2
|
+
import { r as isPostgresSchema } from "./postgres-schema-Dky_Jff8.mjs";
|
|
3
|
+
import { t as createResolveExistingEnumValues } from "./enum-planning-DHQE3zSH.mjs";
|
|
4
|
+
import { t as parsePostgresDefault } from "./default-normalizer-DFHtpCPH.mjs";
|
|
5
|
+
import { t as normalizeSchemaNativeType } from "./native-type-normalizer-BUUe8USD.mjs";
|
|
6
|
+
import { n as postgresPlannerStrategies, t as planIssues } from "./issue-planner-ttX4mOiF.mjs";
|
|
7
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-D6KXC2DH.mjs";
|
|
8
|
+
import { extractCodecControlHooks, partitionCallsByControlPolicy, partitionIssuesByControlPolicy, planFieldEventOperations, plannerFailure } from "@prisma-next/family-sql/control";
|
|
9
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
10
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
11
|
+
import { isPostgresEnumStorageEntry, storageTableAt } from "@prisma-next/sql-contract/types";
|
|
12
|
+
import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
|
|
13
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
14
|
+
//#region src/core/migrations/control-policy.ts
|
|
15
|
+
/**
|
|
16
|
+
* Factory calls that create a whole, previously-absent top-level storage
|
|
17
|
+
* object. Used to decide whether `tolerated` permits a call (it only allows
|
|
18
|
+
* creating absent objects, never modifying existing ones).
|
|
19
|
+
*
|
|
20
|
+
* Deliberately an explicit, closed set rather than a `factoryName`
|
|
21
|
+
* create/alter/drop classification: it answers exactly one yes/no question
|
|
22
|
+
* and is fail-closed. Any call not listed here — including future or
|
|
23
|
+
* extension-contributed factories — is treated as NOT object-creation, so it
|
|
24
|
+
* is suppressed under `tolerated` rather than permissively emitted.
|
|
25
|
+
*/
|
|
26
|
+
const OBJECT_CREATION_FACTORIES = new Set([
|
|
27
|
+
"createTable",
|
|
28
|
+
"createEnumType",
|
|
29
|
+
"createSchema"
|
|
30
|
+
]);
|
|
31
|
+
function createsNewTopLevelObject(call) {
|
|
32
|
+
return OBJECT_CREATION_FACTORIES.has(call.factoryName);
|
|
33
|
+
}
|
|
34
|
+
function ddlSchemaNameForNamespace(contract, namespaceId) {
|
|
35
|
+
const namespace = contract.storage.namespaces[namespaceId];
|
|
36
|
+
return isPostgresSchema(namespace) ? namespace.ddlSchemaName(contract.storage) : namespaceId;
|
|
37
|
+
}
|
|
38
|
+
function resolveNamespaceIdForTable(contract, tableName, ddlSchemaName) {
|
|
39
|
+
for (const namespaceId of Object.keys(contract.storage.namespaces)) {
|
|
40
|
+
if (!storageTableAt(contract.storage, namespaceId, tableName)) continue;
|
|
41
|
+
if (ddlSchemaName === void 0 || ddlSchemaNameForNamespace(contract, namespaceId) === ddlSchemaName) return namespaceId;
|
|
42
|
+
}
|
|
43
|
+
return UNBOUND_NAMESPACE_ID;
|
|
44
|
+
}
|
|
45
|
+
function resolveNamespaceIdForDdlSchema(contract, ddlSchemaName) {
|
|
46
|
+
for (const namespaceId of Object.keys(contract.storage.namespaces)) {
|
|
47
|
+
const ns = contract.storage.namespaces[namespaceId];
|
|
48
|
+
if (isPostgresSchema(ns) && ns.ddlSchemaName(contract.storage) === ddlSchemaName) return namespaceId;
|
|
49
|
+
if (namespaceId === ddlSchemaName) return namespaceId;
|
|
50
|
+
}
|
|
51
|
+
return UNBOUND_NAMESPACE_ID;
|
|
52
|
+
}
|
|
53
|
+
function postgresCallFields(call) {
|
|
54
|
+
return {
|
|
55
|
+
...ifDefined("schemaName", "schemaName" in call ? call.schemaName : void 0),
|
|
56
|
+
...ifDefined("tableName", "tableName" in call ? call.tableName : void 0),
|
|
57
|
+
...ifDefined("columnName", "columnName" in call ? call.columnName : void 0),
|
|
58
|
+
...ifDefined("typeName", "typeName" in call ? call.typeName : void 0)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function formatPostgresControlPolicySubjectLabel(factoryName, subject, contract) {
|
|
62
|
+
if (subject?.table) return `${factoryName}(${ddlSchemaNameForNamespace(contract, subject.namespaceId)}.${subject.table})`;
|
|
63
|
+
if (subject?.typeName) return `${factoryName}(${ddlSchemaNameForNamespace(contract, subject.namespaceId)}.${subject.typeName})`;
|
|
64
|
+
return factoryName;
|
|
65
|
+
}
|
|
66
|
+
function resolvePostgresCallControlPolicySubject(call, contract) {
|
|
67
|
+
const callFields = postgresCallFields(call);
|
|
68
|
+
const createsNewObject = createsNewTopLevelObject(call);
|
|
69
|
+
if (call.factoryName === "createSchema" && callFields.schemaName) return {
|
|
70
|
+
namespaceId: resolveNamespaceIdForDdlSchema(contract, callFields.schemaName),
|
|
71
|
+
createsNewObject
|
|
72
|
+
};
|
|
73
|
+
if (callFields.typeName && call.factoryName !== "addColumn") {
|
|
74
|
+
const namespaceId = callFields.schemaName ? resolveNamespaceIdForDdlSchema(contract, callFields.schemaName) : UNBOUND_NAMESPACE_ID;
|
|
75
|
+
const ns = contract.storage.namespaces[namespaceId];
|
|
76
|
+
const rawEnum = ns && "enum" in ns && ns.enum != null ? ns.enum[callFields.typeName] : void 0;
|
|
77
|
+
return {
|
|
78
|
+
namespaceId,
|
|
79
|
+
...ifDefined("explicitNodeControlPolicy", isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : void 0),
|
|
80
|
+
typeName: callFields.typeName,
|
|
81
|
+
createsNewObject
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (callFields.tableName) {
|
|
85
|
+
const namespaceId = resolveNamespaceIdForTable(contract, callFields.tableName, callFields.schemaName);
|
|
86
|
+
const tableControlPolicy = storageTableAt(contract.storage, namespaceId, callFields.tableName)?.control;
|
|
87
|
+
return {
|
|
88
|
+
namespaceId,
|
|
89
|
+
...ifDefined("explicitNodeControlPolicy", tableControlPolicy),
|
|
90
|
+
table: callFields.tableName,
|
|
91
|
+
...ifDefined("column", callFields.columnName),
|
|
92
|
+
createsNewObject
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (callFields.schemaName) return {
|
|
96
|
+
namespaceId: resolveNamespaceIdForDdlSchema(contract, callFields.schemaName),
|
|
97
|
+
createsNewObject
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Issue kinds that describe the absence of a whole, top-level Postgres
|
|
102
|
+
* object — the same kinds `createsNewTopLevelObject` recognises for calls.
|
|
103
|
+
* Used by {@link resolvePostgresIssueCreationFactoryName} to decide whether
|
|
104
|
+
* a `tolerated` subject permits the issue to flow into the planner
|
|
105
|
+
* (create-if-absent) and to seed the suppressed-subject warning's
|
|
106
|
+
* `factoryName` when the planner is skipped.
|
|
107
|
+
*/
|
|
108
|
+
const POSTGRES_ISSUE_CREATION_FACTORY = Object.freeze({
|
|
109
|
+
missing_schema: "createSchema",
|
|
110
|
+
missing_table: "createTable",
|
|
111
|
+
type_missing: "createEnumType"
|
|
112
|
+
});
|
|
113
|
+
function resolvePostgresIssueCreationFactoryName(issue) {
|
|
114
|
+
return POSTGRES_ISSUE_CREATION_FACTORY[issue.kind];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolve the control-policy subject coordinate for a single
|
|
118
|
+
* {@link SchemaIssue}. Mirrors the resolution `resolvePostgresCallControlPolicySubject`
|
|
119
|
+
* performs for a generated DDL call, but works *off the issue* — so the
|
|
120
|
+
* planner can partition issues by effective policy before the diff engine
|
|
121
|
+
* runs. `createsNewObject` is derived from the issue's kind: schema/table/
|
|
122
|
+
* type-missing issues describe a brand-new top-level object; everything else
|
|
123
|
+
* touches an existing object.
|
|
124
|
+
*
|
|
125
|
+
* An `extra_table` issue carries no contract namespace coordinate (the table
|
|
126
|
+
* isn't in any contract namespace), so the subject's `namespaceId` falls
|
|
127
|
+
* back to {@link UNBOUND_NAMESPACE_ID}; the call-side resolver does the same
|
|
128
|
+
* for the `DropTableCall` it produces.
|
|
129
|
+
*/
|
|
130
|
+
function resolvePostgresIssueControlPolicySubject(issue, contract) {
|
|
131
|
+
const createsNewObject = POSTGRES_ISSUE_CREATION_FACTORY[issue.kind] !== void 0;
|
|
132
|
+
if (issue.kind === "missing_schema" && issue.namespaceId) return {
|
|
133
|
+
namespaceId: issue.namespaceId,
|
|
134
|
+
createsNewObject
|
|
135
|
+
};
|
|
136
|
+
if ("typeName" in issue && issue.typeName) {
|
|
137
|
+
const namespaceId = "namespaceId" in issue && issue.namespaceId ? issue.namespaceId : UNBOUND_NAMESPACE_ID;
|
|
138
|
+
const ns = contract.storage.namespaces[namespaceId];
|
|
139
|
+
const rawEnum = ns && "enum" in ns && ns.enum != null ? ns.enum[issue.typeName] : void 0;
|
|
140
|
+
return {
|
|
141
|
+
namespaceId,
|
|
142
|
+
...ifDefined("explicitNodeControlPolicy", isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : void 0),
|
|
143
|
+
typeName: issue.typeName,
|
|
144
|
+
createsNewObject
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if ("table" in issue && issue.table) {
|
|
148
|
+
const namespaceId = "namespaceId" in issue && issue.namespaceId ? issue.namespaceId : resolveNamespaceIdForTable(contract, issue.table, void 0);
|
|
149
|
+
return {
|
|
150
|
+
namespaceId,
|
|
151
|
+
...ifDefined("explicitNodeControlPolicy", storageTableAt(contract.storage, namespaceId, issue.table)?.control),
|
|
152
|
+
table: issue.table,
|
|
153
|
+
...ifDefined("column", "column" in issue ? issue.column : void 0),
|
|
154
|
+
createsNewObject
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/core/migrations/verify-postgres-namespaces.ts
|
|
160
|
+
/**
|
|
161
|
+
* Resolves the live-database schema name for a given namespace
|
|
162
|
+
* coordinate. Mirrors `resolveDdlSchemaForNamespace` in
|
|
163
|
+
* `planner-strategies.ts` so the verifier's projection and the
|
|
164
|
+
* planner's projection always agree — Postgres-aware namespaces (the
|
|
165
|
+
* production path) dispatch to `ddlSchemaName(storage)`, and bare
|
|
166
|
+
* object payloads (used by some tests) fall back to the coordinate
|
|
167
|
+
* itself.
|
|
168
|
+
*/
|
|
169
|
+
function resolveDdlSchemaName(storage, namespaceId) {
|
|
170
|
+
const namespace = storage.namespaces[namespaceId];
|
|
171
|
+
if (isPostgresSchema(namespace)) return namespace.ddlSchemaName(storage);
|
|
172
|
+
return namespaceId;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Reads the introspected list of schema names from the Postgres-flavoured
|
|
176
|
+
* annotations slot on the schema IR. Defaults to the always-present
|
|
177
|
+
* `public` schema when introspection did not populate the slot — a fresh
|
|
178
|
+
* Postgres database always carries `public` (unless an operator dropped
|
|
179
|
+
* it manually), so any verifier path that runs without an enriched
|
|
180
|
+
* introspection still suppresses the redundant `CREATE SCHEMA "public"`.
|
|
181
|
+
*
|
|
182
|
+
* Production introspection (`PostgresControlAdapter.introspect`) is the
|
|
183
|
+
* authoritative source: it queries `pg_namespace` and writes every
|
|
184
|
+
* non-system schema into `annotations.pg.existingSchemas`. Tests that
|
|
185
|
+
* want to assert against a richer initial state pass the slot
|
|
186
|
+
* explicitly via the schema IR.
|
|
187
|
+
*/
|
|
188
|
+
function existingSchemasFromSchema(schema) {
|
|
189
|
+
const slot = schema.annotations?.pg?.existingSchemas;
|
|
190
|
+
if (Array.isArray(slot)) return slot.filter((s) => typeof s === "string");
|
|
191
|
+
return ["public"];
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Emits a `missing_schema` issue for every contract-declared Postgres
|
|
195
|
+
* namespace whose live container does not yet exist.
|
|
196
|
+
*
|
|
197
|
+
* A namespace's live container is the schema returned by its
|
|
198
|
+
* polymorphic `ddlSchemaName(storage)` method — named schemas resolve
|
|
199
|
+
* to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`
|
|
200
|
+
* and is skipped explicitly (late-bound namespaces have no fixed DDL
|
|
201
|
+
* schema). Issues are emitted only when the resolved name is a real,
|
|
202
|
+
* creatable schema (not the unbound sentinel) and is missing from the
|
|
203
|
+
* introspected list. `public` is suppressed implicitly because the
|
|
204
|
+
* introspection (or its sensible default) always carries it.
|
|
205
|
+
*
|
|
206
|
+
* Each emitted issue stamps `namespaceId` with the contract namespace
|
|
207
|
+
* coordinate so the downstream `mapIssueToCall` re-resolves the DDL
|
|
208
|
+
* schema name through the same polymorphic path — keeping the
|
|
209
|
+
* coordinate, not the resolved name, as the issue's stable identity.
|
|
210
|
+
*/
|
|
211
|
+
function verifyPostgresNamespacePresence(input) {
|
|
212
|
+
const { contract, schema } = input;
|
|
213
|
+
const existing = new Set(existingSchemasFromSchema(schema));
|
|
214
|
+
const issues = [];
|
|
215
|
+
const namespaceIds = Object.keys(contract.storage.namespaces).sort();
|
|
216
|
+
for (const namespaceId of namespaceIds) {
|
|
217
|
+
if (namespaceId === UNBOUND_NAMESPACE_ID) continue;
|
|
218
|
+
const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);
|
|
219
|
+
if (ddlName === UNBOUND_NAMESPACE_ID) continue;
|
|
220
|
+
if (existing.has(ddlName)) continue;
|
|
221
|
+
issues.push({
|
|
222
|
+
kind: "missing_schema",
|
|
223
|
+
namespaceId,
|
|
224
|
+
message: `Schema "${ddlName}" is missing from database`
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return issues;
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/core/migrations/planner.ts
|
|
231
|
+
function createPostgresMigrationPlanner() {
|
|
232
|
+
return new PostgresMigrationPlanner();
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Postgres migration planner — a thin wrapper over `planIssues`.
|
|
236
|
+
*
|
|
237
|
+
* `plan()` verifies the live schema against the target contract (producing
|
|
238
|
+
* `SchemaIssue[]`) and delegates to `planIssues` with the unified
|
|
239
|
+
* `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,
|
|
240
|
+
* type-change, nullable-tightening, codec-hook storage types,
|
|
241
|
+
* component-declared dependency installs, and shared-temp-default /
|
|
242
|
+
* empty-table-guarded NOT-NULL add-column. The same strategy list runs for
|
|
243
|
+
* `migration plan`, `db update`, and `db init`; behavior diverges purely on
|
|
244
|
+
* `policy.allowedOperationClasses` (the data-safe strategies short-circuit
|
|
245
|
+
* when `'data'` is excluded). The issue planner applies operation-class
|
|
246
|
+
* policy gates and emits a single `PostgresOpFactoryCall[]` that drives both
|
|
247
|
+
* the runtime-ops view (via `renderOps`) and the `renderTypeScript()`
|
|
248
|
+
* authoring surface.
|
|
249
|
+
*/
|
|
250
|
+
var PostgresMigrationPlanner = class {
|
|
251
|
+
plan(options) {
|
|
252
|
+
return this.planSql(options);
|
|
253
|
+
}
|
|
254
|
+
emptyMigration(context, spaceId) {
|
|
255
|
+
return new TypeScriptRenderablePostgresMigration([], {
|
|
256
|
+
from: context.fromHash,
|
|
257
|
+
to: context.toHash
|
|
258
|
+
}, spaceId);
|
|
259
|
+
}
|
|
260
|
+
planSql(options) {
|
|
261
|
+
const schemaName = options.schemaName ?? Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ?? UNBOUND_NAMESPACE_ID;
|
|
262
|
+
const policyResult = this.ensureAdditivePolicy(options.policy);
|
|
263
|
+
if (policyResult) return policyResult;
|
|
264
|
+
const schemaIssues = this.collectSchemaIssues(options);
|
|
265
|
+
const codecHooks = extractCodecControlHooks(options.frameworkComponents);
|
|
266
|
+
const storageTypes = options.contract.storage.types ?? {};
|
|
267
|
+
const issuePartition = partitionIssuesByControlPolicy({
|
|
268
|
+
issues: schemaIssues,
|
|
269
|
+
contract: options.contract,
|
|
270
|
+
resolveControlPolicySubject: (issue) => resolvePostgresIssueControlPolicySubject(issue, options.contract),
|
|
271
|
+
resolveCreationFactoryName: resolvePostgresIssueCreationFactoryName,
|
|
272
|
+
formatSubjectLabel: (factoryName, subject) => formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract)
|
|
273
|
+
});
|
|
274
|
+
const result = planIssues({
|
|
275
|
+
issues: issuePartition.plannable,
|
|
276
|
+
toContract: options.contract,
|
|
277
|
+
fromContract: options.fromContract,
|
|
278
|
+
schemaName,
|
|
279
|
+
codecHooks,
|
|
280
|
+
storageTypes,
|
|
281
|
+
schema: options.schema,
|
|
282
|
+
policy: options.policy,
|
|
283
|
+
frameworkComponents: options.frameworkComponents,
|
|
284
|
+
strategies: postgresPlannerStrategies
|
|
285
|
+
});
|
|
286
|
+
if (!result.ok) return plannerFailure(result.failure);
|
|
287
|
+
const fieldEventPartition = partitionCallsByControlPolicy({
|
|
288
|
+
calls: blindCast(planFieldEventOperations({
|
|
289
|
+
priorContract: options.fromContract,
|
|
290
|
+
newContract: options.contract,
|
|
291
|
+
codecHooks
|
|
292
|
+
})),
|
|
293
|
+
contract: options.contract,
|
|
294
|
+
resolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),
|
|
295
|
+
resolveFactoryName: (call) => call.factoryName,
|
|
296
|
+
formatSubjectLabel: (factoryName, subject) => formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract)
|
|
297
|
+
});
|
|
298
|
+
const calls = [...result.value.calls, ...fieldEventPartition.kept];
|
|
299
|
+
const warnings = [...issuePartition.warnings, ...fieldEventPartition.warnings];
|
|
300
|
+
return Object.freeze({
|
|
301
|
+
kind: "success",
|
|
302
|
+
plan: new TypeScriptRenderablePostgresMigration(calls, {
|
|
303
|
+
from: options.fromContract?.storage.storageHash ?? null,
|
|
304
|
+
to: options.contract.storage.storageHash
|
|
305
|
+
}, options.spaceId),
|
|
306
|
+
...warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
ensureAdditivePolicy(policy) {
|
|
310
|
+
if (!policy.allowedOperationClasses.includes("additive")) return plannerFailure([{
|
|
311
|
+
kind: "unsupportedOperation",
|
|
312
|
+
summary: "Migration planner requires additive operations be allowed",
|
|
313
|
+
why: "The planner requires the \"additive\" operation class to be allowed in the policy."
|
|
314
|
+
}]);
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
collectSchemaIssues(options) {
|
|
318
|
+
const allowed = options.policy.allowedOperationClasses;
|
|
319
|
+
const strict = allowed.includes("widening") || allowed.includes("destructive");
|
|
320
|
+
const verifyResult = verifySqlSchema({
|
|
321
|
+
contract: options.contract,
|
|
322
|
+
schema: options.schema,
|
|
323
|
+
strict,
|
|
324
|
+
typeMetadataRegistry: /* @__PURE__ */ new Map(),
|
|
325
|
+
frameworkComponents: options.frameworkComponents,
|
|
326
|
+
normalizeDefault: parsePostgresDefault,
|
|
327
|
+
normalizeNativeType: normalizeSchemaNativeType,
|
|
328
|
+
columnsCompatible: postgresColumnsCompatible,
|
|
329
|
+
resolveExistingEnumValues: createResolveExistingEnumValues(options.contract.storage)
|
|
330
|
+
});
|
|
331
|
+
const namespaceIssues = verifyPostgresNamespacePresence({
|
|
332
|
+
contract: options.contract,
|
|
333
|
+
schema: options.schema
|
|
334
|
+
});
|
|
335
|
+
if (namespaceIssues.length === 0) return verifyResult.schema.issues;
|
|
336
|
+
return [...namespaceIssues, ...verifyResult.schema.issues];
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
//#endregion
|
|
340
|
+
export { createPostgresMigrationPlanner as t };
|
|
341
|
+
|
|
342
|
+
//# sourceMappingURL=planner-y-bVvDFR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-y-bVvDFR.mjs","names":[],"sources":["../src/core/migrations/control-policy.ts","../src/core/migrations/verify-postgres-namespaces.ts","../src/core/migrations/planner.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { ControlPolicySubject } from '@prisma-next/family-sql/control';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n isPostgresEnumStorageEntry,\n type SqlStorage,\n storageTableAt,\n} from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { isPostgresSchema } from '../postgres-schema';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\n\n/**\n * Factory calls that create a whole, previously-absent top-level storage\n * object. Used to decide whether `tolerated` permits a call (it only allows\n * creating absent objects, never modifying existing ones).\n *\n * Deliberately an explicit, closed set rather than a `factoryName`\n * create/alter/drop classification: it answers exactly one yes/no question\n * and is fail-closed. Any call not listed here — including future or\n * extension-contributed factories — is treated as NOT object-creation, so it\n * is suppressed under `tolerated` rather than permissively emitted.\n */\nconst OBJECT_CREATION_FACTORIES: ReadonlySet<string> = new Set<string>([\n 'createTable',\n 'createEnumType',\n 'createSchema',\n]);\n\nfunction createsNewTopLevelObject(call: PostgresOpFactoryCall): boolean {\n return OBJECT_CREATION_FACTORIES.has(call.factoryName);\n}\n\nfunction ddlSchemaNameForNamespace(contract: Contract<SqlStorage>, namespaceId: string): string {\n const namespace = contract.storage.namespaces[namespaceId];\n return isPostgresSchema(namespace) ? namespace.ddlSchemaName(contract.storage) : namespaceId;\n}\n\nfunction resolveNamespaceIdForTable(\n contract: Contract<SqlStorage>,\n tableName: string,\n ddlSchemaName: string | undefined,\n): string {\n for (const namespaceId of Object.keys(contract.storage.namespaces)) {\n const table = storageTableAt(contract.storage, namespaceId, tableName);\n if (!table) continue;\n if (\n ddlSchemaName === undefined ||\n ddlSchemaNameForNamespace(contract, namespaceId) === ddlSchemaName\n ) {\n return namespaceId;\n }\n }\n return UNBOUND_NAMESPACE_ID;\n}\n\nfunction resolveNamespaceIdForDdlSchema(\n contract: Contract<SqlStorage>,\n ddlSchemaName: string,\n): string {\n for (const namespaceId of Object.keys(contract.storage.namespaces)) {\n const ns = contract.storage.namespaces[namespaceId];\n if (isPostgresSchema(ns) && ns.ddlSchemaName(contract.storage) === ddlSchemaName) {\n return namespaceId;\n }\n if (namespaceId === ddlSchemaName) {\n return namespaceId;\n }\n }\n return UNBOUND_NAMESPACE_ID;\n}\n\ninterface PostgresCallFields {\n readonly schemaName?: string;\n readonly tableName?: string;\n readonly columnName?: string;\n readonly typeName?: string;\n}\n\nfunction postgresCallFields(call: PostgresOpFactoryCall): PostgresCallFields {\n return {\n ...ifDefined('schemaName', 'schemaName' in call ? call.schemaName : undefined),\n ...ifDefined('tableName', 'tableName' in call ? call.tableName : undefined),\n ...ifDefined('columnName', 'columnName' in call ? call.columnName : undefined),\n ...ifDefined('typeName', 'typeName' in call ? call.typeName : undefined),\n };\n}\n\nexport function formatPostgresControlPolicySubjectLabel(\n factoryName: string,\n subject: ControlPolicySubject | undefined,\n contract: Contract<SqlStorage>,\n): string {\n if (subject?.table) {\n const ddlSchema = ddlSchemaNameForNamespace(contract, subject.namespaceId);\n return `${factoryName}(${ddlSchema}.${subject.table})`;\n }\n if (subject?.typeName) {\n const ddlSchema = ddlSchemaNameForNamespace(contract, subject.namespaceId);\n return `${factoryName}(${ddlSchema}.${subject.typeName})`;\n }\n return factoryName;\n}\n\nexport function resolvePostgresCallControlPolicySubject(\n call: PostgresOpFactoryCall,\n contract: Contract<SqlStorage>,\n): ControlPolicySubject | undefined {\n const callFields = postgresCallFields(call);\n const createsNewObject = createsNewTopLevelObject(call);\n\n if (call.factoryName === 'createSchema' && callFields.schemaName) {\n return {\n namespaceId: resolveNamespaceIdForDdlSchema(contract, callFields.schemaName),\n createsNewObject,\n };\n }\n\n if (callFields.typeName && call.factoryName !== 'addColumn') {\n const namespaceId = callFields.schemaName\n ? resolveNamespaceIdForDdlSchema(contract, callFields.schemaName)\n : UNBOUND_NAMESPACE_ID;\n const ns = contract.storage.namespaces[namespaceId];\n const rawEnum =\n ns && 'enum' in ns && ns.enum != null ? ns.enum[callFields.typeName] : undefined;\n const controlPolicy = isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : undefined;\n return {\n namespaceId,\n ...ifDefined('explicitNodeControlPolicy', controlPolicy),\n typeName: callFields.typeName,\n createsNewObject,\n };\n }\n\n if (callFields.tableName) {\n const namespaceId = resolveNamespaceIdForTable(\n contract,\n callFields.tableName,\n callFields.schemaName,\n );\n const table = storageTableAt(contract.storage, namespaceId, callFields.tableName);\n const tableControlPolicy = table?.control;\n return {\n namespaceId,\n ...ifDefined('explicitNodeControlPolicy', tableControlPolicy),\n table: callFields.tableName,\n ...ifDefined('column', callFields.columnName),\n createsNewObject,\n };\n }\n\n if (callFields.schemaName) {\n return {\n namespaceId: resolveNamespaceIdForDdlSchema(contract, callFields.schemaName),\n createsNewObject,\n };\n }\n\n return undefined;\n}\n\n/**\n * Issue kinds that describe the absence of a whole, top-level Postgres\n * object — the same kinds `createsNewTopLevelObject` recognises for calls.\n * Used by {@link resolvePostgresIssueCreationFactoryName} to decide whether\n * a `tolerated` subject permits the issue to flow into the planner\n * (create-if-absent) and to seed the suppressed-subject warning's\n * `factoryName` when the planner is skipped.\n */\nconst POSTGRES_ISSUE_CREATION_FACTORY: Readonly<Record<string, string>> = Object.freeze({\n missing_schema: 'createSchema',\n missing_table: 'createTable',\n type_missing: 'createEnumType',\n});\n\nexport function resolvePostgresIssueCreationFactoryName(issue: SchemaIssue): string | undefined {\n return POSTGRES_ISSUE_CREATION_FACTORY[issue.kind];\n}\n\n/**\n * Resolve the control-policy subject coordinate for a single\n * {@link SchemaIssue}. Mirrors the resolution `resolvePostgresCallControlPolicySubject`\n * performs for a generated DDL call, but works *off the issue* — so the\n * planner can partition issues by effective policy before the diff engine\n * runs. `createsNewObject` is derived from the issue's kind: schema/table/\n * type-missing issues describe a brand-new top-level object; everything else\n * touches an existing object.\n *\n * An `extra_table` issue carries no contract namespace coordinate (the table\n * isn't in any contract namespace), so the subject's `namespaceId` falls\n * back to {@link UNBOUND_NAMESPACE_ID}; the call-side resolver does the same\n * for the `DropTableCall` it produces.\n */\nexport function resolvePostgresIssueControlPolicySubject(\n issue: SchemaIssue,\n contract: Contract<SqlStorage>,\n): ControlPolicySubject | undefined {\n const createsNewObject = POSTGRES_ISSUE_CREATION_FACTORY[issue.kind] !== undefined;\n\n if (issue.kind === 'missing_schema' && issue.namespaceId) {\n return { namespaceId: issue.namespaceId, createsNewObject };\n }\n\n if ('typeName' in issue && issue.typeName) {\n const namespaceId =\n 'namespaceId' in issue && issue.namespaceId ? issue.namespaceId : UNBOUND_NAMESPACE_ID;\n const ns = contract.storage.namespaces[namespaceId];\n const rawEnum = ns && 'enum' in ns && ns.enum != null ? ns.enum[issue.typeName] : undefined;\n const controlPolicy = isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : undefined;\n return {\n namespaceId,\n ...ifDefined('explicitNodeControlPolicy', controlPolicy),\n typeName: issue.typeName,\n createsNewObject,\n };\n }\n\n if ('table' in issue && issue.table) {\n const namespaceId =\n 'namespaceId' in issue && issue.namespaceId\n ? issue.namespaceId\n : resolveNamespaceIdForTable(contract, issue.table, undefined);\n const table = storageTableAt(contract.storage, namespaceId, issue.table);\n return {\n namespaceId,\n ...ifDefined('explicitNodeControlPolicy', table?.control),\n table: issue.table,\n ...ifDefined('column', 'column' in issue ? issue.column : undefined),\n createsNewObject,\n };\n }\n\n return undefined;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Resolves the live-database schema name for a given namespace\n * coordinate. Mirrors `resolveDdlSchemaForNamespace` in\n * `planner-strategies.ts` so the verifier's projection and the\n * planner's projection always agree — Postgres-aware namespaces (the\n * production path) dispatch to `ddlSchemaName(storage)`, and bare\n * object payloads (used by some tests) fall back to the coordinate\n * itself.\n */\nfunction resolveDdlSchemaName(storage: SqlStorage, namespaceId: string): string {\n const namespace = storage.namespaces[namespaceId];\n if (isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/**\n * Reads the introspected list of schema names from the Postgres-flavoured\n * annotations slot on the schema IR. Defaults to the always-present\n * `public` schema when introspection did not populate the slot — a fresh\n * Postgres database always carries `public` (unless an operator dropped\n * it manually), so any verifier path that runs without an enriched\n * introspection still suppresses the redundant `CREATE SCHEMA \"public\"`.\n *\n * Production introspection (`PostgresControlAdapter.introspect`) is the\n * authoritative source: it queries `pg_namespace` and writes every\n * non-system schema into `annotations.pg.existingSchemas`. Tests that\n * want to assert against a richer initial state pass the slot\n * explicitly via the schema IR.\n */\nfunction existingSchemasFromSchema(schema: SqlSchemaIR): readonly string[] {\n const annotations = (schema as { annotations?: { pg?: { existingSchemas?: unknown } } })\n .annotations;\n const slot = annotations?.pg?.existingSchemas;\n if (Array.isArray(slot)) {\n return slot.filter((s): s is string => typeof s === 'string');\n }\n return ['public'];\n}\n\n/**\n * Emits a `missing_schema` issue for every contract-declared Postgres\n * namespace whose live container does not yet exist.\n *\n * A namespace's live container is the schema returned by its\n * polymorphic `ddlSchemaName(storage)` method — named schemas resolve\n * to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`\n * and is skipped explicitly (late-bound namespaces have no fixed DDL\n * schema). Issues are emitted only when the resolved name is a real,\n * creatable schema (not the unbound sentinel) and is missing from the\n * introspected list. `public` is suppressed implicitly because the\n * introspection (or its sensible default) always carries it.\n *\n * Each emitted issue stamps `namespaceId` with the contract namespace\n * coordinate so the downstream `mapIssueToCall` re-resolves the DDL\n * schema name through the same polymorphic path — keeping the\n * coordinate, not the resolved name, as the issue's stable identity.\n */\nexport function verifyPostgresNamespacePresence(input: {\n readonly contract: Contract<SqlStorage>;\n readonly schema: SqlSchemaIR;\n}): readonly SchemaIssue[] {\n const { contract, schema } = input;\n const existing = new Set(existingSchemasFromSchema(schema));\n const issues: SchemaIssue[] = [];\n const namespaceIds = Object.keys(contract.storage.namespaces).sort();\n for (const namespaceId of namespaceIds) {\n if (namespaceId === UNBOUND_NAMESPACE_ID) continue;\n const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);\n if (ddlName === UNBOUND_NAMESPACE_ID) continue;\n if (existing.has(ddlName)) continue;\n issues.push({\n kind: 'missing_schema',\n namespaceId,\n message: `Schema \"${ddlName}\" is missing from database`,\n });\n }\n return issues;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlMigrationPlannerPlanOptions,\n SqlPlannerConflict,\n SqlPlannerFailureResult,\n} from '@prisma-next/family-sql/control';\nimport {\n extractCodecControlHooks,\n partitionCallsByControlPolicy,\n partitionIssuesByControlPolicy,\n planFieldEventOperations,\n plannerFailure,\n} from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n MigrationPlanner,\n MigrationPlanWithAuthoringSurface,\n MigrationScaffoldContext,\n SchemaIssue,\n} from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { postgresColumnsCompatible } from '../column-type-compatibility';\nimport { parsePostgresDefault } from '../default-normalizer';\nimport { normalizeSchemaNativeType } from '../native-type-normalizer';\nimport {\n formatPostgresControlPolicySubjectLabel,\n resolvePostgresCallControlPolicySubject,\n resolvePostgresIssueControlPolicySubject,\n resolvePostgresIssueCreationFactoryName,\n} from './control-policy';\nimport { createResolveExistingEnumValues } from './enum-planning';\nimport { planIssues } from './issue-planner';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\nimport { TypeScriptRenderablePostgresMigration } from './planner-produced-postgres-migration';\nimport { postgresPlannerStrategies } from './planner-strategies';\nimport { verifyPostgresNamespacePresence } from './verify-postgres-namespaces';\n\ntype PlannerFrameworkComponents = SqlMigrationPlannerPlanOptions extends {\n readonly frameworkComponents: infer T;\n}\n ? T\n : ReadonlyArray<unknown>;\n\ntype PlannerOptionsWithComponents = SqlMigrationPlannerPlanOptions & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ntype VerifySqlSchemaOptionsWithComponents = Parameters<typeof verifySqlSchema>[0] & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\nexport function createPostgresMigrationPlanner(): PostgresMigrationPlanner {\n return new PostgresMigrationPlanner();\n}\n\n/**\n * Result of `PostgresMigrationPlanner.plan()`. A discriminated union whose\n * success variant carries a `TypeScriptRenderablePostgresMigration` — a\n * migration object that both the CLI (via `renderTypeScript()`) and the\n * SQL-typed callers (via `operations`, `describe()`, etc.) consume\n * uniformly.\n */\nexport type PostgresPlanResult =\n | {\n readonly kind: 'success';\n readonly plan: TypeScriptRenderablePostgresMigration;\n readonly warnings?: readonly SqlPlannerConflict[];\n }\n | SqlPlannerFailureResult;\n\n/**\n * Postgres migration planner — a thin wrapper over `planIssues`.\n *\n * `plan()` verifies the live schema against the target contract (producing\n * `SchemaIssue[]`) and delegates to `planIssues` with the unified\n * `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,\n * type-change, nullable-tightening, codec-hook storage types,\n * component-declared dependency installs, and shared-temp-default /\n * empty-table-guarded NOT-NULL add-column. The same strategy list runs for\n * `migration plan`, `db update`, and `db init`; behavior diverges purely on\n * `policy.allowedOperationClasses` (the data-safe strategies short-circuit\n * when `'data'` is excluded). The issue planner applies operation-class\n * policy gates and emits a single `PostgresOpFactoryCall[]` that drives both\n * the runtime-ops view (via `renderOps`) and the `renderTypeScript()`\n * authoring surface.\n */\nexport class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {\n plan(options: {\n readonly contract: unknown;\n readonly schema: unknown;\n readonly policy: MigrationOperationPolicy;\n /**\n * The \"from\" contract (state the planner assumes the database starts\n * at), or `null` for reconciliation flows. Only `migration plan` ever\n * supplies a non-null value; `db update` / `db init` reconcile against\n * the live schema and pass `null`. When present alongside the\n * `'data'` operation class, strategies that need from/to column-shape\n * comparisons (unsafe type change, nullability tightening) activate.\n *\n * Typed as the framework `Contract | null` to satisfy the\n * `MigrationPlanner` interface contract; `planSql` narrows to the SQL\n * shape via `SqlMigrationPlannerPlanOptions`. Used to populate\n * `describe().from` on the produced plan as\n * `fromContract?.storage.storageHash ?? null`.\n */\n readonly fromContract: Contract | null;\n readonly schemaName?: string;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n /**\n * Contract space this plan applies to. Stamped onto the produced\n * {@link TypeScriptRenderablePostgresMigration.spaceId} so the runner keys\n * the marker row by the right space.\n */\n readonly spaceId: string;\n }): PostgresPlanResult {\n return this.planSql(options as SqlMigrationPlannerPlanOptions);\n }\n\n emptyMigration(\n context: MigrationScaffoldContext,\n spaceId: string,\n ): MigrationPlanWithAuthoringSurface {\n return new TypeScriptRenderablePostgresMigration(\n [],\n {\n from: context.fromHash,\n to: context.toHash,\n },\n spaceId,\n );\n }\n\n private planSql(options: SqlMigrationPlannerPlanOptions): PostgresPlanResult {\n const schemaName =\n options.schemaName ??\n Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ??\n UNBOUND_NAMESPACE_ID;\n const policyResult = this.ensureAdditivePolicy(options.policy);\n if (policyResult) {\n return policyResult;\n }\n\n const schemaIssues = this.collectSchemaIssues(options);\n const codecHooks = extractCodecControlHooks(options.frameworkComponents);\n const storageTypes = options.contract.storage.types ?? {};\n\n // Input-side control-policy partition. `external` / `observed` subjects\n // — and non-creation issues for `tolerated` subjects — are dropped from\n // the planner's input entirely; the planner never observes them, never\n // diffs them, never generates DDL for them. Suppression warnings are\n // built directly from the suppressed partition (one per subject), so the\n // user-visible message survives even when the planner would have failed\n // to model the subject's live shape.\n const issuePartition = partitionIssuesByControlPolicy({\n issues: schemaIssues,\n contract: options.contract,\n resolveControlPolicySubject: (issue) =>\n resolvePostgresIssueControlPolicySubject(issue, options.contract),\n resolveCreationFactoryName: resolvePostgresIssueCreationFactoryName,\n formatSubjectLabel: (factoryName, subject) =>\n formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract),\n });\n\n const result = planIssues({\n issues: issuePartition.plannable,\n toContract: options.contract,\n // `fromContract` is only supplied by `migration plan`. It is `null` for\n // `db update` / `db init`, which means data-safety strategies needing\n // from/to comparisons (unsafe type change, nullable tightening) are\n // inapplicable there — reconciliation falls through to\n // `mapIssueToCall`'s direct destructive handlers.\n fromContract: options.fromContract,\n schemaName,\n codecHooks,\n storageTypes,\n schema: options.schema,\n policy: options.policy,\n frameworkComponents: options.frameworkComponents,\n strategies: postgresPlannerStrategies,\n });\n\n if (!result.ok) {\n return plannerFailure(result.failure);\n }\n\n // Inline `onFieldEvent`-emitted ops after structural DDL. The fixed\n // ordering is `structural → added → dropped → altered`, with\n // within-group sorting by `(tableName, fieldName)` so re-emits are\n // byte-stable. The hook fires only at the application emitter —\n // extension-space planning never reaches this helper.\n const fieldEventOps = planFieldEventOperations({\n priorContract: options.fromContract,\n newContract: options.contract,\n codecHooks,\n });\n // Codec hook ops are target-agnostic `OpFactoryCall`; Postgres planning\n // lifts them at this integration boundary (see field-event-planner JSDoc).\n const fieldEventPostgresCalls = blindCast<\n readonly PostgresOpFactoryCall[],\n 'Codec hook ops conform to PostgresOpFactoryCall at the app emitter boundary'\n >(fieldEventOps);\n const fieldEventPartition = partitionCallsByControlPolicy({\n calls: fieldEventPostgresCalls,\n contract: options.contract,\n resolveControlPolicySubject: (call) =>\n resolvePostgresCallControlPolicySubject(call, options.contract),\n resolveFactoryName: (call) => call.factoryName,\n formatSubjectLabel: (factoryName, subject) =>\n formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract),\n });\n const calls = [...result.value.calls, ...fieldEventPartition.kept];\n const warnings: SqlPlannerConflict[] = [\n ...issuePartition.warnings,\n ...fieldEventPartition.warnings,\n ];\n\n return Object.freeze({\n kind: 'success' as const,\n plan: new TypeScriptRenderablePostgresMigration(\n calls,\n {\n from: options.fromContract?.storage.storageHash ?? null,\n to: options.contract.storage.storageHash,\n },\n options.spaceId,\n ),\n ...(warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}),\n });\n }\n\n private ensureAdditivePolicy(policy: MigrationOperationPolicy) {\n if (!policy.allowedOperationClasses.includes('additive')) {\n return plannerFailure([\n {\n kind: 'unsupportedOperation',\n summary: 'Migration planner requires additive operations be allowed',\n why: 'The planner requires the \"additive\" operation class to be allowed in the policy.',\n },\n ]);\n }\n return null;\n }\n\n private collectSchemaIssues(options: PlannerOptionsWithComponents): readonly SchemaIssue[] {\n // `db init` uses additive-only policy and intentionally ignores extra\n // schema objects. Any reconciliation-capable policy (widening or\n // destructive) must inspect extras to reconcile strict equality.\n const allowed = options.policy.allowedOperationClasses;\n const strict = allowed.includes('widening') || allowed.includes('destructive');\n const verifyOptions: VerifySqlSchemaOptionsWithComponents = {\n contract: options.contract,\n schema: options.schema,\n strict,\n typeMetadataRegistry: new Map(),\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parsePostgresDefault,\n normalizeNativeType: normalizeSchemaNativeType,\n columnsCompatible: postgresColumnsCompatible,\n resolveExistingEnumValues: createResolveExistingEnumValues(options.contract.storage),\n };\n const verifyResult = verifySqlSchema(verifyOptions);\n // Schema presence is a Postgres-specific concern (no equivalent in\n // SQLite / Mongo), so the issue emission lives in the target layer\n // rather than in the family verifier. Stitch it in here so a single\n // `SchemaIssue[]` flows through `planIssues` and the planner emits\n // CREATE SCHEMA in the dep bucket before any CreateTableCall.\n const namespaceIssues = verifyPostgresNamespacePresence({\n contract: options.contract,\n schema: options.schema,\n });\n if (namespaceIssues.length === 0) {\n return verifyResult.schema.issues;\n }\n return [...namespaceIssues, ...verifyResult.schema.issues];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,4BAAiD,IAAI,IAAY;CACrE;CACA;CACA;AACF,CAAC;AAED,SAAS,yBAAyB,MAAsC;CACtE,OAAO,0BAA0B,IAAI,KAAK,WAAW;AACvD;AAEA,SAAS,0BAA0B,UAAgC,aAA6B;CAC9F,MAAM,YAAY,SAAS,QAAQ,WAAW;CAC9C,OAAO,iBAAiB,SAAS,IAAI,UAAU,cAAc,SAAS,OAAO,IAAI;AACnF;AAEA,SAAS,2BACP,UACA,WACA,eACQ;CACR,KAAK,MAAM,eAAe,OAAO,KAAK,SAAS,QAAQ,UAAU,GAAG;EAElE,IAAI,CADU,eAAe,SAAS,SAAS,aAAa,SACnD,GAAG;EACZ,IACE,kBAAkB,KAAA,KAClB,0BAA0B,UAAU,WAAW,MAAM,eAErD,OAAO;CAEX;CACA,OAAO;AACT;AAEA,SAAS,+BACP,UACA,eACQ;CACR,KAAK,MAAM,eAAe,OAAO,KAAK,SAAS,QAAQ,UAAU,GAAG;EAClE,MAAM,KAAK,SAAS,QAAQ,WAAW;EACvC,IAAI,iBAAiB,EAAE,KAAK,GAAG,cAAc,SAAS,OAAO,MAAM,eACjE,OAAO;EAET,IAAI,gBAAgB,eAClB,OAAO;CAEX;CACA,OAAO;AACT;AASA,SAAS,mBAAmB,MAAiD;CAC3E,OAAO;EACL,GAAG,UAAU,cAAc,gBAAgB,OAAO,KAAK,aAAa,KAAA,CAAS;EAC7E,GAAG,UAAU,aAAa,eAAe,OAAO,KAAK,YAAY,KAAA,CAAS;EAC1E,GAAG,UAAU,cAAc,gBAAgB,OAAO,KAAK,aAAa,KAAA,CAAS;EAC7E,GAAG,UAAU,YAAY,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SAA+D;EAIzF,MAAM,UAAU,QAAQ,OAAO;EAC/B,MAAM,SAAS,QAAQ,SAAS,UAAU,KAAK,QAAQ,SAAS,aAAa;EAY7E,MAAM,eAAe,gBAAgB;GAVnC,UAAU,QAAQ;GAClB,QAAQ,QAAQ;GAChB;GACA,sCAAsB,IAAI,IAAI;GAC9B,qBAAqB,QAAQ;GAC7B,kBAAkB;GAClB,qBAAqB;GACrB,mBAAmB;GACnB,2BAA2B,gCAAgC,QAAQ,SAAS,OAAO;EAEpC,CAAC;EAMlD,MAAM,kBAAkB,gCAAgC;GACtD,UAAU,QAAQ;GAClB,QAAQ,QAAQ;EAClB,CAAC;EACD,IAAI,gBAAgB,WAAW,GAC7B,OAAO,aAAa,OAAO;EAE7B,OAAO,CAAC,GAAG,iBAAiB,GAAG,aAAa,OAAO,MAAM;CAC3D;AACF"}
|
package/dist/planner.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-
|
|
2
|
-
import { MigrationOperationPolicy, SqlPlannerFailureResult } from "@prisma-next/family-sql/control";
|
|
1
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-RdjC7aUC.mjs";
|
|
2
|
+
import { MigrationOperationPolicy, SqlPlannerConflict, SqlPlannerFailureResult } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { Contract } from "@prisma-next/contract/types";
|
|
5
5
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
@@ -16,6 +16,7 @@ declare function createPostgresMigrationPlanner(): PostgresMigrationPlanner;
|
|
|
16
16
|
type PostgresPlanResult = {
|
|
17
17
|
readonly kind: 'success';
|
|
18
18
|
readonly plan: TypeScriptRenderablePostgresMigration;
|
|
19
|
+
readonly warnings?: readonly SqlPlannerConflict[];
|
|
19
20
|
} | SqlPlannerFailureResult;
|
|
20
21
|
/**
|
|
21
22
|
* Postgres migration planner — a thin wrapper over `planIssues`.
|
package/dist/planner.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"mappings":";;;;;;;iBAsDgB,8BAAA,CAAA,GAAkC,wBAAwB;;AAA1E;;;;AAA0E;AAW1E;KAAY,kBAAA;EAAA,SAEG,IAAA;EAAA,SACA,IAAA,EAAM,qCAAA;EAAA,SACN,QAAA,YAAoB,kBAAA;AAAA,IAE/B,uBAAA;;;;;;;;;;AAAuB;AAkB3B;;;;;;cAAa,wBAAA,YAAoC,gBAAA;EAC/C,IAAA,CAAK,OAAA;IAAA,SACM,QAAA;IAAA,SACA,MAAA;IAAA,SACA,MAAA,EAAQ,wBAAA;IAJ4C;;;;;;;;;;;;;;IAAA,SAmBpD,YAAA,EAAc,QAAA;IAAA,SACd,UAAA;IAAA,SACA,mBAAA,EAAqB,aAAA,CAAc,8BAAA;IAW9C;;;;;IAAA,SALW,OAAA;EAAA,IACP,kBAAA;EAIJ,cAAA,CACE,OAAA,EAAS,wBAAA,EACT,OAAA,WACC,iCAAA;EAAA,QAWK,OAAA;EAAA,QAkGA,oBAAA;EAAA,QAaA,mBAAA;AAAA"}
|
package/dist/planner.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createPostgresMigrationPlanner } from "./planner-
|
|
1
|
+
import { t as createPostgresMigrationPlanner } from "./planner-y-bVvDFR.mjs";
|
|
2
2
|
export { createPostgresMigrationPlanner };
|
package/dist/{postgres-contract-serializer-BnOboPWs.mjs → postgres-contract-serializer-BYpK6TkY.mjs}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as postgresAuthoringEntityTypes } from "./descriptor-meta-runtime-
|
|
2
|
-
import { r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-
|
|
1
|
+
import { n as postgresAuthoringEntityTypes } from "./descriptor-meta-runtime-BBL7VdnR.mjs";
|
|
2
|
+
import { r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-Dky_Jff8.mjs";
|
|
3
3
|
import { NamespaceBase, UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
4
4
|
import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
|
|
5
5
|
import { isAuthoringEntityTypeDescriptor } from "@prisma-next/framework-components/authoring";
|
|
@@ -102,4 +102,4 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
|
102
102
|
//#endregion
|
|
103
103
|
export { PostgresContractSerializer as t };
|
|
104
104
|
|
|
105
|
-
//# sourceMappingURL=postgres-contract-serializer-
|
|
105
|
+
//# sourceMappingURL=postgres-contract-serializer-BYpK6TkY.mjs.map
|