drizzle-kit 0.26.2-31c8041 → 0.26.2-53e089b

Sign up to get free protection for your applications and to get access to all the features.
package/api.js CHANGED
@@ -7722,7 +7722,7 @@ var init_vector = __esm({
7722
7722
  });
7723
7723
 
7724
7724
  // src/serializer/pgSchema.ts
7725
- 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;
7725
+ 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;
7726
7726
  var init_pgSchema = __esm({
7727
7727
  "src/serializer/pgSchema.ts"() {
7728
7728
  "use strict";
@@ -7933,7 +7933,12 @@ var init_pgSchema = __esm({
7933
7933
  for: enumType(["ALL", "SELECT", "INSERT", "UPDATE", "DELETE"]).optional(),
7934
7934
  to: stringType().array().optional(),
7935
7935
  using: stringType().optional(),
7936
- withCheck: stringType().optional()
7936
+ withCheck: stringType().optional(),
7937
+ on: stringType().optional()
7938
+ }).strict();
7939
+ policySquashed = objectType({
7940
+ name: stringType(),
7941
+ values: stringType()
7937
7942
  }).strict();
7938
7943
  viewWithOption = objectType({
7939
7944
  checkOption: enumType(["local", "cascaded"]).optional(),
@@ -8113,6 +8118,7 @@ var init_pgSchema = __esm({
8113
8118
  views: recordType(stringType(), view2).default({}),
8114
8119
  sequences: recordType(stringType(), sequenceSchema).default({}),
8115
8120
  roles: recordType(stringType(), roleSchema).default({}),
8121
+ policies: recordType(stringType(), policy).default({}),
8116
8122
  _meta: objectType({
8117
8123
  schemas: recordType(stringType(), stringType()),
8118
8124
  tables: recordType(stringType(), stringType()),
@@ -8161,7 +8167,8 @@ var init_pgSchema = __esm({
8161
8167
  schemas: recordType(stringType(), stringType()),
8162
8168
  views: recordType(stringType(), view2),
8163
8169
  sequences: recordType(stringType(), sequenceSquashed),
8164
- roles: recordType(stringType(), roleSchema).default({})
8170
+ roles: recordType(stringType(), roleSchema).default({}),
8171
+ policies: recordType(stringType(), policy).default({})
8165
8172
  }).strict();
8166
8173
  pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
8167
8174
  pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
@@ -8244,22 +8251,23 @@ var init_pgSchema = __esm({
8244
8251
  squashFK: (fk4) => {
8245
8252
  return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo || "public"}`;
8246
8253
  },
8247
- squashPolicy: (policy2) => {
8248
- return `${policy2.name}--${policy2.as}--${policy2.for}--${policy2.to?.join(",")}--${policy2.using}--${policy2.withCheck}`;
8254
+ squashPolicy: (policy4) => {
8255
+ return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.using}--${policy4.withCheck}--${policy4.on}`;
8249
8256
  },
8250
- unsquashPolicy: (policy2) => {
8251
- const splitted = policy2.split("--");
8257
+ unsquashPolicy: (policy4) => {
8258
+ const splitted = policy4.split("--");
8252
8259
  return {
8253
8260
  name: splitted[0],
8254
8261
  as: splitted[1],
8255
8262
  for: splitted[2],
8256
8263
  to: splitted[3].split(","),
8257
8264
  using: splitted[4] !== "undefined" ? splitted[4] : void 0,
8258
- withCheck: splitted[5] !== "undefined" ? splitted[5] : void 0
8265
+ withCheck: splitted[5] !== "undefined" ? splitted[5] : void 0,
8266
+ on: splitted[6] !== "undefined" ? splitted[6] : void 0
8259
8267
  };
8260
8268
  },
8261
- squashPolicyPush: (policy2) => {
8262
- return `${policy2.name}--${policy2.as}--${policy2.for}--${policy2.to?.join(",")}`;
8269
+ squashPolicyPush: (policy4) => {
8270
+ return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.on}`;
8263
8271
  },
8264
8272
  squashPK: (pk) => {
8265
8273
  return `${pk.columns.join(",")};${pk.name}`;
@@ -8373,8 +8381,8 @@ var init_pgSchema = __esm({
8373
8381
  return PgSquasher.squashUnique(unq);
8374
8382
  }
8375
8383
  );
8376
- const squashedPolicies = mapValues(it[1].policies, (policy2) => {
8377
- return action === "push" ? PgSquasher.squashPolicyPush(policy2) : PgSquasher.squashPolicy(policy2);
8384
+ const squashedPolicies = mapValues(it[1].policies, (policy4) => {
8385
+ return action === "push" ? PgSquasher.squashPolicyPush(policy4) : PgSquasher.squashPolicy(policy4);
8378
8386
  });
8379
8387
  const squashedChecksContraints = mapValues(
8380
8388
  it[1].checkConstraints,
@@ -8411,6 +8419,17 @@ var init_pgSchema = __esm({
8411
8419
  ];
8412
8420
  })
8413
8421
  );
8422
+ const mappedPolicies = Object.fromEntries(
8423
+ Object.entries(json3.policies).map((it) => {
8424
+ return [
8425
+ it[0],
8426
+ {
8427
+ name: it[1].name,
8428
+ values: action === "push" ? PgSquasher.squashPolicyPush(it[1]) : PgSquasher.squashPolicy(it[1])
8429
+ }
8430
+ ];
8431
+ })
8432
+ );
8414
8433
  return {
8415
8434
  version: "7",
8416
8435
  dialect: json3.dialect,
@@ -8418,6 +8437,7 @@ var init_pgSchema = __esm({
8418
8437
  enums: json3.enums,
8419
8438
  schemas: json3.schemas,
8420
8439
  views: json3.views,
8440
+ policies: mappedPolicies,
8421
8441
  sequences: mappedSequences,
8422
8442
  roles: json3.roles
8423
8443
  };
@@ -8430,6 +8450,8 @@ var init_pgSchema = __esm({
8430
8450
  tables: {},
8431
8451
  enums: {},
8432
8452
  schemas: {},
8453
+ policies: {},
8454
+ roles: {},
8433
8455
  sequences: {},
8434
8456
  _meta: {
8435
8457
  schemas: {},
@@ -11426,6 +11448,14 @@ function diffSchemasOrTables(left, right) {
11426
11448
  const deleted = result.filter((it) => it[0].endsWith("__deleted")).map((it) => it[1]);
11427
11449
  return { added, deleted };
11428
11450
  }
11451
+ function diffIndPolicies(left, right) {
11452
+ left = JSON.parse(JSON.stringify(left));
11453
+ right = JSON.parse(JSON.stringify(right));
11454
+ const result = Object.entries((0, import_json_diff.diff)(left, right) ?? {});
11455
+ const added = result.filter((it) => it[0].endsWith("__added")).map((it) => it[1]);
11456
+ const deleted = result.filter((it) => it[0].endsWith("__deleted")).map((it) => it[1]);
11457
+ return { added, deleted };
11458
+ }
11429
11459
  function diffColumns(left, right) {
11430
11460
  left = JSON.parse(JSON.stringify(left));
11431
11461
  right = JSON.parse(JSON.stringify(right));
@@ -11498,6 +11528,7 @@ function applyJsonDiff(json1, json22) {
11498
11528
  difference.enums = difference.enums || {};
11499
11529
  difference.sequences = difference.sequences || {};
11500
11530
  difference.roles = difference.roles || {};
11531
+ difference.policies = difference.policies || {};
11501
11532
  difference.views = difference.views || {};
11502
11533
  const schemaKeys = Object.keys(difference.schemas);
11503
11534
  for (let key of schemaKeys) {
@@ -11558,6 +11589,10 @@ function applyJsonDiff(json1, json22) {
11558
11589
  const alteredRoles = rolesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map((it) => {
11559
11590
  return json22.roles[it[0]];
11560
11591
  });
11592
+ const policiesEntries = Object.entries(difference.policies);
11593
+ const alteredPolicies = policiesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map((it) => {
11594
+ return json22.policies[it[0]];
11595
+ });
11561
11596
  const viewsEntries = Object.entries(difference.views);
11562
11597
  const alteredViews = viewsEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map(
11563
11598
  ([nameWithSchema, view4]) => {
@@ -11632,7 +11667,8 @@ function applyJsonDiff(json1, json22) {
11632
11667
  alteredEnums,
11633
11668
  alteredSequences,
11634
11669
  alteredRoles,
11635
- alteredViews
11670
+ alteredViews,
11671
+ alteredPolicies
11636
11672
  };
11637
11673
  }
11638
11674
  var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
@@ -12089,7 +12125,7 @@ function fromJson(statements, dialect4, action, json22) {
12089
12125
  }).filter((it) => it !== "");
12090
12126
  return result;
12091
12127
  }
12092
- 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;
12128
+ 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;
12093
12129
  var init_sqlgenerator = __esm({
12094
12130
  "src/sqlgenerator.ts"() {
12095
12131
  "use strict";
@@ -12182,14 +12218,14 @@ var init_sqlgenerator = __esm({
12182
12218
  return statement.type === "create_policy" && dialect4 === "postgresql";
12183
12219
  }
12184
12220
  convert(statement) {
12185
- const policy2 = statement.data;
12221
+ const policy4 = statement.data;
12186
12222
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12187
- const usingPart = policy2.using ? ` USING (${policy2.using})` : "";
12188
- const withCheckPart = policy2.withCheck ? ` WITH CHECK (${policy2.withCheck})` : "";
12189
- const policyToPart = policy2.to?.map(
12223
+ const usingPart = policy4.using ? ` USING (${policy4.using})` : "";
12224
+ const withCheckPart = policy4.withCheck ? ` WITH CHECK (${policy4.withCheck})` : "";
12225
+ const policyToPart = policy4.to?.map(
12190
12226
  (v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
12191
12227
  ).join(", ");
12192
- return `CREATE POLICY "${policy2.name}" ON ${tableNameWithSchema} AS ${policy2.as?.toUpperCase()} FOR ${policy2.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12228
+ return `CREATE POLICY "${policy4.name}" ON ${tableNameWithSchema} AS ${policy4.as?.toUpperCase()} FOR ${policy4.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12193
12229
  }
12194
12230
  };
12195
12231
  PgDropPolicyConvertor = class extends Convertor {
@@ -12197,9 +12233,9 @@ var init_sqlgenerator = __esm({
12197
12233
  return statement.type === "drop_policy" && dialect4 === "postgresql";
12198
12234
  }
12199
12235
  convert(statement) {
12200
- const policy2 = statement.data;
12236
+ const policy4 = statement.data;
12201
12237
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12202
- return `DROP POLICY "${policy2.name}" ON ${tableNameWithSchema} CASCADE;`;
12238
+ return `DROP POLICY "${policy4.name}" ON ${tableNameWithSchema} CASCADE;`;
12203
12239
  }
12204
12240
  };
12205
12241
  PgRenamePolicyConvertor = class extends Convertor {
@@ -12224,6 +12260,49 @@ var init_sqlgenerator = __esm({
12224
12260
  return `ALTER POLICY "${oldPolicy.name}" ON ${tableNameWithSchema} TO ${newPolicy.to}${usingPart}${withCheckPart};`;
12225
12261
  }
12226
12262
  };
12263
+ PgCreateIndPolicyConvertor = class extends Convertor {
12264
+ can(statement, dialect4) {
12265
+ return statement.type === "create_ind_policy" && dialect4 === "postgresql";
12266
+ }
12267
+ convert(statement) {
12268
+ const policy4 = statement.data;
12269
+ const usingPart = policy4.using ? ` USING (${policy4.using})` : "";
12270
+ const withCheckPart = policy4.withCheck ? ` WITH CHECK (${policy4.withCheck})` : "";
12271
+ const policyToPart = policy4.to?.map(
12272
+ (v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
12273
+ ).join(", ");
12274
+ return `CREATE POLICY "${policy4.name}" ON ${policy4.on} AS ${policy4.as?.toUpperCase()} FOR ${policy4.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12275
+ }
12276
+ };
12277
+ PgDropIndPolicyConvertor = class extends Convertor {
12278
+ can(statement, dialect4) {
12279
+ return statement.type === "drop_ind_policy" && dialect4 === "postgresql";
12280
+ }
12281
+ convert(statement) {
12282
+ const policy4 = statement.data;
12283
+ return `DROP POLICY "${policy4.name}" ON ${policy4.on} CASCADE;`;
12284
+ }
12285
+ };
12286
+ PgRenameIndPolicyConvertor = class extends Convertor {
12287
+ can(statement, dialect4) {
12288
+ return statement.type === "rename_ind_policy" && dialect4 === "postgresql";
12289
+ }
12290
+ convert(statement) {
12291
+ return `ALTER POLICY "${statement.oldName}" ON ${statement.tableKey} RENAME TO "${statement.newName}";`;
12292
+ }
12293
+ };
12294
+ PgAlterIndPolicyConvertor = class extends Convertor {
12295
+ can(statement, dialect4) {
12296
+ return statement.type === "alter_ind_policy" && dialect4 === "postgresql";
12297
+ }
12298
+ convert(statement) {
12299
+ const newPolicy = statement.newData;
12300
+ const oldPolicy = statement.oldData;
12301
+ const usingPart = newPolicy.using ? ` USING (${newPolicy.using})` : oldPolicy.using ? ` USING (${oldPolicy.using})` : "";
12302
+ const withCheckPart = newPolicy.withCheck ? ` WITH CHECK (${newPolicy.withCheck})` : oldPolicy.withCheck ? ` WITH CHECK (${oldPolicy.withCheck})` : "";
12303
+ return `ALTER POLICY "${oldPolicy.name}" ON ${oldPolicy.on} TO ${newPolicy.to}${usingPart}${withCheckPart};`;
12304
+ }
12305
+ };
12227
12306
  PgEnableRlsConvertor = class extends Convertor {
12228
12307
  can(statement, dialect4) {
12229
12308
  return statement.type === "enable_rls" && dialect4 === "postgresql";
@@ -14115,6 +14194,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
14115
14194
  convertors.push(new PgCreatePolicyConvertor());
14116
14195
  convertors.push(new PgDropPolicyConvertor());
14117
14196
  convertors.push(new PgRenamePolicyConvertor());
14197
+ convertors.push(new PgAlterIndPolicyConvertor());
14198
+ convertors.push(new PgCreateIndPolicyConvertor());
14199
+ convertors.push(new PgDropIndPolicyConvertor());
14200
+ convertors.push(new PgRenameIndPolicyConvertor());
14118
14201
  convertors.push(new PgEnableRlsConvertor());
14119
14202
  convertors.push(new PgDisableRlsConvertor());
14120
14203
  convertors.push(new PgDropRoleConvertor());
@@ -14420,7 +14503,7 @@ var init_sqlitePushUtils = __esm({
14420
14503
  });
14421
14504
 
14422
14505
  // src/jsonStatements.ts
14423
- 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;
14506
+ 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;
14424
14507
  var init_jsonStatements = __esm({
14425
14508
  "src/jsonStatements.ts"() {
14426
14509
  "use strict";
@@ -15545,6 +15628,16 @@ var init_jsonStatements = __esm({
15545
15628
  };
15546
15629
  });
15547
15630
  };
15631
+ prepareRenameIndPolicyJsons = (renames) => {
15632
+ return renames.map((it) => {
15633
+ return {
15634
+ type: "rename_ind_policy",
15635
+ tableKey: it.from.on,
15636
+ oldName: it.from.name,
15637
+ newName: it.to.name
15638
+ };
15639
+ });
15640
+ };
15548
15641
  prepareCreatePolicyJsons = (tableName, schema4, policies) => {
15549
15642
  return policies.map((it) => {
15550
15643
  return {
@@ -15555,6 +15648,15 @@ var init_jsonStatements = __esm({
15555
15648
  };
15556
15649
  });
15557
15650
  };
15651
+ prepareCreateIndPolicyJsons = (policies) => {
15652
+ return policies.map((it) => {
15653
+ return {
15654
+ type: "create_ind_policy",
15655
+ tableName: it.on,
15656
+ data: it
15657
+ };
15658
+ });
15659
+ };
15558
15660
  prepareDropPolicyJsons = (tableName, schema4, policies) => {
15559
15661
  return policies.map((it) => {
15560
15662
  return {
@@ -15565,6 +15667,15 @@ var init_jsonStatements = __esm({
15565
15667
  };
15566
15668
  });
15567
15669
  };
15670
+ prepareDropIndPolicyJsons = (policies) => {
15671
+ return policies.map((it) => {
15672
+ return {
15673
+ type: "drop_ind_policy",
15674
+ tableName: it.on,
15675
+ data: it
15676
+ };
15677
+ });
15678
+ };
15568
15679
  prepareAlterPolicyJson = (tableName, schema4, oldPolicy, newPolicy) => {
15569
15680
  return {
15570
15681
  type: "alter_policy",
@@ -15574,6 +15685,13 @@ var init_jsonStatements = __esm({
15574
15685
  schema: schema4
15575
15686
  };
15576
15687
  };
15688
+ prepareAlterIndPolicyJson = (oldPolicy, newPolicy) => {
15689
+ return {
15690
+ type: "alter_ind_policy",
15691
+ oldData: oldPolicy,
15692
+ newData: newPolicy
15693
+ };
15694
+ };
15577
15695
  preparePgCreateIndexesJson = (tableName, schema4, indexes, fullSchema, action) => {
15578
15696
  if (action === "push") {
15579
15697
  return Object.values(indexes).map((indexData) => {
@@ -16515,6 +16633,7 @@ var init_snapshotsDiffer = __esm({
16515
16633
  alteredEnums: changedEnumSchema.array(),
16516
16634
  alteredSequences: sequenceSquashed.array(),
16517
16635
  alteredRoles: roleSchema.array(),
16636
+ alteredPolicies: policySquashed.array(),
16518
16637
  alteredViews: alteredPgViewSchema.array()
16519
16638
  }).strict();
16520
16639
  diffResultSchemeMysql = objectType({
@@ -16572,7 +16691,7 @@ var init_snapshotsDiffer = __esm({
16572
16691
  }
16573
16692
  return column4;
16574
16693
  };
16575
- applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, policyResolver2, roleResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
16694
+ applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, policyResolver2, indPolicyResolver2, roleResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
16576
16695
  const schemasDiff = diffSchemasOrTables(json1.schemas, json22.schemas);
16577
16696
  const {
16578
16697
  created: createdSchemas,
@@ -16789,24 +16908,24 @@ var init_snapshotsDiffer = __esm({
16789
16908
  const columnCreates = [];
16790
16909
  const columnDeletes = [];
16791
16910
  for (let entry of Object.values(res)) {
16792
- const { renamed, created, deleted } = await columnsResolver2({
16911
+ const { renamed, created: created2, deleted: deleted2 } = await columnsResolver2({
16793
16912
  tableName: entry.name,
16794
16913
  schema: entry.schema,
16795
16914
  deleted: entry.columns.deleted,
16796
16915
  created: entry.columns.added
16797
16916
  });
16798
- if (created.length > 0) {
16917
+ if (created2.length > 0) {
16799
16918
  columnCreates.push({
16800
16919
  table: entry.name,
16801
16920
  schema: entry.schema,
16802
- columns: created
16921
+ columns: created2
16803
16922
  });
16804
16923
  }
16805
- if (deleted.length > 0) {
16924
+ if (deleted2.length > 0) {
16806
16925
  columnDeletes.push({
16807
16926
  table: entry.name,
16808
16927
  schema: entry.schema,
16809
- columns: deleted
16928
+ columns: deleted2
16810
16929
  });
16811
16930
  }
16812
16931
  if (renamed.length > 0) {
@@ -16846,24 +16965,24 @@ var init_snapshotsDiffer = __esm({
16846
16965
  const policyCreates = [];
16847
16966
  const policyDeletes = [];
16848
16967
  for (let entry of Object.values(policyRes)) {
16849
- const { renamed, created, deleted } = await policyResolver2({
16968
+ const { renamed, created: created2, deleted: deleted2 } = await policyResolver2({
16850
16969
  tableName: entry.name,
16851
16970
  schema: entry.schema,
16852
16971
  deleted: entry.policies.deleted.map(PgSquasher.unsquashPolicy),
16853
16972
  created: entry.policies.added.map(PgSquasher.unsquashPolicy)
16854
16973
  });
16855
- if (created.length > 0) {
16974
+ if (created2.length > 0) {
16856
16975
  policyCreates.push({
16857
16976
  table: entry.name,
16858
16977
  schema: entry.schema,
16859
- columns: created
16978
+ columns: created2
16860
16979
  });
16861
16980
  }
16862
- if (deleted.length > 0) {
16981
+ if (deleted2.length > 0) {
16863
16982
  policyDeletes.push({
16864
16983
  table: entry.name,
16865
16984
  schema: entry.schema,
16866
- columns: deleted
16985
+ columns: deleted2
16867
16986
  });
16868
16987
  }
16869
16988
  if (renamed.length > 0) {
@@ -16887,12 +17006,12 @@ var init_snapshotsDiffer = __esm({
16887
17006
  (tableKey2, tableValue) => {
16888
17007
  const patchedPolicies = mapKeys(
16889
17008
  tableValue.policies,
16890
- (policyKey, policy2) => {
17009
+ (policyKey, policy4) => {
16891
17010
  const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
16892
17011
  const newName = columnChangeFor(policyKey, rens);
16893
- const unsquashedPolicy = PgSquasher.unsquashPolicy(policy2);
17012
+ const unsquashedPolicy = PgSquasher.unsquashPolicy(policy4);
16894
17013
  unsquashedPolicy.name = newName;
16895
- policy2 = PgSquasher.squashPolicy(unsquashedPolicy);
17014
+ policy4 = PgSquasher.squashPolicy(unsquashedPolicy);
16896
17015
  return newName;
16897
17016
  }
16898
17017
  );
@@ -16900,7 +17019,46 @@ var init_snapshotsDiffer = __esm({
16900
17019
  return [tableKey2, tableValue];
16901
17020
  }
16902
17021
  );
16903
- const viewsDiff = diffSchemasOrTables(policyPatchedSnap1.views, json22.views);
17022
+ const indPolicyRes = diffIndPolicies(policyPatchedSnap1.policies, json22.policies);
17023
+ const indPolicyCreates = [];
17024
+ const indPolicyDeletes = [];
17025
+ const { renamed: indPolicyRenames, created, deleted } = await indPolicyResolver2({
17026
+ deleted: indPolicyRes.deleted.map((t) => PgSquasher.unsquashPolicy(t.values)),
17027
+ created: indPolicyRes.added.map((t) => PgSquasher.unsquashPolicy(t.values))
17028
+ });
17029
+ if (created.length > 0) {
17030
+ indPolicyCreates.push({
17031
+ policies: created
17032
+ });
17033
+ }
17034
+ if (deleted.length > 0) {
17035
+ indPolicyDeletes.push({
17036
+ policies: deleted
17037
+ });
17038
+ }
17039
+ const indPolicyRenamesDict = indPolicyRenames.reduce(
17040
+ (acc, it) => {
17041
+ acc[it.from.name] = {
17042
+ nameFrom: it.from.name,
17043
+ nameTo: it.to.name
17044
+ };
17045
+ return acc;
17046
+ },
17047
+ {}
17048
+ );
17049
+ const indPolicyPatchedSnap1 = copy(policyPatchedSnap1);
17050
+ indPolicyPatchedSnap1.policies = mapEntries(
17051
+ indPolicyPatchedSnap1.policies,
17052
+ (policyKey, policyValue) => {
17053
+ const key = policyKey;
17054
+ const change = indPolicyRenamesDict[key];
17055
+ if (change) {
17056
+ policyValue.name = change.nameTo;
17057
+ }
17058
+ return [policyKey, policyValue];
17059
+ }
17060
+ );
17061
+ const viewsDiff = diffSchemasOrTables(indPolicyPatchedSnap1.views, json22.views);
16904
17062
  const {
16905
17063
  created: createdViews,
16906
17064
  deleted: deletedViews,
@@ -17041,16 +17199,16 @@ var init_snapshotsDiffer = __esm({
17041
17199
  );
17042
17200
  if (it.alteredUniqueConstraints) {
17043
17201
  const added = {};
17044
- const deleted = {};
17202
+ const deleted2 = {};
17045
17203
  for (const k of Object.keys(it.alteredUniqueConstraints)) {
17046
17204
  added[k] = it.alteredUniqueConstraints[k].__new;
17047
- deleted[k] = it.alteredUniqueConstraints[k].__old;
17205
+ deleted2[k] = it.alteredUniqueConstraints[k].__old;
17048
17206
  }
17049
17207
  addedUniqueConstraints.push(
17050
17208
  ...prepareAddUniqueConstraintPg(it.name, it.schema, added)
17051
17209
  );
17052
17210
  deletedUniqueConstraints.push(
17053
- ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
17211
+ ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted2)
17054
17212
  );
17055
17213
  }
17056
17214
  createCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
@@ -17061,13 +17219,13 @@ var init_snapshotsDiffer = __esm({
17061
17219
  );
17062
17220
  if (it.alteredCheckConstraints && action !== "push") {
17063
17221
  const added = {};
17064
- const deleted = {};
17222
+ const deleted2 = {};
17065
17223
  for (const k of Object.keys(it.alteredCheckConstraints)) {
17066
17224
  added[k] = it.alteredCheckConstraints[k].__new;
17067
- deleted[k] = it.alteredCheckConstraints[k].__old;
17225
+ deleted2[k] = it.alteredCheckConstraints[k].__old;
17068
17226
  }
17069
17227
  createCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
17070
- deleteCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
17228
+ deleteCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted2));
17071
17229
  }
17072
17230
  jsonCreatedCheckConstraints.push(...createCheckConstraints);
17073
17231
  jsonDeletedCheckConstraints.push(...deleteCheckConstraints);
@@ -17115,8 +17273,68 @@ var init_snapshotsDiffer = __esm({
17115
17273
  const jsonDropPoliciesStatements = [];
17116
17274
  const jsonAlterPoliciesStatements = [];
17117
17275
  const jsonRenamePoliciesStatements = [];
17276
+ const jsonRenameIndPoliciesStatements = [];
17277
+ const jsonCreateIndPoliciesStatements = [];
17278
+ const jsonDropIndPoliciesStatements = [];
17279
+ const jsonAlterIndPoliciesStatements = [];
17118
17280
  const jsonEnableRLSStatements = [];
17119
17281
  const jsonDisableRLSStatements = [];
17282
+ for (let it of indPolicyRenames) {
17283
+ jsonRenameIndPoliciesStatements.push(
17284
+ ...prepareRenameIndPolicyJsons([it])
17285
+ );
17286
+ }
17287
+ for (const it of indPolicyCreates) {
17288
+ jsonCreateIndPoliciesStatements.push(
17289
+ ...prepareCreateIndPolicyJsons(
17290
+ it.policies
17291
+ )
17292
+ );
17293
+ }
17294
+ for (const it of indPolicyDeletes) {
17295
+ jsonDropIndPoliciesStatements.push(
17296
+ ...prepareDropIndPolicyJsons(
17297
+ it.policies
17298
+ )
17299
+ );
17300
+ }
17301
+ typedResult.alteredPolicies.forEach(({ values }) => {
17302
+ const policy4 = PgSquasher.unsquashPolicy(values);
17303
+ const newPolicy = json1.policies[policy4.name];
17304
+ const oldPolicy = json22.policies[policy4.name];
17305
+ if (newPolicy.as !== oldPolicy.as) {
17306
+ jsonDropIndPoliciesStatements.push(
17307
+ ...prepareDropIndPolicyJsons(
17308
+ [oldPolicy]
17309
+ )
17310
+ );
17311
+ jsonCreateIndPoliciesStatements.push(
17312
+ ...prepareCreateIndPolicyJsons(
17313
+ [newPolicy]
17314
+ )
17315
+ );
17316
+ return;
17317
+ }
17318
+ if (newPolicy.for !== oldPolicy.for) {
17319
+ jsonDropIndPoliciesStatements.push(
17320
+ ...prepareDropIndPolicyJsons(
17321
+ [oldPolicy]
17322
+ )
17323
+ );
17324
+ jsonCreateIndPoliciesStatements.push(
17325
+ ...prepareCreateIndPolicyJsons(
17326
+ [newPolicy]
17327
+ )
17328
+ );
17329
+ return;
17330
+ }
17331
+ jsonAlterIndPoliciesStatements.push(
17332
+ prepareAlterIndPolicyJson(
17333
+ oldPolicy,
17334
+ newPolicy
17335
+ )
17336
+ );
17337
+ });
17120
17338
  for (let it of policyRenames) {
17121
17339
  jsonRenamePoliciesStatements.push(
17122
17340
  ...prepareRenamePolicyJsons(it.table, it.schema, it.renames)
@@ -17504,6 +17722,10 @@ var init_snapshotsDiffer = __esm({
17504
17722
  jsonStatements.push(...jsonDropPoliciesStatements);
17505
17723
  jsonStatements.push(...jsonCreatePoliciesStatements);
17506
17724
  jsonStatements.push(...jsonAlterPoliciesStatements);
17725
+ jsonStatements.push(...jsonRenameIndPoliciesStatements);
17726
+ jsonStatements.push(...jsonDropIndPoliciesStatements);
17727
+ jsonStatements.push(...jsonCreateIndPoliciesStatements);
17728
+ jsonStatements.push(...jsonAlterIndPoliciesStatements);
17507
17729
  jsonStatements.push(...createViews);
17508
17730
  jsonStatements.push(...dropEnums);
17509
17731
  jsonStatements.push(...dropSequences);
@@ -18896,7 +19118,7 @@ var init_outputs = __esm({
18896
19118
  });
18897
19119
 
18898
19120
  // src/cli/commands/migrate.ts
18899
- var import_hanji2, schemasResolver, tablesResolver, viewsResolver, mySqlViewsResolver, sqliteViewsResolver, sequencesResolver, roleResolver, policyResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedConflict, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
19121
+ var import_hanji2, schemasResolver, tablesResolver, viewsResolver, mySqlViewsResolver, sqliteViewsResolver, sequencesResolver, roleResolver, policyResolver, indPolicyResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedConflict, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
18900
19122
  var init_migrate = __esm({
18901
19123
  "src/cli/commands/migrate.ts"() {
18902
19124
  "use strict";
@@ -19039,6 +19261,18 @@ var init_migrate = __esm({
19039
19261
  renamed: result.renamed
19040
19262
  };
19041
19263
  };
19264
+ indPolicyResolver = async (input) => {
19265
+ const result = await promptNamedConflict(
19266
+ input.created,
19267
+ input.deleted,
19268
+ "policy"
19269
+ );
19270
+ return {
19271
+ created: result.created,
19272
+ deleted: result.deleted,
19273
+ renamed: result.renamed
19274
+ };
19275
+ };
19042
19276
  enumsResolver = async (input) => {
19043
19277
  try {
19044
19278
  const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
@@ -27491,6 +27725,8 @@ var init_policies = __esm({
27491
27725
  __publicField(this, "to");
27492
27726
  __publicField(this, "using");
27493
27727
  __publicField(this, "withCheck");
27728
+ /** @internal */
27729
+ __publicField(this, "_linkedTable");
27494
27730
  this.name = name2;
27495
27731
  if (config) {
27496
27732
  this.as = config.as;
@@ -27500,6 +27736,10 @@ var init_policies = __esm({
27500
27736
  this.withCheck = config.withCheck;
27501
27737
  }
27502
27738
  }
27739
+ link(table4) {
27740
+ this._linkedTable = table4;
27741
+ return this;
27742
+ }
27503
27743
  };
27504
27744
  __publicField(PgPolicy, _a147, "PgPolicy");
27505
27745
  }
@@ -28165,12 +28405,13 @@ var init_pgSerializer = __esm({
28165
28405
  indexName = (tableName, columns) => {
28166
28406
  return `${tableName}_${columns.join("_")}_index`;
28167
28407
  };
28168
- generatePgSnapshot = (tables, enums, schemas, sequences, roles, views, matViews, casing2, schemaFilter) => {
28408
+ generatePgSnapshot = (tables, enums, schemas, sequences, roles, policies, views, matViews, casing2, schemaFilter) => {
28169
28409
  const dialect4 = new PgDialect({ casing: casing2 });
28170
28410
  const result = {};
28171
28411
  const resultViews = {};
28172
28412
  const sequencesToReturn = {};
28173
28413
  const rolesToReturn = {};
28414
+ const policiesToReturn = {};
28174
28415
  const indexesInSchema = {};
28175
28416
  for (const table4 of tables) {
28176
28417
  const checksInTable = {};
@@ -28183,7 +28424,7 @@ var init_pgSerializer = __esm({
28183
28424
  schema: schema4,
28184
28425
  primaryKeys,
28185
28426
  uniqueConstraints,
28186
- policies,
28427
+ policies: policies2,
28187
28428
  enableRLS
28188
28429
  } = getTableConfig(table4);
28189
28430
  if (schemaFilter && !schemaFilter.includes(schema4 ?? "public")) {
@@ -28443,17 +28684,17 @@ ${withStyle.errorWarning(
28443
28684
  with: value.config.with ?? {}
28444
28685
  };
28445
28686
  });
28446
- policies.forEach((policy2) => {
28687
+ policies2.forEach((policy4) => {
28447
28688
  const mappedTo = [];
28448
- if (!policy2.to) {
28689
+ if (!policy4.to) {
28449
28690
  mappedTo.push("public");
28450
28691
  } else {
28451
- if (policy2.to && typeof policy2.to === "string") {
28452
- mappedTo.push(policy2.to);
28453
- } else if (policy2.to && is(policy2.to, PgRole)) {
28454
- mappedTo.push(policy2.to.name);
28455
- } else if (policy2.to && Array.isArray(policy2.to)) {
28456
- policy2.to.forEach((it) => {
28692
+ if (policy4.to && typeof policy4.to === "string") {
28693
+ mappedTo.push(policy4.to);
28694
+ } else if (policy4.to && is(policy4.to, PgRole)) {
28695
+ mappedTo.push(policy4.to.name);
28696
+ } else if (policy4.to && Array.isArray(policy4.to)) {
28697
+ policy4.to.forEach((it) => {
28457
28698
  if (typeof it === "string") {
28458
28699
  mappedTo.push(it);
28459
28700
  } else if (is(it, PgRole)) {
@@ -28462,13 +28703,24 @@ ${withStyle.errorWarning(
28462
28703
  });
28463
28704
  }
28464
28705
  }
28465
- policiesObject[policy2.name] = {
28466
- name: policy2.name,
28467
- as: policy2.as?.toUpperCase() ?? "PERMISSIVE",
28468
- for: policy2.for?.toUpperCase() ?? "ALL",
28706
+ if (policiesObject[policy4.name] !== void 0) {
28707
+ console.log(
28708
+ `
28709
+ ${withStyle.errorWarning(
28710
+ `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
28711
+ policy4.name
28712
+ )} name`
28713
+ )}`
28714
+ );
28715
+ process.exit(1);
28716
+ }
28717
+ policiesObject[policy4.name] = {
28718
+ name: policy4.name,
28719
+ as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28720
+ for: policy4.for?.toUpperCase() ?? "ALL",
28469
28721
  to: mappedTo.sort(),
28470
- using: is(policy2.using, SQL) ? dialect4.sqlToQuery(policy2.using).sql : void 0,
28471
- withCheck: is(policy2.withCheck, SQL) ? dialect4.sqlToQuery(policy2.withCheck).sql : void 0
28722
+ using: is(policy4.using, SQL) ? dialect4.sqlToQuery(policy4.using).sql : void 0,
28723
+ withCheck: is(policy4.withCheck, SQL) ? dialect4.sqlToQuery(policy4.withCheck).sql : void 0
28472
28724
  };
28473
28725
  });
28474
28726
  checks.forEach((check) => {
@@ -28512,6 +28764,64 @@ ${withStyle.errorWarning(
28512
28764
  isRLSEnabled: enableRLS
28513
28765
  };
28514
28766
  }
28767
+ for (const policy4 of policies) {
28768
+ if (!policy4._linkedTable) {
28769
+ console.log(
28770
+ `
28771
+ ${withStyle.errorWarning(
28772
+ `"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:`
28773
+ )}`
28774
+ );
28775
+ continue;
28776
+ }
28777
+ const tableConfig = getTableConfig(policy4._linkedTable);
28778
+ const tableKey2 = `${tableConfig.schema ?? "public"}.${tableConfig.name}`;
28779
+ const mappedTo = [];
28780
+ if (!policy4.to) {
28781
+ mappedTo.push("public");
28782
+ } else {
28783
+ if (policy4.to && typeof policy4.to === "string") {
28784
+ mappedTo.push(policy4.to);
28785
+ } else if (policy4.to && is(policy4.to, PgRole)) {
28786
+ mappedTo.push(policy4.to.name);
28787
+ } else if (policy4.to && Array.isArray(policy4.to)) {
28788
+ policy4.to.forEach((it) => {
28789
+ if (typeof it === "string") {
28790
+ mappedTo.push(it);
28791
+ } else if (is(it, PgRole)) {
28792
+ mappedTo.push(it.name);
28793
+ }
28794
+ });
28795
+ }
28796
+ }
28797
+ if (result[tableKey2]?.policies[policy4.name] !== void 0 || policiesToReturn[policy4.name] !== void 0) {
28798
+ console.log(
28799
+ `
28800
+ ${withStyle.errorWarning(
28801
+ `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
28802
+ policy4.name
28803
+ )} name`
28804
+ )}`
28805
+ );
28806
+ process.exit(1);
28807
+ }
28808
+ const mappedPolicy = {
28809
+ name: policy4.name,
28810
+ as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28811
+ for: policy4.for?.toUpperCase() ?? "ALL",
28812
+ to: mappedTo.sort(),
28813
+ using: is(policy4.using, SQL) ? dialect4.sqlToQuery(policy4.using).sql : void 0,
28814
+ withCheck: is(policy4.withCheck, SQL) ? dialect4.sqlToQuery(policy4.withCheck).sql : void 0
28815
+ };
28816
+ if (result[tableKey2]) {
28817
+ result[tableKey2].policies[policy4.name] = mappedPolicy;
28818
+ } else {
28819
+ policiesToReturn[policy4.name] = {
28820
+ ...mappedPolicy,
28821
+ on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
28822
+ };
28823
+ }
28824
+ }
28515
28825
  for (const sequence of sequences) {
28516
28826
  const name2 = sequence.seqName;
28517
28827
  if (typeof sequencesToReturn[`${sequence.schema ?? "public"}.${name2}`] === "undefined") {
@@ -28700,6 +29010,7 @@ ${withStyle.errorWarning(
28700
29010
  schemas: schemasObject,
28701
29011
  sequences: sequencesToReturn,
28702
29012
  roles: rolesToReturn,
29013
+ policies: policiesToReturn,
28703
29014
  views: resultViews,
28704
29015
  _meta: {
28705
29016
  schemas: {},
@@ -29451,6 +29762,7 @@ WHERE
29451
29762
  schemas: schemasObject,
29452
29763
  sequences: sequencesToReturn,
29453
29764
  roles: rolesToReturn,
29765
+ policies: {},
29454
29766
  views,
29455
29767
  _meta: {
29456
29768
  schemas: {},
@@ -38810,7 +39122,14 @@ var init_cli = __esm({
38810
39122
  schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
38811
39123
  extensionsFilters: literalType("postgis").array().optional(),
38812
39124
  verbose: booleanType().optional(),
38813
- strict: booleanType().optional()
39125
+ strict: booleanType().optional(),
39126
+ entities: objectType({
39127
+ roles: booleanType().or(objectType({
39128
+ provider: stringType().optional(),
39129
+ include: stringType().array().optional(),
39130
+ exclude: stringType().array().optional()
39131
+ })).optional().default(false)
39132
+ }).optional()
38814
39133
  }).passthrough();
38815
39134
  pullParams = objectType({
38816
39135
  config: stringType().optional(),
@@ -39097,6 +39416,7 @@ var init_pgImports = __esm({
39097
39416
  const schemas = [];
39098
39417
  const sequences = [];
39099
39418
  const roles = [];
39419
+ const policies = [];
39100
39420
  const views = [];
39101
39421
  const matViews = [];
39102
39422
  const i0values = Object.values(exports2);
@@ -39123,8 +39443,11 @@ var init_pgImports = __esm({
39123
39443
  if (is(t, PgRole)) {
39124
39444
  roles.push(t);
39125
39445
  }
39446
+ if (is(t, PgPolicy)) {
39447
+ policies.push(t);
39448
+ }
39126
39449
  });
39127
- return { tables, enums, schemas, sequences, views, matViews, roles };
39450
+ return { tables, enums, schemas, sequences, views, matViews, roles, policies };
39128
39451
  };
39129
39452
  }
39130
39453
  });
@@ -39993,6 +40316,7 @@ var generateDrizzleJson = (imports, prevId, schemaFilters, casing2) => {
39993
40316
  prepared.schemas,
39994
40317
  prepared.sequences,
39995
40318
  prepared.roles,
40319
+ prepared.policies,
39996
40320
  prepared.views,
39997
40321
  prepared.matViews,
39998
40322
  casing2,
@@ -40017,6 +40341,7 @@ var generateMigration = async (prev, cur) => {
40017
40341
  enumsResolver,
40018
40342
  sequencesResolver,
40019
40343
  policyResolver,
40344
+ indPolicyResolver,
40020
40345
  roleResolver,
40021
40346
  tablesResolver,
40022
40347
  columnsResolver,
@@ -40052,6 +40377,7 @@ var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
40052
40377
  enumsResolver,
40053
40378
  sequencesResolver,
40054
40379
  policyResolver,
40380
+ indPolicyResolver,
40055
40381
  roleResolver,
40056
40382
  tablesResolver,
40057
40383
  columnsResolver,