@prisma-next/target-postgres 0.13.0 → 0.14.0-dev.2
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-CTikp1if.mjs → codec-ids-BvytN2P8.mjs} +3 -3
- package/dist/codec-ids-BvytN2P8.mjs.map +1 -0
- package/dist/{codec-ids-B1vOchLE.d.mts → codec-ids-CnXu9Qy3.d.mts} +3 -3
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-CnFiNML4.d.mts → codec-types-DHCkwPKE.d.mts} +3 -3
- package/dist/{codec-types-CnFiNML4.d.mts.map → codec-types-DHCkwPKE.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-CBpEv4s5.d.mts → codecs--0A5_4Bq.d.mts} +26 -23
- package/dist/codecs--0A5_4Bq.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +28 -35
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +163 -15
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +4 -17
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +21 -27
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-D25tLeYU.mjs → data-transform-BOWpliq8.mjs} +9 -17
- package/dist/data-transform-BOWpliq8.mjs.map +1 -0
- package/dist/{data-transform-DGOqcLrf.d.mts → data-transform-DDgWdB5o.d.mts} +2 -2
- package/dist/data-transform-DDgWdB5o.d.mts.map +1 -0
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/ddl-QDyOSeLc.mjs +251 -0
- package/dist/ddl-QDyOSeLc.mjs.map +1 -0
- package/dist/ddl.d.mts +2 -2
- package/dist/ddl.mjs +2 -2
- package/dist/descriptor-meta-CpGygXpI.mjs +140 -0
- package/dist/descriptor-meta-CpGygXpI.mjs.map +1 -0
- package/dist/{issue-planner-Br0pt1Ea.mjs → issue-planner-DL6g3CmE.mjs} +52 -366
- package/dist/issue-planner-DL6g3CmE.mjs.map +1 -0
- package/dist/issue-planner.d.mts +8 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +5 -92
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/{nodes-DZk2JZG3.mjs → nodes-Bbhs2rwj.mjs} +31 -2
- package/dist/nodes-Bbhs2rwj.mjs.map +1 -0
- package/dist/{nodes-779hmCfL.d.mts → nodes-pLeLgdis.d.mts} +30 -3
- package/dist/nodes-pLeLgdis.d.mts.map +1 -0
- package/dist/{op-factory-call-D2aAUhmS.mjs → op-factory-call-D_p5vxwt.mjs} +601 -418
- package/dist/op-factory-call-D_p5vxwt.mjs.map +1 -0
- package/dist/{op-factory-call-DMA86_2D.d.mts → op-factory-call-DmQEc3XV.d.mts} +119 -72
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +36 -15
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-CAYPJObw.mjs → planner-Bs_baQax.mjs} +25 -45
- package/dist/planner-Bs_baQax.mjs.map +1 -0
- package/dist/{planner-ddl-builders-Cw2n2llW.mjs → planner-ddl-builders-B2wOwLqI.mjs} +2 -2
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +4 -4
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-BIpa5p2I.mjs → planner-identity-values-CJPha2Sz.mjs} +3 -9
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -0
- package/dist/planner-identity-values.d.mts +1 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-NSEhWL0L.mjs → planner-produced-postgres-migration-Cji5vxUf.mjs} +6 -4
- package/dist/planner-produced-postgres-migration-Cji5vxUf.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-B4EDvLdz.d.mts → planner-produced-postgres-migration-QqHa2C2l.d.mts} +5 -6
- package/dist/planner-produced-postgres-migration-QqHa2C2l.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/planner-sql-checks-jqUUGyQR.mjs +152 -0
- package/dist/planner-sql-checks-jqUUGyQR.mjs.map +1 -0
- package/dist/planner-sql-checks.d.mts +3 -49
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +2 -2
- package/dist/{planner-type-resolution-836DExFN.mjs → planner-type-resolution-Bt2f_q-F.mjs} +1 -6
- package/dist/planner-type-resolution-Bt2f_q-F.mjs.map +1 -0
- package/dist/planner.d.mts +4 -4
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-DYTyXjPf.mjs → postgres-contract-serializer-k3TAcPMY.mjs} +30 -37
- package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +1 -0
- package/dist/postgres-migration-B5jKrXv3.mjs +145 -0
- package/dist/postgres-migration-B5jKrXv3.mjs.map +1 -0
- package/dist/postgres-migration-Y4YBJqkS.d.mts +181 -0
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +1 -0
- package/dist/{postgres-schema-BuxCxbvB.mjs → postgres-schema-COGZ1ark.mjs} +82 -23
- package/dist/postgres-schema-COGZ1ark.mjs.map +1 -0
- package/dist/{render-ops-BpjstrKQ.mjs → render-ops-BREh1kHe.mjs} +10 -5
- package/dist/render-ops-BREh1kHe.mjs.map +1 -0
- package/dist/render-ops.d.mts +2 -2
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/runtime.d.mts +1 -0
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/table-source-BvFo7gVs.d.mts +15 -0
- package/dist/table-source-BvFo7gVs.d.mts.map +1 -0
- package/dist/types.d.mts +34 -19
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -3
- package/package.json +17 -18
- package/src/contract-free/checks.ts +363 -0
- package/src/contract-free/ddl.ts +28 -1
- package/src/core/authoring.ts +43 -44
- package/src/core/codec-helpers.ts +0 -17
- package/src/core/codec-ids.ts +1 -1
- package/src/core/codec-type-map.ts +2 -2
- package/src/core/codecs.ts +43 -48
- package/src/core/ddl/nodes.ts +59 -1
- package/src/core/migrations/control-policy.ts +17 -47
- package/src/core/migrations/issue-planner.ts +34 -70
- package/src/core/migrations/op-factory-call.ts +486 -215
- package/src/core/migrations/operations/columns.ts +175 -140
- package/src/core/migrations/operations/constraints.ts +79 -108
- package/src/core/migrations/operations/data-transform.ts +15 -18
- package/src/core/migrations/operations/dependencies.ts +16 -14
- package/src/core/migrations/operations/indexes.ts +31 -28
- package/src/core/migrations/operations/shared.ts +2 -2
- package/src/core/migrations/operations/tables.ts +13 -14
- package/src/core/migrations/planner-ddl-builders.ts +3 -4
- package/src/core/migrations/planner-identity-values.ts +4 -28
- package/src/core/migrations/planner-produced-postgres-migration.ts +15 -7
- package/src/core/migrations/planner-recipes.ts +44 -39
- package/src/core/migrations/planner-sql-checks.ts +3 -178
- package/src/core/migrations/planner-strategies.ts +76 -449
- package/src/core/migrations/planner-type-resolution.ts +2 -20
- package/src/core/migrations/planner.ts +6 -6
- package/src/core/migrations/postgres-migration.ts +287 -7
- package/src/core/migrations/render-ops.ts +26 -13
- package/src/core/migrations/runner.ts +26 -20
- package/src/core/postgres-contract-serializer.ts +37 -54
- package/src/core/postgres-enum-type-schema.ts +17 -0
- package/src/core/postgres-schema.ts +86 -46
- package/src/exports/codecs.ts +2 -2
- package/src/exports/contract-free.ts +22 -1
- package/src/exports/control.ts +0 -22
- package/src/exports/ddl.ts +4 -0
- package/src/exports/migration.ts +1 -29
- package/src/exports/op-factory-call.ts +0 -4
- package/src/exports/planner-sql-checks.ts +0 -7
- package/src/exports/types.ts +0 -1
- package/dist/codec-ids-B1vOchLE.d.mts.map +0 -1
- package/dist/codec-ids-CTikp1if.mjs.map +0 -1
- package/dist/codecs-CBpEv4s5.d.mts.map +0 -1
- package/dist/data-transform-D25tLeYU.mjs.map +0 -1
- package/dist/data-transform-DGOqcLrf.d.mts.map +0 -1
- package/dist/ddl-77SyXgFt.mjs +0 -30
- package/dist/ddl-77SyXgFt.mjs.map +0 -1
- package/dist/descriptor-meta-DKmj-IMN.mjs +0 -14
- package/dist/descriptor-meta-DKmj-IMN.mjs.map +0 -1
- package/dist/descriptor-meta-runtime-My8_s4cs.mjs +0 -130
- package/dist/descriptor-meta-runtime-My8_s4cs.mjs.map +0 -1
- package/dist/enum-planning-BCyvlFHk.mjs +0 -0
- package/dist/enum-planning-BCyvlFHk.mjs.map +0 -1
- package/dist/enum-planning.d.mts +0 -86
- package/dist/enum-planning.d.mts.map +0 -1
- package/dist/enum-planning.mjs +0 -2
- package/dist/issue-planner-Br0pt1Ea.mjs.map +0 -1
- package/dist/nodes-779hmCfL.d.mts.map +0 -1
- package/dist/nodes-DZk2JZG3.mjs.map +0 -1
- package/dist/op-factory-call-D2aAUhmS.mjs.map +0 -1
- package/dist/op-factory-call-DMA86_2D.d.mts.map +0 -1
- package/dist/planner-CAYPJObw.mjs.map +0 -1
- package/dist/planner-ddl-builders-Cw2n2llW.mjs.map +0 -1
- package/dist/planner-identity-values-BIpa5p2I.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-B4EDvLdz.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-NSEhWL0L.mjs.map +0 -1
- package/dist/planner-sql-checks-DAdhnI2c.mjs +0 -272
- package/dist/planner-sql-checks-DAdhnI2c.mjs.map +0 -1
- package/dist/planner-type-resolution-836DExFN.mjs.map +0 -1
- package/dist/postgres-contract-serializer-DYTyXjPf.mjs.map +0 -1
- package/dist/postgres-enum-type-BVn63a89.d.mts +0 -72
- package/dist/postgres-enum-type-BVn63a89.d.mts.map +0 -1
- package/dist/postgres-enum-type-DPKqCBem.mjs +0 -62
- package/dist/postgres-enum-type-DPKqCBem.mjs.map +0 -1
- package/dist/postgres-migration-COore9Mz.mjs +0 -71
- package/dist/postgres-migration-COore9Mz.mjs.map +0 -1
- package/dist/postgres-migration-DZ_gLUOW.d.mts +0 -72
- package/dist/postgres-migration-DZ_gLUOW.d.mts.map +0 -1
- package/dist/postgres-schema-BuxCxbvB.mjs.map +0 -1
- package/dist/render-ops-BpjstrKQ.mjs.map +0 -1
- package/dist/shared-DarONYBZ.d.mts +0 -43
- package/dist/shared-DarONYBZ.d.mts.map +0 -1
- package/src/core/migrations/enum-planning.ts +0 -213
- package/src/core/migrations/operations/enums.ts +0 -114
- package/src/core/postgres-enum-type.ts +0 -89
- package/src/exports/enum-planning.ts +0 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-Bs_baQax.mjs","names":["#lowerer"],"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 { entityAt, UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage, StorageTable } 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 '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 = entityAt<StorageTable>(contract.storage, {\n namespaceId,\n entityKind: 'table',\n entityName: tableName,\n });\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}\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 };\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 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.tableName) {\n const namespaceId = resolveNamespaceIdForTable(\n contract,\n callFields.tableName,\n callFields.schemaName,\n );\n const tableControlPolicy = entityAt<StorageTable>(contract.storage, {\n namespaceId,\n entityKind: 'table',\n entityName: callFields.tableName,\n })?.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});\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 ('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 = entityAt<StorageTable>(contract.storage, {\n namespaceId,\n entityKind: 'table',\n entityName: issue.table,\n });\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 type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';\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 { parsePostgresDefault } from '../default-normalizer';\nimport { normalizeSchemaNativeType } from '../native-type-normalizer';\nimport {\n formatPostgresControlPolicySubjectLabel,\n resolvePostgresCallControlPolicySubject,\n resolvePostgresIssueControlPolicySubject,\n resolvePostgresIssueCreationFactoryName,\n} from './control-policy';\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(\n lowerer: ExecuteRequestLowerer,\n): PostgresMigrationPlanner {\n return new PostgresMigrationPlanner(lowerer);\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 readonly #lowerer: ExecuteRequestLowerer | undefined;\n\n constructor(lowerer?: ExecuteRequestLowerer) {\n this.#lowerer = lowerer;\n }\n\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 this.#lowerer,\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 this.#lowerer,\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 };\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":";;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,4BAAiD,IAAI,IAAY,CACrE,eACA,cACF,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;EAMlE,IAAI,CALU,SAAuB,SAAS,SAAS;GACrD;GACA,YAAY;GACZ,YAAY;EACd,CACS,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;AAQA,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;CAC/E;AACF;AAEA,SAAgB,wCACd,aACA,SACA,UACQ;CACR,IAAI,SAAS,O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EACjE,MAAM,WAAiC,CACrC,GAAG,eAAe,UAClB,GAAG,oBAAoB,QACzB;EAEA,OAAO,OAAO,OAAO;GACnB,MAAM;GACN,MAAM,IAAI,sCACR,OACA;IACE,MAAM,QAAQ,cAAc,QAAQ,eAAe;IACnD,IAAI,QAAQ,SAAS,QAAQ;GAC/B,GACA,QAAQ,SACR,KAAKA,QACP;GACA,GAAI,SAAS,SAAS,IAAI,EAAE,UAAU,OAAO,OAAO,QAAQ,EAAE,IAAI,CAAC;EACrE,CAAC;CACH;CAEA,qBAA6B,QAAkC;EAC7D,IAAI,CAAC,OAAO,wBAAwB,SAAS,UAAU,GACrD,OAAO,eAAe,CACpB;GACE,MAAM;GACN,SAAS;GACT,KAAK;EACP,CACF,CAAC;EAEH,OAAO;CACT;CAEA,oBAA4B,SAA+D;EAIzF,MAAM,UAAU,QAAQ,OAAO;EAC/B,MAAM,SAAS,QAAQ,SAAS,UAAU,KAAK,QAAQ,SAAS,aAAa;EAU7E,MAAM,eAAe,gBAAgB;GARnC,UAAU,QAAQ;GAClB,QAAQ,QAAQ;GAChB;GACA,sCAAsB,IAAI,IAAI;GAC9B,qBAAqB,QAAQ;GAC7B,kBAAkB;GAClB,qBAAqB;EAE0B,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
|
|
2
|
-
import { t as resolveColumnTypeMetadata } from "./planner-type-resolution-
|
|
2
|
+
import { t as resolveColumnTypeMetadata } from "./planner-type-resolution-Bt2f_q-F.mjs";
|
|
3
3
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
4
4
|
//#region src/core/migrations/planner-ddl-builders.ts
|
|
5
5
|
function buildCreateTableSql(qualifiedTableName, table, codecHooks, storageTypes = {}) {
|
|
@@ -105,4 +105,4 @@ function buildAddColumnSql(qualifiedTableName, columnName, column, codecHooks, t
|
|
|
105
105
|
//#endregion
|
|
106
106
|
export { renderDefaultLiteral as a, buildCreateTableSql as i, buildColumnDefaultSql as n, buildColumnTypeSql as r, buildAddColumnSql as t };
|
|
107
107
|
|
|
108
|
-
//# sourceMappingURL=planner-ddl-builders-
|
|
108
|
+
//# sourceMappingURL=planner-ddl-builders-B2wOwLqI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-ddl-builders-B2wOwLqI.mjs","names":[],"sources":["../src/core/migrations/planner-ddl-builders.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type {\n StorageColumn,\n StorageTable,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport type { PostgresColumnDefault } from '../types';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\nexport function buildCreateTableSql(\n qualifiedTableName: string,\n table: StorageTable,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance> = {},\n): string {\n const columnDefinitions = Object.entries(table.columns).map(\n ([columnName, column]: [string, StorageColumn]) => {\n const parts = [\n quoteIdentifier(columnName),\n buildColumnTypeSql(column, codecHooks, storageTypes),\n buildColumnDefaultSql(column.default, column),\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n },\n );\n\n const constraintDefinitions: string[] = [];\n if (table.primaryKey) {\n constraintDefinitions.push(\n `PRIMARY KEY (${table.primaryKey.columns.map(quoteIdentifier).join(', ')})`,\n );\n }\n\n const allDefinitions = [...columnDefinitions, ...constraintDefinitions];\n return `CREATE TABLE ${qualifiedTableName} (\\n ${allDefinitions.join(',\\n ')}\\n)`;\n}\n\n/**\n * Pattern for safe PostgreSQL type names.\n * Allows letters, digits, underscores, spaces (for \"double precision\", \"character varying\"),\n * and trailing [] for array types.\n */\nconst SAFE_NATIVE_TYPE_PATTERN = /^[a-zA-Z][a-zA-Z0-9_ ]*(\\[\\])?$/;\n\nfunction assertSafeNativeType(nativeType: string): void {\n if (!SAFE_NATIVE_TYPE_PATTERN.test(nativeType)) {\n throw new Error(\n `Unsafe native type name in contract: \"${nativeType}\". ` +\n 'Native type names must match /^[a-zA-Z][a-zA-Z0-9_ ]*(\\\\[\\\\])?$/',\n );\n }\n}\n\n/**\n * Sanity check against accidental SQL injection from malformed contract files.\n * Rejects semicolons, SQL comment tokens, and dollar-quoting.\n * Not a comprehensive security boundary — the contract is developer-authored.\n */\nfunction assertSafeDefaultExpression(expression: string): void {\n if (expression.includes(';') || /--|\\/\\*|\\$\\$|\\bSELECT\\b/i.test(expression)) {\n throw new Error(\n `Unsafe default expression in contract: \"${expression}\". ` +\n 'Default expressions must not contain semicolons, SQL comment tokens, dollar-quoting, or subqueries.',\n );\n }\n}\n\n/**\n * Renders the SQL type for a column in DDL context.\n *\n * @param allowPseudoTypes - When true (default), autoincrement integer columns\n * produce SERIAL/BIGSERIAL/SMALLSERIAL pseudo-types. Set to false for contexts\n * like ALTER COLUMN TYPE where pseudo-types are invalid.\n */\nexport function buildColumnTypeSql(\n column: StorageColumn,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance> = {},\n allowPseudoTypes = true,\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n\n if (allowPseudoTypes) {\n const columnDefault = column.default;\n if (columnDefault?.kind === 'function' && columnDefault.expression === 'autoincrement()') {\n if (resolved.nativeType === 'int4' || resolved.nativeType === 'integer') {\n return 'SERIAL';\n }\n if (resolved.nativeType === 'int8' || resolved.nativeType === 'bigint') {\n return 'BIGSERIAL';\n }\n if (resolved.nativeType === 'int2' || resolved.nativeType === 'smallint') {\n return 'SMALLSERIAL';\n }\n }\n }\n\n const expanded = expandParameterizedTypeSql(resolved, codecHooks);\n if (expanded !== null) {\n return expanded;\n }\n\n if (column.typeRef) {\n return quoteIdentifier(resolved.nativeType);\n }\n\n assertSafeNativeType(resolved.nativeType);\n return resolved.nativeType;\n}\n\nfunction expandParameterizedTypeSql(\n column: Pick<StorageColumn, 'nativeType' | 'codecId' | 'typeParams'>,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n): string | null {\n if (!column.typeParams || Object.keys(column.typeParams).length === 0) {\n return null;\n }\n\n if (!column.codecId) {\n throw new Error(\n `Column declares typeParams for nativeType \"${column.nativeType}\" but has no codecId. ` +\n 'Ensure the column is associated with a codec.',\n );\n }\n\n const hooks = codecHooks.get(column.codecId);\n if (!hooks?.expandNativeType) {\n if (hooks?.planTypeOperations) {\n return null;\n }\n throw new Error(\n `Column declares typeParams for nativeType \"${column.nativeType}\" ` +\n `but no expandNativeType hook is registered for codecId \"${column.codecId}\". ` +\n 'Ensure the extension providing this codec is included in extensionPacks.',\n );\n }\n\n const expanded = hooks.expandNativeType({\n nativeType: column.nativeType,\n codecId: column.codecId,\n ...ifDefined('typeParams', column.typeParams),\n });\n\n return expanded !== column.nativeType ? expanded : null;\n}\n\n/** Autoincrement columns use SERIAL types, so this returns empty for them. */\nexport function buildColumnDefaultSql(\n columnDefault: PostgresColumnDefault | undefined,\n column?: StorageColumn,\n): string {\n if (!columnDefault) {\n return '';\n }\n\n switch (columnDefault.kind) {\n case 'literal':\n return `DEFAULT ${renderDefaultLiteral(columnDefault.value, column)}`;\n case 'function': {\n if (columnDefault.expression === 'autoincrement()') {\n return '';\n }\n assertSafeDefaultExpression(columnDefault.expression);\n return `DEFAULT (${columnDefault.expression})`;\n }\n case 'sequence':\n return `DEFAULT nextval('${escapeLiteral(quoteIdentifier(columnDefault.name))}'::regclass)`;\n }\n}\n\nexport function renderDefaultLiteral(value: unknown, column?: StorageColumn): string {\n const isJsonColumn = column?.nativeType === 'json' || column?.nativeType === 'jsonb';\n\n if (value instanceof Date) {\n return `'${escapeLiteral(value.toISOString())}'`;\n }\n if (typeof value === 'string') {\n return `'${escapeLiteral(value)}'`;\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (value === null) {\n return 'NULL';\n }\n const json = JSON.stringify(value);\n if (isJsonColumn) {\n return `'${escapeLiteral(json)}'::${column.nativeType}`;\n }\n return `'${escapeLiteral(json)}'`;\n}\n\nexport function buildAddColumnSql(\n qualifiedTableName: string,\n columnName: string,\n column: StorageColumn,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n temporaryDefault?: string | null,\n storageTypes: Record<string, StorageTypeInstance> = {},\n): string {\n const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);\n const defaultSql =\n buildColumnDefaultSql(column.default, column) ||\n (temporaryDefault ? `DEFAULT ${temporaryDefault}` : '');\n const parts = [\n `ALTER TABLE ${qualifiedTableName}`,\n `ADD COLUMN ${quoteIdentifier(columnName)} ${typeSql}`,\n defaultSql,\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n}\n"],"mappings":";;;;AAWA,SAAgB,oBACd,oBACA,OACA,YACA,eAAoD,CAAC,GAC7C;CACR,MAAM,oBAAoB,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KACrD,CAAC,YAAY,YAAqC;EAOjD,OANc;GACZ,gBAAgB,UAAU;GAC1B,mBAAmB,QAAQ,YAAY,YAAY;GACnD,sBAAsB,OAAO,SAAS,MAAM;GAC5C,OAAO,WAAW,KAAK;EACzB,CAAC,CAAC,OAAO,OACE,CAAC,CAAC,KAAK,GAAG;CACvB,CACF;CAEA,MAAM,wBAAkC,CAAC;CACzC,IAAI,MAAM,YACR,sBAAsB,KACpB,gBAAgB,MAAM,WAAW,QAAQ,IAAI,eAAe,CAAC,CAAC,KAAK,IAAI,EAAE,EAC3E;CAIF,OAAO,gBAAg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U,EAAE,GAAG;EAC7C;EACA,OAAO,WAAW,KAAK;CACzB,CAAC,CAAC,OAAO,OACE,CAAC,CAAC,KAAK,GAAG;AACvB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as PostgresColumnDefault } from "./types-BDKkx8MA.mjs";
|
|
2
2
|
import { CodecControlHooks } from "@prisma-next/family-sql/control";
|
|
3
|
-
import {
|
|
3
|
+
import { StorageColumn, StorageTable, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
4
4
|
|
|
5
5
|
//#region src/core/migrations/planner-ddl-builders.d.ts
|
|
6
|
-
declare function buildCreateTableSql(qualifiedTableName: string, table: StorageTable, codecHooks: ReadonlyMap<string, CodecControlHooks>, storageTypes?: Record<string, StorageTypeInstance
|
|
6
|
+
declare function buildCreateTableSql(qualifiedTableName: string, table: StorageTable, codecHooks: ReadonlyMap<string, CodecControlHooks>, storageTypes?: Record<string, StorageTypeInstance>): string;
|
|
7
7
|
/**
|
|
8
8
|
* Renders the SQL type for a column in DDL context.
|
|
9
9
|
*
|
|
@@ -11,11 +11,11 @@ declare function buildCreateTableSql(qualifiedTableName: string, table: StorageT
|
|
|
11
11
|
* produce SERIAL/BIGSERIAL/SMALLSERIAL pseudo-types. Set to false for contexts
|
|
12
12
|
* like ALTER COLUMN TYPE where pseudo-types are invalid.
|
|
13
13
|
*/
|
|
14
|
-
declare function buildColumnTypeSql(column: StorageColumn, codecHooks: ReadonlyMap<string, CodecControlHooks>, storageTypes?: Record<string, StorageTypeInstance
|
|
14
|
+
declare function buildColumnTypeSql(column: StorageColumn, codecHooks: ReadonlyMap<string, CodecControlHooks>, storageTypes?: Record<string, StorageTypeInstance>, allowPseudoTypes?: boolean): string;
|
|
15
15
|
/** Autoincrement columns use SERIAL types, so this returns empty for them. */
|
|
16
16
|
declare function buildColumnDefaultSql(columnDefault: PostgresColumnDefault | undefined, column?: StorageColumn): string;
|
|
17
17
|
declare function renderDefaultLiteral(value: unknown, column?: StorageColumn): string;
|
|
18
|
-
declare function buildAddColumnSql(qualifiedTableName: string, columnName: string, column: StorageColumn, codecHooks: ReadonlyMap<string, CodecControlHooks>, temporaryDefault?: string | null, storageTypes?: Record<string, StorageTypeInstance
|
|
18
|
+
declare function buildAddColumnSql(qualifiedTableName: string, columnName: string, column: StorageColumn, codecHooks: ReadonlyMap<string, CodecControlHooks>, temporaryDefault?: string | null, storageTypes?: Record<string, StorageTypeInstance>): string;
|
|
19
19
|
//#endregion
|
|
20
20
|
export { buildAddColumnSql, buildColumnDefaultSql, buildColumnTypeSql, buildCreateTableSql, renderDefaultLiteral };
|
|
21
21
|
//# sourceMappingURL=planner-ddl-builders.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner-ddl-builders.d.mts","names":[],"sources":["../src/core/migrations/planner-ddl-builders.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"planner-ddl-builders.d.mts","names":[],"sources":["../src/core/migrations/planner-ddl-builders.ts"],"mappings":";;;;;iBAWgB,mBAAA,CACd,kBAAA,UACA,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,WAAA,SAAoB,iBAAA,GAChC,YAAA,GAAc,MAAA,SAAe,mBAAA;;AAJ/B;;;;;;iBAkEgB,kBAAA,CACd,MAAA,EAAQ,aAAA,EACR,UAAA,EAAY,WAAA,SAAoB,iBAAA,GAChC,YAAA,GAAc,MAAA,SAAe,mBAAA,GAC7B,gBAAA;;iBAqEc,qBAAA,CACd,aAAA,EAAe,qBAAA,cACf,MAAA,GAAS,aAAa;AAAA,iBAqBR,oBAAA,CAAqB,KAAA,WAAgB,MAAA,GAAS,aAAa;AAAA,iBAsB3D,iBAAA,CACd,kBAAA,UACA,UAAA,UACA,MAAA,EAAQ,aAAA,EACR,UAAA,EAAY,WAAA,SAAoB,iBAAA,GAChC,gBAAA,kBACA,YAAA,GAAc,MAAA,SAAe,mBAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as renderDefaultLiteral, i as buildCreateTableSql, n as buildColumnDefaultSql, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-
|
|
1
|
+
import { a as renderDefaultLiteral, i as buildCreateTableSql, n as buildColumnDefaultSql, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-B2wOwLqI.mjs";
|
|
2
2
|
export { buildAddColumnSql, buildColumnDefaultSql, buildColumnTypeSql, buildCreateTableSql, renderDefaultLiteral };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
2
|
-
import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
3
2
|
//#region src/core/migrations/planner-identity-values.ts
|
|
4
3
|
/**
|
|
5
4
|
* Resolves the identity value (monoid neutral element) as a SQL literal for a column's type.
|
|
@@ -8,14 +7,9 @@ import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
|
8
7
|
*/
|
|
9
8
|
function resolveIdentityValue(column, codecHooks, storageTypes = {}) {
|
|
10
9
|
const referencedType = column.typeRef ? storageTypes[column.typeRef] : void 0;
|
|
11
|
-
const
|
|
12
|
-
const referencedBinding = referencedIsEnum ? referencedType.codecBinding ?? {
|
|
13
|
-
codecId: referencedType.codecId,
|
|
14
|
-
typeParams: { values: referencedType.values }
|
|
15
|
-
} : void 0;
|
|
16
|
-
const codecId = referencedBinding?.codecId ?? (referencedType && !referencedIsEnum ? referencedType.codecId : void 0) ?? column.codecId;
|
|
10
|
+
const codecId = referencedType?.codecId ?? column.codecId;
|
|
17
11
|
const nativeType = referencedType?.nativeType ?? column.nativeType;
|
|
18
|
-
const typeParams =
|
|
12
|
+
const typeParams = referencedType?.typeParams ?? column.typeParams;
|
|
19
13
|
if (codecId) {
|
|
20
14
|
const hookDefault = codecHooks.get(codecId)?.resolveIdentityValue?.({
|
|
21
15
|
nativeType,
|
|
@@ -93,4 +87,4 @@ function buildBitIdentityValue(typeParams) {
|
|
|
93
87
|
//#endregion
|
|
94
88
|
export { resolveIdentityValue as n, buildBuiltinIdentityValue as t };
|
|
95
89
|
|
|
96
|
-
//# sourceMappingURL=planner-identity-values-
|
|
90
|
+
//# sourceMappingURL=planner-identity-values-CJPha2Sz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-identity-values-CJPha2Sz.mjs","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\n/**\n * Resolves the identity value (monoid neutral element) as a SQL literal for a column's type.\n * Checks codec hooks first (extensions can provide type-specific identity values),\n * then falls back to the built-in map.\n */\nexport function resolveIdentityValue(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance> = {},\n): string | null {\n const referencedType = column.typeRef ? storageTypes[column.typeRef] : undefined;\n const codecId = referencedType?.codecId ?? column.codecId;\n const nativeType = referencedType?.nativeType ?? column.nativeType;\n const typeParams = referencedType?.typeParams ?? column.typeParams;\n\n if (codecId) {\n const hookDefault = codecHooks.get(codecId)?.resolveIdentityValue?.({\n nativeType,\n codecId,\n ...ifDefined('typeParams', typeParams),\n });\n if (hookDefault !== undefined) {\n return hookDefault;\n }\n }\n\n return buildBuiltinIdentityValue(nativeType, typeParams);\n}\n\n/**\n * Returns the built-in identity value (monoid neutral element) as a SQL literal for the given\n * PostgreSQL native type — e.g. 0 for integers, '' for text, false for booleans.\n *\n * This is the planner's fallback when no codec hook provides a type-specific identity value.\n *\n * Returns null for unrecognized types (for example enums and extension-owned types without a\n * hook), which causes the planner to fall back to the empty-table precheck.\n *\n * @internal Exported for testing only.\n */\nexport function buildBuiltinIdentityValue(\n nativeType: string,\n typeParams?: Record<string, unknown>,\n): string | null {\n const normalizedNativeType = normalizeIdentityValueNativeType(nativeType);\n\n if (normalizedNativeType.endsWith('[]')) {\n return \"'{}'\";\n }\n\n switch (normalizedNativeType) {\n case 'text':\n case 'character':\n case 'bpchar':\n case 'character varying':\n case 'varchar':\n return \"''\";\n\n case 'int2':\n case 'int4':\n case 'int8':\n case 'integer':\n case 'bigint':\n case 'smallint':\n case 'float4':\n case 'float8':\n case 'real':\n case 'double precision':\n case 'numeric':\n case 'decimal':\n return '0';\n\n case 'bool':\n case 'boolean':\n return 'false';\n\n case 'uuid':\n return \"'00000000-0000-0000-0000-000000000000'\";\n\n case 'json':\n return \"'{}'::json\";\n case 'jsonb':\n return \"'{}'::jsonb\";\n\n case 'date':\n case 'timestamp':\n case 'timestamptz':\n case 'timestamp with time zone':\n case 'timestamp without time zone':\n return \"'epoch'\";\n\n case 'time':\n case 'time without time zone':\n return \"'00:00:00'\";\n case 'timetz':\n case 'time with time zone':\n return \"'00:00:00+00'\";\n\n case 'interval':\n return \"'0'\";\n\n case 'bytea':\n return \"''::bytea\";\n case 'tsvector':\n return \"''::tsvector\";\n\n case 'bit':\n return buildBitIdentityValue(typeParams);\n case 'bit varying':\n case 'varbit':\n return \"B''\";\n\n default:\n return null;\n }\n}\n\nfunction normalizeIdentityValueNativeType(nativeType: string): string {\n return nativeType.trim().toLowerCase().replace(/\\s+/g, ' ');\n}\n\nfunction buildBitIdentityValue(typeParams?: Record<string, unknown>): string | null {\n const length = typeParams?.['length'];\n if (length === undefined) {\n return \"B'0'\";\n }\n if (typeof length !== 'number' || !Number.isInteger(length) || length <= 0) {\n return null;\n }\n return `B'${'0'.repeat(length)}'`;\n}\n"],"mappings":";;;;;;;AASA,SAAgB,qBACd,QACA,YACA,eAAoD,CAAC,GACtC;CACf,MAAM,iBAAiB,OAAO,UAAU,aAAa,OAAO,WAAW,KAAA;CACvE,MAAM,UAAU,gBAAgB,WAAW,OAAO;CAClD,MAAM,aAAa,gBAAgB,cAAc,OAAO;CACxD,MAAM,aAAa,gBAAgB,cAAc,OAAO;CAExD,IAAI,SAAS;E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M,EAAE;AACjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CodecControlHooks } from "@prisma-next/family-sql/control";
|
|
2
|
-
import {
|
|
2
|
+
import { StorageColumn, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
3
3
|
|
|
4
4
|
//#region src/core/migrations/planner-identity-values.d.ts
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner-identity-values.d.mts","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"planner-identity-values.d.mts","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"mappings":";;;;;;;;AA8CsC;;;;;;;iBAFtB,yBAAA,CACd,UAAA,UACA,UAAA,GAAa,MAAM"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as buildBuiltinIdentityValue } from "./planner-identity-values-
|
|
1
|
+
import { t as buildBuiltinIdentityValue } from "./planner-identity-values-CJPha2Sz.mjs";
|
|
2
2
|
export { buildBuiltinIdentityValue };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as PostgresMigration } from "./postgres-migration-
|
|
2
|
-
import { t as renderOps } from "./render-ops-
|
|
1
|
+
import { t as PostgresMigration } from "./postgres-migration-B5jKrXv3.mjs";
|
|
2
|
+
import { t as renderOps } from "./render-ops-BREh1kHe.mjs";
|
|
3
3
|
import { t as renderCallsToTypeScript } from "./render-typescript-KMgosran.mjs";
|
|
4
4
|
//#region src/core/migrations/planner-produced-postgres-migration.ts
|
|
5
5
|
var TypeScriptRenderablePostgresMigration = class extends PostgresMigration {
|
|
@@ -7,6 +7,7 @@ var TypeScriptRenderablePostgresMigration = class extends PostgresMigration {
|
|
|
7
7
|
#meta;
|
|
8
8
|
#spaceId;
|
|
9
9
|
#lowerer;
|
|
10
|
+
#operationsCache;
|
|
10
11
|
constructor(calls, meta, spaceId, lowerer) {
|
|
11
12
|
super();
|
|
12
13
|
this.#calls = calls;
|
|
@@ -15,7 +16,8 @@ var TypeScriptRenderablePostgresMigration = class extends PostgresMigration {
|
|
|
15
16
|
this.#lowerer = lowerer;
|
|
16
17
|
}
|
|
17
18
|
get operations() {
|
|
18
|
-
|
|
19
|
+
this.#operationsCache ??= renderOps(this.#calls, this.#lowerer);
|
|
20
|
+
return this.#operationsCache;
|
|
19
21
|
}
|
|
20
22
|
describe() {
|
|
21
23
|
return this.#meta;
|
|
@@ -38,4 +40,4 @@ var TypeScriptRenderablePostgresMigration = class extends PostgresMigration {
|
|
|
38
40
|
//#endregion
|
|
39
41
|
export { TypeScriptRenderablePostgresMigration as t };
|
|
40
42
|
|
|
41
|
-
//# sourceMappingURL=planner-produced-postgres-migration-
|
|
43
|
+
//# sourceMappingURL=planner-produced-postgres-migration-Cji5vxUf.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-produced-postgres-migration-Cji5vxUf.mjs","names":["#calls","#meta","#spaceId","#lowerer","#operationsCache"],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":["/**\n * Planner-produced Postgres migration.\n *\n * Returned by `PostgresMigrationPlanner.plan(...)` and `emptyMigration(...)`.\n * Holds the migration IR (`PostgresOpFactoryCall[]`) alongside\n * `MigrationMeta` and exposes both the runtime-ops view (`get operations`)\n * and the TypeScript authoring view (`renderTypeScript()`). Satisfies\n * `MigrationPlanWithAuthoringSurface` so the CLI can uniformly serialize any\n * planner result back to `migration.ts`.\n *\n * Extends the family-level `SqlMigration` alias rather than the target-local\n * migration base directly — mirrors Mongo's `PlannerProducedMongoMigration`\n * shape and keeps CLI wiring one step removed from target internals.\n *\n * Placeholder-bearing plans: `renderTypeScript()` always succeeds and embeds\n * `() => placeholder(\"slot\")` at each stub. `operations`, in contrast, is\n * _not safe to enumerate_ on a stub-bearing plan — `DataTransformCall.toOp()`\n * throws `PN-MIG-2001` because a planner-stubbed closure cannot be lowered\n * to a runtime op. Callers that know a plan may carry stubs must render to\n * `migration.ts`, let the user fill the slots, and re-load the edited\n * migration before enumerating ops. The walk-schema planner does not emit\n * `DataTransformCall`s today, so this asymmetry is invisible until the\n * issue-planner integration lands in Phase 2.\n */\n\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';\nimport type {\n MigrationPlanWithAuthoringSurface,\n OpFactoryCall,\n} from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\nimport { PostgresMigration } from './postgres-migration';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\n\nexport class TypeScriptRenderablePostgresMigration\n extends PostgresMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly OpFactoryCall[];\n readonly #meta: MigrationMeta;\n readonly #spaceId: string;\n readonly #lowerer: ExecuteRequestLowerer | undefined;\n #operationsCache:\n | readonly (\n | SqlMigrationPlanOperation<PostgresPlanTargetDetails>\n | Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>\n )[]\n | undefined;\n\n constructor(\n calls: readonly OpFactoryCall[],\n meta: MigrationMeta,\n spaceId: string,\n lowerer?: ExecuteRequestLowerer,\n ) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n this.#spaceId = spaceId;\n this.#lowerer = lowerer;\n }\n\n override get operations(): readonly (\n | SqlMigrationPlanOperation<PostgresPlanTargetDetails>\n | Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>\n )[] {\n this.#operationsCache ??= renderOps(this.#calls, this.#lowerer);\n return this.#operationsCache;\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n /**\n * Contract space this planner-produced plan applies to. Threaded\n * from the planner options so the runner keys the marker row by\n * the right space when executing the plan.\n */\n get spaceId(): string {\n return this.#spaceId;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, { from: this.#meta.from, to: this.#meta.to });\n }\n}\n"],"mappings":";;;;AAqCA,IAAa,wCAAb,cACU,kBAEV;CACE;CACA;CACA;CACA;CACA;CAOA,YACE,OACA,MACA,SACA,SACA;EACA,MAAM;EACN,KAAKA,SAAS;EACd,KAAKC,QAAQ;EACb,KAAKC,WAAW;EAChB,KAAKC,WAAW;CAClB;CAEA,IAAa,aAGT;EACF,KAAKC,qBAAqB,UAAU,KAAKJ,QAAQ,KAAKG,QAAQ;EAC9D,OAAO,KAAKC;CACd;CAEA,WAAmC;EACjC,OAAO,KAAKH;CACd;;;;;;CAOA,IAAI,UAAkB;EACpB,OAAO,KAAKC;CACd;CAEA,mBAA2B;EACzB,OAAO,wBAAwB,KAAKF,QAAQ;GAAE,MAAM,KAAKC,MAAM;GAAM,IAAI,KAAKA,MAAM;EAAG,CAAC;CAC1F;AACF"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
|
|
2
|
-
import { t as PostgresMigration } from "./postgres-migration-
|
|
2
|
+
import { t as PostgresMigration } from "./postgres-migration-Y4YBJqkS.mjs";
|
|
3
3
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
4
4
|
import { MigrationPlanWithAuthoringSurface, OpFactoryCall } from "@prisma-next/framework-components/control";
|
|
5
|
-
import {
|
|
5
|
+
import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
|
|
6
6
|
import { MigrationMeta } from "@prisma-next/migration-tools/migration";
|
|
7
7
|
|
|
8
8
|
//#region src/core/migrations/planner-produced-postgres-migration.d.ts
|
|
9
|
-
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
10
9
|
declare class TypeScriptRenderablePostgresMigration extends PostgresMigration implements MigrationPlanWithAuthoringSurface {
|
|
11
10
|
#private;
|
|
12
|
-
constructor(calls: readonly OpFactoryCall[], meta: MigrationMeta, spaceId: string, lowerer?:
|
|
13
|
-
get operations(): readonly
|
|
11
|
+
constructor(calls: readonly OpFactoryCall[], meta: MigrationMeta, spaceId: string, lowerer?: ExecuteRequestLowerer);
|
|
12
|
+
get operations(): readonly (SqlMigrationPlanOperation<PostgresPlanTargetDetails> | Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>)[];
|
|
14
13
|
describe(): MigrationMeta;
|
|
15
14
|
/**
|
|
16
15
|
* Contract space this planner-produced plan applies to. Threaded
|
|
@@ -22,4 +21,4 @@ declare class TypeScriptRenderablePostgresMigration extends PostgresMigration im
|
|
|
22
21
|
}
|
|
23
22
|
//#endregion
|
|
24
23
|
export { TypeScriptRenderablePostgresMigration as t };
|
|
25
|
-
//# sourceMappingURL=planner-produced-postgres-migration-
|
|
24
|
+
//# sourceMappingURL=planner-produced-postgres-migration-QqHa2C2l.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-produced-postgres-migration-QqHa2C2l.d.mts","names":[],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"mappings":";;;;;;;;cAqCa,qCAAA,SACH,iBAAA,YACG,iCAAA;EAAA;cAcT,KAAA,WAAgB,aAAA,IAChB,IAAA,EAAM,aAAA,EACN,OAAA,UACA,OAAA,GAAU,qBAAA;EAAA,IASC,UAAA,cACT,yBAAA,CAA0B,yBAAA,IAC1B,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAM7B,QAAA,IAAY,aAAA;EARR;;;;;EAAA,IAiBT,OAAA;EAIJ,gBAAA;AAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-
|
|
1
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-QqHa2C2l.mjs";
|
|
2
2
|
export { TypeScriptRenderablePostgresMigration };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-
|
|
1
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-Cji5vxUf.mjs";
|
|
2
2
|
export { TypeScriptRenderablePostgresMigration };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { i as postgresCreateNamespace } from "./postgres-schema-COGZ1ark.mjs";
|
|
2
|
+
import { i as quoteIdentifier } from "./sql-utils-DcfMz4MQ.mjs";
|
|
3
|
+
import { t as resolveColumnTypeMetadata } from "./planner-type-resolution-Bt2f_q-F.mjs";
|
|
4
|
+
//#region src/core/migrations/planner-sql-checks.ts
|
|
5
|
+
/**
|
|
6
|
+
* String-keyed entry points the migration ops use to render
|
|
7
|
+
* schema-qualified DDL and catalog checks. The `schema` argument is
|
|
8
|
+
* interpreted as a namespace coordinate: the framework `__unbound__`
|
|
9
|
+
* sentinel resolves to the late-bound `PostgresUnboundSchema` singleton
|
|
10
|
+
* (which elides the qualifier so `search_path` decides at runtime); any
|
|
11
|
+
* other id materialises a `PostgresSchema(id)` whose qualifier is the
|
|
12
|
+
* named schema. Helpers route through these `Namespace` concretions so
|
|
13
|
+
* the unbound branch lives in the polymorphic override, not the call
|
|
14
|
+
* site.
|
|
15
|
+
*/
|
|
16
|
+
function qualifyTableName(schema, table) {
|
|
17
|
+
return postgresCreateNamespace({
|
|
18
|
+
id: schema,
|
|
19
|
+
entries: { table: {} }
|
|
20
|
+
}).qualifyTable(table);
|
|
21
|
+
}
|
|
22
|
+
const FORMAT_TYPE_DISPLAY = new Map([
|
|
23
|
+
["int2", "smallint"],
|
|
24
|
+
["int4", "integer"],
|
|
25
|
+
["int8", "bigint"],
|
|
26
|
+
["float4", "real"],
|
|
27
|
+
["float8", "double precision"],
|
|
28
|
+
["bool", "boolean"],
|
|
29
|
+
["timestamp", "timestamp without time zone"],
|
|
30
|
+
["timestamptz", "timestamp with time zone"],
|
|
31
|
+
["time", "time without time zone"],
|
|
32
|
+
["timetz", "time with time zone"]
|
|
33
|
+
]);
|
|
34
|
+
const UNQUOTED_POSTGRES_IDENTIFIER_PATTERN = /^[a-z_][a-z0-9_$]*$/;
|
|
35
|
+
const POSTGRES_RESERVED_IDENTIFIER_WORDS = new Set([
|
|
36
|
+
"all",
|
|
37
|
+
"analyse",
|
|
38
|
+
"analyze",
|
|
39
|
+
"and",
|
|
40
|
+
"any",
|
|
41
|
+
"array",
|
|
42
|
+
"as",
|
|
43
|
+
"asc",
|
|
44
|
+
"asymmetric",
|
|
45
|
+
"authorization",
|
|
46
|
+
"between",
|
|
47
|
+
"binary",
|
|
48
|
+
"both",
|
|
49
|
+
"case",
|
|
50
|
+
"cast",
|
|
51
|
+
"check",
|
|
52
|
+
"collate",
|
|
53
|
+
"column",
|
|
54
|
+
"constraint",
|
|
55
|
+
"create",
|
|
56
|
+
"current_catalog",
|
|
57
|
+
"current_date",
|
|
58
|
+
"current_role",
|
|
59
|
+
"current_time",
|
|
60
|
+
"current_timestamp",
|
|
61
|
+
"current_user",
|
|
62
|
+
"default",
|
|
63
|
+
"deferrable",
|
|
64
|
+
"desc",
|
|
65
|
+
"distinct",
|
|
66
|
+
"do",
|
|
67
|
+
"else",
|
|
68
|
+
"end",
|
|
69
|
+
"except",
|
|
70
|
+
"false",
|
|
71
|
+
"fetch",
|
|
72
|
+
"for",
|
|
73
|
+
"foreign",
|
|
74
|
+
"freeze",
|
|
75
|
+
"from",
|
|
76
|
+
"full",
|
|
77
|
+
"grant",
|
|
78
|
+
"group",
|
|
79
|
+
"having",
|
|
80
|
+
"ilike",
|
|
81
|
+
"in",
|
|
82
|
+
"initially",
|
|
83
|
+
"inner",
|
|
84
|
+
"intersect",
|
|
85
|
+
"into",
|
|
86
|
+
"is",
|
|
87
|
+
"isnull",
|
|
88
|
+
"join",
|
|
89
|
+
"lateral",
|
|
90
|
+
"leading",
|
|
91
|
+
"left",
|
|
92
|
+
"like",
|
|
93
|
+
"limit",
|
|
94
|
+
"localtime",
|
|
95
|
+
"localtimestamp",
|
|
96
|
+
"natural",
|
|
97
|
+
"not",
|
|
98
|
+
"notnull",
|
|
99
|
+
"null",
|
|
100
|
+
"offset",
|
|
101
|
+
"on",
|
|
102
|
+
"only",
|
|
103
|
+
"or",
|
|
104
|
+
"order",
|
|
105
|
+
"outer",
|
|
106
|
+
"overlaps",
|
|
107
|
+
"placing",
|
|
108
|
+
"primary",
|
|
109
|
+
"references",
|
|
110
|
+
"right",
|
|
111
|
+
"select",
|
|
112
|
+
"session_user",
|
|
113
|
+
"similar",
|
|
114
|
+
"some",
|
|
115
|
+
"symmetric",
|
|
116
|
+
"table",
|
|
117
|
+
"then",
|
|
118
|
+
"to",
|
|
119
|
+
"trailing",
|
|
120
|
+
"true",
|
|
121
|
+
"union",
|
|
122
|
+
"unique",
|
|
123
|
+
"user",
|
|
124
|
+
"using",
|
|
125
|
+
"variadic",
|
|
126
|
+
"verbose",
|
|
127
|
+
"when",
|
|
128
|
+
"where",
|
|
129
|
+
"window",
|
|
130
|
+
"with"
|
|
131
|
+
]);
|
|
132
|
+
function formatUserDefinedTypeName(identifier) {
|
|
133
|
+
if (UNQUOTED_POSTGRES_IDENTIFIER_PATTERN.test(identifier) && !POSTGRES_RESERVED_IDENTIFIER_WORDS.has(identifier)) return identifier;
|
|
134
|
+
return quoteIdentifier(identifier);
|
|
135
|
+
}
|
|
136
|
+
function buildExpectedFormatType(column, codecHooks, storageTypes = {}) {
|
|
137
|
+
const resolved = resolveColumnTypeMetadata(column, storageTypes);
|
|
138
|
+
if (resolved.typeParams && resolved.codecId) {
|
|
139
|
+
const hooks = codecHooks.get(resolved.codecId);
|
|
140
|
+
if (hooks?.expandNativeType) return hooks.expandNativeType({
|
|
141
|
+
nativeType: resolved.nativeType,
|
|
142
|
+
codecId: resolved.codecId,
|
|
143
|
+
typeParams: resolved.typeParams
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (column.typeRef) return formatUserDefinedTypeName(resolved.nativeType);
|
|
147
|
+
return FORMAT_TYPE_DISPLAY.get(resolved.nativeType) ?? resolved.nativeType;
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { qualifyTableName as n, buildExpectedFormatType as t };
|
|
151
|
+
|
|
152
|
+
//# sourceMappingURL=planner-sql-checks-jqUUGyQR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-sql-checks-jqUUGyQR.mjs","names":[],"sources":["../src/core/migrations/planner-sql-checks.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport { postgresCreateNamespace } from '../postgres-schema';\nimport { 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, entries: { table: {} } }).qualifyTable(table);\n}\n\nconst FORMAT_TYPE_DISPLAY: ReadonlyMap<string, string> = new Map([\n ['int2', 'smallint'],\n ['int4', 'integer'],\n ['int8', 'bigint'],\n ['float4', 'real'],\n ['float8', 'double precision'],\n ['bool', 'boolean'],\n ['timestamp', 'timestamp without time zone'],\n ['timestamptz', 'timestamp with time zone'],\n ['time', 'time without time zone'],\n ['timetz', 'time with time zone'],\n]);\n\nconst UNQUOTED_POSTGRES_IDENTIFIER_PATTERN = /^[a-z_][a-z0-9_$]*$/;\n\nconst POSTGRES_RESERVED_IDENTIFIER_WORDS = new Set([\n 'all',\n 'analyse',\n 'analyze',\n 'and',\n 'any',\n 'array',\n 'as',\n 'asc',\n 'asymmetric',\n 'authorization',\n 'between',\n 'binary',\n 'both',\n 'case',\n 'cast',\n 'check',\n 'collate',\n 'column',\n 'constraint',\n 'create',\n 'current_catalog',\n 'current_date',\n 'current_role',\n 'current_time',\n 'current_timestamp',\n 'current_user',\n 'default',\n 'deferrable',\n 'desc',\n 'distinct',\n 'do',\n 'else',\n 'end',\n 'except',\n 'false',\n 'fetch',\n 'for',\n 'foreign',\n 'freeze',\n 'from',\n 'full',\n 'grant',\n 'group',\n 'having',\n 'ilike',\n 'in',\n 'initially',\n 'inner',\n 'intersect',\n 'into',\n 'is',\n 'isnull',\n 'join',\n 'lateral',\n 'leading',\n 'left',\n 'like',\n 'limit',\n 'localtime',\n 'localtimestamp',\n 'natural',\n 'not',\n 'notnull',\n 'null',\n 'offset',\n 'on',\n 'only',\n 'or',\n 'order',\n 'outer',\n 'overlaps',\n 'placing',\n 'primary',\n 'references',\n 'right',\n 'select',\n 'session_user',\n 'similar',\n 'some',\n 'symmetric',\n 'table',\n 'then',\n 'to',\n 'trailing',\n 'true',\n 'union',\n 'unique',\n 'user',\n 'using',\n 'variadic',\n 'verbose',\n 'when',\n 'where',\n 'window',\n 'with',\n]);\n\nfunction formatUserDefinedTypeName(identifier: string): string {\n if (\n UNQUOTED_POSTGRES_IDENTIFIER_PATTERN.test(identifier) &&\n !POSTGRES_RESERVED_IDENTIFIER_WORDS.has(identifier)\n ) {\n return identifier;\n }\n\n return quoteIdentifier(identifier);\n}\n\nexport function buildExpectedFormatType(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance> = {},\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n\n if (resolved.typeParams && resolved.codecId) {\n const hooks = codecHooks.get(resolved.codecId);\n if (hooks?.expandNativeType) {\n return hooks.expandNativeType({\n nativeType: resolved.nativeType,\n codecId: resolved.codecId,\n typeParams: resolved.typeParams,\n });\n }\n }\n\n if (column.typeRef) {\n return formatUserDefinedTypeName(resolved.nativeType);\n }\n\n return FORMAT_TYPE_DISPLAY.get(resolved.nativeType) ?? resolved.nativeType;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAgB,iBAAiB,QAAgB,OAAuB;CACtE,OAAO,wBAAwB;EAAE,IAAI;EAAQ,SAAS,EAAE,OAAO,CAAC,EAAE;CAAE,CAAC,CAAC,CAAC,aAAa,KAAK;AAC3F;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,eAAoD,CAAC,GAC7C;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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CodecControlHooks } from "@prisma-next/family-sql/control";
|
|
2
|
-
import {
|
|
2
|
+
import { StorageColumn, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
3
3
|
|
|
4
4
|
//#region src/core/migrations/planner-sql-checks.d.ts
|
|
5
5
|
/**
|
|
@@ -14,53 +14,7 @@ import { PostgresEnumStorageEntry, StorageColumn, StorageTypeInstance } from "@p
|
|
|
14
14
|
* site.
|
|
15
15
|
*/
|
|
16
16
|
declare function qualifyTableName(schema: string, table: string): string;
|
|
17
|
-
declare function
|
|
18
|
-
/**
|
|
19
|
-
* When `table` is omitted the check matches by name + schema across all tables.
|
|
20
|
-
* Pass `table` to scope the check to a single table (prevents false matches on
|
|
21
|
-
* identically-named constraints in different tables).
|
|
22
|
-
*/
|
|
23
|
-
declare function constraintExistsCheck({
|
|
24
|
-
constraintName,
|
|
25
|
-
schema,
|
|
26
|
-
table,
|
|
27
|
-
exists
|
|
28
|
-
}: {
|
|
29
|
-
constraintName: string;
|
|
30
|
-
schema: string;
|
|
31
|
-
table?: string;
|
|
32
|
-
exists?: boolean;
|
|
33
|
-
}): string;
|
|
34
|
-
declare function columnExistsCheck({
|
|
35
|
-
schema,
|
|
36
|
-
table,
|
|
37
|
-
column,
|
|
38
|
-
exists
|
|
39
|
-
}: {
|
|
40
|
-
schema: string;
|
|
41
|
-
table: string;
|
|
42
|
-
column: string;
|
|
43
|
-
exists?: boolean;
|
|
44
|
-
}): string;
|
|
45
|
-
declare function columnNullabilityCheck({
|
|
46
|
-
schema,
|
|
47
|
-
table,
|
|
48
|
-
column,
|
|
49
|
-
nullable
|
|
50
|
-
}: {
|
|
51
|
-
schema: string;
|
|
52
|
-
table: string;
|
|
53
|
-
column: string;
|
|
54
|
-
nullable: boolean;
|
|
55
|
-
}): string;
|
|
56
|
-
declare function tableIsEmptyCheck(qualifiedTableName: string): string;
|
|
57
|
-
declare function columnHasNoDefaultCheck(opts: {
|
|
58
|
-
schema: string;
|
|
59
|
-
table: string;
|
|
60
|
-
column: string;
|
|
61
|
-
}): string;
|
|
62
|
-
declare function buildExpectedFormatType(column: StorageColumn, codecHooks: Map<string, CodecControlHooks>, storageTypes?: Record<string, StorageTypeInstance | PostgresEnumStorageEntry>): string;
|
|
63
|
-
declare function tableHasPrimaryKeyCheck(schema: string, table: string, exists: boolean, constraintName?: string): string;
|
|
17
|
+
declare function buildExpectedFormatType(column: StorageColumn, codecHooks: Map<string, CodecControlHooks>, storageTypes?: Record<string, StorageTypeInstance>): string;
|
|
64
18
|
//#endregion
|
|
65
|
-
export { buildExpectedFormatType,
|
|
19
|
+
export { buildExpectedFormatType, qualifyTableName };
|
|
66
20
|
//# sourceMappingURL=planner-sql-checks.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner-sql-checks.d.mts","names":[],"sources":["../src/core/migrations/planner-sql-checks.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"planner-sql-checks.d.mts","names":[],"sources":["../src/core/migrations/planner-sql-checks.ts"],"mappings":";;;;;;AAiBA;;;;AAA8D;AAgI9D;;;;iBAhIgB,gBAAA,CAAiB,MAAA,UAAgB,KAAa;AAAA,iBAgI9C,uBAAA,CACd,MAAA,EAAQ,aAAA,EACR,UAAA,EAAY,GAAA,SAAY,iBAAA,GACxB,YAAA,GAAc,MAAA,SAAe,mBAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { buildExpectedFormatType,
|
|
1
|
+
import { n as qualifyTableName, t as buildExpectedFormatType } from "./planner-sql-checks-jqUUGyQR.mjs";
|
|
2
|
+
export { buildExpectedFormatType, qualifyTableName };
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
2
1
|
//#region src/core/migrations/planner-type-resolution.ts
|
|
3
2
|
function resolveColumnTypeMetadata(column, storageTypes) {
|
|
4
3
|
if (!column.typeRef) return column;
|
|
5
4
|
const referencedType = storageTypes[column.typeRef];
|
|
6
5
|
if (!referencedType) return column;
|
|
7
|
-
if (isPostgresEnumStorageEntry(referencedType)) return {
|
|
8
|
-
codecId: referencedType.codecId,
|
|
9
|
-
nativeType: referencedType.nativeType
|
|
10
|
-
};
|
|
11
6
|
return {
|
|
12
7
|
codecId: referencedType.codecId,
|
|
13
8
|
nativeType: referencedType.nativeType,
|
|
@@ -17,4 +12,4 @@ function resolveColumnTypeMetadata(column, storageTypes) {
|
|
|
17
12
|
//#endregion
|
|
18
13
|
export { resolveColumnTypeMetadata as t };
|
|
19
14
|
|
|
20
|
-
//# sourceMappingURL=planner-type-resolution-
|
|
15
|
+
//# sourceMappingURL=planner-type-resolution-Bt2f_q-F.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-type-resolution-Bt2f_q-F.mjs","names":[],"sources":["../src/core/migrations/planner-type-resolution.ts"],"sourcesContent":["import type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';\n\nexport type ResolvedColumnTypeMetadata = Pick<\n StorageColumn,\n 'nativeType' | 'codecId' | 'typeParams'\n>;\n\nexport function resolveColumnTypeMetadata(\n column: StorageColumn,\n storageTypes: Readonly<Record<string, StorageTypeInstance>>,\n): ResolvedColumnTypeMetadata {\n if (!column.typeRef) {\n return column;\n }\n\n const referencedType = storageTypes[column.typeRef];\n if (!referencedType) {\n return column;\n }\n\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n typeParams: referencedType.typeParams,\n };\n}\n"],"mappings":";AAOA,SAAgB,0BACd,QACA,cAC4B;CAC5B,IAAI,CAAC,OAAO,SACV,OAAO;CAGT,MAAM,iBAAiB,aAAa,OAAO;CAC3C,IAAI,CAAC,gBACH,OAAO;CAGT,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;EAC3B,YAAY,eAAe;CAC7B;AACF"}
|
package/dist/planner.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-
|
|
1
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-QqHa2C2l.mjs";
|
|
2
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
|
-
import {
|
|
5
|
+
import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
|
|
6
6
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
7
7
|
|
|
8
8
|
//#region src/core/migrations/planner.d.ts
|
|
9
|
-
declare function createPostgresMigrationPlanner(lowerer:
|
|
9
|
+
declare function createPostgresMigrationPlanner(lowerer: ExecuteRequestLowerer): PostgresMigrationPlanner;
|
|
10
10
|
/**
|
|
11
11
|
* Result of `PostgresMigrationPlanner.plan()`. A discriminated union whose
|
|
12
12
|
* success variant carries a `TypeScriptRenderablePostgresMigration` — a
|
|
@@ -37,7 +37,7 @@ type PostgresPlanResult = {
|
|
|
37
37
|
*/
|
|
38
38
|
declare class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {
|
|
39
39
|
#private;
|
|
40
|
-
constructor(lowerer?:
|
|
40
|
+
constructor(lowerer?: ExecuteRequestLowerer);
|
|
41
41
|
plan(options: {
|
|
42
42
|
readonly contract: unknown;
|
|
43
43
|
readonly schema: unknown;
|
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":";;;;;;;;iBAqDgB,8BAAA,CACd,OAAA,EAAS,qBAAA,GACR,wBAAwB;;AAF3B;;;;;;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;EAAA;cAGnC,OAAA,GAAU,qBAAA;EAItB,IAAA,CAAK,OAAA;IAAA,SACM,QAAA;IAAA,SACA,MAAA;IAAA,SACA,MAAA,EAAQ,wBAAA;IA6BR;;;;;;;;;;;;;;IAAA,SAdA,YAAA,EAAc,QAAA;IAAA,SACd,UAAA;IAAA,SACA,mBAAA,EAAqB,aAAA,CAAc,8BAAA;IADnC;;;;;IAAA,SAOA,OAAA;EAAA,IACP,kBAAA;EAIJ,cAAA,CACE,OAAA,EAAS,wBAAA,EACT,OAAA,WACC,iCAAA;EAAA,QAYK,OAAA;EAAA,QAmGA,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-Bs_baQax.mjs";
|
|
2
2
|
export { createPostgresMigrationPlanner };
|