@prisma/orm-target-postgres 8.0.0-rc.20-dev.8 → 8.0.0-rc.20-dev.10

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.
Files changed (57) hide show
  1. package/dist/{control-policy-DtU5u9Dm-44r_OF94.mjs → control-policy-BcplTDhK-DMJjsg6l.mjs} +5 -3
  2. package/dist/control-policy-BcplTDhK-DMJjsg6l.mjs.map +1 -0
  3. package/dist/{diff-database-schema-DAEzWtzU-DoyVgKqh.mjs → diff-database-schema-zWe9Lrh7-CD7T95HL.mjs} +3 -3
  4. package/dist/{diff-database-schema-DAEzWtzU-DoyVgKqh.mjs.map → diff-database-schema-zWe9Lrh7-CD7T95HL.mjs.map} +1 -1
  5. package/dist/{errors-D3Mj-x0o.d.mts → errors-LdIppowi.d.mts} +2 -2
  6. package/dist/{errors-D3Mj-x0o.d.mts.map → errors-LdIppowi.d.mts.map} +1 -1
  7. package/dist/{issue-planner-D-On52xP.d.mts → issue-planner-BLiMn8iP.d.mts} +2 -2
  8. package/dist/{issue-planner-D-On52xP.d.mts.map → issue-planner-BLiMn8iP.d.mts.map} +1 -1
  9. package/dist/migration-Be_iuIpn.mjs.map +1 -1
  10. package/dist/{migration-D4lMmLVj.d.mts → migration-cnT6b-9x.d.mts} +2 -2
  11. package/dist/{migration-D4lMmLVj.d.mts.map → migration-cnT6b-9x.d.mts.map} +1 -1
  12. package/dist/{op-factory-call-gGX-mZu--0QUG5xH4.mjs → op-factory-call-CNXvLsqS-BT9PCNDI.mjs} +159 -4
  13. package/dist/op-factory-call-CNXvLsqS-BT9PCNDI.mjs.map +1 -0
  14. package/dist/op-factory-call-D9O6cXRE.d.mts +1 -0
  15. package/dist/{op-factory-call-nLHvNx0O-BTBhGbOF.d.mts → op-factory-call-DeaoFqMW-XAP00c7U.d.mts} +43 -6
  16. package/dist/{op-factory-call-nLHvNx0O-BTBhGbOF.d.mts.map → op-factory-call-DeaoFqMW-XAP00c7U.d.mts.map} +1 -1
  17. package/dist/{planner-BYD9uL95-BYETKJX3.mjs → planner-B_mJlpS3-Cp4ZLLMC.mjs} +106 -14
  18. package/dist/planner-B_mJlpS3-Cp4ZLLMC.mjs.map +1 -0
  19. package/dist/{planner-AD3Dt57t.d.mts → planner-RW8za3Vm.d.mts} +2 -2
  20. package/dist/{planner-AD3Dt57t.d.mts.map → planner-RW8za3Vm.d.mts.map} +1 -1
  21. package/dist/{planner-produced-postgres-migration-DyIXJ3MR-DHO5wn_X.d.mts → planner-produced-postgres-migration-DtjZyo7p-CQxcHWwC.d.mts} +3 -3
  22. package/dist/planner-produced-postgres-migration-DtjZyo7p-CQxcHWwC.d.mts.map +1 -0
  23. package/dist/planner-produced-postgres-migration-JI4uclWQ.d.mts +1 -0
  24. package/dist/{planner-produced-postgres-migration-BFJVBalB-DoWrL1oX.mjs → planner-produced-postgres-migration-W1MyA8gh-CsJ2mBwk.mjs} +4 -4
  25. package/dist/{planner-produced-postgres-migration-BFJVBalB-DoWrL1oX.mjs.map → planner-produced-postgres-migration-W1MyA8gh-CsJ2mBwk.mjs.map} +1 -1
  26. package/dist/{postgres-migration-C5deJ3Ne-C4Jxu-e6.d.mts → postgres-migration-CDPlleMc-B4JQjDcN.d.mts} +33 -3
  27. package/dist/postgres-migration-CDPlleMc-B4JQjDcN.d.mts.map +1 -0
  28. package/dist/{postgres-migration-DG6SF-aU-DjRMnDmA.mjs → postgres-migration-iX1KfbM2-CF0mqcmz.mjs} +26 -5
  29. package/dist/postgres-migration-iX1KfbM2-CF0mqcmz.mjs.map +1 -0
  30. package/dist/{render-ops-BgqtCw9Z-T8BPTX85.mjs → render-ops-DszuGMgp--NFBbNry.mjs} +3 -3
  31. package/dist/{render-ops-BgqtCw9Z-T8BPTX85.mjs.map → render-ops-DszuGMgp--NFBbNry.mjs.map} +1 -1
  32. package/dist/target.d.mts +10 -10
  33. package/dist/target.mjs +8 -8
  34. package/dist/target__control.mjs +44 -5
  35. package/dist/target__control.mjs.map +1 -1
  36. package/dist/target__diff-database-schema.mjs +1 -1
  37. package/dist/target__errors.d.mts +1 -1
  38. package/dist/target__issue-planner.d.mts +1 -1
  39. package/dist/target__issue-planner.mjs +1 -1
  40. package/dist/target__migration.d.mts +2 -2
  41. package/dist/target__migration.mjs +2 -2
  42. package/dist/target__op-factory-call.d.mts +3 -3
  43. package/dist/target__op-factory-call.mjs +2 -2
  44. package/dist/target__planner-produced-postgres-migration.d.mts +2 -2
  45. package/dist/target__planner-produced-postgres-migration.mjs +1 -1
  46. package/dist/target__planner.d.mts +1 -1
  47. package/dist/target__planner.mjs +2 -2
  48. package/dist/target__render-ops.mjs +1 -1
  49. package/package.json +9 -9
  50. package/dist/control-policy-DtU5u9Dm-44r_OF94.mjs.map +0 -1
  51. package/dist/op-factory-call-CRaVUOb_.d.mts +0 -1
  52. package/dist/op-factory-call-gGX-mZu--0QUG5xH4.mjs.map +0 -1
  53. package/dist/planner-BYD9uL95-BYETKJX3.mjs.map +0 -1
  54. package/dist/planner-produced-postgres-migration-BBUwtjA_.d.mts +0 -1
  55. package/dist/planner-produced-postgres-migration-DyIXJ3MR-DHO5wn_X.d.mts.map +0 -1
  56. package/dist/postgres-migration-C5deJ3Ne-C4Jxu-e6.d.mts.map +0 -1
  57. package/dist/postgres-migration-DG6SF-aU-DjRMnDmA.mjs.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import { c as postgresError } from "./errors-BrhQYgdL-IvZHPjwL.mjs";
2
2
  import { a as quoteQualifiedName, i as quoteIdentifier, n as escapeLiteral, o as validateEnumValueLength, t as POSTGRES_QUOTING } from "./sql-utils-Bnw3JbWf-BN0gcjZB.mjs";
3
3
  import { t as DEFAULT_NAMESPACE_ID } from "./namespace-ids-xtp_ZY86-Cxc0dBbO.mjs";
4
+ import { h as postgresCreateNamespace } from "./postgres-schema-C6w1rzOF-D1fdwqRx.mjs";
4
5
  import { A as indexDefinitionAst, B as schemaHoldsNoObjectsAst, C as disableRowLevelSecurity$1, D as dropSchema$1, E as dropPolicy, F as relationKindAst, H as sequenceValuesFitAst, I as rlsEnabledAst, L as rlsPolicyDefinitionAst, M as nativeEnumTypeExistsAst, N as nativeEnumValueExistsAst, O as dropType, P as noNullValuesAst, R as rlsPolicyExistsAst, S as createType, T as dropIndex$1, U as tableExistsAst, V as sequenceNameAvailableAst, W as tableIsEmptyAst, _ as constraintExistsAst, a as alterPolicyRename, b as createSchema, c as alterTableSetSchema, d as columnExistsAst, f as columnNullabilityAst, g as constraintDefinitionAst, h as columnTypeOidAst, i as alterIndexRename, j as indexExistsAst, k as extensionExistsAst, l as columnDefaultAst, m as columnTypeAst, n as addConstraintAction, o as alterSchemaRename, p as columnOwnsSequenceAst, q as unboundTableMovedAst, r as alterColumnTypeAction, s as alterTable, t as addColumnAction, u as columnDefaultSequenceAst, v as createIndex$1, w as dropDefaultAction, x as createTable, y as createPolicy, z as schemaExistsAst } from "./ddl-B7Rqlz6D-B7dRDgYb.mjs";
5
6
  import { i as policyRoleList, t as POLICY_COMMAND_SQL } from "./canonicalize-RdxoUHao-FTTkizfe.mjs";
6
7
  import { t as postgresObjectName } from "./postgres-object-name-FPikIvOw-B8FfJI7z.mjs";
@@ -16,11 +17,11 @@ import { expectAbsent, expectPresent } from "@prisma/orm-framework/components/co
16
17
  import { namingOf } from "@prisma/orm-family-sql/schema-ir/naming";
17
18
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
18
19
  import { checkExpression, col } from "@prisma/orm-family-sql/relational-core/contract-free";
19
- import { checkSqlDefaultText, checkSqlExpressionText, convertedColumnMeta, createSqlTextSources, isUnfilledSlot, requiredColumnMeta, slotSource, sqlOfSlot } from "@prisma/orm-family-sql/family/control";
20
+ import { checkSqlDefaultText, checkSqlExpressionText, convertedColumnMeta, createSqlTextSources, encodeStoredValue, isUnfilledSlot, requiredColumnMeta, rowsHoldingValueMeta, slotSource, sqlOfSlot } from "@prisma/orm-family-sql/family/control";
20
21
  import { unfilledPlaceholderOperation } from "@prisma/orm-framework/errors/migration";
21
22
  import { TsExpression, jsonToTsSource, tsObjectSource } from "@prisma/orm-framework/ts-render";
22
23
  import { REFERENTIAL_ACTION_SQL } from "@prisma/orm-family-sql/contract/referential-action-sql";
23
- //#region ../../../3-targets/postgres/1-target/dist/op-factory-call-gGX-mZu-.mjs
24
+ //#region ../../../3-targets/postgres/1-target/dist/op-factory-call-CNXvLsqS.mjs
24
25
  /**
25
26
  * Maps a planner schema name to the contract-free DDL builder's optional
26
27
  * `schema` field: the unbound sentinel becomes `undefined` (the builder omits
@@ -1091,6 +1092,61 @@ async function dropSchema(schemaName, lowerer) {
1091
1092
  postcheck: [step(`verify schema "${schemaName}" does not exist`, absent.sql, absent.params)]
1092
1093
  };
1093
1094
  }
1095
+ /** A stored value as operation ids, labels and step descriptions write it. */
1096
+ function storedValueText(value) {
1097
+ return JSON.stringify(value);
1098
+ }
1099
+ function idText(value) {
1100
+ return String(value);
1101
+ }
1102
+ function holdingValue(column, many) {
1103
+ return many ? `$1 = ANY(${column})` : `${column} = $1`;
1104
+ }
1105
+ function valueAbsentCheck(schemaName, tableName, columnName, value, many) {
1106
+ const column = quoteIdentifier(columnName);
1107
+ return step(many ? `verify no list in column "${columnName}" of "${tableName}" holds value ${storedValueText(value)}` : `verify no row of "${tableName}" holds value ${storedValueText(value)} in column "${columnName}"`, `SELECT NOT EXISTS (SELECT 1 FROM ${qualifyTableName(schemaName, tableName)} WHERE ${holdingValue(column, many)}) AS result`, [value]);
1108
+ }
1109
+ function replaceStoredValue(schemaName, tableName, columnName, from, to, many) {
1110
+ const column = quoteIdentifier(columnName);
1111
+ const replaced = many ? `array_replace(${column}, $1, $2)` : "$2";
1112
+ return {
1113
+ id: `replaceStoredValue.${tableName}.${columnName}.${idText(from)}`,
1114
+ label: `Replace value ${storedValueText(from)} with ${storedValueText(to)} in column "${columnName}" of "${tableName}"`,
1115
+ operationClass: "widening",
1116
+ target: targetDetails("column", columnName, schemaName, tableName),
1117
+ precheck: [],
1118
+ execute: [step(`replace value ${storedValueText(from)} with ${storedValueText(to)} in column "${columnName}"`, `UPDATE ${qualifyTableName(schemaName, tableName)} SET ${column} = ${replaced} WHERE ${holdingValue(column, many)}`, [from, to])],
1119
+ postcheck: [valueAbsentCheck(schemaName, tableName, columnName, from, many)]
1120
+ };
1121
+ }
1122
+ function removeStoredValue(schemaName, tableName, columnName, value, many, mark) {
1123
+ const column = quoteIdentifier(columnName);
1124
+ const qualified = qualifyTableName(schemaName, tableName);
1125
+ const removed = many ? `array_remove(${column}, $1)` : "NULL";
1126
+ const takesNull = `ensure column "${columnName}" of "${tableName}" takes NULL, or no row holds ${storedValueText(value)} in it`;
1127
+ return {
1128
+ id: `removeStoredValue.${tableName}.${columnName}.${idText(value)}`,
1129
+ label: `Remove value ${storedValueText(value)} from column "${columnName}" of "${tableName}"`,
1130
+ operationClass: "destructive",
1131
+ target: targetDetails("column", columnName, schemaName, tableName),
1132
+ precheck: many ? [] : [{
1133
+ ...step(takesNull, `SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = ${schemaSqlExpression(schemaName)} AND table_name = $2 AND column_name = $3 AND is_nullable = 'YES') OR NOT EXISTS (SELECT 1 FROM ${qualified} WHERE ${column} = $1) AS result`, [
1134
+ value,
1135
+ tableName,
1136
+ columnName
1137
+ ]),
1138
+ ...mark === void 0 ? {} : { meta: rowsHoldingValueMeta(mark) }
1139
+ }],
1140
+ execute: [step(`remove value ${storedValueText(value)} from column "${columnName}"`, `UPDATE ${qualified} SET ${column} = ${removed} WHERE ${holdingValue(column, many)}`, [value])],
1141
+ postcheck: [valueAbsentCheck(schemaName, tableName, columnName, value, many)]
1142
+ };
1143
+ }
1144
+ function schemaSqlExpression(schemaName) {
1145
+ return postgresCreateNamespace({
1146
+ id: schemaName,
1147
+ entries: { table: {} }
1148
+ }).schemaSqlExpression();
1149
+ }
1094
1150
  async function dropTable(schemaName, tableName, lowerer) {
1095
1151
  const qualified = qualifyTableName(schemaName, tableName);
1096
1152
  const checks = tableExistsAst(schemaName, tableName);
@@ -2608,6 +2664,105 @@ var AddNativeEnumValueCall = class extends PostgresOpFactoryCallNode {
2608
2664
  return [];
2609
2665
  }
2610
2666
  };
2667
+ function replaceStoredValueSource(location, from, to, many, codec) {
2668
+ return `this.replaceStoredValue({ ${[
2669
+ ...location,
2670
+ `from: ${from}`,
2671
+ `to: ${to}`,
2672
+ ...many ? ["many: true"] : [],
2673
+ ...codecRefSource(codec)
2674
+ ].join(", ")} })`;
2675
+ }
2676
+ function codecRefSource(codec) {
2677
+ return codec === void 0 ? [] : [`codecRef: ${jsonToTsSource(codec.codecRef)}`];
2678
+ }
2679
+ function requireStoredValue(value, factory, location, argument) {
2680
+ if (typeof value === "string" || typeof value === "number" && Number.isFinite(value)) return value;
2681
+ const got = value;
2682
+ throw postgresError("CONTRACT.ARGUMENT_INVALID", `${factory}({ ${location.join(", ")} }): ${argument} must be a string or a number; got ${typeof got === "number" || got === void 0 ? String(got) : JSON.stringify(got)}`, { meta: { what: `${factory} ${argument}` } });
2683
+ }
2684
+ /** Changes one stored value of a column to another, in every row, or in every list of a list column. */
2685
+ var ReplaceStoredValueCall = class extends PostgresOpFactoryCallNode {
2686
+ factoryName = "replaceStoredValue";
2687
+ operationClass = "widening";
2688
+ schemaName;
2689
+ tableName;
2690
+ columnName;
2691
+ from;
2692
+ to;
2693
+ many;
2694
+ /** The column's codec, which writes `from` and `to` as the database stores them. */
2695
+ codec;
2696
+ label;
2697
+ constructor(schemaName, tableName, columnName, from, to, many, codec) {
2698
+ super();
2699
+ const location = columnCallLocation(schemaName, tableName, columnName);
2700
+ this.codec = codec;
2701
+ this.schemaName = schemaName;
2702
+ this.tableName = tableName;
2703
+ this.columnName = columnName;
2704
+ this.from = requireStoredValue(from, this.factoryName, location, "from");
2705
+ this.to = requireStoredValue(to, this.factoryName, location, "to");
2706
+ this.many = many;
2707
+ this.label = `Replace value ${storedValueText(from)} with ${storedValueText(to)} in column "${columnName}" of "${tableName}"`;
2708
+ this.freeze();
2709
+ }
2710
+ async toOp() {
2711
+ return replaceStoredValue(this.schemaName, this.tableName, this.columnName, await encodeStoredValue(this.from, this.codec), await encodeStoredValue(this.to, this.codec), this.many);
2712
+ }
2713
+ renderTypeScript() {
2714
+ return replaceStoredValueSource(columnCallLocation(this.schemaName, this.tableName, this.columnName), jsonToTsSource(this.from), jsonToTsSource(this.to), this.many, this.codec);
2715
+ }
2716
+ importRequirements() {
2717
+ return [];
2718
+ }
2719
+ };
2720
+ /** Removes one stored value of a column: sets it to NULL, or takes it out of every list of a list column. */
2721
+ var RemoveStoredValueCall = class extends PostgresOpFactoryCallNode {
2722
+ factoryName = "removeStoredValue";
2723
+ operationClass = "destructive";
2724
+ schemaName;
2725
+ tableName;
2726
+ columnName;
2727
+ value;
2728
+ many;
2729
+ /** The column's codec, which writes `value` as the database stores it. */
2730
+ codec;
2731
+ /** The enum value whose stored value is removed, which the check that fails while rows of a required column hold it names. */
2732
+ enumValue;
2733
+ label;
2734
+ constructor(schemaName, tableName, columnName, value, many, codec, enumValue) {
2735
+ super();
2736
+ this.codec = codec;
2737
+ this.enumValue = enumValue;
2738
+ this.schemaName = schemaName;
2739
+ this.tableName = tableName;
2740
+ this.columnName = columnName;
2741
+ this.value = requireStoredValue(value, this.factoryName, columnCallLocation(schemaName, tableName, columnName), "value");
2742
+ this.many = many;
2743
+ this.label = `Remove value ${storedValueText(value)} from column "${columnName}" of "${tableName}"`;
2744
+ this.freeze();
2745
+ }
2746
+ async toOp() {
2747
+ return removeStoredValue(this.schemaName, this.tableName, this.columnName, await encodeStoredValue(this.value, this.codec), this.many, this.enumValue === void 0 ? void 0 : {
2748
+ enumValue: this.enumValue,
2749
+ value: this.value,
2750
+ ...this.codec === void 0 ? {} : { codecRef: this.codec.codecRef }
2751
+ });
2752
+ }
2753
+ renderTypeScript() {
2754
+ return `this.removeStoredValue({ ${[
2755
+ ...columnCallLocation(this.schemaName, this.tableName, this.columnName),
2756
+ `value: ${jsonToTsSource(this.value)}`,
2757
+ ...this.many ? ["many: true"] : [],
2758
+ ...codecRefSource(this.codec),
2759
+ ...this.enumValue === void 0 ? [] : [`enumValue: ${jsonToTsSource(this.enumValue)}`]
2760
+ ].join(", ")} })`;
2761
+ }
2762
+ importRequirements() {
2763
+ return [];
2764
+ }
2765
+ };
2611
2766
  /**
2612
2767
  * A planner-generated data-transform stub. `checkSlot` and `runSlot` name
2613
2768
  * the unfilled authoring slots that the rendered `migration.ts` will expose
@@ -2813,6 +2968,6 @@ function columnNameOfCall(call) {
2813
2968
  if ("column" in call && call.column instanceof DdlColumn) return call.column.name;
2814
2969
  }
2815
2970
  //#endregion
2816
- export { RenameColumnCall as A, alterColumnTypeCallText as B, DropNativeEnumTypeCall as C, DropTableCall as D, DropSchemaCall as E, RenameTableCall as F, postgresDefaultToDdlColumnDefault as G, createExtension as H, SCHEMA_OBJECTS_SQL as I, schemaContentsOf as J, renameTableStatement as K, SetDefaultCall as L, RenameIndexCall as M, RenamePostgresRlsPolicyCall as N, EnableRowLevelSecurityCall as O, RenameSchemaCall as P, SetNotNullCall as R, DropIndexCall as S, DropPostgresRlsPolicyCall as T, installExtension as U, columnNameOfCall as V, isPostgresOpFactoryCall as W, schemaObjectsSummary as Y, DisableRowLevelSecurityCall as _, AddNativeEnumValueCall as a, DropConstraintCall as b, AddUniqueCall as c, CreateIndexCall as d, CreateNativeEnumTypeCall as f, DataTransformCall as g, CreateTableCall as h, AddForeignKeyCall as i, RenameConstraintCall as j, RawSqlCall as k, AlterColumnTypeCall as l, CreateSchemaCall as m, AddColumnCall as n, AddPrimaryKeyCall as o, CreatePostgresRlsPolicyCall as p, schemaBlockingObjects as q, AddColumnWithTemporaryDefaultCall as r, AddRequiredColumnToEmptyTableCall as s, AddCheckConstraintCall as t, CreateExtensionCall as u, DropCheckConstraintCall as v, DropNotNullCall as w, DropDefaultCall as x, DropColumnCall as y, SetTableSchemaCall as z };
2971
+ export { RemoveStoredValueCall as A, SetNotNullCall as B, DropNativeEnumTypeCall as C, DropTableCall as D, DropSchemaCall as E, RenameSchemaCall as F, installExtension as G, alterColumnTypeCallText as H, RenameTableCall as I, renameTableStatement as J, isPostgresOpFactoryCall as K, ReplaceStoredValueCall as L, RenameConstraintCall as M, RenameIndexCall as N, EnableRowLevelSecurityCall as O, RenamePostgresRlsPolicyCall as P, SCHEMA_OBJECTS_SQL as R, DropIndexCall as S, DropPostgresRlsPolicyCall as T, columnNameOfCall as U, SetTableSchemaCall as V, createExtension as W, schemaContentsOf as X, schemaBlockingObjects as Y, schemaObjectsSummary as Z, DisableRowLevelSecurityCall as _, AddNativeEnumValueCall as a, DropConstraintCall as b, AddUniqueCall as c, CreateIndexCall as d, CreateNativeEnumTypeCall as f, DataTransformCall as g, CreateTableCall as h, AddForeignKeyCall as i, RenameColumnCall as j, RawSqlCall as k, AlterColumnTypeCall as l, CreateSchemaCall as m, AddColumnCall as n, AddPrimaryKeyCall as o, CreatePostgresRlsPolicyCall as p, postgresDefaultToDdlColumnDefault as q, AddColumnWithTemporaryDefaultCall as r, AddRequiredColumnToEmptyTableCall as s, AddCheckConstraintCall as t, CreateExtensionCall as u, DropCheckConstraintCall as v, DropNotNullCall as w, DropDefaultCall as x, DropColumnCall as y, SetDefaultCall as z };
2817
2972
 
2818
- //# sourceMappingURL=op-factory-call-gGX-mZu--0QUG5xH4.mjs.map
2973
+ //# sourceMappingURL=op-factory-call-CNXvLsqS-BT9PCNDI.mjs.map