@prisma-next/target-postgres 0.16.0-dev.25 → 0.16.0-dev.26
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/{authoring-BCzcFRay.mjs → authoring-DnO1B0N9.mjs} +7 -14
- package/dist/authoring-DnO1B0N9.mjs.map +1 -0
- package/dist/canonicalize-C7zKHw8m.mjs +59 -0
- package/dist/canonicalize-C7zKHw8m.mjs.map +1 -0
- package/dist/{canonicalize-D1F4vUnP.d.mts → canonicalize-CQlxSR4D.d.mts} +3 -18
- package/dist/canonicalize-CQlxSR4D.d.mts.map +1 -0
- package/dist/contract-free.d.mts +1 -1
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +1 -1
- package/dist/{control-policy-B-_34g05.mjs → control-policy-DEwdS3oK.mjs} +23 -24
- package/dist/control-policy-DEwdS3oK.mjs.map +1 -0
- package/dist/control.mjs +10 -7
- package/dist/control.mjs.map +1 -1
- package/dist/{ddl-DYEob9xQ.mjs → ddl-BQC6u-L9.mjs} +27 -3
- package/dist/{ddl-DYEob9xQ.mjs.map → ddl-BQC6u-L9.mjs.map} +1 -1
- package/dist/ddl.d.mts +3 -3
- package/dist/ddl.mjs +2 -2
- package/dist/{descriptor-meta-D_0ZKcj-.mjs → descriptor-meta-DGlJurgA.mjs} +2 -2
- package/dist/{descriptor-meta-D_0ZKcj-.mjs.map → descriptor-meta-DGlJurgA.mjs.map} +1 -1
- package/dist/{diff-database-schema-C9H09OD3.mjs → diff-database-schema-qRPwuYBH.mjs} +22 -12
- package/dist/diff-database-schema-qRPwuYBH.mjs.map +1 -0
- package/dist/diff-database-schema.mjs +1 -1
- package/dist/errors.d.mts +4 -2
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +2 -2
- package/dist/issue-planner.d.mts +2 -2
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +2 -2
- package/dist/migration.mjs +2 -2
- package/dist/{nodes-DJC5B8Id.mjs → nodes-04EILM-z.mjs} +65 -2
- package/dist/nodes-04EILM-z.mjs.map +1 -0
- package/dist/{nodes-CQzM2hR0.d.mts → nodes-DjCsN-uv.d.mts} +69 -4
- package/dist/nodes-DjCsN-uv.d.mts.map +1 -0
- package/dist/{op-factory-call-DT7kdjVP.d.mts → op-factory-call-0TB5XNij.d.mts} +46 -8
- package/dist/op-factory-call-0TB5XNij.d.mts.map +1 -0
- package/dist/{op-factory-call-BVYLIojV.mjs → op-factory-call-CIaPDDUc.mjs} +104 -27
- package/dist/op-factory-call-CIaPDDUc.mjs.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.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-4sj5cJCY.mjs → planner-BhnkIJX-.mjs} +117 -9
- package/dist/planner-BhnkIJX-.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-CcQPDWmX.mjs → planner-produced-postgres-migration-BE3EJIRK.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-CcQPDWmX.mjs.map → planner-produced-postgres-migration-BE3EJIRK.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-8QP8eMph.d.mts → planner-produced-postgres-migration-CRAHl6ak.d.mts} +2 -2
- package/dist/planner-produced-postgres-migration-CRAHl6ak.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-schema-lookup-CiVaAQP-.mjs → planner-schema-lookup-D3Y_OL-C.mjs} +3 -3
- package/dist/planner-schema-lookup-D3Y_OL-C.mjs.map +1 -0
- package/dist/planner-schema-lookup.mjs +1 -1
- package/dist/planner.d.mts +21 -1
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-view-B8yXVWYe.mjs → postgres-contract-view-BeIEyZfD.mjs} +2 -2
- package/dist/{postgres-contract-view-B8yXVWYe.mjs.map → postgres-contract-view-BeIEyZfD.mjs.map} +1 -1
- package/dist/{postgres-migration-GIOABsAa.mjs → postgres-migration--BzvpA92.mjs} +7 -4
- package/dist/postgres-migration--BzvpA92.mjs.map +1 -0
- package/dist/{postgres-migration-DLIvzHjX.d.mts → postgres-migration-BXelnqHO.d.mts} +15 -10
- package/dist/postgres-migration-BXelnqHO.d.mts.map +1 -0
- package/dist/rls-canonicalize.d.mts +2 -26
- package/dist/rls-canonicalize.mjs +2 -2
- package/dist/runtime.mjs +1 -1
- package/package.json +20 -20
- package/src/contract-free/ddl.ts +47 -0
- package/src/core/authoring.ts +10 -22
- package/src/core/ddl/nodes.ts +104 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +24 -13
- package/src/core/migrations/issue-planner.ts +40 -13
- package/src/core/migrations/op-factory-call.ts +100 -9
- package/src/core/migrations/operations/indexes.ts +80 -35
- package/src/core/migrations/planner-schema-lookup.ts +2 -2
- package/src/core/migrations/planner.ts +155 -5
- package/src/core/migrations/postgres-migration.ts +26 -8
- package/src/core/psl-infer/infer-psl-contract.ts +8 -1
- package/src/core/rls/canonicalize.ts +4 -21
- package/src/exports/ddl.ts +4 -0
- package/src/exports/errors.ts +1 -1
- package/src/exports/op-factory-call.ts +1 -0
- package/src/exports/rls-canonicalize.ts +0 -6
- package/dist/authoring-BCzcFRay.mjs.map +0 -1
- package/dist/canonicalize-D1F4vUnP.d.mts.map +0 -1
- package/dist/control-policy-B-_34g05.mjs.map +0 -1
- package/dist/diff-database-schema-C9H09OD3.mjs.map +0 -1
- package/dist/nodes-CQzM2hR0.d.mts.map +0 -1
- package/dist/nodes-DJC5B8Id.mjs.map +0 -1
- package/dist/op-factory-call-BVYLIojV.mjs.map +0 -1
- package/dist/op-factory-call-DT7kdjVP.d.mts.map +0 -1
- package/dist/planner-4sj5cJCY.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-8QP8eMph.d.mts.map +0 -1
- package/dist/planner-schema-lookup-CiVaAQP-.mjs.map +0 -1
- package/dist/postgres-migration-DLIvzHjX.d.mts.map +0 -1
- package/dist/postgres-migration-GIOABsAa.mjs.map +0 -1
- package/dist/rls-canonicalize.d.mts.map +0 -1
- package/dist/wire-name-DbQ9-2RC.mjs +0 -104
- package/dist/wire-name-DbQ9-2RC.mjs.map +0 -1
- package/src/core/rls/wire-name.ts +0 -33
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-migration--BzvpA92.mjs","names":["SqlMigration","#endView","#startView"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport { MigrationContractViews } from '@prisma-next/migration-tools/migration';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { PostgresContractView } from '../postgres-contract-view';\nimport { PostgresRlsPolicy, type PostgresRlsPolicyInput } from '../postgres-rls-policy';\nimport {\n AddCheckConstraintCall,\n AddColumnCall,\n AddForeignKeyCall,\n AddNativeEnumValueCall,\n AddPrimaryKeyCall,\n AddUniqueCall,\n AlterColumnTypeCall,\n type AlterColumnTypeOptions,\n CreateIndexCall,\n CreateNativeEnumTypeCall,\n CreatePostgresRlsPolicyCall,\n CreateSchemaCall,\n CreateTableCall,\n DisableRowLevelSecurityCall,\n DropCheckConstraintCall,\n DropColumnCall,\n DropConstraintCall,\n DropDefaultCall,\n DropIndexCall,\n DropNativeEnumTypeCall,\n DropNotNullCall,\n DropPostgresRlsPolicyCall,\n DropTableCall,\n EnableRowLevelSecurityCall,\n RenameIndexCall,\n RenamePostgresRlsPolicyCall,\n SetDefaultCall,\n SetNotNullCall,\n} from './op-factory-call';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport { installExtension } from './operations/dependencies';\nimport type { CreateIndexExtras } from './operations/indexes';\nimport type { ForeignKeySpec } from './operations/shared';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n *\n * Every method requires an explicit `schema`. Postgres migrations name their\n * schema deliberately — there is no default and no `search_path`-relative\n * option. A migration that left the schema unspecified would resolve against\n * whatever `search_path` the connection happened to carry, and that ambiguity\n * is an antipattern in a migration. (The unbound/unspecified namespace concept\n * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)\n */\nexport abstract class PostgresMigration<\n Start extends Contract<SqlStorage> = Contract<SqlStorage>,\n End extends Contract<SqlStorage> = Contract<SqlStorage>,\n> extends SqlMigration<PostgresPlanTargetDetails, 'postgres', Start, End> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `controlAdapterFor`\n * throws a MIGRATION.POSTGRES_CONTROL_STACK_MISSING in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n #endView = new MigrationContractViews<PostgresContractView<End>>(\n this,\n 'PostgresMigration',\n (json) => PostgresContractView.fromJson<End>(json),\n );\n #startView = new MigrationContractViews<PostgresContractView<Start>>(\n this,\n 'PostgresMigration',\n (json) => PostgresContractView.fromJson<Start>(json),\n );\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Returns the materialized control adapter, or throws a MIGRATION.POSTGRES_CONTROL_STACK_MISSING naming\n * `operation` when the migration was constructed without a `ControlStack`.\n * Single home for the null-check that every DDL/DML method shares.\n */\n private controlAdapterFor(operation: string): SqlControlAdapter<'postgres'> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing(operation);\n }\n return this.controlAdapter;\n }\n\n /**\n * The typed, schema-qualified Postgres view over this migration's end-state\n * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws\n * if no `endContractJson` was provided.\n */\n get endContract(): PostgresContractView<End> {\n return this.#endView.endContract;\n }\n\n /**\n * The typed Postgres view over this migration's start-state contract, or\n * `null` for a baseline migration (no `startContractJson`).\n */\n get startContract(): PostgresContractView<Start> | null {\n return this.#startView.startContract;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return dataTransform(contract, name, options, this.controlAdapterFor('dataTransform'));\n }\n\n /**\n * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createTable(options: {\n readonly schema: string;\n readonly table: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n readonly constraints?: readonly DdlTableConstraint[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new CreateTableCall(\n options.schema,\n options.table,\n options.columns,\n options.constraints,\n ).toOp(this.controlAdapterFor('createTable'));\n }\n\n /**\n * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createSchema(options: {\n readonly schema: string;\n readonly ifNotExists?: boolean;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new CreateSchemaCall(options.schema).toOp(this.controlAdapterFor('createSchema'));\n }\n\n /**\n * Emit a `CREATE TYPE ... AS ENUM (...)` migration operation for a managed\n * native enum. Builds a typed DDL node and lowers it through the stored\n * control adapter (members render in declaration order). Throws if no adapter\n * is present.\n */\n protected createNativeEnumType(options: {\n readonly schema: string;\n readonly typeName: string;\n readonly members: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new CreateNativeEnumTypeCall(options.schema, options.typeName, options.members).toOp(\n this.controlAdapterFor('createNativeEnumType'),\n );\n }\n\n /**\n * Emit a `DROP TYPE` migration operation for a managed native enum, lowered\n * through the stored control adapter. Throws if no adapter is present.\n */\n protected dropNativeEnumType(options: {\n readonly schema: string;\n readonly typeName: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropNativeEnumTypeCall(options.schema, options.typeName).toOp(\n this.controlAdapterFor('dropNativeEnumType'),\n );\n }\n\n /**\n * Emit an `ALTER TYPE ... ADD VALUE` migration operation appending one\n * member to a managed native enum, lowered through the stored control\n * adapter. Throws if no adapter is present. Every appended value is its\n * own operation — call this once per value to append more than one.\n */\n protected addNativeEnumValue(options: {\n readonly schema: string;\n readonly typeName: string;\n readonly value: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new AddNativeEnumValueCall(options.schema, options.typeName, options.value).toOp(\n this.controlAdapterFor('addNativeEnumValue'),\n );\n }\n\n protected addColumn(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: DdlColumn;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new AddColumnCall(options.schema, options.table, options.column).toOp(\n this.controlAdapterFor('addColumn'),\n );\n }\n\n protected addPrimaryKey(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly columns: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new AddPrimaryKeyCall(\n options.schema,\n options.table,\n options.constraint,\n options.columns,\n ).toOp(this.controlAdapterFor('addPrimaryKey'));\n }\n\n protected addUnique(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly columns: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new AddUniqueCall(\n options.schema,\n options.table,\n options.constraint,\n options.columns,\n ).toOp(this.controlAdapterFor('addUnique'));\n }\n\n protected addForeignKey(options: {\n readonly schema: string;\n readonly table: string;\n readonly foreignKey: ForeignKeySpec;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(\n this.controlAdapterFor('addForeignKey'),\n );\n }\n\n protected addCheckConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly column: string;\n readonly values: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new AddCheckConstraintCall(\n options.schema,\n options.table,\n options.constraint,\n options.column,\n options.values,\n ).toOp(this.controlAdapterFor('addCheckConstraint'));\n }\n\n protected dropCheckConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(\n this.controlAdapterFor('dropCheckConstraint'),\n );\n }\n\n protected dropConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropConstraintCall(\n options.schema,\n options.table,\n options.constraint,\n options.kind ?? 'unique',\n ).toOp(this.controlAdapterFor('dropConstraint'));\n }\n\n protected dropTable(options: {\n readonly schema: string;\n readonly table: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropTableCall(options.schema, options.table).toOp(\n this.controlAdapterFor('dropTable'),\n );\n }\n\n protected dropColumn(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropColumnCall(options.schema, options.table, options.column).toOp(\n this.controlAdapterFor('dropColumn'),\n );\n }\n\n protected alterColumnType(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly options: AlterColumnTypeOptions;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new AlterColumnTypeCall(\n options.schema,\n options.table,\n options.column,\n options.options,\n ).toOp(this.controlAdapterFor('alterColumnType'));\n }\n\n protected setNotNull(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new SetNotNullCall(options.schema, options.table, options.column).toOp(\n this.controlAdapterFor('setNotNull'),\n );\n }\n\n protected dropNotNull(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropNotNullCall(options.schema, options.table, options.column).toOp(\n this.controlAdapterFor('dropNotNull'),\n );\n }\n\n protected setDefault(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly defaultSql: string;\n readonly operationClass?: 'additive' | 'widening';\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new SetDefaultCall(\n options.schema,\n options.table,\n options.column,\n options.defaultSql,\n options.operationClass,\n ).toOp(this.controlAdapterFor('setDefault'));\n }\n\n protected dropDefault(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropDefaultCall(options.schema, options.table, options.column).toOp(\n this.controlAdapterFor('dropDefault'),\n );\n }\n\n protected createIndex(\n options: {\n readonly schema: string;\n readonly table: string;\n readonly index: string;\n readonly extras?: CreateIndexExtras;\n } & (\n | { readonly columns: readonly string[]; readonly expression?: never }\n | { readonly expression: string; readonly columns?: never }\n ),\n ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new CreateIndexCall(\n options.schema,\n options.table,\n options.index,\n options.columns !== undefined\n ? { columns: options.columns }\n : { expression: options.expression },\n options.extras,\n ).toOp(this.controlAdapterFor('createIndex'));\n }\n\n protected renameIndex(options: {\n readonly schema: string;\n readonly table: string;\n readonly from: string;\n readonly to: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new RenameIndexCall(options.schema, options.table, options.from, options.to).toOp(\n this.controlAdapterFor('renameIndex'),\n );\n }\n\n protected dropIndex(options: {\n readonly schema: string;\n readonly table: string;\n readonly index: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropIndexCall(options.schema, options.table, options.index).toOp(\n this.controlAdapterFor('dropIndex'),\n );\n }\n\n protected installExtension(options: {\n readonly extensionName: string;\n readonly invariantId: string;\n readonly id: string;\n readonly label?: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return installExtension(options, this.controlAdapterFor('installExtension'));\n }\n\n protected enableRowLevelSecurity(options: {\n readonly schema: string;\n readonly table: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new EnableRowLevelSecurityCall(options.schema, options.table).toOp(\n this.controlAdapterFor('enableRowLevelSecurity'),\n );\n }\n\n protected disableRowLevelSecurity(options: {\n readonly schema: string;\n readonly table: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DisableRowLevelSecurityCall(options.schema, options.table).toOp(\n this.controlAdapterFor('disableRowLevelSecurity'),\n );\n }\n\n protected createRlsPolicy(options: {\n readonly schema: string;\n readonly table: string;\n readonly policy: PostgresRlsPolicyInput;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new CreatePostgresRlsPolicyCall(\n options.schema,\n options.table,\n new PostgresRlsPolicy(options.policy),\n ).toOp(this.controlAdapterFor('createRlsPolicy'));\n }\n\n protected dropRlsPolicy(options: {\n readonly schema: string;\n readonly table: string;\n readonly policy: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new DropPostgresRlsPolicyCall(options.schema, options.table, options.policy).toOp(\n this.controlAdapterFor('dropRlsPolicy'),\n );\n }\n\n protected renameRlsPolicy(options: {\n readonly schema: string;\n readonly table: string;\n readonly from: string;\n readonly to: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n return new RenamePostgresRlsPolicyCall(\n options.schema,\n options.table,\n options.from,\n options.to,\n ).toOp(this.controlAdapterFor('renameRlsPolicy'));\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as PostgresPlanTargetDetails } from "./planner-target-details-HkP4RrRO.mjs";
|
|
2
2
|
import { n as DataTransformOptions } from "./data-transform-CGvE8yGx.mjs";
|
|
3
3
|
import { n as PostgresRlsPolicyInput } from "./postgres-rls-policy-CYXdqG9B.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { F as ForeignKeySpec, P as CreateIndexExtras, l as AlterColumnTypeOptions } from "./op-factory-call-0TB5XNij.mjs";
|
|
5
5
|
import { t as PostgresContractView } from "./postgres-contract-view-CeU7FJjW.mjs";
|
|
6
6
|
import { DdlColumn, DdlTableConstraint } from "@prisma-next/sql-relational-core/ast";
|
|
7
7
|
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
@@ -9,13 +9,7 @@ import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
|
9
9
|
import { ControlStack } from "@prisma-next/framework-components/control";
|
|
10
10
|
import { Migration } from "@prisma-next/family-sql/migration";
|
|
11
11
|
import { Contract } from "@prisma-next/contract/types";
|
|
12
|
-
import {
|
|
13
|
-
//#region src/core/migrations/operations/indexes.d.ts
|
|
14
|
-
interface CreateIndexExtras {
|
|
15
|
-
readonly type?: string;
|
|
16
|
-
readonly options?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
12
|
+
import { SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
|
|
19
13
|
//#region src/core/migrations/postgres-migration.d.ts
|
|
20
14
|
/**
|
|
21
15
|
* Target-owned base class for Postgres migrations.
|
|
@@ -210,8 +204,19 @@ declare abstract class PostgresMigration<Start extends Contract<SqlStorage> = Co
|
|
|
210
204
|
readonly schema: string;
|
|
211
205
|
readonly table: string;
|
|
212
206
|
readonly index: string;
|
|
213
|
-
readonly columns: readonly string[];
|
|
214
207
|
readonly extras?: CreateIndexExtras;
|
|
208
|
+
} & ({
|
|
209
|
+
readonly columns: readonly string[];
|
|
210
|
+
readonly expression?: never;
|
|
211
|
+
} | {
|
|
212
|
+
readonly expression: string;
|
|
213
|
+
readonly columns?: never;
|
|
214
|
+
})): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
215
|
+
protected renameIndex(options: {
|
|
216
|
+
readonly schema: string;
|
|
217
|
+
readonly table: string;
|
|
218
|
+
readonly from: string;
|
|
219
|
+
readonly to: string;
|
|
215
220
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
216
221
|
protected dropIndex(options: {
|
|
217
222
|
readonly schema: string;
|
|
@@ -251,4 +256,4 @@ declare abstract class PostgresMigration<Start extends Contract<SqlStorage> = Co
|
|
|
251
256
|
}
|
|
252
257
|
//#endregion
|
|
253
258
|
export { PostgresMigration as t };
|
|
254
|
-
//# sourceMappingURL=postgres-migration-
|
|
259
|
+
//# sourceMappingURL=postgres-migration-BXelnqHO.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-migration-BXelnqHO.d.mts","names":[],"sources":["../src/core/migrations/postgres-migration.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA0EsB,kBACpB,cAAc,SAAS,cAAc,SAAS,aAC9C,YAAY,SAAS,cAAc,SAAS,qBACpC,UAAa,uCAAuC,OAAO;;WAC1D;;;;;;;qBAQU,gBAAgB;cAavB,QAAQ;;;;;;UAeZ;;;;;;MAYJ,eAAe,qBAAqB;;;;;MAQpC,iBAAiB,qBAAqB;;;;;;YAShC,cAAc,kBAAkB,SAAS,aACjD,UAAU,WACV,cACA,SAAS,uBACR,QAAQ,0BAA0B;;;;;;YAS3B,YAAY;aACX;aACA;aACA;aACA,kBAAkB;aAClB,uBAAuB;MAC9B,QAAQ,0BAA0B;;;;;;YAc5B,aAAa;aACZ;aACA;MACP,QAAQ,0BAA0B;;;;;;;YAU5B,qBAAqB;aACpB;aACA;aACA;MACP,QAAQ,0BAA0B;;;;;YAU5B,mBAAmB;aAClB;aACA;MACP,QAAQ,0BAA0B;;;;;;;YAY5B,mBAAmB;aAClB;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,UAAU;aACT;aACA;aACA,QAAQ;MACf,QAAQ,0BAA0B;YAM5B,cAAc;aACb;aACA;aACA;aACA;MACP,QAAQ,0BAA0B;YAS5B,UAAU;aACT;aACA;aACA;aACA;MACP,QAAQ,0BAA0B;YAS5B,cAAc;aACb;aACA;aACA,YAAY;MACnB,QAAQ,0BAA0B;YAM5B,mBAAmB;aAClB;aACA;aACA;aACA;aACA;MACP,QAAQ,0BAA0B;YAU5B,oBAAoB;aACnB;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,eAAe;aACd;aACA;aACA;aACA;MACP,QAAQ,0BAA0B;YAS5B,UAAU;aACT;aACA;MACP,QAAQ,0BAA0B;YAM5B,WAAW;aACV;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,gBAAgB;aACf;aACA;aACA;aACA,SAAS;MAChB,QAAQ,0BAA0B;YAS5B,WAAW;aACV;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,YAAY;aACX;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,WAAW;aACV;aACA;aACA;aACA;aACA;MACP,QAAQ,0BAA0B;YAU5B,YAAY;aACX;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,YACR;aACW;aACA;aACA;aACA,SAAS;;aAEL;aAAqC;;aACrC;aAA6B;OAE3C,QAAQ,0BAA0B;YAY3B,YAAY;aACX;aACA;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,UAAU;aACT;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,iBAAiB;aAChB;aACA;aACA;aACA;MACP,QAAQ,0BAA0B;YAI5B,uBAAuB;aACtB;aACA;MACP,QAAQ,0BAA0B;YAM5B,wBAAwB;aACvB;aACA;MACP,QAAQ,0BAA0B;YAM5B,gBAAgB;aACf;aACA;aACA,QAAQ;MACf,QAAQ,0BAA0B;YAQ5B,cAAc;aACb;aACA;aACA;MACP,QAAQ,0BAA0B;YAM5B,gBAAgB;aACf;aACA;aACA;aACA;MACP,QAAQ,0BAA0B"}
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface RlsPolicyWireName {
|
|
4
|
-
/** The user-supplied part before the `_<8hex>` suffix. */
|
|
5
|
-
readonly prefix: string;
|
|
6
|
-
/** The 8-lowercase-hex content-hash suffix. */
|
|
7
|
-
readonly hash: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Assembles an RLS policy wire name from its user-supplied prefix and its
|
|
11
|
-
* 8-hex content-hash suffix. This module owns the `<prefix>_<hash>` format
|
|
12
|
-
* on both sides — construction here and parsing in
|
|
13
|
-
* {@link parseRlsPolicyWireName} — so the two never drift.
|
|
14
|
-
*/
|
|
15
|
-
declare function formatRlsPolicyWireName(prefix: string, hash: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Splits an RLS policy wire name (`<prefix>_<8hex>`) into its prefix and
|
|
18
|
-
* content-hash suffix. Returns `undefined` when the name does not follow the
|
|
19
|
-
* wire-name shape (e.g. a policy created outside the toolchain) — callers
|
|
20
|
-
* treat such names as all-prefix. Consumed by introspection (prefix
|
|
21
|
-
* extraction) and by rename pairing (same hash, different prefix).
|
|
22
|
-
*/
|
|
23
|
-
declare function parseRlsPolicyWireName(name: string): RlsPolicyWireName | undefined;
|
|
24
|
-
//#endregion
|
|
25
|
-
export { type ContentHashParts, POLICY_OPERATION_PREDICATES, type RlsPolicyOperation, type RlsPolicyWireName, computeContentHash, formatRlsPolicyWireName, normalizePredicate, parseRlsPolicyWireName };
|
|
26
|
-
//# sourceMappingURL=rls-canonicalize.d.mts.map
|
|
1
|
+
import { i as computeContentHash, n as POLICY_OPERATION_PREDICATES, r as RlsPolicyOperation, t as ContentHashParts } from "./canonicalize-CQlxSR4D.mjs";
|
|
2
|
+
export { type ContentHashParts, POLICY_OPERATION_PREDICATES, type RlsPolicyOperation, computeContentHash };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { POLICY_OPERATION_PREDICATES, computeContentHash
|
|
1
|
+
import { n as computeContentHash, t as POLICY_OPERATION_PREDICATES } from "./canonicalize-C7zKHw8m.mjs";
|
|
2
|
+
export { POLICY_OPERATION_PREDICATES, computeContentHash };
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-UwYdV8fD.mjs";
|
|
2
|
-
import { n as PostgresContractSerializer, t as PostgresContractView } from "./postgres-contract-view-
|
|
2
|
+
import { n as PostgresContractSerializer, t as PostgresContractView } from "./postgres-contract-view-BeIEyZfD.mjs";
|
|
3
3
|
//#region src/exports/runtime.ts
|
|
4
4
|
/**
|
|
5
5
|
* Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.16.0-dev.
|
|
3
|
+
"version": "0.16.0-dev.26",
|
|
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.16.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.16.0-dev.
|
|
11
|
-
"@prisma-next/errors": "0.16.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.16.0-dev.
|
|
13
|
-
"@prisma-next/framework-components": "0.16.0-dev.
|
|
14
|
-
"@prisma-next/migration-tools": "0.16.0-dev.
|
|
15
|
-
"@prisma-next/psl-parser": "0.16.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract": "0.16.0-dev.
|
|
17
|
-
"@prisma-next/sql-errors": "0.16.0-dev.
|
|
18
|
-
"@prisma-next/sql-operations": "0.16.0-dev.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.16.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.16.0-dev.
|
|
21
|
-
"@prisma-next/ts-render": "0.16.0-dev.
|
|
22
|
-
"@prisma-next/utils": "0.16.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.16.0-dev.26",
|
|
10
|
+
"@prisma-next/contract": "0.16.0-dev.26",
|
|
11
|
+
"@prisma-next/errors": "0.16.0-dev.26",
|
|
12
|
+
"@prisma-next/family-sql": "0.16.0-dev.26",
|
|
13
|
+
"@prisma-next/framework-components": "0.16.0-dev.26",
|
|
14
|
+
"@prisma-next/migration-tools": "0.16.0-dev.26",
|
|
15
|
+
"@prisma-next/psl-parser": "0.16.0-dev.26",
|
|
16
|
+
"@prisma-next/sql-contract": "0.16.0-dev.26",
|
|
17
|
+
"@prisma-next/sql-errors": "0.16.0-dev.26",
|
|
18
|
+
"@prisma-next/sql-operations": "0.16.0-dev.26",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.16.0-dev.26",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.16.0-dev.26",
|
|
21
|
+
"@prisma-next/ts-render": "0.16.0-dev.26",
|
|
22
|
+
"@prisma-next/utils": "0.16.0-dev.26",
|
|
23
23
|
"@standard-schema/spec": "^1.1.0",
|
|
24
24
|
"arktype": "^2.2.2",
|
|
25
25
|
"pathe": "^2.0.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@prisma-next/psl-printer": "0.16.0-dev.
|
|
29
|
-
"@prisma-next/sql-contract-psl": "0.16.0-dev.
|
|
30
|
-
"@prisma-next/test-utils": "0.16.0-dev.
|
|
31
|
-
"@prisma-next/tsconfig": "0.16.0-dev.
|
|
32
|
-
"@prisma-next/tsdown": "0.16.0-dev.
|
|
28
|
+
"@prisma-next/psl-printer": "0.16.0-dev.26",
|
|
29
|
+
"@prisma-next/sql-contract-psl": "0.16.0-dev.26",
|
|
30
|
+
"@prisma-next/test-utils": "0.16.0-dev.26",
|
|
31
|
+
"@prisma-next/tsconfig": "0.16.0-dev.26",
|
|
32
|
+
"@prisma-next/tsdown": "0.16.0-dev.26",
|
|
33
33
|
"tsdown": "0.22.8",
|
|
34
34
|
"typescript": "5.9.3",
|
|
35
35
|
"vitest": "4.1.10"
|
package/src/contract-free/ddl.ts
CHANGED
|
@@ -2,14 +2,18 @@ import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-
|
|
|
2
2
|
import {
|
|
3
3
|
AddColumnAction,
|
|
4
4
|
type AnyAlterTableAction,
|
|
5
|
+
type DdlIndexElements,
|
|
5
6
|
DropDefaultAction,
|
|
7
|
+
PostgresAlterIndexRename,
|
|
6
8
|
PostgresAlterPolicyRename,
|
|
7
9
|
PostgresAlterTable,
|
|
10
|
+
PostgresCreateIndex,
|
|
8
11
|
PostgresCreatePolicy,
|
|
9
12
|
PostgresCreateSchema,
|
|
10
13
|
PostgresCreateTable,
|
|
11
14
|
PostgresCreateType,
|
|
12
15
|
PostgresDisableRowLevelSecurity,
|
|
16
|
+
PostgresDropIndex,
|
|
13
17
|
PostgresDropPolicy,
|
|
14
18
|
PostgresDropType,
|
|
15
19
|
type RlsPolicyOperation,
|
|
@@ -149,6 +153,49 @@ export function alterPolicyRename(options: {
|
|
|
149
153
|
return new PostgresAlterPolicyRename(options);
|
|
150
154
|
}
|
|
151
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Build a Postgres `CREATE [UNIQUE] INDEX` DDL node. Identifiers (`schema`,
|
|
158
|
+
* `table`, `name`, column elements, `type`, option keys) are quoted by the
|
|
159
|
+
* renderer; the `expression` element list and the `where` predicate are
|
|
160
|
+
* inserted verbatim (opaque SQL). An absent `schema` renders the object
|
|
161
|
+
* names unqualified (the unbound namespace).
|
|
162
|
+
*/
|
|
163
|
+
export function createIndex(options: {
|
|
164
|
+
readonly schema: string | undefined;
|
|
165
|
+
readonly table: string;
|
|
166
|
+
readonly name: string;
|
|
167
|
+
readonly unique: boolean;
|
|
168
|
+
readonly elements: DdlIndexElements;
|
|
169
|
+
readonly type: string | undefined;
|
|
170
|
+
readonly options: Record<string, unknown> | undefined;
|
|
171
|
+
readonly where: string | undefined;
|
|
172
|
+
}): PostgresCreateIndex {
|
|
173
|
+
return new PostgresCreateIndex(options);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Build a Postgres `DROP INDEX` DDL node. The index name (and optional
|
|
178
|
+
* schema) are quoted by the renderer.
|
|
179
|
+
*/
|
|
180
|
+
export function dropIndex(options: {
|
|
181
|
+
readonly schema: string | undefined;
|
|
182
|
+
readonly name: string;
|
|
183
|
+
}): PostgresDropIndex {
|
|
184
|
+
return new PostgresDropIndex(options);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Build a Postgres `ALTER INDEX … RENAME TO` DDL node. Identifiers are
|
|
189
|
+
* quoted by the renderer.
|
|
190
|
+
*/
|
|
191
|
+
export function alterIndexRename(options: {
|
|
192
|
+
readonly schema: string | undefined;
|
|
193
|
+
readonly from: string;
|
|
194
|
+
readonly to: string;
|
|
195
|
+
}): PostgresAlterIndexRename {
|
|
196
|
+
return new PostgresAlterIndexRename(options);
|
|
197
|
+
}
|
|
198
|
+
|
|
152
199
|
/**
|
|
153
200
|
* Build a Postgres `ALTER TABLE … DISABLE ROW LEVEL SECURITY` DDL node.
|
|
154
201
|
* Identifiers (`schema`, `table`) are quoted by the renderer.
|
package/src/core/authoring.ts
CHANGED
|
@@ -22,6 +22,11 @@ import type {
|
|
|
22
22
|
ResolvedPslModelRefs,
|
|
23
23
|
} from '@prisma-next/sql-contract/entity-handle-lowering-hook';
|
|
24
24
|
import type { SqlValueSetDerivingEntityTypeOutput } from '@prisma-next/sql-contract/value-set-derivation-hook';
|
|
25
|
+
import {
|
|
26
|
+
assertWireNamePrefixLength,
|
|
27
|
+
formatWireName,
|
|
28
|
+
normalizeSqlBody,
|
|
29
|
+
} from '@prisma-next/sql-schema-ir/naming';
|
|
25
30
|
import { assertDefined } from '@prisma-next/utils/assertions';
|
|
26
31
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
27
32
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
@@ -37,12 +42,7 @@ import {
|
|
|
37
42
|
PostgresRlsPolicySchema,
|
|
38
43
|
PostgresRoleSchema,
|
|
39
44
|
} from './postgres-validators';
|
|
40
|
-
import {
|
|
41
|
-
computeContentHash,
|
|
42
|
-
normalizePredicate,
|
|
43
|
-
POLICY_OPERATION_PREDICATES,
|
|
44
|
-
} from './rls/canonicalize';
|
|
45
|
-
import { formatRlsPolicyWireName } from './rls/wire-name';
|
|
45
|
+
import { computeContentHash, POLICY_OPERATION_PREDICATES } from './rls/canonicalize';
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* `pg.enum(<ref>)` registers as an ordinary type constructor whose sole
|
|
@@ -154,10 +154,10 @@ function buildRlsPolicyEntity(input: {
|
|
|
154
154
|
readonly withCheck?: string;
|
|
155
155
|
}): PostgresRlsPolicy {
|
|
156
156
|
const wireHash = computeContentHash({
|
|
157
|
-
...ifDefined('using', input.using !== undefined ?
|
|
157
|
+
...ifDefined('using', input.using !== undefined ? normalizeSqlBody(input.using) : undefined),
|
|
158
158
|
...ifDefined(
|
|
159
159
|
'withCheck',
|
|
160
|
-
input.withCheck !== undefined ?
|
|
160
|
+
input.withCheck !== undefined ? normalizeSqlBody(input.withCheck) : undefined,
|
|
161
161
|
),
|
|
162
162
|
roles: input.roles,
|
|
163
163
|
operation: input.operation,
|
|
@@ -165,7 +165,7 @@ function buildRlsPolicyEntity(input: {
|
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
return new PostgresRlsPolicy({
|
|
168
|
-
name:
|
|
168
|
+
name: formatWireName(input.prefix, wireHash),
|
|
169
169
|
prefix: input.prefix,
|
|
170
170
|
tableName: input.tableName,
|
|
171
171
|
namespaceId: input.namespaceId,
|
|
@@ -684,12 +684,6 @@ export const postgresAuthoringFieldPresets = {
|
|
|
684
684
|
},
|
|
685
685
|
} as const satisfies AuthoringFieldNamespace;
|
|
686
686
|
|
|
687
|
-
/**
|
|
688
|
-
* Postgres identifiers cap at 63 characters and the wire name appends a
|
|
689
|
-
* 9-character `_<8hex>` suffix, so the authored prefix is bounded at 54.
|
|
690
|
-
*/
|
|
691
|
-
const RLS_POLICY_PREFIX_MAX_LENGTH = 54;
|
|
692
|
-
|
|
693
687
|
interface RlsRoleHandleShape {
|
|
694
688
|
readonly entityKind: 'role';
|
|
695
689
|
readonly name: string;
|
|
@@ -824,13 +818,7 @@ export function postgresLowerEntityHandles(
|
|
|
824
818
|
|
|
825
819
|
for (const { handle: policy, refs } of policies) {
|
|
826
820
|
const prefix = policy.name;
|
|
827
|
-
|
|
828
|
-
throw postgresError(
|
|
829
|
-
'CONTRACT.POLICY_INVALID',
|
|
830
|
-
`defineContract: policy prefix "${prefix}" exceeds the ${RLS_POLICY_PREFIX_MAX_LENGTH}-character maximum (Postgres identifiers cap at 63 characters and the wire name appends a 9-character hash suffix).`,
|
|
831
|
-
{ meta: { prefix, reason: 'prefix-too-long' } },
|
|
832
|
-
);
|
|
833
|
-
}
|
|
821
|
+
assertWireNamePrefixLength(prefix, 'defineContract: policy prefix');
|
|
834
822
|
const coordinate = requireLocalTarget(refs, `policy "${prefix}"`);
|
|
835
823
|
if (!enablements.has(coordinateKey(coordinate))) {
|
|
836
824
|
const target = refs['target'];
|
package/src/core/ddl/nodes.ts
CHANGED
|
@@ -73,6 +73,9 @@ export interface PostgresDdlVisitor<R> {
|
|
|
73
73
|
createPolicy(node: PostgresCreatePolicy): R;
|
|
74
74
|
dropPolicy(node: PostgresDropPolicy): R;
|
|
75
75
|
alterPolicyRename(node: PostgresAlterPolicyRename): R;
|
|
76
|
+
createIndex(node: PostgresCreateIndex): R;
|
|
77
|
+
dropIndex(node: PostgresDropIndex): R;
|
|
78
|
+
alterIndexRename(node: PostgresAlterIndexRename): R;
|
|
76
79
|
disableRowLevelSecurity(node: PostgresDisableRowLevelSecurity): R;
|
|
77
80
|
}
|
|
78
81
|
|
|
@@ -284,6 +287,104 @@ export class PostgresAlterPolicyRename extends PostgresDdlNode {
|
|
|
284
287
|
}
|
|
285
288
|
}
|
|
286
289
|
|
|
290
|
+
/**
|
|
291
|
+
* The element list between the parens of CREATE INDEX: either a column
|
|
292
|
+
* tuple (each identifier quoted by the renderer) or one opaque expression
|
|
293
|
+
* string covering the entire list, inserted verbatim — the same opaque-SQL
|
|
294
|
+
* stance as RLS policy predicates (ADR 234).
|
|
295
|
+
*/
|
|
296
|
+
export type DdlIndexElements =
|
|
297
|
+
| { readonly columns: readonly string[] }
|
|
298
|
+
| { readonly expression: string };
|
|
299
|
+
|
|
300
|
+
export class PostgresCreateIndex extends PostgresDdlNode {
|
|
301
|
+
readonly kind = 'create-index' as const;
|
|
302
|
+
/** Absent ⇔ unqualified (the unbound namespace — `search_path` decides). */
|
|
303
|
+
readonly schema: string | undefined;
|
|
304
|
+
readonly table: string;
|
|
305
|
+
readonly name: string;
|
|
306
|
+
readonly unique: boolean;
|
|
307
|
+
readonly elements: DdlIndexElements;
|
|
308
|
+
readonly type: string | undefined;
|
|
309
|
+
readonly options: Record<string, unknown> | undefined;
|
|
310
|
+
/**
|
|
311
|
+
* Partial-index predicate (WHERE body, without the keyword). Inserted
|
|
312
|
+
* verbatim, never quoted or escaped.
|
|
313
|
+
*/
|
|
314
|
+
readonly where: string | undefined;
|
|
315
|
+
|
|
316
|
+
constructor(options: {
|
|
317
|
+
readonly schema: string | undefined;
|
|
318
|
+
readonly table: string;
|
|
319
|
+
readonly name: string;
|
|
320
|
+
readonly unique: boolean;
|
|
321
|
+
readonly elements: DdlIndexElements;
|
|
322
|
+
readonly type: string | undefined;
|
|
323
|
+
readonly options: Record<string, unknown> | undefined;
|
|
324
|
+
readonly where: string | undefined;
|
|
325
|
+
}) {
|
|
326
|
+
super();
|
|
327
|
+
this.schema = options.schema;
|
|
328
|
+
this.table = options.table;
|
|
329
|
+
this.name = options.name;
|
|
330
|
+
this.unique = options.unique;
|
|
331
|
+
this.elements =
|
|
332
|
+
'columns' in options.elements
|
|
333
|
+
? { columns: Object.freeze([...options.elements.columns]) }
|
|
334
|
+
: { expression: options.elements.expression };
|
|
335
|
+
this.type = options.type;
|
|
336
|
+
this.options = options.options;
|
|
337
|
+
this.where = options.where;
|
|
338
|
+
this.freeze();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
override accept<R>(visitor: PostgresDdlVisitor<R>): R {
|
|
342
|
+
return visitor.createIndex(this);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export class PostgresDropIndex extends PostgresDdlNode {
|
|
347
|
+
readonly kind = 'drop-index' as const;
|
|
348
|
+
/** Absent ⇔ unqualified (the unbound namespace). */
|
|
349
|
+
readonly schema: string | undefined;
|
|
350
|
+
readonly name: string;
|
|
351
|
+
|
|
352
|
+
constructor(options: { readonly schema: string | undefined; readonly name: string }) {
|
|
353
|
+
super();
|
|
354
|
+
this.schema = options.schema;
|
|
355
|
+
this.name = options.name;
|
|
356
|
+
this.freeze();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
override accept<R>(visitor: PostgresDdlVisitor<R>): R {
|
|
360
|
+
return visitor.dropIndex(this);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export class PostgresAlterIndexRename extends PostgresDdlNode {
|
|
365
|
+
readonly kind = 'alter-index-rename' as const;
|
|
366
|
+
/** Absent ⇔ unqualified (the unbound namespace). */
|
|
367
|
+
readonly schema: string | undefined;
|
|
368
|
+
readonly from: string;
|
|
369
|
+
readonly to: string;
|
|
370
|
+
|
|
371
|
+
constructor(options: {
|
|
372
|
+
readonly schema: string | undefined;
|
|
373
|
+
readonly from: string;
|
|
374
|
+
readonly to: string;
|
|
375
|
+
}) {
|
|
376
|
+
super();
|
|
377
|
+
this.schema = options.schema;
|
|
378
|
+
this.from = options.from;
|
|
379
|
+
this.to = options.to;
|
|
380
|
+
this.freeze();
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
override accept<R>(visitor: PostgresDdlVisitor<R>): R {
|
|
384
|
+
return visitor.alterIndexRename(this);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
287
388
|
export class PostgresDisableRowLevelSecurity extends PostgresDdlNode {
|
|
288
389
|
readonly kind = 'disable-row-level-security' as const;
|
|
289
390
|
readonly schema: string;
|
|
@@ -310,4 +411,7 @@ export type AnyPostgresDdlNode =
|
|
|
310
411
|
| PostgresCreatePolicy
|
|
311
412
|
| PostgresDropPolicy
|
|
312
413
|
| PostgresAlterPolicyRename
|
|
414
|
+
| PostgresCreateIndex
|
|
415
|
+
| PostgresDropIndex
|
|
416
|
+
| PostgresAlterIndexRename
|
|
313
417
|
| PostgresDisableRowLevelSecurity;
|
|
@@ -193,19 +193,30 @@ export function contractToPostgresDatabaseSchemaNode(
|
|
|
193
193
|
dependsOn: columnDependsOn(ddlSchema, tableName, u.columns),
|
|
194
194
|
}),
|
|
195
195
|
);
|
|
196
|
-
const indexes = sqlTable.indexes.map(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
196
|
+
const indexes = sqlTable.indexes.map((i) => {
|
|
197
|
+
const base = {
|
|
198
|
+
name: i.name,
|
|
199
|
+
prefix: i.prefix,
|
|
200
|
+
where: i.where,
|
|
201
|
+
unique: i.unique,
|
|
202
|
+
partial: i.partial,
|
|
203
|
+
type: i.type,
|
|
204
|
+
options: i.options,
|
|
205
|
+
annotations: i.annotations,
|
|
206
|
+
// Expression indexes stamp chains to every column of the table —
|
|
207
|
+
// the same over-approximation the family derivation uses.
|
|
208
|
+
dependsOn: columnDependsOn(
|
|
209
|
+
ddlSchema,
|
|
210
|
+
tableName,
|
|
211
|
+
i.columns ?? Object.keys(sqlTable.columns),
|
|
212
|
+
),
|
|
213
|
+
};
|
|
214
|
+
return new SqlIndexIR(
|
|
215
|
+
i.expression !== undefined
|
|
216
|
+
? { ...base, expression: i.expression }
|
|
217
|
+
: { ...base, columns: i.columns ?? [] },
|
|
218
|
+
);
|
|
219
|
+
});
|
|
209
220
|
const primaryKey =
|
|
210
221
|
sqlTable.primaryKey !== undefined
|
|
211
222
|
? new PrimaryKey({
|
|
@@ -30,7 +30,6 @@ import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
|
30
30
|
import type { SqlStorage, StorageTypeInstance } from '@prisma-next/sql-contract/types';
|
|
31
31
|
import type { DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';
|
|
32
32
|
import * as contractFree from '@prisma-next/sql-relational-core/contract-free';
|
|
33
|
-
import { defaultIndexName } from '@prisma-next/sql-schema-ir/naming';
|
|
34
33
|
import {
|
|
35
34
|
RelationalSchemaNodeKind,
|
|
36
35
|
type SqlColumnDefaultIR,
|
|
@@ -200,6 +199,7 @@ function classifyCall(call: PostgresOpFactoryCall): CallCategory {
|
|
|
200
199
|
case 'addUnique':
|
|
201
200
|
return 'unique';
|
|
202
201
|
case 'createIndex':
|
|
202
|
+
case 'renameIndex':
|
|
203
203
|
return 'index';
|
|
204
204
|
case 'addForeignKey':
|
|
205
205
|
return 'foreignKey';
|
|
@@ -248,6 +248,7 @@ function conflictKindForCall(call: PostgresOpFactoryCall): SqlPlannerConflict['k
|
|
|
248
248
|
case 'dropConstraint':
|
|
249
249
|
return 'foreignKeyConflict';
|
|
250
250
|
case 'createIndex':
|
|
251
|
+
case 'renameIndex':
|
|
251
252
|
case 'dropIndex':
|
|
252
253
|
return 'indexIncompatible';
|
|
253
254
|
default:
|
|
@@ -263,6 +264,7 @@ function locationForCall(call: PostgresOpFactoryCall): SqlPlannerConflict['locat
|
|
|
263
264
|
tableName?: string;
|
|
264
265
|
columnName?: string;
|
|
265
266
|
indexName?: string;
|
|
267
|
+
newIndexName?: string;
|
|
266
268
|
constraintName?: string;
|
|
267
269
|
typeName?: string;
|
|
268
270
|
};
|
|
@@ -281,7 +283,10 @@ function locationForCall(call: PostgresOpFactoryCall): SqlPlannerConflict['locat
|
|
|
281
283
|
location.entityName = anyCall.typeName;
|
|
282
284
|
}
|
|
283
285
|
if (anyCall.columnName) location.column = anyCall.columnName;
|
|
286
|
+
// A rename call carries old/new index names; the new name is the index's
|
|
287
|
+
// contract-side identity, so it is the conflict location.
|
|
284
288
|
if (anyCall.indexName) location.index = anyCall.indexName;
|
|
289
|
+
else if (anyCall.newIndexName) location.index = anyCall.newIndexName;
|
|
285
290
|
if (anyCall.constraintName) location.constraint = anyCall.constraintName;
|
|
286
291
|
return Object.keys(location).length > 0 ? (location as SqlPlannerConflictLocation) : undefined;
|
|
287
292
|
}
|
|
@@ -476,11 +481,7 @@ function buildCreateTableCallsFromNode(
|
|
|
476
481
|
),
|
|
477
482
|
];
|
|
478
483
|
for (const index of table.indexes) {
|
|
479
|
-
|
|
480
|
-
const extras: { type?: string; options?: Record<string, unknown> } = {};
|
|
481
|
-
if (index.type !== undefined) extras.type = index.type;
|
|
482
|
-
if (index.options !== undefined) extras.options = index.options;
|
|
483
|
-
calls.push(new CreateIndexCall(schemaName, table.name, indexName, [...index.columns], extras));
|
|
484
|
+
calls.push(createIndexCallFromNode(index, schemaName, table.name));
|
|
484
485
|
}
|
|
485
486
|
for (const fk of table.foreignKeys) {
|
|
486
487
|
calls.push(new AddForeignKeyCall(schemaName, table.name, fkSpecFromNode(fk, table.name)));
|
|
@@ -808,6 +809,37 @@ function mapUniqueNodeIssue(
|
|
|
808
809
|
return notOk(nodeConflict('indexIncompatible', issue.path.join('/')));
|
|
809
810
|
}
|
|
810
811
|
|
|
812
|
+
/**
|
|
813
|
+
* The CreateIndexCall for a name-identified index node: the node's own name
|
|
814
|
+
* verbatim, its element list (column tuple or opaque expression), and the
|
|
815
|
+
* unique/type/options/where attributes carried through.
|
|
816
|
+
*/
|
|
817
|
+
export function createIndexCallFromNode(
|
|
818
|
+
index: SqlIndexIR,
|
|
819
|
+
schemaName: string,
|
|
820
|
+
tableName: string,
|
|
821
|
+
): CreateIndexCall {
|
|
822
|
+
const extras: {
|
|
823
|
+
type?: string;
|
|
824
|
+
options?: Record<string, unknown>;
|
|
825
|
+
where?: string;
|
|
826
|
+
unique?: boolean;
|
|
827
|
+
} = {};
|
|
828
|
+
if (index.type !== undefined) extras.type = index.type;
|
|
829
|
+
if (index.options !== undefined) extras.options = index.options;
|
|
830
|
+
if (index.where !== undefined) extras.where = index.where;
|
|
831
|
+
if (index.unique) extras.unique = true;
|
|
832
|
+
return new CreateIndexCall(
|
|
833
|
+
schemaName,
|
|
834
|
+
tableName,
|
|
835
|
+
index.name,
|
|
836
|
+
index.columns !== undefined
|
|
837
|
+
? { columns: [...index.columns] }
|
|
838
|
+
: { expression: index.expression ?? '' },
|
|
839
|
+
extras,
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
|
|
811
843
|
function mapIndexNodeIssue(
|
|
812
844
|
issue: SchemaDiffIssue,
|
|
813
845
|
schemaName: string,
|
|
@@ -818,19 +850,14 @@ function mapIndexNodeIssue(
|
|
|
818
850
|
SqlIndexIR,
|
|
819
851
|
'a not-found index issue always carries the expected index node'
|
|
820
852
|
>(issue.expected);
|
|
821
|
-
|
|
822
|
-
const extras: { type?: string; options?: Record<string, unknown> } = {};
|
|
823
|
-
if (index.type !== undefined) extras.type = index.type;
|
|
824
|
-
if (index.options !== undefined) extras.options = index.options;
|
|
825
|
-
return ok([new CreateIndexCall(schemaName, tableName, indexName, [...index.columns], extras)]);
|
|
853
|
+
return ok([createIndexCallFromNode(index, schemaName, tableName)]);
|
|
826
854
|
}
|
|
827
855
|
if (issueOutcome(issue) === 'not-expected') {
|
|
828
856
|
const index = blindCast<
|
|
829
857
|
SqlIndexIR,
|
|
830
858
|
'a not-expected index issue always carries the actual index node'
|
|
831
859
|
>(issue.actual);
|
|
832
|
-
|
|
833
|
-
return ok([new DropIndexCall(schemaName, tableName, indexName)]);
|
|
860
|
+
return ok([new DropIndexCall(schemaName, tableName, index.name)]);
|
|
834
861
|
}
|
|
835
862
|
return notOk(nodeConflict('indexIncompatible', issue.path.join('/')));
|
|
836
863
|
}
|