drizzle-kit 0.26.2-4cb1bdb → 0.26.2-53e089b

Sign up to get free protection for your applications and to get access to all the features.
package/api.mjs CHANGED
@@ -7727,7 +7727,7 @@ var init_vector = __esm({
7727
7727
  });
7728
7728
 
7729
7729
  // src/serializer/pgSchema.ts
7730
- var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, roleSchema, sequenceSquashed, columnV7, column2, checkConstraint2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, policy, viewWithOption, matViewWithOption, mergedViewWithOption, view2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
7730
+ var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, roleSchema, sequenceSquashed, columnV7, column2, checkConstraint2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, policy, policySquashed, viewWithOption, matViewWithOption, mergedViewWithOption, view2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
7731
7731
  var init_pgSchema = __esm({
7732
7732
  "src/serializer/pgSchema.ts"() {
7733
7733
  "use strict";
@@ -7938,7 +7938,12 @@ var init_pgSchema = __esm({
7938
7938
  for: enumType(["ALL", "SELECT", "INSERT", "UPDATE", "DELETE"]).optional(),
7939
7939
  to: stringType().array().optional(),
7940
7940
  using: stringType().optional(),
7941
- withCheck: stringType().optional()
7941
+ withCheck: stringType().optional(),
7942
+ on: stringType().optional()
7943
+ }).strict();
7944
+ policySquashed = objectType({
7945
+ name: stringType(),
7946
+ values: stringType()
7942
7947
  }).strict();
7943
7948
  viewWithOption = objectType({
7944
7949
  checkOption: enumType(["local", "cascaded"]).optional(),
@@ -8118,6 +8123,7 @@ var init_pgSchema = __esm({
8118
8123
  views: recordType(stringType(), view2).default({}),
8119
8124
  sequences: recordType(stringType(), sequenceSchema).default({}),
8120
8125
  roles: recordType(stringType(), roleSchema).default({}),
8126
+ policies: recordType(stringType(), policy).default({}),
8121
8127
  _meta: objectType({
8122
8128
  schemas: recordType(stringType(), stringType()),
8123
8129
  tables: recordType(stringType(), stringType()),
@@ -8166,7 +8172,8 @@ var init_pgSchema = __esm({
8166
8172
  schemas: recordType(stringType(), stringType()),
8167
8173
  views: recordType(stringType(), view2),
8168
8174
  sequences: recordType(stringType(), sequenceSquashed),
8169
- roles: recordType(stringType(), roleSchema).default({})
8175
+ roles: recordType(stringType(), roleSchema).default({}),
8176
+ policies: recordType(stringType(), policy).default({})
8170
8177
  }).strict();
8171
8178
  pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
8172
8179
  pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
@@ -8249,22 +8256,23 @@ var init_pgSchema = __esm({
8249
8256
  squashFK: (fk4) => {
8250
8257
  return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo || "public"}`;
8251
8258
  },
8252
- squashPolicy: (policy2) => {
8253
- return `${policy2.name}--${policy2.as}--${policy2.for}--${policy2.to?.join(",")}--${policy2.using}--${policy2.withCheck}`;
8259
+ squashPolicy: (policy4) => {
8260
+ return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.using}--${policy4.withCheck}--${policy4.on}`;
8254
8261
  },
8255
- unsquashPolicy: (policy2) => {
8256
- const splitted = policy2.split("--");
8262
+ unsquashPolicy: (policy4) => {
8263
+ const splitted = policy4.split("--");
8257
8264
  return {
8258
8265
  name: splitted[0],
8259
8266
  as: splitted[1],
8260
8267
  for: splitted[2],
8261
8268
  to: splitted[3].split(","),
8262
8269
  using: splitted[4] !== "undefined" ? splitted[4] : void 0,
8263
- withCheck: splitted[5] !== "undefined" ? splitted[5] : void 0
8270
+ withCheck: splitted[5] !== "undefined" ? splitted[5] : void 0,
8271
+ on: splitted[6] !== "undefined" ? splitted[6] : void 0
8264
8272
  };
8265
8273
  },
8266
- squashPolicyPush: (policy2) => {
8267
- return `${policy2.name}--${policy2.as}--${policy2.for}--${policy2.to?.join(",")}`;
8274
+ squashPolicyPush: (policy4) => {
8275
+ return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.on}`;
8268
8276
  },
8269
8277
  squashPK: (pk) => {
8270
8278
  return `${pk.columns.join(",")};${pk.name}`;
@@ -8378,8 +8386,8 @@ var init_pgSchema = __esm({
8378
8386
  return PgSquasher.squashUnique(unq);
8379
8387
  }
8380
8388
  );
8381
- const squashedPolicies = mapValues(it[1].policies, (policy2) => {
8382
- return action === "push" ? PgSquasher.squashPolicyPush(policy2) : PgSquasher.squashPolicy(policy2);
8389
+ const squashedPolicies = mapValues(it[1].policies, (policy4) => {
8390
+ return action === "push" ? PgSquasher.squashPolicyPush(policy4) : PgSquasher.squashPolicy(policy4);
8383
8391
  });
8384
8392
  const squashedChecksContraints = mapValues(
8385
8393
  it[1].checkConstraints,
@@ -8416,6 +8424,17 @@ var init_pgSchema = __esm({
8416
8424
  ];
8417
8425
  })
8418
8426
  );
8427
+ const mappedPolicies = Object.fromEntries(
8428
+ Object.entries(json3.policies).map((it) => {
8429
+ return [
8430
+ it[0],
8431
+ {
8432
+ name: it[1].name,
8433
+ values: action === "push" ? PgSquasher.squashPolicyPush(it[1]) : PgSquasher.squashPolicy(it[1])
8434
+ }
8435
+ ];
8436
+ })
8437
+ );
8419
8438
  return {
8420
8439
  version: "7",
8421
8440
  dialect: json3.dialect,
@@ -8423,6 +8442,7 @@ var init_pgSchema = __esm({
8423
8442
  enums: json3.enums,
8424
8443
  schemas: json3.schemas,
8425
8444
  views: json3.views,
8445
+ policies: mappedPolicies,
8426
8446
  sequences: mappedSequences,
8427
8447
  roles: json3.roles
8428
8448
  };
@@ -8435,6 +8455,8 @@ var init_pgSchema = __esm({
8435
8455
  tables: {},
8436
8456
  enums: {},
8437
8457
  schemas: {},
8458
+ policies: {},
8459
+ roles: {},
8438
8460
  sequences: {},
8439
8461
  _meta: {
8440
8462
  schemas: {},
@@ -11431,6 +11453,14 @@ function diffSchemasOrTables(left, right) {
11431
11453
  const deleted = result.filter((it) => it[0].endsWith("__deleted")).map((it) => it[1]);
11432
11454
  return { added, deleted };
11433
11455
  }
11456
+ function diffIndPolicies(left, right) {
11457
+ left = JSON.parse(JSON.stringify(left));
11458
+ right = JSON.parse(JSON.stringify(right));
11459
+ const result = Object.entries((0, import_json_diff.diff)(left, right) ?? {});
11460
+ const added = result.filter((it) => it[0].endsWith("__added")).map((it) => it[1]);
11461
+ const deleted = result.filter((it) => it[0].endsWith("__deleted")).map((it) => it[1]);
11462
+ return { added, deleted };
11463
+ }
11434
11464
  function diffColumns(left, right) {
11435
11465
  left = JSON.parse(JSON.stringify(left));
11436
11466
  right = JSON.parse(JSON.stringify(right));
@@ -11503,6 +11533,7 @@ function applyJsonDiff(json1, json22) {
11503
11533
  difference.enums = difference.enums || {};
11504
11534
  difference.sequences = difference.sequences || {};
11505
11535
  difference.roles = difference.roles || {};
11536
+ difference.policies = difference.policies || {};
11506
11537
  difference.views = difference.views || {};
11507
11538
  const schemaKeys = Object.keys(difference.schemas);
11508
11539
  for (let key of schemaKeys) {
@@ -11563,6 +11594,10 @@ function applyJsonDiff(json1, json22) {
11563
11594
  const alteredRoles = rolesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map((it) => {
11564
11595
  return json22.roles[it[0]];
11565
11596
  });
11597
+ const policiesEntries = Object.entries(difference.policies);
11598
+ const alteredPolicies = policiesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map((it) => {
11599
+ return json22.policies[it[0]];
11600
+ });
11566
11601
  const viewsEntries = Object.entries(difference.views);
11567
11602
  const alteredViews = viewsEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map(
11568
11603
  ([nameWithSchema, view4]) => {
@@ -11637,7 +11672,8 @@ function applyJsonDiff(json1, json22) {
11637
11672
  alteredEnums,
11638
11673
  alteredSequences,
11639
11674
  alteredRoles,
11640
- alteredViews
11675
+ alteredViews,
11676
+ alteredPolicies
11641
11677
  };
11642
11678
  }
11643
11679
  var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
@@ -12094,7 +12130,7 @@ function fromJson(statements, dialect4, action, json22) {
12094
12130
  }).filter((it) => it !== "");
12095
12131
  return result;
12096
12132
  }
12097
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
12133
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgCreateIndPolicyConvertor, PgDropIndPolicyConvertor, PgRenameIndPolicyConvertor, PgAlterIndPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
12098
12134
  var init_sqlgenerator = __esm({
12099
12135
  "src/sqlgenerator.ts"() {
12100
12136
  "use strict";
@@ -12187,14 +12223,14 @@ var init_sqlgenerator = __esm({
12187
12223
  return statement.type === "create_policy" && dialect4 === "postgresql";
12188
12224
  }
12189
12225
  convert(statement) {
12190
- const policy2 = statement.data;
12226
+ const policy4 = statement.data;
12191
12227
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12192
- const usingPart = policy2.using ? ` USING (${policy2.using})` : "";
12193
- const withCheckPart = policy2.withCheck ? ` WITH CHECK (${policy2.withCheck})` : "";
12194
- const policyToPart = policy2.to?.map(
12228
+ const usingPart = policy4.using ? ` USING (${policy4.using})` : "";
12229
+ const withCheckPart = policy4.withCheck ? ` WITH CHECK (${policy4.withCheck})` : "";
12230
+ const policyToPart = policy4.to?.map(
12195
12231
  (v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
12196
12232
  ).join(", ");
12197
- return `CREATE POLICY "${policy2.name}" ON ${tableNameWithSchema} AS ${policy2.as?.toUpperCase()} FOR ${policy2.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12233
+ return `CREATE POLICY "${policy4.name}" ON ${tableNameWithSchema} AS ${policy4.as?.toUpperCase()} FOR ${policy4.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12198
12234
  }
12199
12235
  };
12200
12236
  PgDropPolicyConvertor = class extends Convertor {
@@ -12202,9 +12238,9 @@ var init_sqlgenerator = __esm({
12202
12238
  return statement.type === "drop_policy" && dialect4 === "postgresql";
12203
12239
  }
12204
12240
  convert(statement) {
12205
- const policy2 = statement.data;
12241
+ const policy4 = statement.data;
12206
12242
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12207
- return `DROP POLICY "${policy2.name}" ON ${tableNameWithSchema} CASCADE;`;
12243
+ return `DROP POLICY "${policy4.name}" ON ${tableNameWithSchema} CASCADE;`;
12208
12244
  }
12209
12245
  };
12210
12246
  PgRenamePolicyConvertor = class extends Convertor {
@@ -12229,6 +12265,49 @@ var init_sqlgenerator = __esm({
12229
12265
  return `ALTER POLICY "${oldPolicy.name}" ON ${tableNameWithSchema} TO ${newPolicy.to}${usingPart}${withCheckPart};`;
12230
12266
  }
12231
12267
  };
12268
+ PgCreateIndPolicyConvertor = class extends Convertor {
12269
+ can(statement, dialect4) {
12270
+ return statement.type === "create_ind_policy" && dialect4 === "postgresql";
12271
+ }
12272
+ convert(statement) {
12273
+ const policy4 = statement.data;
12274
+ const usingPart = policy4.using ? ` USING (${policy4.using})` : "";
12275
+ const withCheckPart = policy4.withCheck ? ` WITH CHECK (${policy4.withCheck})` : "";
12276
+ const policyToPart = policy4.to?.map(
12277
+ (v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
12278
+ ).join(", ");
12279
+ return `CREATE POLICY "${policy4.name}" ON ${policy4.on} AS ${policy4.as?.toUpperCase()} FOR ${policy4.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12280
+ }
12281
+ };
12282
+ PgDropIndPolicyConvertor = class extends Convertor {
12283
+ can(statement, dialect4) {
12284
+ return statement.type === "drop_ind_policy" && dialect4 === "postgresql";
12285
+ }
12286
+ convert(statement) {
12287
+ const policy4 = statement.data;
12288
+ return `DROP POLICY "${policy4.name}" ON ${policy4.on} CASCADE;`;
12289
+ }
12290
+ };
12291
+ PgRenameIndPolicyConvertor = class extends Convertor {
12292
+ can(statement, dialect4) {
12293
+ return statement.type === "rename_ind_policy" && dialect4 === "postgresql";
12294
+ }
12295
+ convert(statement) {
12296
+ return `ALTER POLICY "${statement.oldName}" ON ${statement.tableKey} RENAME TO "${statement.newName}";`;
12297
+ }
12298
+ };
12299
+ PgAlterIndPolicyConvertor = class extends Convertor {
12300
+ can(statement, dialect4) {
12301
+ return statement.type === "alter_ind_policy" && dialect4 === "postgresql";
12302
+ }
12303
+ convert(statement) {
12304
+ const newPolicy = statement.newData;
12305
+ const oldPolicy = statement.oldData;
12306
+ const usingPart = newPolicy.using ? ` USING (${newPolicy.using})` : oldPolicy.using ? ` USING (${oldPolicy.using})` : "";
12307
+ const withCheckPart = newPolicy.withCheck ? ` WITH CHECK (${newPolicy.withCheck})` : oldPolicy.withCheck ? ` WITH CHECK (${oldPolicy.withCheck})` : "";
12308
+ return `ALTER POLICY "${oldPolicy.name}" ON ${oldPolicy.on} TO ${newPolicy.to}${usingPart}${withCheckPart};`;
12309
+ }
12310
+ };
12232
12311
  PgEnableRlsConvertor = class extends Convertor {
12233
12312
  can(statement, dialect4) {
12234
12313
  return statement.type === "enable_rls" && dialect4 === "postgresql";
@@ -14120,6 +14199,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
14120
14199
  convertors.push(new PgCreatePolicyConvertor());
14121
14200
  convertors.push(new PgDropPolicyConvertor());
14122
14201
  convertors.push(new PgRenamePolicyConvertor());
14202
+ convertors.push(new PgAlterIndPolicyConvertor());
14203
+ convertors.push(new PgCreateIndPolicyConvertor());
14204
+ convertors.push(new PgDropIndPolicyConvertor());
14205
+ convertors.push(new PgRenameIndPolicyConvertor());
14123
14206
  convertors.push(new PgEnableRlsConvertor());
14124
14207
  convertors.push(new PgDisableRlsConvertor());
14125
14208
  convertors.push(new PgDropRoleConvertor());
@@ -14425,7 +14508,7 @@ var init_sqlitePushUtils = __esm({
14425
14508
  });
14426
14509
 
14427
14510
  // src/jsonStatements.ts
14428
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateRoleJson, prepareAlterRoleJson, prepareDropRoleJson, prepareRenameRoleJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, prepareRenamePolicyJsons, prepareCreatePolicyJsons, prepareDropPolicyJsons, prepareAlterPolicyJson, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCheckConstraint, prepareDeleteCheckConstraint, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql, preparePgCreateViewJson, prepareMySqlCreateViewJson, prepareSqliteCreateViewJson, prepareDropViewJson, prepareRenameViewJson, preparePgAlterViewAlterSchemaJson, preparePgAlterViewAddWithOptionJson, preparePgAlterViewDropWithOptionJson, preparePgAlterViewAlterTablespaceJson, preparePgAlterViewAlterUsingJson, prepareMySqlAlterView;
14511
+ var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateRoleJson, prepareAlterRoleJson, prepareDropRoleJson, prepareRenameRoleJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, prepareRenamePolicyJsons, prepareRenameIndPolicyJsons, prepareCreatePolicyJsons, prepareCreateIndPolicyJsons, prepareDropPolicyJsons, prepareDropIndPolicyJsons, prepareAlterPolicyJson, prepareAlterIndPolicyJson, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCheckConstraint, prepareDeleteCheckConstraint, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql, preparePgCreateViewJson, prepareMySqlCreateViewJson, prepareSqliteCreateViewJson, prepareDropViewJson, prepareRenameViewJson, preparePgAlterViewAlterSchemaJson, preparePgAlterViewAddWithOptionJson, preparePgAlterViewDropWithOptionJson, preparePgAlterViewAlterTablespaceJson, preparePgAlterViewAlterUsingJson, prepareMySqlAlterView;
14429
14512
  var init_jsonStatements = __esm({
14430
14513
  "src/jsonStatements.ts"() {
14431
14514
  "use strict";
@@ -15550,6 +15633,16 @@ var init_jsonStatements = __esm({
15550
15633
  };
15551
15634
  });
15552
15635
  };
15636
+ prepareRenameIndPolicyJsons = (renames) => {
15637
+ return renames.map((it) => {
15638
+ return {
15639
+ type: "rename_ind_policy",
15640
+ tableKey: it.from.on,
15641
+ oldName: it.from.name,
15642
+ newName: it.to.name
15643
+ };
15644
+ });
15645
+ };
15553
15646
  prepareCreatePolicyJsons = (tableName, schema4, policies) => {
15554
15647
  return policies.map((it) => {
15555
15648
  return {
@@ -15560,6 +15653,15 @@ var init_jsonStatements = __esm({
15560
15653
  };
15561
15654
  });
15562
15655
  };
15656
+ prepareCreateIndPolicyJsons = (policies) => {
15657
+ return policies.map((it) => {
15658
+ return {
15659
+ type: "create_ind_policy",
15660
+ tableName: it.on,
15661
+ data: it
15662
+ };
15663
+ });
15664
+ };
15563
15665
  prepareDropPolicyJsons = (tableName, schema4, policies) => {
15564
15666
  return policies.map((it) => {
15565
15667
  return {
@@ -15570,6 +15672,15 @@ var init_jsonStatements = __esm({
15570
15672
  };
15571
15673
  });
15572
15674
  };
15675
+ prepareDropIndPolicyJsons = (policies) => {
15676
+ return policies.map((it) => {
15677
+ return {
15678
+ type: "drop_ind_policy",
15679
+ tableName: it.on,
15680
+ data: it
15681
+ };
15682
+ });
15683
+ };
15573
15684
  prepareAlterPolicyJson = (tableName, schema4, oldPolicy, newPolicy) => {
15574
15685
  return {
15575
15686
  type: "alter_policy",
@@ -15579,6 +15690,13 @@ var init_jsonStatements = __esm({
15579
15690
  schema: schema4
15580
15691
  };
15581
15692
  };
15693
+ prepareAlterIndPolicyJson = (oldPolicy, newPolicy) => {
15694
+ return {
15695
+ type: "alter_ind_policy",
15696
+ oldData: oldPolicy,
15697
+ newData: newPolicy
15698
+ };
15699
+ };
15582
15700
  preparePgCreateIndexesJson = (tableName, schema4, indexes, fullSchema, action) => {
15583
15701
  if (action === "push") {
15584
15702
  return Object.values(indexes).map((indexData) => {
@@ -16520,6 +16638,7 @@ var init_snapshotsDiffer = __esm({
16520
16638
  alteredEnums: changedEnumSchema.array(),
16521
16639
  alteredSequences: sequenceSquashed.array(),
16522
16640
  alteredRoles: roleSchema.array(),
16641
+ alteredPolicies: policySquashed.array(),
16523
16642
  alteredViews: alteredPgViewSchema.array()
16524
16643
  }).strict();
16525
16644
  diffResultSchemeMysql = objectType({
@@ -16577,7 +16696,7 @@ var init_snapshotsDiffer = __esm({
16577
16696
  }
16578
16697
  return column4;
16579
16698
  };
16580
- applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, policyResolver2, roleResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
16699
+ applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, policyResolver2, indPolicyResolver2, roleResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
16581
16700
  const schemasDiff = diffSchemasOrTables(json1.schemas, json22.schemas);
16582
16701
  const {
16583
16702
  created: createdSchemas,
@@ -16794,24 +16913,24 @@ var init_snapshotsDiffer = __esm({
16794
16913
  const columnCreates = [];
16795
16914
  const columnDeletes = [];
16796
16915
  for (let entry of Object.values(res)) {
16797
- const { renamed, created, deleted } = await columnsResolver2({
16916
+ const { renamed, created: created2, deleted: deleted2 } = await columnsResolver2({
16798
16917
  tableName: entry.name,
16799
16918
  schema: entry.schema,
16800
16919
  deleted: entry.columns.deleted,
16801
16920
  created: entry.columns.added
16802
16921
  });
16803
- if (created.length > 0) {
16922
+ if (created2.length > 0) {
16804
16923
  columnCreates.push({
16805
16924
  table: entry.name,
16806
16925
  schema: entry.schema,
16807
- columns: created
16926
+ columns: created2
16808
16927
  });
16809
16928
  }
16810
- if (deleted.length > 0) {
16929
+ if (deleted2.length > 0) {
16811
16930
  columnDeletes.push({
16812
16931
  table: entry.name,
16813
16932
  schema: entry.schema,
16814
- columns: deleted
16933
+ columns: deleted2
16815
16934
  });
16816
16935
  }
16817
16936
  if (renamed.length > 0) {
@@ -16851,24 +16970,24 @@ var init_snapshotsDiffer = __esm({
16851
16970
  const policyCreates = [];
16852
16971
  const policyDeletes = [];
16853
16972
  for (let entry of Object.values(policyRes)) {
16854
- const { renamed, created, deleted } = await policyResolver2({
16973
+ const { renamed, created: created2, deleted: deleted2 } = await policyResolver2({
16855
16974
  tableName: entry.name,
16856
16975
  schema: entry.schema,
16857
16976
  deleted: entry.policies.deleted.map(PgSquasher.unsquashPolicy),
16858
16977
  created: entry.policies.added.map(PgSquasher.unsquashPolicy)
16859
16978
  });
16860
- if (created.length > 0) {
16979
+ if (created2.length > 0) {
16861
16980
  policyCreates.push({
16862
16981
  table: entry.name,
16863
16982
  schema: entry.schema,
16864
- columns: created
16983
+ columns: created2
16865
16984
  });
16866
16985
  }
16867
- if (deleted.length > 0) {
16986
+ if (deleted2.length > 0) {
16868
16987
  policyDeletes.push({
16869
16988
  table: entry.name,
16870
16989
  schema: entry.schema,
16871
- columns: deleted
16990
+ columns: deleted2
16872
16991
  });
16873
16992
  }
16874
16993
  if (renamed.length > 0) {
@@ -16892,12 +17011,12 @@ var init_snapshotsDiffer = __esm({
16892
17011
  (tableKey2, tableValue) => {
16893
17012
  const patchedPolicies = mapKeys(
16894
17013
  tableValue.policies,
16895
- (policyKey, policy2) => {
17014
+ (policyKey, policy4) => {
16896
17015
  const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
16897
17016
  const newName = columnChangeFor(policyKey, rens);
16898
- const unsquashedPolicy = PgSquasher.unsquashPolicy(policy2);
17017
+ const unsquashedPolicy = PgSquasher.unsquashPolicy(policy4);
16899
17018
  unsquashedPolicy.name = newName;
16900
- policy2 = PgSquasher.squashPolicy(unsquashedPolicy);
17019
+ policy4 = PgSquasher.squashPolicy(unsquashedPolicy);
16901
17020
  return newName;
16902
17021
  }
16903
17022
  );
@@ -16905,7 +17024,46 @@ var init_snapshotsDiffer = __esm({
16905
17024
  return [tableKey2, tableValue];
16906
17025
  }
16907
17026
  );
16908
- const viewsDiff = diffSchemasOrTables(policyPatchedSnap1.views, json22.views);
17027
+ const indPolicyRes = diffIndPolicies(policyPatchedSnap1.policies, json22.policies);
17028
+ const indPolicyCreates = [];
17029
+ const indPolicyDeletes = [];
17030
+ const { renamed: indPolicyRenames, created, deleted } = await indPolicyResolver2({
17031
+ deleted: indPolicyRes.deleted.map((t) => PgSquasher.unsquashPolicy(t.values)),
17032
+ created: indPolicyRes.added.map((t) => PgSquasher.unsquashPolicy(t.values))
17033
+ });
17034
+ if (created.length > 0) {
17035
+ indPolicyCreates.push({
17036
+ policies: created
17037
+ });
17038
+ }
17039
+ if (deleted.length > 0) {
17040
+ indPolicyDeletes.push({
17041
+ policies: deleted
17042
+ });
17043
+ }
17044
+ const indPolicyRenamesDict = indPolicyRenames.reduce(
17045
+ (acc, it) => {
17046
+ acc[it.from.name] = {
17047
+ nameFrom: it.from.name,
17048
+ nameTo: it.to.name
17049
+ };
17050
+ return acc;
17051
+ },
17052
+ {}
17053
+ );
17054
+ const indPolicyPatchedSnap1 = copy(policyPatchedSnap1);
17055
+ indPolicyPatchedSnap1.policies = mapEntries(
17056
+ indPolicyPatchedSnap1.policies,
17057
+ (policyKey, policyValue) => {
17058
+ const key = policyKey;
17059
+ const change = indPolicyRenamesDict[key];
17060
+ if (change) {
17061
+ policyValue.name = change.nameTo;
17062
+ }
17063
+ return [policyKey, policyValue];
17064
+ }
17065
+ );
17066
+ const viewsDiff = diffSchemasOrTables(indPolicyPatchedSnap1.views, json22.views);
16909
17067
  const {
16910
17068
  created: createdViews,
16911
17069
  deleted: deletedViews,
@@ -17046,16 +17204,16 @@ var init_snapshotsDiffer = __esm({
17046
17204
  );
17047
17205
  if (it.alteredUniqueConstraints) {
17048
17206
  const added = {};
17049
- const deleted = {};
17207
+ const deleted2 = {};
17050
17208
  for (const k of Object.keys(it.alteredUniqueConstraints)) {
17051
17209
  added[k] = it.alteredUniqueConstraints[k].__new;
17052
- deleted[k] = it.alteredUniqueConstraints[k].__old;
17210
+ deleted2[k] = it.alteredUniqueConstraints[k].__old;
17053
17211
  }
17054
17212
  addedUniqueConstraints.push(
17055
17213
  ...prepareAddUniqueConstraintPg(it.name, it.schema, added)
17056
17214
  );
17057
17215
  deletedUniqueConstraints.push(
17058
- ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
17216
+ ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted2)
17059
17217
  );
17060
17218
  }
17061
17219
  createCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
@@ -17066,13 +17224,13 @@ var init_snapshotsDiffer = __esm({
17066
17224
  );
17067
17225
  if (it.alteredCheckConstraints && action !== "push") {
17068
17226
  const added = {};
17069
- const deleted = {};
17227
+ const deleted2 = {};
17070
17228
  for (const k of Object.keys(it.alteredCheckConstraints)) {
17071
17229
  added[k] = it.alteredCheckConstraints[k].__new;
17072
- deleted[k] = it.alteredCheckConstraints[k].__old;
17230
+ deleted2[k] = it.alteredCheckConstraints[k].__old;
17073
17231
  }
17074
17232
  createCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
17075
- deleteCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
17233
+ deleteCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted2));
17076
17234
  }
17077
17235
  jsonCreatedCheckConstraints.push(...createCheckConstraints);
17078
17236
  jsonDeletedCheckConstraints.push(...deleteCheckConstraints);
@@ -17120,8 +17278,68 @@ var init_snapshotsDiffer = __esm({
17120
17278
  const jsonDropPoliciesStatements = [];
17121
17279
  const jsonAlterPoliciesStatements = [];
17122
17280
  const jsonRenamePoliciesStatements = [];
17281
+ const jsonRenameIndPoliciesStatements = [];
17282
+ const jsonCreateIndPoliciesStatements = [];
17283
+ const jsonDropIndPoliciesStatements = [];
17284
+ const jsonAlterIndPoliciesStatements = [];
17123
17285
  const jsonEnableRLSStatements = [];
17124
17286
  const jsonDisableRLSStatements = [];
17287
+ for (let it of indPolicyRenames) {
17288
+ jsonRenameIndPoliciesStatements.push(
17289
+ ...prepareRenameIndPolicyJsons([it])
17290
+ );
17291
+ }
17292
+ for (const it of indPolicyCreates) {
17293
+ jsonCreateIndPoliciesStatements.push(
17294
+ ...prepareCreateIndPolicyJsons(
17295
+ it.policies
17296
+ )
17297
+ );
17298
+ }
17299
+ for (const it of indPolicyDeletes) {
17300
+ jsonDropIndPoliciesStatements.push(
17301
+ ...prepareDropIndPolicyJsons(
17302
+ it.policies
17303
+ )
17304
+ );
17305
+ }
17306
+ typedResult.alteredPolicies.forEach(({ values }) => {
17307
+ const policy4 = PgSquasher.unsquashPolicy(values);
17308
+ const newPolicy = json1.policies[policy4.name];
17309
+ const oldPolicy = json22.policies[policy4.name];
17310
+ if (newPolicy.as !== oldPolicy.as) {
17311
+ jsonDropIndPoliciesStatements.push(
17312
+ ...prepareDropIndPolicyJsons(
17313
+ [oldPolicy]
17314
+ )
17315
+ );
17316
+ jsonCreateIndPoliciesStatements.push(
17317
+ ...prepareCreateIndPolicyJsons(
17318
+ [newPolicy]
17319
+ )
17320
+ );
17321
+ return;
17322
+ }
17323
+ if (newPolicy.for !== oldPolicy.for) {
17324
+ jsonDropIndPoliciesStatements.push(
17325
+ ...prepareDropIndPolicyJsons(
17326
+ [oldPolicy]
17327
+ )
17328
+ );
17329
+ jsonCreateIndPoliciesStatements.push(
17330
+ ...prepareCreateIndPolicyJsons(
17331
+ [newPolicy]
17332
+ )
17333
+ );
17334
+ return;
17335
+ }
17336
+ jsonAlterIndPoliciesStatements.push(
17337
+ prepareAlterIndPolicyJson(
17338
+ oldPolicy,
17339
+ newPolicy
17340
+ )
17341
+ );
17342
+ });
17125
17343
  for (let it of policyRenames) {
17126
17344
  jsonRenamePoliciesStatements.push(
17127
17345
  ...prepareRenamePolicyJsons(it.table, it.schema, it.renames)
@@ -17509,6 +17727,10 @@ var init_snapshotsDiffer = __esm({
17509
17727
  jsonStatements.push(...jsonDropPoliciesStatements);
17510
17728
  jsonStatements.push(...jsonCreatePoliciesStatements);
17511
17729
  jsonStatements.push(...jsonAlterPoliciesStatements);
17730
+ jsonStatements.push(...jsonRenameIndPoliciesStatements);
17731
+ jsonStatements.push(...jsonDropIndPoliciesStatements);
17732
+ jsonStatements.push(...jsonCreateIndPoliciesStatements);
17733
+ jsonStatements.push(...jsonAlterIndPoliciesStatements);
17512
17734
  jsonStatements.push(...createViews);
17513
17735
  jsonStatements.push(...dropEnums);
17514
17736
  jsonStatements.push(...dropSequences);
@@ -18901,7 +19123,7 @@ var init_outputs = __esm({
18901
19123
  });
18902
19124
 
18903
19125
  // src/cli/commands/migrate.ts
18904
- var import_hanji2, schemasResolver, tablesResolver, viewsResolver, mySqlViewsResolver, sqliteViewsResolver, sequencesResolver, roleResolver, policyResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedConflict, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
19126
+ var import_hanji2, schemasResolver, tablesResolver, viewsResolver, mySqlViewsResolver, sqliteViewsResolver, sequencesResolver, roleResolver, policyResolver, indPolicyResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedConflict, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
18905
19127
  var init_migrate = __esm({
18906
19128
  "src/cli/commands/migrate.ts"() {
18907
19129
  "use strict";
@@ -19044,6 +19266,18 @@ var init_migrate = __esm({
19044
19266
  renamed: result.renamed
19045
19267
  };
19046
19268
  };
19269
+ indPolicyResolver = async (input) => {
19270
+ const result = await promptNamedConflict(
19271
+ input.created,
19272
+ input.deleted,
19273
+ "policy"
19274
+ );
19275
+ return {
19276
+ created: result.created,
19277
+ deleted: result.deleted,
19278
+ renamed: result.renamed
19279
+ };
19280
+ };
19047
19281
  enumsResolver = async (input) => {
19048
19282
  try {
19049
19283
  const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
@@ -27496,6 +27730,8 @@ var init_policies = __esm({
27496
27730
  __publicField(this, "to");
27497
27731
  __publicField(this, "using");
27498
27732
  __publicField(this, "withCheck");
27733
+ /** @internal */
27734
+ __publicField(this, "_linkedTable");
27499
27735
  this.name = name2;
27500
27736
  if (config) {
27501
27737
  this.as = config.as;
@@ -27505,6 +27741,10 @@ var init_policies = __esm({
27505
27741
  this.withCheck = config.withCheck;
27506
27742
  }
27507
27743
  }
27744
+ link(table4) {
27745
+ this._linkedTable = table4;
27746
+ return this;
27747
+ }
27508
27748
  };
27509
27749
  __publicField(PgPolicy, _a147, "PgPolicy");
27510
27750
  }
@@ -28170,12 +28410,13 @@ var init_pgSerializer = __esm({
28170
28410
  indexName = (tableName, columns) => {
28171
28411
  return `${tableName}_${columns.join("_")}_index`;
28172
28412
  };
28173
- generatePgSnapshot = (tables, enums, schemas, sequences, roles, views, matViews, casing2, schemaFilter) => {
28413
+ generatePgSnapshot = (tables, enums, schemas, sequences, roles, policies, views, matViews, casing2, schemaFilter) => {
28174
28414
  const dialect4 = new PgDialect({ casing: casing2 });
28175
28415
  const result = {};
28176
28416
  const resultViews = {};
28177
28417
  const sequencesToReturn = {};
28178
28418
  const rolesToReturn = {};
28419
+ const policiesToReturn = {};
28179
28420
  const indexesInSchema = {};
28180
28421
  for (const table4 of tables) {
28181
28422
  const checksInTable = {};
@@ -28188,7 +28429,7 @@ var init_pgSerializer = __esm({
28188
28429
  schema: schema4,
28189
28430
  primaryKeys,
28190
28431
  uniqueConstraints,
28191
- policies,
28432
+ policies: policies2,
28192
28433
  enableRLS
28193
28434
  } = getTableConfig(table4);
28194
28435
  if (schemaFilter && !schemaFilter.includes(schema4 ?? "public")) {
@@ -28448,17 +28689,17 @@ ${withStyle.errorWarning(
28448
28689
  with: value.config.with ?? {}
28449
28690
  };
28450
28691
  });
28451
- policies.forEach((policy2) => {
28692
+ policies2.forEach((policy4) => {
28452
28693
  const mappedTo = [];
28453
- if (!policy2.to) {
28694
+ if (!policy4.to) {
28454
28695
  mappedTo.push("public");
28455
28696
  } else {
28456
- if (policy2.to && typeof policy2.to === "string") {
28457
- mappedTo.push(policy2.to);
28458
- } else if (policy2.to && is(policy2.to, PgRole)) {
28459
- mappedTo.push(policy2.to.name);
28460
- } else if (policy2.to && Array.isArray(policy2.to)) {
28461
- policy2.to.forEach((it) => {
28697
+ if (policy4.to && typeof policy4.to === "string") {
28698
+ mappedTo.push(policy4.to);
28699
+ } else if (policy4.to && is(policy4.to, PgRole)) {
28700
+ mappedTo.push(policy4.to.name);
28701
+ } else if (policy4.to && Array.isArray(policy4.to)) {
28702
+ policy4.to.forEach((it) => {
28462
28703
  if (typeof it === "string") {
28463
28704
  mappedTo.push(it);
28464
28705
  } else if (is(it, PgRole)) {
@@ -28467,13 +28708,24 @@ ${withStyle.errorWarning(
28467
28708
  });
28468
28709
  }
28469
28710
  }
28470
- policiesObject[policy2.name] = {
28471
- name: policy2.name,
28472
- as: policy2.as?.toUpperCase() ?? "PERMISSIVE",
28473
- for: policy2.for?.toUpperCase() ?? "ALL",
28711
+ if (policiesObject[policy4.name] !== void 0) {
28712
+ console.log(
28713
+ `
28714
+ ${withStyle.errorWarning(
28715
+ `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
28716
+ policy4.name
28717
+ )} name`
28718
+ )}`
28719
+ );
28720
+ process.exit(1);
28721
+ }
28722
+ policiesObject[policy4.name] = {
28723
+ name: policy4.name,
28724
+ as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28725
+ for: policy4.for?.toUpperCase() ?? "ALL",
28474
28726
  to: mappedTo.sort(),
28475
- using: is(policy2.using, SQL) ? dialect4.sqlToQuery(policy2.using).sql : void 0,
28476
- withCheck: is(policy2.withCheck, SQL) ? dialect4.sqlToQuery(policy2.withCheck).sql : void 0
28727
+ using: is(policy4.using, SQL) ? dialect4.sqlToQuery(policy4.using).sql : void 0,
28728
+ withCheck: is(policy4.withCheck, SQL) ? dialect4.sqlToQuery(policy4.withCheck).sql : void 0
28477
28729
  };
28478
28730
  });
28479
28731
  checks.forEach((check) => {
@@ -28517,6 +28769,64 @@ ${withStyle.errorWarning(
28517
28769
  isRLSEnabled: enableRLS
28518
28770
  };
28519
28771
  }
28772
+ for (const policy4 of policies) {
28773
+ if (!policy4._linkedTable) {
28774
+ console.log(
28775
+ `
28776
+ ${withStyle.errorWarning(
28777
+ `"Policy ${policy4.name} was skipped because it was not linked to any table. You should either include the policy in a table or use .link() on the policy to link it to any table you have. For more information, please check:`
28778
+ )}`
28779
+ );
28780
+ continue;
28781
+ }
28782
+ const tableConfig = getTableConfig(policy4._linkedTable);
28783
+ const tableKey2 = `${tableConfig.schema ?? "public"}.${tableConfig.name}`;
28784
+ const mappedTo = [];
28785
+ if (!policy4.to) {
28786
+ mappedTo.push("public");
28787
+ } else {
28788
+ if (policy4.to && typeof policy4.to === "string") {
28789
+ mappedTo.push(policy4.to);
28790
+ } else if (policy4.to && is(policy4.to, PgRole)) {
28791
+ mappedTo.push(policy4.to.name);
28792
+ } else if (policy4.to && Array.isArray(policy4.to)) {
28793
+ policy4.to.forEach((it) => {
28794
+ if (typeof it === "string") {
28795
+ mappedTo.push(it);
28796
+ } else if (is(it, PgRole)) {
28797
+ mappedTo.push(it.name);
28798
+ }
28799
+ });
28800
+ }
28801
+ }
28802
+ if (result[tableKey2]?.policies[policy4.name] !== void 0 || policiesToReturn[policy4.name] !== void 0) {
28803
+ console.log(
28804
+ `
28805
+ ${withStyle.errorWarning(
28806
+ `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
28807
+ policy4.name
28808
+ )} name`
28809
+ )}`
28810
+ );
28811
+ process.exit(1);
28812
+ }
28813
+ const mappedPolicy = {
28814
+ name: policy4.name,
28815
+ as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28816
+ for: policy4.for?.toUpperCase() ?? "ALL",
28817
+ to: mappedTo.sort(),
28818
+ using: is(policy4.using, SQL) ? dialect4.sqlToQuery(policy4.using).sql : void 0,
28819
+ withCheck: is(policy4.withCheck, SQL) ? dialect4.sqlToQuery(policy4.withCheck).sql : void 0
28820
+ };
28821
+ if (result[tableKey2]) {
28822
+ result[tableKey2].policies[policy4.name] = mappedPolicy;
28823
+ } else {
28824
+ policiesToReturn[policy4.name] = {
28825
+ ...mappedPolicy,
28826
+ on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
28827
+ };
28828
+ }
28829
+ }
28520
28830
  for (const sequence of sequences) {
28521
28831
  const name2 = sequence.seqName;
28522
28832
  if (typeof sequencesToReturn[`${sequence.schema ?? "public"}.${name2}`] === "undefined") {
@@ -28705,6 +29015,7 @@ ${withStyle.errorWarning(
28705
29015
  schemas: schemasObject,
28706
29016
  sequences: sequencesToReturn,
28707
29017
  roles: rolesToReturn,
29018
+ policies: policiesToReturn,
28708
29019
  views: resultViews,
28709
29020
  _meta: {
28710
29021
  schemas: {},
@@ -29456,6 +29767,7 @@ WHERE
29456
29767
  schemas: schemasObject,
29457
29768
  sequences: sequencesToReturn,
29458
29769
  roles: rolesToReturn,
29770
+ policies: {},
29459
29771
  views,
29460
29772
  _meta: {
29461
29773
  schemas: {},
@@ -38815,7 +39127,14 @@ var init_cli = __esm({
38815
39127
  schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
38816
39128
  extensionsFilters: literalType("postgis").array().optional(),
38817
39129
  verbose: booleanType().optional(),
38818
- strict: booleanType().optional()
39130
+ strict: booleanType().optional(),
39131
+ entities: objectType({
39132
+ roles: booleanType().or(objectType({
39133
+ provider: stringType().optional(),
39134
+ include: stringType().array().optional(),
39135
+ exclude: stringType().array().optional()
39136
+ })).optional().default(false)
39137
+ }).optional()
38819
39138
  }).passthrough();
38820
39139
  pullParams = objectType({
38821
39140
  config: stringType().optional(),
@@ -39102,6 +39421,7 @@ var init_pgImports = __esm({
39102
39421
  const schemas = [];
39103
39422
  const sequences = [];
39104
39423
  const roles = [];
39424
+ const policies = [];
39105
39425
  const views = [];
39106
39426
  const matViews = [];
39107
39427
  const i0values = Object.values(exports);
@@ -39128,8 +39448,11 @@ var init_pgImports = __esm({
39128
39448
  if (is(t, PgRole)) {
39129
39449
  roles.push(t);
39130
39450
  }
39451
+ if (is(t, PgPolicy)) {
39452
+ policies.push(t);
39453
+ }
39131
39454
  });
39132
- return { tables, enums, schemas, sequences, views, matViews, roles };
39455
+ return { tables, enums, schemas, sequences, views, matViews, roles, policies };
39133
39456
  };
39134
39457
  }
39135
39458
  });
@@ -39984,6 +40307,7 @@ var generateDrizzleJson = (imports, prevId, schemaFilters, casing2) => {
39984
40307
  prepared.schemas,
39985
40308
  prepared.sequences,
39986
40309
  prepared.roles,
40310
+ prepared.policies,
39987
40311
  prepared.views,
39988
40312
  prepared.matViews,
39989
40313
  casing2,
@@ -40008,6 +40332,7 @@ var generateMigration = async (prev, cur) => {
40008
40332
  enumsResolver,
40009
40333
  sequencesResolver,
40010
40334
  policyResolver,
40335
+ indPolicyResolver,
40011
40336
  roleResolver,
40012
40337
  tablesResolver,
40013
40338
  columnsResolver,
@@ -40043,6 +40368,7 @@ var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
40043
40368
  enumsResolver,
40044
40369
  sequencesResolver,
40045
40370
  policyResolver,
40371
+ indPolicyResolver,
40046
40372
  roleResolver,
40047
40373
  tablesResolver,
40048
40374
  columnsResolver,