@prisma-next/target-postgres 0.14.0-dev.49 → 0.14.0-dev.50
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/control-policy-DUFgy9jO.mjs +1103 -0
- package/dist/control-policy-DUFgy9jO.mjs.map +1 -0
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +19 -40
- package/dist/control.mjs.map +1 -1
- package/dist/default-normalizer.mjs +247 -1
- package/dist/default-normalizer.mjs.map +1 -0
- package/dist/diff-database-schema-BmSmWcaY.mjs +313 -0
- package/dist/diff-database-schema-BmSmWcaY.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +46 -0
- package/dist/diff-database-schema.d.mts.map +1 -0
- package/dist/diff-database-schema.mjs +2 -0
- package/dist/issue-planner.d.mts +34 -10
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +2 -2
- package/dist/migration.d.mts +2 -2
- package/dist/migration.mjs +2 -2
- package/dist/native-type-normalizer.mjs +37 -1
- package/dist/native-type-normalizer.mjs.map +1 -0
- package/dist/{op-factory-call-BuoGT5UI.mjs → op-factory-call-BKRnMgrB.mjs} +2 -2
- package/dist/op-factory-call-BKRnMgrB.mjs.map +1 -0
- package/dist/{op-factory-call-Caqus-Qg.d.mts → op-factory-call-Dt-Jx5JS.d.mts} +2 -2
- package/dist/{op-factory-call-Caqus-Qg.d.mts.map → op-factory-call-Dt-Jx5JS.d.mts.map} +1 -1
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/planner-BMBRPzsv.mjs +367 -0
- package/dist/planner-BMBRPzsv.mjs.map +1 -0
- package/dist/planner-ddl-builders-B8Nn6nHN.mjs.map +1 -1
- package/dist/planner-ddl-builders.d.mts +2 -2
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
- package/dist/planner-identity-values.d.mts +7 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +2 -2
- package/dist/{planner-produced-postgres-migration-CtJi4sgS.d.mts → planner-produced-postgres-migration-C0a7I1-e.d.mts} +2 -2
- package/dist/{planner-produced-postgres-migration-CtJi4sgS.d.mts.map → planner-produced-postgres-migration-C0a7I1-e.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-C2_H6Vvl.mjs → planner-produced-postgres-migration-Dp6IO_gj.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-C2_H6Vvl.mjs.map → planner-produced-postgres-migration-Dp6IO_gj.mjs.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-sql-checks-Cze3vMfe.mjs.map +1 -1
- package/dist/planner-sql-checks.d.mts +1 -1
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner.d.mts +27 -67
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +3 -2
- package/dist/{postgres-database-schema-node-os8ogEap.d.mts → postgres-database-schema-node-C9bTuMrd.d.mts} +14 -7
- package/dist/postgres-database-schema-node-C9bTuMrd.d.mts.map +1 -0
- package/dist/{postgres-migration-D0QIVE-p.mjs → postgres-migration-D0jwzYDT.mjs} +2 -2
- package/dist/{postgres-migration-D0QIVE-p.mjs.map → postgres-migration-D0jwzYDT.mjs.map} +1 -1
- package/dist/{postgres-migration-CfyKDT7b.d.mts → postgres-migration-DFaxuRyI.d.mts} +2 -2
- package/dist/{postgres-migration-CfyKDT7b.d.mts.map → postgres-migration-DFaxuRyI.d.mts.map} +1 -1
- package/dist/{postgres-table-schema-node-Clei_xel.mjs → postgres-table-schema-node-BgaSrxYN.mjs} +30 -29
- package/dist/postgres-table-schema-node-BgaSrxYN.mjs.map +1 -0
- package/dist/schema-node-kinds-ClScchhi.mjs +76 -0
- package/dist/schema-node-kinds-ClScchhi.mjs.map +1 -0
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +1 -1
- package/package.json +21 -20
- package/src/core/migrations/column-ddl-rendering.ts +117 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +25 -1
- package/src/core/migrations/control-policy.ts +68 -48
- package/src/core/migrations/diff-database-schema.ts +242 -153
- package/src/core/migrations/issue-planner.ts +621 -667
- package/src/core/migrations/operations/constraints.ts +1 -1
- package/src/core/migrations/planner-ddl-builders.ts +5 -2
- package/src/core/migrations/planner-identity-values.ts +1 -1
- package/src/core/migrations/planner-sql-checks.ts +1 -1
- package/src/core/migrations/planner-strategies.ts +248 -208
- package/src/core/migrations/planner.ts +180 -74
- package/src/core/migrations/runner.ts +1 -4
- package/src/core/migrations/verify-postgres-namespaces.ts +26 -15
- package/src/core/postgres-schema-verifier.ts +10 -7
- package/src/core/psl-infer/infer-psl-contract.ts +5 -10
- package/src/core/schema-ir/postgres-database-schema-node.ts +3 -6
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +8 -9
- package/src/core/schema-ir/postgres-policy-schema-node.ts +3 -6
- package/src/core/schema-ir/postgres-role-schema-node.ts +3 -6
- package/src/core/schema-ir/postgres-table-schema-node.ts +20 -9
- package/src/core/schema-ir/schema-node-kinds.ts +80 -2
- package/src/exports/control.ts +10 -43
- package/src/exports/diff-database-schema.ts +7 -0
- package/src/exports/issue-planner.ts +1 -1
- package/src/exports/op-factory-call.ts +1 -0
- package/src/exports/planner-identity-values.ts +4 -1
- package/src/exports/planner.ts +0 -1
- package/dist/default-normalizer-Dug8Fez9.mjs +0 -248
- package/dist/default-normalizer-Dug8Fez9.mjs.map +0 -1
- package/dist/issue-planner-Cbh-xTEr.mjs +0 -849
- package/dist/issue-planner-Cbh-xTEr.mjs.map +0 -1
- package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
- package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
- package/dist/op-factory-call-BuoGT5UI.mjs.map +0 -1
- package/dist/planner-Bq0Z2sVO.mjs +0 -641
- package/dist/planner-Bq0Z2sVO.mjs.map +0 -1
- package/dist/postgres-database-schema-node-os8ogEap.d.mts.map +0 -1
- package/dist/postgres-table-schema-node-Clei_xel.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-table-schema-node-BgaSrxYN.mjs","names":[],"sources":["../src/core/schema-ir/postgres-database-schema-node.ts","../src/core/schema-ir/postgres-namespace-schema-node.ts","../src/core/schema-ir/postgres-policy-schema-node.ts","../src/core/schema-ir/postgres-role-schema-node.ts","../src/core/schema-ir/postgres-table-schema-node.ts"],"sourcesContent":["import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { assertNode, SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';\nimport type { PostgresNamespaceSchemaNode } from './postgres-namespace-schema-node';\nimport type { PostgresRoleSchemaNode } from './postgres-role-schema-node';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresDatabaseSchemaNodeInput {\n readonly namespaces: Readonly<Record<string, PostgresNamespaceSchemaNode>>;\n readonly roles: readonly PostgresRoleSchemaNode[];\n readonly existingSchemas: readonly string[];\n readonly pgVersion: string;\n}\n\n/**\n * The root of the Postgres schema-diff tree: one node per database.\n *\n * `id` is the fixed sentinel `'database'` — the root has no siblings and\n * the value is never emitted into migration paths. `isEqualTo` is identity\n * (roots always share the `'database'` id). `children()` returns namespace\n * nodes only; roles are held on the root but not yielded (role diffing is a\n * later slice).\n */\nexport class PostgresDatabaseSchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.database;\n\n readonly namespaces: Readonly<Record<string, PostgresNamespaceSchemaNode>>;\n readonly roles: readonly PostgresRoleSchemaNode[];\n readonly existingSchemas: readonly string[];\n readonly pgVersion: string;\n\n constructor(input: PostgresDatabaseSchemaNodeInput) {\n super();\n this.namespaces = Object.freeze({ ...input.namespaces });\n this.roles = Object.freeze([...input.roles]);\n this.existingSchemas = Object.freeze([...input.existingSchemas]);\n this.pgVersion = input.pgVersion;\n freezeNode(this);\n }\n\n get id(): string {\n return 'database';\n }\n\n isEqualTo(other: DiffableNode): boolean {\n return this.id === other.id;\n }\n\n children(): readonly DiffableNode[] {\n return Object.values(this.namespaces);\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresDatabaseSchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.database;\n }\n\n static assert(node: SqlSchemaIRNode): asserts node is PostgresDatabaseSchemaNode {\n assertNode(node, 'PostgresDatabaseSchemaNode', PostgresDatabaseSchemaNode.is);\n }\n}\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { assertNode, SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';\nimport type { PostgresTableSchemaNode } from './postgres-table-schema-node';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresNamespaceSchemaNodeInput {\n readonly schemaName: string;\n readonly tables: Readonly<Record<string, PostgresTableSchemaNode>>;\n readonly nativeEnumTypeNames: readonly string[];\n}\n\n/**\n * One-per-Postgres-schema diff-tree node. Groups the tables belonging to a\n * single namespace. Per-schema consumers (the relational planner,\n * toSchemaView) read this node's `tables` field structurally via\n * `blindCast`/`SqlSchemaIRNode` — not through a static `SqlSchemaIR`\n * assignment — because `nodeKind` now carries this node's own literal\n * (`postgres-namespace`), distinct from `SqlSchemaIR`'s own (`sql-schema`).\n *\n * `id` is the schema name. `isEqualTo` is identity — two namespace nodes are\n * equal iff their ids (schema names) match. `children()` returns the table\n * nodes. Per-schema metadata is carried on the typed `nativeEnumTypeNames`\n * field, not an annotations bag.\n */\nexport class PostgresNamespaceSchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.namespace;\n\n readonly schemaName: string;\n readonly tables: Readonly<Record<string, PostgresTableSchemaNode>>;\n readonly nativeEnumTypeNames: readonly string[];\n\n constructor(input: PostgresNamespaceSchemaNodeInput) {\n super();\n this.schemaName = input.schemaName;\n this.tables = Object.freeze({ ...input.tables });\n this.nativeEnumTypeNames = Object.freeze([...input.nativeEnumTypeNames]);\n freezeNode(this);\n }\n\n get id(): string {\n return this.schemaName;\n }\n\n isEqualTo(other: DiffableNode): boolean {\n return this.id === other.id;\n }\n\n children(): readonly DiffableNode[] {\n return Object.values(this.tables);\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresNamespaceSchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.namespace;\n }\n\n static assert(node: SqlSchemaIRNode): asserts node is PostgresNamespaceSchemaNode {\n assertNode(node, 'PostgresNamespaceSchemaNode', PostgresNamespaceSchemaNode.is);\n }\n}\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { assertNode, SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { RlsPolicyOperation } from '../postgres-rls-policy';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresPolicySchemaNodeInput {\n /** Full wire name: `<prefix>_<8hex>`. */\n readonly name: string;\n /** User-supplied prefix (the part before the `_<8hex>` suffix). */\n readonly prefix: string;\n /** Name of the table this policy attaches to, by name within the same schema. */\n readonly tableName: string;\n /** Namespace coordinate (schema name). */\n readonly namespaceId: string;\n readonly operation: RlsPolicyOperation;\n /** Sorted role names rendered in `TO <roles>`. */\n readonly roles: readonly string[];\n /** USING predicate SQL string, if present. */\n readonly using?: string;\n /** WITH CHECK predicate SQL string, if present. */\n readonly withCheck?: string;\n /** `true` = `AS PERMISSIVE`, `false` = `AS RESTRICTIVE`. */\n readonly permissive: boolean;\n}\n\n/**\n * Schema-diff leaf node for a Postgres row-level security policy.\n *\n * This is a derived, transient node walked by the differ — it is NEVER serialized.\n * Built by project-from-contract and project-from-database from their respective\n * `PostgresRlsPolicy` contract entities / introspected rows.\n *\n * `id` is the wire name (`<prefix>_<sha256(body)[0..8]>`), so name-equality is\n * body-equality. `isEqualTo` compares names only — never byte-compare predicate\n * bodies, because Postgres reprints them.\n */\nexport class PostgresPolicySchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.policy;\n\n readonly name: string;\n readonly prefix: string;\n readonly tableName: string;\n readonly namespaceId: string;\n readonly operation: RlsPolicyOperation;\n readonly roles: readonly string[];\n declare readonly using?: string;\n declare readonly withCheck?: string;\n readonly permissive: boolean;\n\n constructor(input: PostgresPolicySchemaNodeInput) {\n super();\n this.name = input.name;\n this.prefix = input.prefix;\n this.tableName = input.tableName;\n this.namespaceId = input.namespaceId;\n this.operation = input.operation;\n this.roles = Object.freeze([...input.roles]);\n if (input.using !== undefined) this.using = input.using;\n if (input.withCheck !== undefined) this.withCheck = input.withCheck;\n this.permissive = input.permissive;\n freezeNode(this);\n }\n\n get id(): string {\n return this.name;\n }\n\n children(): readonly DiffableNode[] {\n return [];\n }\n\n isEqualTo(other: DiffableNode): boolean {\n const node = blindCast<\n SqlSchemaIRNode,\n 'every diff-tree node the differ pairs is a SqlSchemaIRNode; the guard rejects non-policy kinds'\n >(other);\n PostgresPolicySchemaNode.assert(node);\n return this.id === node.id;\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresPolicySchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.policy;\n }\n\n static assert(node: SqlSchemaIRNode | undefined): asserts node is PostgresPolicySchemaNode {\n assertNode(node, 'PostgresPolicySchemaNode', PostgresPolicySchemaNode.is);\n }\n}\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { assertNode, SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresRoleSchemaNodeInput {\n readonly name: string;\n /**\n * Namespace coordinate. Roles are cluster-scoped; callers pass\n * `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`.\n */\n readonly namespaceId: string;\n}\n\n/**\n * Schema-diff leaf node for a Postgres database role.\n *\n * This is a derived, transient node walked by the differ — it is NEVER serialized.\n * Built by project-from-contract and project-from-database from their respective\n * `PostgresRole` contract entities / introspected rows.\n *\n * Roles are cluster-scoped, so `id` is the role name alone. `isEqualTo` compares\n * names — name-equality is role-equality for cluster-scoped objects.\n */\nexport class PostgresRoleSchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.role;\n\n readonly name: string;\n readonly namespaceId: string;\n\n constructor(input: PostgresRoleSchemaNodeInput) {\n super();\n this.name = input.name;\n this.namespaceId = input.namespaceId;\n freezeNode(this);\n }\n\n get id(): string {\n return this.name;\n }\n\n children(): readonly DiffableNode[] {\n return [];\n }\n\n isEqualTo(other: DiffableNode): boolean {\n const node = blindCast<\n SqlSchemaIRNode,\n 'every diff-tree node the differ pairs is a SqlSchemaIRNode; the guard rejects non-role kinds'\n >(other);\n PostgresRoleSchemaNode.assert(node);\n return this.id === node.id;\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresRoleSchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.role;\n }\n\n static assert(node: SqlSchemaIRNode): asserts node is PostgresRoleSchemaNode {\n assertNode(node, 'PostgresRoleSchemaNode', PostgresRoleSchemaNode.is);\n }\n}\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport {\n assertNode,\n PrimaryKey,\n type SqlAnnotations,\n SqlCheckConstraintIR,\n SqlColumnIR,\n SqlForeignKeyIR,\n SqlIndexIR,\n SqlSchemaIRNode,\n type SqlTableIRInput,\n SqlUniqueIR,\n} from '@prisma-next/sql-schema-ir/types';\nimport type { PostgresPolicySchemaNode } from './postgres-policy-schema-node';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresTableSchemaNodeInput extends SqlTableIRInput {\n readonly policies?: readonly PostgresPolicySchemaNode[];\n}\n\n/**\n * Postgres-specific table schema-diff node. Carries all `SqlTableIR` fields\n * plus `policies`, and implements `DiffableNode` so the table instance is\n * directly the diff-tree node — no separate wrapper needed.\n *\n * Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because\n * `SqlTableIR` calls `freezeNode` in its own constructor, which prevents\n * subclass field initialisation.\n *\n * `id` is the table name. `isEqualTo` is identity — two table nodes are equal\n * iff their ids (names) match; the table's own structural drift is entirely\n * expressed by its children. `children()` returns every column, the primary\n * key (when present), every foreign key, unique, index, and check constraint,\n * plus the policy nodes — one flat list, so a drifted column and a drifted\n * policy are both reported by the same walk. Order is deterministic (object\n * key order for columns, array order for the rest) so two structurally equal\n * tables always produce the same child list.\n */\nexport class PostgresTableSchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.table;\n\n readonly name: string;\n readonly columns: Readonly<Record<string, SqlColumnIR>>;\n readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;\n readonly uniques: ReadonlyArray<SqlUniqueIR>;\n readonly indexes: ReadonlyArray<SqlIndexIR>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly annotations?: SqlAnnotations;\n declare readonly checks?: ReadonlyArray<SqlCheckConstraintIR>;\n readonly policies: readonly PostgresPolicySchemaNode[];\n\n constructor(input: PostgresTableSchemaNodeInput) {\n super();\n this.name = input.name;\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([key, col]) => [\n key,\n col instanceof SqlColumnIR ? col : new SqlColumnIR(col),\n ]),\n ),\n );\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk))),\n );\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u))),\n );\n this.indexes = Object.freeze(\n input.indexes.map((i) => (i instanceof SqlIndexIR ? i : new SqlIndexIR(i))),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n if (input.annotations !== undefined) this.annotations = input.annotations;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(\n input.checks.map((c) =>\n c instanceof SqlCheckConstraintIR ? c : new SqlCheckConstraintIR(c),\n ),\n );\n }\n this.policies = Object.freeze([...(input.policies ?? [])]);\n freezeNode(this);\n }\n\n get id(): string {\n return this.name;\n }\n\n isEqualTo(other: DiffableNode): boolean {\n return this.id === other.id;\n }\n\n children(): readonly DiffableNode[] {\n return [\n ...Object.values(this.columns),\n ...(this.primaryKey ? [this.primaryKey] : []),\n ...this.foreignKeys,\n ...this.uniques,\n ...this.indexes,\n ...(this.checks ?? []),\n ...this.policies,\n ];\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresTableSchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.table;\n }\n\n static assert(node: SqlSchemaIRNode): asserts node is PostgresTableSchemaNode {\n assertNode(node, 'PostgresTableSchemaNode', PostgresTableSchemaNode.is);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,IAAa,6BAAb,MAAa,mCAAmC,gBAAwC;CACtF,WAA6B,uBAAuB;CAEpD;CACA;CACA;CACA;CAEA,YAAY,OAAwC;EAClD,MAAM;EACN,KAAK,aAAa,OAAO,OAAO,EAAE,GAAG,MAAM,WAAW,CAAC;EACvD,KAAK,QAAQ,OAAO,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC;EAC3C,KAAK,kBAAkB,OAAO,OAAO,CAAC,GAAG,MAAM,eAAe,CAAC;EAC/D,KAAK,YAAY,MAAM;EACvB,WAAW,IAAI;CACjB;CAEA,IAAI,KAAa;EACf,OAAO;CACT;CAEA,UAAU,OAA8B;EACtC,OAAO,KAAK,OAAO,MAAM;CAC3B;CAEA,WAAoC;EACl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
1
|
+
import { relationalNodeEntityKind, relationalNodeGranularity } from "@prisma-next/sql-schema-ir/types";
|
|
2
|
+
//#region src/core/schema-ir/schema-node-kinds.ts
|
|
3
|
+
/**
|
|
4
|
+
* The `nodeKind` discriminant for each Postgres schema-diff node. Each node
|
|
5
|
+
* carries a unique value; the static `is`/`assert` guards compare against these
|
|
6
|
+
* identifiers rather than spelling the string inline or using `instanceof`. The
|
|
7
|
+
* field is an enumerable own property carried on every node instance.
|
|
8
|
+
*/
|
|
9
|
+
const PostgresSchemaNodeKind = {
|
|
10
|
+
database: "postgres-database",
|
|
11
|
+
namespace: "postgres-namespace",
|
|
12
|
+
table: "postgres-table",
|
|
13
|
+
policy: "postgres-policy",
|
|
14
|
+
role: "postgres-role"
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The one real map from a Postgres-specific `nodeKind` to the
|
|
18
|
+
* framework-neutral {@link DiffSubjectGranularity} its diff issues carry —
|
|
19
|
+
* resolution is by `nodeKind` equality against this map, never a
|
|
20
|
+
* `nodeKind`-suffix string match and never anything stamped on the node.
|
|
21
|
+
*/
|
|
22
|
+
const POSTGRES_NODE_GRANULARITY = {
|
|
23
|
+
[PostgresSchemaNodeKind.database]: "structural",
|
|
24
|
+
[PostgresSchemaNodeKind.namespace]: "namespace",
|
|
25
|
+
[PostgresSchemaNodeKind.table]: "entity",
|
|
26
|
+
[PostgresSchemaNodeKind.policy]: "structural",
|
|
27
|
+
[PostgresSchemaNodeKind.role]: "structural"
|
|
28
|
+
};
|
|
29
|
+
function isPostgresSchemaNodeKind(nodeKind) {
|
|
30
|
+
return Object.hasOwn(POSTGRES_NODE_GRANULARITY, nodeKind);
|
|
31
|
+
}
|
|
32
|
+
/** Looks up the subject granularity for a Postgres-specific `nodeKind`. */
|
|
33
|
+
function postgresNodeGranularity(nodeKind) {
|
|
34
|
+
return POSTGRES_NODE_GRANULARITY[nodeKind];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The subject granularity for any node kind that appears in a Postgres diff
|
|
38
|
+
* tree — the tree mixes Postgres-specific kinds (database/namespace/table/
|
|
39
|
+
* policy/role) with the relational leaf kinds (columns, constraints, indexes,
|
|
40
|
+
* …), so this dispatches to whichever family/target map owns the kind. Called
|
|
41
|
+
* on demand by consumers (the family verdict, the framework aggregate's
|
|
42
|
+
* unclaimed-elements sweep, via the {@link
|
|
43
|
+
* import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}
|
|
44
|
+
* capability) — never stamped onto the issue or the node.
|
|
45
|
+
*/
|
|
46
|
+
function postgresDiffSubjectGranularity(nodeKind) {
|
|
47
|
+
return isPostgresSchemaNodeKind(nodeKind) ? postgresNodeGranularity(nodeKind) : relationalNodeGranularity(nodeKind);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The one real map from a Postgres-specific `nodeKind` to its storage
|
|
51
|
+
* `entityKind` — the same vocabulary the contract storage's `entries`
|
|
52
|
+
* dictionary keys use. Only the whole-table kind has an entity of its own;
|
|
53
|
+
* database/namespace/policy/role nodes map to nothing here (a namespace is
|
|
54
|
+
* addressed by id, not by an `entries` kind; policies and roles are
|
|
55
|
+
* structural, never a sibling space's unclaimed entity).
|
|
56
|
+
*/
|
|
57
|
+
const POSTGRES_NODE_ENTITY_KIND = { [PostgresSchemaNodeKind.table]: "table" };
|
|
58
|
+
/** Looks up the storage entityKind for a Postgres-specific `nodeKind`. */
|
|
59
|
+
function postgresNodeEntityKind(nodeKind) {
|
|
60
|
+
return POSTGRES_NODE_ENTITY_KIND[nodeKind];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The storage `entityKind` for any node kind that appears in a Postgres diff
|
|
64
|
+
* tree — sibling of {@link postgresDiffSubjectGranularity}, dispatching the
|
|
65
|
+
* same way to whichever family/target map owns the kind. Called on demand by
|
|
66
|
+
* the framework aggregate's unclaimed-elements sweep via the {@link
|
|
67
|
+
* import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}
|
|
68
|
+
* capability — never stamped onto the issue or the node.
|
|
69
|
+
*/
|
|
70
|
+
function postgresDiffSubjectEntityKind(nodeKind) {
|
|
71
|
+
return isPostgresSchemaNodeKind(nodeKind) ? postgresNodeEntityKind(nodeKind) : relationalNodeEntityKind(nodeKind);
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { postgresDiffSubjectEntityKind as n, postgresDiffSubjectGranularity as r, PostgresSchemaNodeKind as t };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=schema-node-kinds-ClScchhi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-node-kinds-ClScchhi.mjs","names":[],"sources":["../src/core/schema-ir/schema-node-kinds.ts"],"sourcesContent":["import type {\n DiffableNode,\n DiffSubjectGranularity,\n} from '@prisma-next/framework-components/control';\nimport {\n relationalNodeEntityKind,\n relationalNodeGranularity,\n type SqlSchemaIRNode,\n} from '@prisma-next/sql-schema-ir/types';\n\n/**\n * A Postgres schema-diff-tree node: a `SqlSchemaIRNode` that also implements\n * `DiffableNode` (the five `Postgres*SchemaNode` classes). `SqlSchemaIRNode`\n * alone is not a `DiffableNode` — its relational subclasses (`SqlColumnIR`, …)\n * carry no `id`/`isEqualTo`/`children` — so this intersection is the honest node\n * type the differ produces and the planner consumes (`SchemaDiff<SqlSchemaDiffNode>`).\n */\nexport type SqlSchemaDiffNode = SqlSchemaIRNode & DiffableNode;\n\n/**\n * The `nodeKind` discriminant for each Postgres schema-diff node. Each node\n * carries a unique value; the static `is`/`assert` guards compare against these\n * identifiers rather than spelling the string inline or using `instanceof`. The\n * field is an enumerable own property carried on every node instance.\n */\nexport const PostgresSchemaNodeKind = {\n database: 'postgres-database',\n namespace: 'postgres-namespace',\n table: 'postgres-table',\n policy: 'postgres-policy',\n role: 'postgres-role',\n} as const;\n\nexport type PostgresSchemaNodeKind =\n (typeof PostgresSchemaNodeKind)[keyof typeof PostgresSchemaNodeKind];\n\n/**\n * The one real map from a Postgres-specific `nodeKind` to the\n * framework-neutral {@link DiffSubjectGranularity} its diff issues carry —\n * resolution is by `nodeKind` equality against this map, never a\n * `nodeKind`-suffix string match and never anything stamped on the node.\n */\nconst POSTGRES_NODE_GRANULARITY: Readonly<Record<PostgresSchemaNodeKind, DiffSubjectGranularity>> =\n {\n [PostgresSchemaNodeKind.database]: 'structural',\n [PostgresSchemaNodeKind.namespace]: 'namespace',\n [PostgresSchemaNodeKind.table]: 'entity',\n [PostgresSchemaNodeKind.policy]: 'structural',\n [PostgresSchemaNodeKind.role]: 'structural',\n };\n\nfunction isPostgresSchemaNodeKind(nodeKind: string): nodeKind is PostgresSchemaNodeKind {\n return Object.hasOwn(POSTGRES_NODE_GRANULARITY, nodeKind);\n}\n\n/** Looks up the subject granularity for a Postgres-specific `nodeKind`. */\nexport function postgresNodeGranularity(nodeKind: PostgresSchemaNodeKind): DiffSubjectGranularity {\n return POSTGRES_NODE_GRANULARITY[nodeKind];\n}\n\n/**\n * The subject granularity for any node kind that appears in a Postgres diff\n * tree — the tree mixes Postgres-specific kinds (database/namespace/table/\n * policy/role) with the relational leaf kinds (columns, constraints, indexes,\n * …), so this dispatches to whichever family/target map owns the kind. Called\n * on demand by consumers (the family verdict, the framework aggregate's\n * unclaimed-elements sweep, via the {@link\n * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}\n * capability) — never stamped onto the issue or the node.\n */\nexport function postgresDiffSubjectGranularity(nodeKind: string): DiffSubjectGranularity {\n return isPostgresSchemaNodeKind(nodeKind)\n ? postgresNodeGranularity(nodeKind)\n : relationalNodeGranularity(nodeKind);\n}\n\n/**\n * The one real map from a Postgres-specific `nodeKind` to its storage\n * `entityKind` — the same vocabulary the contract storage's `entries`\n * dictionary keys use. Only the whole-table kind has an entity of its own;\n * database/namespace/policy/role nodes map to nothing here (a namespace is\n * addressed by id, not by an `entries` kind; policies and roles are\n * structural, never a sibling space's unclaimed entity).\n */\nconst POSTGRES_NODE_ENTITY_KIND: Partial<Readonly<Record<PostgresSchemaNodeKind, string>>> = {\n [PostgresSchemaNodeKind.table]: 'table',\n};\n\n/** Looks up the storage entityKind for a Postgres-specific `nodeKind`. */\nexport function postgresNodeEntityKind(nodeKind: PostgresSchemaNodeKind): string | undefined {\n return POSTGRES_NODE_ENTITY_KIND[nodeKind];\n}\n\n/**\n * The storage `entityKind` for any node kind that appears in a Postgres diff\n * tree — sibling of {@link postgresDiffSubjectGranularity}, dispatching the\n * same way to whichever family/target map owns the kind. Called on demand by\n * the framework aggregate's unclaimed-elements sweep via the {@link\n * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}\n * capability — never stamped onto the issue or the node.\n */\nexport function postgresDiffSubjectEntityKind(nodeKind: string): string | undefined {\n return isPostgresSchemaNodeKind(nodeKind)\n ? postgresNodeEntityKind(nodeKind)\n : relationalNodeEntityKind(nodeKind);\n}\n"],"mappings":";;;;;;;;AAyBA,MAAa,yBAAyB;CACpC,UAAU;CACV,WAAW;CACX,OAAO;CACP,QAAQ;CACR,MAAM;AACR;;;;;;;AAWA,MAAM,4BACJ;EACG,uBAAuB,WAAW;EAClC,uBAAuB,YAAY;EACnC,uBAAuB,QAAQ;EAC/B,uBAAuB,SAAS;EAChC,uBAAuB,OAAO;AACjC;AAEF,SAAS,yBAAyB,UAAsD;CACtF,OAAO,OAAO,OAAO,2BAA2B,QAAQ;AAC1D;;AAGA,SAAgB,wBAAwB,UAA0D;CAChG,OAAO,0BAA0B;AACnC;;;;;;;;;;;AAYA,SAAgB,+BAA+B,UAA0C;CACvF,OAAO,yBAAyB,QAAQ,IACpC,wBAAwB,QAAQ,IAChC,0BAA0B,QAAQ;AACxC;;;;;;;;;AAUA,MAAM,4BAAuF,GAC1F,uBAAuB,QAAQ,QAClC;;AAGA,SAAgB,uBAAuB,UAAsD;CAC3F,OAAO,0BAA0B;AACnC;;;;;;;;;AAUA,SAAgB,8BAA8B,UAAsC;CAClF,OAAO,yBAAyB,QAAQ,IACpC,uBAAuB,QAAQ,IAC/B,yBAAyB,QAAQ;AACvC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as PostgresRlsPolicyInput, r as RlsPolicyOperation, t as PostgresRlsPolicy } from "./postgres-rls-policy--CSddvMR.mjs";
|
|
2
|
+
import { a as PostgresNamespaceSchemaNode, c as PostgresTableSchemaNodeInput, i as PostgresRoleSchemaNodeInput, l as PostgresPolicySchemaNode, n as PostgresDatabaseSchemaNodeInput, o as PostgresNamespaceSchemaNodeInput, r as PostgresRoleSchemaNode, s as PostgresTableSchemaNode, t as PostgresDatabaseSchemaNode, u as PostgresPolicySchemaNodeInput } from "./postgres-database-schema-node-C9bTuMrd.mjs";
|
|
2
3
|
import { t as PostgresColumnDefault } from "./types-BDKkx8MA.mjs";
|
|
3
4
|
import { a as postgresCreateNamespace, c as PostgresRoleInput, i as isPostgresSchema, n as PostgresSchema, r as PostgresUnboundSchema, s as PostgresRole, t as PostgresContract } from "./postgres-schema-DqnhQRvR.mjs";
|
|
4
|
-
import { a as PostgresNamespaceSchemaNode, c as PostgresTableSchemaNodeInput, i as PostgresRoleSchemaNodeInput, l as PostgresPolicySchemaNode, n as PostgresDatabaseSchemaNodeInput, o as PostgresNamespaceSchemaNodeInput, r as PostgresRoleSchemaNode, s as PostgresTableSchemaNode, t as PostgresDatabaseSchemaNode, u as PostgresPolicySchemaNodeInput } from "./postgres-database-schema-node-os8ogEap.mjs";
|
|
5
5
|
export { type PostgresColumnDefault, type PostgresContract, PostgresDatabaseSchemaNode, type PostgresDatabaseSchemaNodeInput, PostgresNamespaceSchemaNode, type PostgresNamespaceSchemaNodeInput, PostgresPolicySchemaNode, type PostgresPolicySchemaNodeInput, PostgresRlsPolicy, type PostgresRlsPolicyInput, PostgresRole, type PostgresRoleInput, PostgresRoleSchemaNode, type PostgresRoleSchemaNodeInput, PostgresSchema, PostgresTableSchemaNode, type PostgresTableSchemaNodeInput, PostgresUnboundSchema, type RlsPolicyOperation, isPostgresSchema, postgresCreateNamespace };
|
package/dist/types.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { f as PostgresRole, i as postgresCreateNamespace, n as PostgresUnboundSchema, p as PostgresRlsPolicy, r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-CajYAwny.mjs";
|
|
2
|
-
import { a as PostgresDatabaseSchemaNode, i as PostgresNamespaceSchemaNode, n as PostgresRoleSchemaNode, r as PostgresPolicySchemaNode, t as PostgresTableSchemaNode } from "./postgres-table-schema-node-
|
|
2
|
+
import { a as PostgresDatabaseSchemaNode, i as PostgresNamespaceSchemaNode, n as PostgresRoleSchemaNode, r as PostgresPolicySchemaNode, t as PostgresTableSchemaNode } from "./postgres-table-schema-node-BgaSrxYN.mjs";
|
|
3
3
|
export { PostgresDatabaseSchemaNode, PostgresNamespaceSchemaNode, PostgresPolicySchemaNode, PostgresRlsPolicy, PostgresRole, PostgresRoleSchemaNode, PostgresSchema, PostgresTableSchemaNode, PostgresUnboundSchema, isPostgresSchema, postgresCreateNamespace };
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.14.0-dev.
|
|
3
|
+
"version": "0.14.0-dev.50",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.14.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.14.0-dev.
|
|
11
|
-
"@prisma-next/errors": "0.14.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.14.0-dev.
|
|
13
|
-
"@prisma-next/framework-components": "0.14.0-dev.
|
|
14
|
-
"@prisma-next/migration-tools": "0.14.0-dev.
|
|
15
|
-
"@prisma-next/sql-contract": "0.14.0-dev.
|
|
16
|
-
"@prisma-next/sql-errors": "0.14.0-dev.
|
|
17
|
-
"@prisma-next/sql-operations": "0.14.0-dev.
|
|
18
|
-
"@prisma-next/sql-relational-core": "0.14.0-dev.
|
|
19
|
-
"@prisma-next/sql-schema-ir": "0.14.0-dev.
|
|
20
|
-
"@prisma-next/ts-render": "0.14.0-dev.
|
|
21
|
-
"@prisma-next/utils": "0.14.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.14.0-dev.50",
|
|
10
|
+
"@prisma-next/contract": "0.14.0-dev.50",
|
|
11
|
+
"@prisma-next/errors": "0.14.0-dev.50",
|
|
12
|
+
"@prisma-next/family-sql": "0.14.0-dev.50",
|
|
13
|
+
"@prisma-next/framework-components": "0.14.0-dev.50",
|
|
14
|
+
"@prisma-next/migration-tools": "0.14.0-dev.50",
|
|
15
|
+
"@prisma-next/sql-contract": "0.14.0-dev.50",
|
|
16
|
+
"@prisma-next/sql-errors": "0.14.0-dev.50",
|
|
17
|
+
"@prisma-next/sql-operations": "0.14.0-dev.50",
|
|
18
|
+
"@prisma-next/sql-relational-core": "0.14.0-dev.50",
|
|
19
|
+
"@prisma-next/sql-schema-ir": "0.14.0-dev.50",
|
|
20
|
+
"@prisma-next/ts-render": "0.14.0-dev.50",
|
|
21
|
+
"@prisma-next/utils": "0.14.0-dev.50",
|
|
22
22
|
"@standard-schema/spec": "^1.1.0",
|
|
23
23
|
"arktype": "^2.2.0",
|
|
24
24
|
"pathe": "^2.0.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/psl-parser": "0.14.0-dev.
|
|
28
|
-
"@prisma-next/psl-printer": "0.14.0-dev.
|
|
29
|
-
"@prisma-next/sql-contract-psl": "0.14.0-dev.
|
|
30
|
-
"@prisma-next/test-utils": "0.14.0-dev.
|
|
31
|
-
"@prisma-next/tsconfig": "0.14.0-dev.
|
|
32
|
-
"@prisma-next/tsdown": "0.14.0-dev.
|
|
27
|
+
"@prisma-next/psl-parser": "0.14.0-dev.50",
|
|
28
|
+
"@prisma-next/psl-printer": "0.14.0-dev.50",
|
|
29
|
+
"@prisma-next/sql-contract-psl": "0.14.0-dev.50",
|
|
30
|
+
"@prisma-next/test-utils": "0.14.0-dev.50",
|
|
31
|
+
"@prisma-next/tsconfig": "0.14.0-dev.50",
|
|
32
|
+
"@prisma-next/tsdown": "0.14.0-dev.50",
|
|
33
33
|
"tsdown": "0.22.1",
|
|
34
34
|
"typescript": "5.9.3",
|
|
35
35
|
"vitest": "4.1.8"
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"./data-transform": "./dist/data-transform.mjs",
|
|
57
57
|
"./ddl": "./dist/ddl.mjs",
|
|
58
58
|
"./default-normalizer": "./dist/default-normalizer.mjs",
|
|
59
|
+
"./diff-database-schema": "./dist/diff-database-schema.mjs",
|
|
59
60
|
"./errors": "./dist/errors.mjs",
|
|
60
61
|
"./issue-planner": "./dist/issue-planner.mjs",
|
|
61
62
|
"./migration": "./dist/migration.mjs",
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { CodecControlHooks } from '@prisma-next/family-sql/control';
|
|
2
|
+
import type { StorageColumn } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import type { DdlColumn } from '@prisma-next/sql-relational-core/ast';
|
|
4
|
+
import * as contractFree from '@prisma-next/sql-relational-core/contract-free';
|
|
5
|
+
import type { SqlColumnDefaultIR, SqlColumnIR } from '@prisma-next/sql-schema-ir/types';
|
|
6
|
+
import { blindCast } from '@prisma-next/utils/casts';
|
|
7
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
8
|
+
import { postgresDefaultToDdlColumnDefault } from './op-factory-call';
|
|
9
|
+
import { buildColumnDefaultSql, buildColumnTypeSql } from './planner-ddl-builders';
|
|
10
|
+
import { resolveIdentityValue } from './planner-identity-values';
|
|
11
|
+
import { buildExpectedFormatType } from './planner-sql-checks';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reconstructs the `StorageColumn`-shaped fields the DDL builder functions
|
|
15
|
+
* (`buildColumnTypeSql`, `buildExpectedFormatType`, `resolveIdentityValue`)
|
|
16
|
+
* expect, from a column node's own stamped codec identity (`codecRef` /
|
|
17
|
+
* `codecBaseNativeType` / `codecNamedType`, Decision 5) — never the
|
|
18
|
+
* contract. The builders were written against `StorageColumn` and are
|
|
19
|
+
* unchanged here; only the shape feeding them moves from the contract to
|
|
20
|
+
* the node. An empty `storageTypes` catalog is passed alongside: the
|
|
21
|
+
* node's fields are already resolved past any `typeRef` indirection, so no
|
|
22
|
+
* live lookup is needed, and passing a non-empty catalog would risk a
|
|
23
|
+
* false `typeRef` hit against an unrelated storage type.
|
|
24
|
+
*/
|
|
25
|
+
function columnLike(
|
|
26
|
+
column: SqlColumnIR,
|
|
27
|
+
): Pick<
|
|
28
|
+
StorageColumn,
|
|
29
|
+
'nativeType' | 'codecId' | 'nullable' | 'many' | 'typeParams' | 'typeRef' | 'default'
|
|
30
|
+
> {
|
|
31
|
+
if (column.codecRef === undefined || column.codecBaseNativeType === undefined) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`columnLike: expected column "${column.name}" carries no codec identity — the expected tree must be derived via contractToSchemaIR for planning`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
nativeType: column.codecBaseNativeType,
|
|
38
|
+
codecId: column.codecRef.codecId,
|
|
39
|
+
nullable: column.nullable,
|
|
40
|
+
// `column.many` is unset on contract-derived columns (array-ness rides
|
|
41
|
+
// on the `nativeType` `[]` suffix there instead) — `codecRef.many`
|
|
42
|
+
// carries it. Hand-built/introspected columns set `column.many` directly.
|
|
43
|
+
...ifDefined('many', column.many ?? column.codecRef.many),
|
|
44
|
+
...ifDefined(
|
|
45
|
+
'typeParams',
|
|
46
|
+
column.codecRef.typeParams !== undefined
|
|
47
|
+
? blindCast<
|
|
48
|
+
Record<string, unknown>,
|
|
49
|
+
'CodecRef.typeParams is JsonValue-shaped; the DDL builders only ever read it as the Record the contract column originally carried'
|
|
50
|
+
>(column.codecRef.typeParams)
|
|
51
|
+
: undefined,
|
|
52
|
+
),
|
|
53
|
+
...(column.codecNamedType ? { typeRef: '<resolved>' } : {}),
|
|
54
|
+
...ifDefined('default', column.resolvedDefault),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Builds the `CREATE TABLE` / `ADD COLUMN` DDL column for an expected column
|
|
60
|
+
* node, resolving type rendering from the node's codec identity against the
|
|
61
|
+
* codec hooks the caller holds — the same builder the pre-`plan(start, end)`
|
|
62
|
+
* op-path called, so the output is byte-identical.
|
|
63
|
+
*/
|
|
64
|
+
export function renderColumnDdl(
|
|
65
|
+
name: string,
|
|
66
|
+
column: SqlColumnIR,
|
|
67
|
+
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
68
|
+
): DdlColumn {
|
|
69
|
+
const like = columnLike(column);
|
|
70
|
+
const typeSql = buildColumnTypeSql(like, codecHooks, {});
|
|
71
|
+
const ddlDefault = postgresDefaultToDdlColumnDefault(like.default);
|
|
72
|
+
return contractFree.col(name, typeSql, {
|
|
73
|
+
...(!column.nullable ? { notNull: true } : {}),
|
|
74
|
+
...ifDefined('default', ddlDefault),
|
|
75
|
+
...ifDefined('codecRef', column.codecRef),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Builds the `ALTER COLUMN … TYPE` operands for an expected column node.
|
|
81
|
+
*/
|
|
82
|
+
export function renderColumnAlterType(
|
|
83
|
+
column: SqlColumnIR,
|
|
84
|
+
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
85
|
+
): { readonly qualifiedTargetType: string; readonly formatTypeExpected: string } {
|
|
86
|
+
const like = columnLike(column);
|
|
87
|
+
return {
|
|
88
|
+
qualifiedTargetType: buildColumnTypeSql(like, codecHooks, {}, false),
|
|
89
|
+
formatTypeExpected: buildExpectedFormatType(like, codecHooks, {}),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Resolves the identity value (monoid neutral element) SQL literal used as
|
|
95
|
+
* the temporary default when adding a NOT-NULL column with no contract
|
|
96
|
+
* default (`notNullAddColumnCallStrategy`'s shared-temp-default backfill).
|
|
97
|
+
* `null` when the column's type has no built-in/codec-provided identity
|
|
98
|
+
* value.
|
|
99
|
+
*/
|
|
100
|
+
export function resolveColumnTemporaryDefault(
|
|
101
|
+
column: SqlColumnIR,
|
|
102
|
+
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
103
|
+
): string | null {
|
|
104
|
+
return resolveIdentityValue(columnLike(column), codecHooks, {});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The column's `SET DEFAULT` clause SQL, resolved from a column-default
|
|
109
|
+
* diff node. `''` when the node carries no resolved default.
|
|
110
|
+
*/
|
|
111
|
+
export function renderColumnDefaultSql(defaultNode: SqlColumnDefaultIR): string {
|
|
112
|
+
if (defaultNode.resolved === undefined) return '';
|
|
113
|
+
return buildColumnDefaultSql(defaultNode.resolved, {
|
|
114
|
+
nativeType: defaultNode.nativeTypeContext ?? '',
|
|
115
|
+
...ifDefined('many', defaultNode.many),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ContractToSchemaIROptions } from '@prisma-next/family-sql/control';
|
|
2
2
|
import { contractNamespaceToSchemaIR } from '@prisma-next/family-sql/control';
|
|
3
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
4
|
+
import { SqlForeignKeyIR } from '@prisma-next/sql-schema-ir/types';
|
|
3
5
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
4
6
|
import type { PostgresRlsPolicy } from '../postgres-rls-policy';
|
|
5
7
|
import type { PostgresContract } from '../postgres-schema';
|
|
@@ -83,10 +85,32 @@ export function contractToPostgresDatabaseSchemaNode(
|
|
|
83
85
|
for (const tableName of Object.keys(ns.table)) {
|
|
84
86
|
const sqlTable = sqlTables[tableName];
|
|
85
87
|
if (sqlTable === undefined) continue;
|
|
88
|
+
// The family conversion stamps `referencedSchema` with the FK target's
|
|
89
|
+
// namespace id verbatim, which can be the unbound sentinel. Resolve it
|
|
90
|
+
// to the real live DDL schema here — introspected FKs already carry the
|
|
91
|
+
// live schema, so this is what lets an expected FK pair (by diff-node
|
|
92
|
+
// id) with its introspected counterpart.
|
|
93
|
+
const foreignKeys = sqlTable.foreignKeys.map(
|
|
94
|
+
(fk) =>
|
|
95
|
+
new SqlForeignKeyIR({
|
|
96
|
+
columns: fk.columns,
|
|
97
|
+
referencedTable: fk.referencedTable,
|
|
98
|
+
referencedColumns: fk.referencedColumns,
|
|
99
|
+
...ifDefined('referencedSchema', fk.referencedSchema),
|
|
100
|
+
...ifDefined('name', fk.name),
|
|
101
|
+
...ifDefined('onDelete', fk.onDelete),
|
|
102
|
+
...ifDefined('onUpdate', fk.onUpdate),
|
|
103
|
+
...ifDefined('annotations', fk.annotations),
|
|
104
|
+
resolvedReferencedNamespace: resolveDdlSchemaForNamespaceStorage(
|
|
105
|
+
contract.storage,
|
|
106
|
+
fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,
|
|
107
|
+
),
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
86
110
|
tables[tableName] = new PostgresTableSchemaNode({
|
|
87
111
|
name: sqlTable.name,
|
|
88
112
|
columns: sqlTable.columns,
|
|
89
|
-
foreignKeys
|
|
113
|
+
foreignKeys,
|
|
90
114
|
uniques: sqlTable.uniques,
|
|
91
115
|
indexes: sqlTable.indexes,
|
|
92
116
|
...ifDefined('primaryKey', sqlTable.primaryKey),
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Contract } from '@prisma-next/contract/types';
|
|
2
2
|
import type { ControlPolicySubject } from '@prisma-next/family-sql/control';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SchemaDiffIssue } from '@prisma-next/framework-components/control';
|
|
4
4
|
import { entityAt, UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
5
5
|
import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
|
|
6
|
+
import { blindCast } from '@prisma-next/utils/casts';
|
|
6
7
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
7
8
|
import { isPostgresSchema } from '../postgres-schema';
|
|
9
|
+
import type { PostgresNamespaceSchemaNode } from '../schema-ir/postgres-namespace-schema-node';
|
|
10
|
+
import type { SqlSchemaDiffNode } from '../schema-ir/schema-node-kinds';
|
|
11
|
+
import { PostgresSchemaNodeKind } from '../schema-ir/schema-node-kinds';
|
|
12
|
+
import { issueColumnName } from './issue-planner';
|
|
8
13
|
import type { PostgresOpFactoryCall } from './op-factory-call';
|
|
9
14
|
|
|
10
15
|
/**
|
|
@@ -56,7 +61,7 @@ function resolveNamespaceIdForTable(
|
|
|
56
61
|
return UNBOUND_NAMESPACE_ID;
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
function resolveNamespaceIdForDdlSchema(
|
|
64
|
+
export function resolveNamespaceIdForDdlSchema(
|
|
60
65
|
contract: Contract<SqlStorage>,
|
|
61
66
|
ddlSchemaName: string,
|
|
62
67
|
): string {
|
|
@@ -143,65 +148,80 @@ export function resolvePostgresCallControlPolicySubject(
|
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
/**
|
|
146
|
-
*
|
|
147
|
-
* object — the same
|
|
148
|
-
* Used by {@link
|
|
149
|
-
* a `tolerated` subject permits the issue to flow into the planner
|
|
151
|
+
* Node kinds that describe the absence of a whole, top-level Postgres
|
|
152
|
+
* object — the same objects `createsNewTopLevelObject` recognises for calls.
|
|
153
|
+
* Used by {@link resolvePostgresNodeIssueCreationFactoryName} to decide
|
|
154
|
+
* whether a `tolerated` subject permits the issue to flow into the planner
|
|
150
155
|
* (create-if-absent) and to seed the suppressed-subject warning's
|
|
151
|
-
* `factoryName` when the planner is skipped.
|
|
156
|
+
* `factoryName` when the planner is skipped. RLS policy creation is not
|
|
157
|
+
* listed here — policy issues never reach this issue-based partition (they
|
|
158
|
+
* are routed to `planPostgresSchemaDiff` and gated via the call-based
|
|
159
|
+
* {@link resolvePostgresCallControlPolicySubject} instead).
|
|
152
160
|
*/
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
missing_rls_policy: 'createRlsPolicy',
|
|
161
|
+
const POSTGRES_NODE_CREATION_FACTORY: Readonly<Record<string, string>> = Object.freeze({
|
|
162
|
+
[PostgresSchemaNodeKind.namespace]: 'createSchema',
|
|
163
|
+
[PostgresSchemaNodeKind.table]: 'createTable',
|
|
157
164
|
});
|
|
158
165
|
|
|
159
|
-
export function
|
|
160
|
-
|
|
166
|
+
export function resolvePostgresNodeIssueCreationFactoryName(
|
|
167
|
+
issue: SchemaDiffIssue<SqlSchemaDiffNode>,
|
|
168
|
+
): string | undefined {
|
|
169
|
+
if (issue.reason !== 'not-found') return undefined;
|
|
170
|
+
const node = issue.expected ?? issue.actual;
|
|
171
|
+
if (node === undefined) return undefined;
|
|
172
|
+
return POSTGRES_NODE_CREATION_FACTORY[node.nodeKind];
|
|
161
173
|
}
|
|
162
174
|
|
|
163
175
|
/**
|
|
164
|
-
* Resolve the control-policy subject coordinate for a single
|
|
165
|
-
* {@link
|
|
166
|
-
* performs for a generated DDL
|
|
167
|
-
*
|
|
168
|
-
* runs. `createsNewObject` is
|
|
169
|
-
*
|
|
170
|
-
* touches an existing object.
|
|
176
|
+
* Resolve the control-policy subject coordinate for a single node-typed
|
|
177
|
+
* {@link SchemaDiffIssue}. Mirrors the resolution
|
|
178
|
+
* `resolvePostgresCallControlPolicySubject` performs for a generated DDL
|
|
179
|
+
* call, but works *off the issue* — so the planner can partition issues by
|
|
180
|
+
* effective policy before the diff engine runs. `createsNewObject` is
|
|
181
|
+
* derived from the node kind + reason: a `not-found` schema/table describes
|
|
182
|
+
* a brand-new top-level object; everything else touches an existing object.
|
|
171
183
|
*
|
|
172
|
-
*
|
|
173
|
-
* isn't
|
|
174
|
-
* back to {@link UNBOUND_NAMESPACE_ID}
|
|
175
|
-
*
|
|
184
|
+
* A `not-expected` table carries no contract namespace coordinate (the live
|
|
185
|
+
* table isn't claimed by any contract namespace), so the subject's
|
|
186
|
+
* `namespaceId` falls back to {@link UNBOUND_NAMESPACE_ID} via
|
|
187
|
+
* `resolveNamespaceIdForTable`'s own fallback — the call-side resolver does
|
|
188
|
+
* the same for the `DropTableCall` it produces.
|
|
176
189
|
*/
|
|
177
|
-
export function
|
|
178
|
-
issue:
|
|
190
|
+
export function resolvePostgresNodeIssueControlPolicySubject(
|
|
191
|
+
issue: SchemaDiffIssue<SqlSchemaDiffNode>,
|
|
179
192
|
contract: Contract<SqlStorage>,
|
|
180
193
|
): ControlPolicySubject | undefined {
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
'namespaceId' in issue && issue.namespaceId
|
|
190
|
-
? issue.namespaceId
|
|
191
|
-
: resolveNamespaceIdForTable(contract, issue.table, undefined);
|
|
192
|
-
const table = entityAt<StorageTable>(contract.storage, {
|
|
193
|
-
namespaceId,
|
|
194
|
-
entityKind: 'table',
|
|
195
|
-
entityName: issue.table,
|
|
196
|
-
});
|
|
194
|
+
const node = issue.expected ?? issue.actual;
|
|
195
|
+
if (node === undefined) return undefined;
|
|
196
|
+
|
|
197
|
+
if (node.nodeKind === PostgresSchemaNodeKind.namespace) {
|
|
198
|
+
const namespaceNode = blindCast<
|
|
199
|
+
PostgresNamespaceSchemaNode,
|
|
200
|
+
'a postgres-namespace diff node is always a PostgresNamespaceSchemaNode'
|
|
201
|
+
>(node);
|
|
197
202
|
return {
|
|
198
|
-
namespaceId,
|
|
199
|
-
|
|
200
|
-
table: issue.table,
|
|
201
|
-
...ifDefined('column', 'column' in issue ? issue.column : undefined),
|
|
202
|
-
createsNewObject,
|
|
203
|
+
namespaceId: resolveNamespaceIdForDdlSchema(contract, namespaceNode.schemaName),
|
|
204
|
+
createsNewObject: issue.reason === 'not-found',
|
|
203
205
|
};
|
|
204
206
|
}
|
|
205
207
|
|
|
206
|
-
|
|
208
|
+
const tableName = issue.path[2];
|
|
209
|
+
if (tableName === undefined) return undefined;
|
|
210
|
+
const ddlSchemaName = issue.path[1];
|
|
211
|
+
const namespaceId = resolveNamespaceIdForTable(contract, tableName, ddlSchemaName);
|
|
212
|
+
const table = entityAt<StorageTable>(contract.storage, {
|
|
213
|
+
namespaceId,
|
|
214
|
+
entityKind: 'table',
|
|
215
|
+
entityName: tableName,
|
|
216
|
+
});
|
|
217
|
+
const createsNewObject =
|
|
218
|
+
node.nodeKind === PostgresSchemaNodeKind.table && issue.reason === 'not-found';
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
namespaceId,
|
|
222
|
+
...ifDefined('explicitNodeControlPolicy', table?.control),
|
|
223
|
+
table: tableName,
|
|
224
|
+
...ifDefined('column', issueColumnName(issue)),
|
|
225
|
+
createsNewObject,
|
|
226
|
+
};
|
|
207
227
|
}
|