drizzle-kit 0.27.1 → 0.27.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api.d.mts CHANGED
@@ -782,10 +782,12 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
782
782
  using: zod.ZodOptional<zod.ZodString>;
783
783
  withCheck: zod.ZodOptional<zod.ZodString>;
784
784
  on: zod.ZodOptional<zod.ZodString>;
785
+ schema: zod.ZodOptional<zod.ZodString>;
785
786
  }, "strict", zod.ZodTypeAny, {
786
787
  name: string;
787
788
  using?: string | undefined;
788
789
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
790
+ schema?: string | undefined;
789
791
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
790
792
  to?: string[] | undefined;
791
793
  withCheck?: string | undefined;
@@ -794,6 +796,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
794
796
  name: string;
795
797
  using?: string | undefined;
796
798
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
799
+ schema?: string | undefined;
797
800
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
798
801
  to?: string[] | undefined;
799
802
  withCheck?: string | undefined;
@@ -881,6 +884,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
881
884
  name: string;
882
885
  using?: string | undefined;
883
886
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
887
+ schema?: string | undefined;
884
888
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
885
889
  to?: string[] | undefined;
886
890
  withCheck?: string | undefined;
@@ -958,6 +962,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
958
962
  name: string;
959
963
  using?: string | undefined;
960
964
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
965
+ schema?: string | undefined;
961
966
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
962
967
  to?: string[] | undefined;
963
968
  withCheck?: string | undefined;
@@ -1328,10 +1333,12 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1328
1333
  using: zod.ZodOptional<zod.ZodString>;
1329
1334
  withCheck: zod.ZodOptional<zod.ZodString>;
1330
1335
  on: zod.ZodOptional<zod.ZodString>;
1336
+ schema: zod.ZodOptional<zod.ZodString>;
1331
1337
  }, "strict", zod.ZodTypeAny, {
1332
1338
  name: string;
1333
1339
  using?: string | undefined;
1334
1340
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1341
+ schema?: string | undefined;
1335
1342
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1336
1343
  to?: string[] | undefined;
1337
1344
  withCheck?: string | undefined;
@@ -1340,6 +1347,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1340
1347
  name: string;
1341
1348
  using?: string | undefined;
1342
1349
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1350
+ schema?: string | undefined;
1343
1351
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1344
1352
  to?: string[] | undefined;
1345
1353
  withCheck?: string | undefined;
@@ -1485,6 +1493,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1485
1493
  name: string;
1486
1494
  using?: string | undefined;
1487
1495
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1496
+ schema?: string | undefined;
1488
1497
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1489
1498
  to?: string[] | undefined;
1490
1499
  withCheck?: string | undefined;
@@ -1570,6 +1579,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1570
1579
  name: string;
1571
1580
  using?: string | undefined;
1572
1581
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1582
+ schema?: string | undefined;
1573
1583
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1574
1584
  to?: string[] | undefined;
1575
1585
  withCheck?: string | undefined;
@@ -1673,6 +1683,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1673
1683
  name: string;
1674
1684
  using?: string | undefined;
1675
1685
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1686
+ schema?: string | undefined;
1676
1687
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1677
1688
  to?: string[] | undefined;
1678
1689
  withCheck?: string | undefined;
@@ -1768,6 +1779,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1768
1779
  name: string;
1769
1780
  using?: string | undefined;
1770
1781
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1782
+ schema?: string | undefined;
1771
1783
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1772
1784
  to?: string[] | undefined;
1773
1785
  withCheck?: string | undefined;
@@ -2363,6 +2375,7 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
2363
2375
  }>;
2364
2376
  policies: Record<string, {
2365
2377
  name: string;
2378
+ schema?: string | undefined;
2366
2379
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
2367
2380
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
2368
2381
  to?: string[] | undefined;
@@ -2378,6 +2391,7 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
2378
2391
  }>;
2379
2392
  policies: Record<string, {
2380
2393
  name: string;
2394
+ schema?: string | undefined;
2381
2395
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
2382
2396
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
2383
2397
  to?: string[] | undefined;
package/api.d.ts CHANGED
@@ -782,10 +782,12 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
782
782
  using: zod.ZodOptional<zod.ZodString>;
783
783
  withCheck: zod.ZodOptional<zod.ZodString>;
784
784
  on: zod.ZodOptional<zod.ZodString>;
785
+ schema: zod.ZodOptional<zod.ZodString>;
785
786
  }, "strict", zod.ZodTypeAny, {
786
787
  name: string;
787
788
  using?: string | undefined;
788
789
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
790
+ schema?: string | undefined;
789
791
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
790
792
  to?: string[] | undefined;
791
793
  withCheck?: string | undefined;
@@ -794,6 +796,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
794
796
  name: string;
795
797
  using?: string | undefined;
796
798
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
799
+ schema?: string | undefined;
797
800
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
798
801
  to?: string[] | undefined;
799
802
  withCheck?: string | undefined;
@@ -881,6 +884,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
881
884
  name: string;
882
885
  using?: string | undefined;
883
886
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
887
+ schema?: string | undefined;
884
888
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
885
889
  to?: string[] | undefined;
886
890
  withCheck?: string | undefined;
@@ -958,6 +962,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
958
962
  name: string;
959
963
  using?: string | undefined;
960
964
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
965
+ schema?: string | undefined;
961
966
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
962
967
  to?: string[] | undefined;
963
968
  withCheck?: string | undefined;
@@ -1328,10 +1333,12 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1328
1333
  using: zod.ZodOptional<zod.ZodString>;
1329
1334
  withCheck: zod.ZodOptional<zod.ZodString>;
1330
1335
  on: zod.ZodOptional<zod.ZodString>;
1336
+ schema: zod.ZodOptional<zod.ZodString>;
1331
1337
  }, "strict", zod.ZodTypeAny, {
1332
1338
  name: string;
1333
1339
  using?: string | undefined;
1334
1340
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1341
+ schema?: string | undefined;
1335
1342
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1336
1343
  to?: string[] | undefined;
1337
1344
  withCheck?: string | undefined;
@@ -1340,6 +1347,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1340
1347
  name: string;
1341
1348
  using?: string | undefined;
1342
1349
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1350
+ schema?: string | undefined;
1343
1351
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1344
1352
  to?: string[] | undefined;
1345
1353
  withCheck?: string | undefined;
@@ -1485,6 +1493,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1485
1493
  name: string;
1486
1494
  using?: string | undefined;
1487
1495
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1496
+ schema?: string | undefined;
1488
1497
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1489
1498
  to?: string[] | undefined;
1490
1499
  withCheck?: string | undefined;
@@ -1570,6 +1579,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1570
1579
  name: string;
1571
1580
  using?: string | undefined;
1572
1581
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1582
+ schema?: string | undefined;
1573
1583
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1574
1584
  to?: string[] | undefined;
1575
1585
  withCheck?: string | undefined;
@@ -1673,6 +1683,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1673
1683
  name: string;
1674
1684
  using?: string | undefined;
1675
1685
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1686
+ schema?: string | undefined;
1676
1687
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1677
1688
  to?: string[] | undefined;
1678
1689
  withCheck?: string | undefined;
@@ -1768,6 +1779,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1768
1779
  name: string;
1769
1780
  using?: string | undefined;
1770
1781
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
1782
+ schema?: string | undefined;
1771
1783
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
1772
1784
  to?: string[] | undefined;
1773
1785
  withCheck?: string | undefined;
@@ -2363,6 +2375,7 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
2363
2375
  }>;
2364
2376
  policies: Record<string, {
2365
2377
  name: string;
2378
+ schema?: string | undefined;
2366
2379
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
2367
2380
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
2368
2381
  to?: string[] | undefined;
@@ -2378,6 +2391,7 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
2378
2391
  }>;
2379
2392
  policies: Record<string, {
2380
2393
  name: string;
2394
+ schema?: string | undefined;
2381
2395
  as?: "PERMISSIVE" | "RESTRICTIVE" | undefined;
2382
2396
  for?: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE" | undefined;
2383
2397
  to?: string[] | undefined;
package/api.js CHANGED
@@ -7756,7 +7756,8 @@ var init_pgSchema = __esm({
7756
7756
  to: stringType().array().optional(),
7757
7757
  using: stringType().optional(),
7758
7758
  withCheck: stringType().optional(),
7759
- on: stringType().optional()
7759
+ on: stringType().optional(),
7760
+ schema: stringType().optional()
7760
7761
  }).strict();
7761
7762
  policySquashed = objectType({
7762
7763
  name: stringType(),
@@ -8091,6 +8092,16 @@ var init_pgSchema = __esm({
8091
8092
  squashPolicyPush: (policy4) => {
8092
8093
  return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.on}`;
8093
8094
  },
8095
+ unsquashPolicyPush: (policy4) => {
8096
+ const splitted = policy4.split("--");
8097
+ return {
8098
+ name: splitted[0],
8099
+ as: splitted[1],
8100
+ for: splitted[2],
8101
+ to: splitted[3].split(","),
8102
+ on: splitted[4] !== "undefined" ? splitted[4] : void 0
8103
+ };
8104
+ },
8094
8105
  squashPK: (pk) => {
8095
8106
  return `${pk.columns.join(",")};${pk.name}`;
8096
8107
  },
@@ -12053,9 +12064,9 @@ var init_sqlgenerator = __esm({
12053
12064
  can(statement, dialect4) {
12054
12065
  return statement.type === "alter_policy" && dialect4 === "postgresql";
12055
12066
  }
12056
- convert(statement) {
12057
- const newPolicy = PgSquasher.unsquashPolicy(statement.newData);
12058
- const oldPolicy = PgSquasher.unsquashPolicy(statement.oldData);
12067
+ convert(statement, _dialect, action) {
12068
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(statement.newData) : PgSquasher.unsquashPolicy(statement.newData);
12069
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(statement.oldData) : PgSquasher.unsquashPolicy(statement.oldData);
12059
12070
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12060
12071
  const usingPart = newPolicy.using ? ` USING (${newPolicy.using})` : oldPolicy.using ? ` USING (${oldPolicy.using})` : "";
12061
12072
  const withCheckPart = newPolicy.withCheck ? ` WITH CHECK (${newPolicy.withCheck})` : oldPolicy.withCheck ? ` WITH CHECK (${oldPolicy.withCheck})` : "";
@@ -12775,7 +12786,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
12775
12786
  can(statement, dialect4) {
12776
12787
  return statement.type === "drop_table" && dialect4 === "postgresql";
12777
12788
  }
12778
- convert(statement) {
12789
+ convert(statement, _d5, action) {
12779
12790
  const { tableName, schema: schema4, policies } = statement;
12780
12791
  const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
12781
12792
  const dropPolicyConvertor = new PgDropPolicyConvertor();
@@ -12783,7 +12794,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
12783
12794
  return dropPolicyConvertor.convert({
12784
12795
  type: "drop_policy",
12785
12796
  tableName,
12786
- data: PgSquasher.unsquashPolicy(p),
12797
+ data: action === "push" ? PgSquasher.unsquashPolicyPush(p) : PgSquasher.unsquashPolicy(p),
12787
12798
  schema: schema4
12788
12799
  });
12789
12800
  }) ?? [];
@@ -16770,8 +16781,10 @@ var init_snapshotsDiffer = __esm({
16770
16781
  const { renamed, created: created2, deleted: deleted2 } = await policyResolver2({
16771
16782
  tableName: entry.name,
16772
16783
  schema: entry.schema,
16773
- deleted: entry.policies.deleted.map(PgSquasher.unsquashPolicy),
16774
- created: entry.policies.added.map(PgSquasher.unsquashPolicy)
16784
+ deleted: entry.policies.deleted.map(
16785
+ action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy
16786
+ ),
16787
+ created: entry.policies.added.map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
16775
16788
  });
16776
16789
  if (created2.length > 0) {
16777
16790
  policyCreates.push({
@@ -16811,7 +16824,7 @@ var init_snapshotsDiffer = __esm({
16811
16824
  (policyKey, policy4) => {
16812
16825
  const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
16813
16826
  const newName = columnChangeFor(policyKey, rens);
16814
- const unsquashedPolicy = PgSquasher.unsquashPolicy(policy4);
16827
+ const unsquashedPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(policy4) : PgSquasher.unsquashPolicy(policy4);
16815
16828
  unsquashedPolicy.name = newName;
16816
16829
  policy4 = PgSquasher.squashPolicy(unsquashedPolicy);
16817
16830
  return newName;
@@ -16825,8 +16838,12 @@ var init_snapshotsDiffer = __esm({
16825
16838
  const indPolicyCreates = [];
16826
16839
  const indPolicyDeletes = [];
16827
16840
  const { renamed: indPolicyRenames, created, deleted } = await indPolicyResolver2({
16828
- deleted: indPolicyRes.deleted.map((t) => PgSquasher.unsquashPolicy(t.values)),
16829
- created: indPolicyRes.added.map((t) => PgSquasher.unsquashPolicy(t.values))
16841
+ deleted: indPolicyRes.deleted.map(
16842
+ (t) => action === "push" ? PgSquasher.unsquashPolicyPush(t.values) : PgSquasher.unsquashPolicy(t.values)
16843
+ ),
16844
+ created: indPolicyRes.added.map(
16845
+ (t) => action === "push" ? PgSquasher.unsquashPolicyPush(t.values) : PgSquasher.unsquashPolicy(t.values)
16846
+ )
16830
16847
  });
16831
16848
  if (created.length > 0) {
16832
16849
  indPolicyCreates.push({
@@ -17101,9 +17118,9 @@ var init_snapshotsDiffer = __esm({
17101
17118
  );
17102
17119
  }
17103
17120
  typedResult.alteredPolicies.forEach(({ values }) => {
17104
- const policy4 = PgSquasher.unsquashPolicy(values);
17105
- const newPolicy = PgSquasher.unsquashPolicy(json22.policies[policy4.name].values);
17106
- const oldPolicy = PgSquasher.unsquashPolicy(json1.policies[policy4.name].values);
17121
+ const policy4 = action === "push" ? PgSquasher.unsquashPolicyPush(values) : PgSquasher.unsquashPolicy(values);
17122
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json22.policies[policy4.name].values);
17123
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json1.policies[policy4.name].values);
17107
17124
  if (newPolicy.as !== oldPolicy.as) {
17108
17125
  jsonDropIndPoliciesStatements.push(
17109
17126
  ...prepareDropIndPolicyJsons(
@@ -17162,8 +17179,8 @@ var init_snapshotsDiffer = __esm({
17162
17179
  }
17163
17180
  alteredTables.forEach((it) => {
17164
17181
  Object.keys(it.alteredPolicies).forEach((policyName) => {
17165
- const newPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__new);
17166
- const oldPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__old);
17182
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(it.alteredPolicies[policyName].__new) : PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__new);
17183
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(it.alteredPolicies[policyName].__old) : PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__old);
17167
17184
  if (newPolicy.as !== oldPolicy.as) {
17168
17185
  jsonDropPoliciesStatements.push(
17169
17186
  ...prepareDropPolicyJsons(
@@ -17217,7 +17234,8 @@ var init_snapshotsDiffer = __esm({
17217
17234
  if (policiesInPreviousState.length > 0 && policiesInCurrentState.length === 0 && !table4.isRLSEnabled) {
17218
17235
  jsonDisableRLSStatements.push({ type: "disable_rls", tableName: table4.name, schema: table4.schema });
17219
17236
  }
17220
- if (table4.isRLSEnabled !== tableInPreviousState.isRLSEnabled) {
17237
+ const wasRlsEnabled = tableInPreviousState ? tableInPreviousState.isRLSEnabled : false;
17238
+ if (table4.isRLSEnabled !== wasRlsEnabled) {
17221
17239
  if (table4.isRLSEnabled) {
17222
17240
  jsonEnableRLSStatements.push({ type: "enable_rls", tableName: table4.name, schema: table4.schema });
17223
17241
  } else if (!table4.isRLSEnabled && policiesInCurrentState.length === 0) {
@@ -17344,7 +17362,11 @@ var init_snapshotsDiffer = __esm({
17344
17362
  });
17345
17363
  jsonCreatePoliciesStatements.push(...[].concat(
17346
17364
  ...createdTables.map(
17347
- (it) => prepareCreatePolicyJsons(it.name, it.schema, Object.values(it.policies).map(PgSquasher.unsquashPolicy))
17365
+ (it) => prepareCreatePolicyJsons(
17366
+ it.name,
17367
+ it.schema,
17368
+ Object.values(it.policies).map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
17369
+ )
17348
17370
  )
17349
17371
  ));
17350
17372
  const createViews = [];
@@ -17559,7 +17581,7 @@ var init_snapshotsDiffer = __esm({
17559
17581
  }
17560
17582
  return true;
17561
17583
  });
17562
- const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
17584
+ const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql", action);
17563
17585
  const uniqueSqlStatements = [];
17564
17586
  sqlStatements.forEach((ss) => {
17565
17587
  if (!uniqueSqlStatements.includes(ss)) {
@@ -28824,6 +28846,7 @@ ${withStyle.errorWarning(
28824
28846
  } else {
28825
28847
  policiesToReturn[policy4.name] = {
28826
28848
  ...mappedPolicy,
28849
+ schema: tableConfig.schema ?? "public",
28827
28850
  on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
28828
28851
  };
28829
28852
  }
@@ -29032,9 +29055,10 @@ ${withStyle.errorWarning(
29032
29055
  while (end > start && str[end - 1] === char3) --end;
29033
29056
  return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
29034
29057
  };
29035
- fromDatabase = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback) => {
29058
+ fromDatabase = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback, tsSchema) => {
29036
29059
  const result = {};
29037
29060
  const views = {};
29061
+ const policies = {};
29038
29062
  const internals = { tables: {} };
29039
29063
  const where = schemaFilters.map((t) => `n.nspname = '${t}'`).join(" or ");
29040
29064
  const allTables = await db.query(
@@ -29160,7 +29184,8 @@ WHERE
29160
29184
  }
29161
29185
  }
29162
29186
  }
29163
- const wherePolicies = schemaFilters.map((t) => `schemaname = '${t}'`).join(" or ");
29187
+ const schemasForLinkedPoliciesInSchema = Object.values(tsSchema?.policies ?? {}).map((it) => it.schema);
29188
+ const wherePolicies = [...schemaFilters, ...schemasForLinkedPoliciesInSchema].map((t) => `schemaname = '${t}'`).join(" or ");
29164
29189
  const policiesByTable = {};
29165
29190
  const allPolicies = await db.query(`SELECT schemaname, tablename, policyname as name, permissive as "as", roles as to, cmd as for, qual as using, with_check as "withCheck" FROM pg_policies${wherePolicies === "" ? "" : ` WHERE ${wherePolicies}`};`);
29166
29191
  for (const dbPolicy of allPolicies) {
@@ -29176,6 +29201,15 @@ WHERE
29176
29201
  [dbPolicy.name]: { ...rest, to: parsedTo, withCheck: parsedWithCheck, using: parsedUsing }
29177
29202
  };
29178
29203
  }
29204
+ if (tsSchema?.policies[dbPolicy.name]) {
29205
+ policies[dbPolicy.name] = {
29206
+ ...rest,
29207
+ to: parsedTo,
29208
+ withCheck: parsedWithCheck,
29209
+ using: parsedUsing,
29210
+ on: tsSchema?.policies[dbPolicy.name].on
29211
+ };
29212
+ }
29179
29213
  }
29180
29214
  if (progressCallback) {
29181
29215
  progressCallback(
@@ -29768,7 +29802,7 @@ WHERE
29768
29802
  schemas: schemasObject,
29769
29803
  sequences: sequencesToReturn,
29770
29804
  roles: rolesToReturn,
29771
- policies: {},
29805
+ policies,
29772
29806
  views,
29773
29807
  _meta: {
29774
29808
  schemas: {},
@@ -39868,7 +39902,7 @@ init_mjs();
39868
39902
  init_global();
39869
39903
  init_pgSerializer();
39870
39904
  init_views();
39871
- var pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
39905
+ var pgPushIntrospect = async (db, filters, schemaFilters, entities, tsSchema) => {
39872
39906
  const matchers = filters.map((it) => {
39873
39907
  return new Minimatch(it);
39874
39908
  });
@@ -39896,7 +39930,7 @@ var pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
39896
39930
  );
39897
39931
  const res = await (0, import_hanji3.renderWithTask)(
39898
39932
  progress,
39899
- fromDatabase(db, filter2, schemaFilters, entities)
39933
+ fromDatabase(db, filter2, schemaFilters, entities, void 0, tsSchema)
39900
39934
  );
39901
39935
  const schema4 = { id: originUUID, prevId: "", ...res };
39902
39936
  const { internal, ...schemaWithoutInternals } = schema4;
@@ -40064,7 +40098,7 @@ var pgSuggestions = async (db, statements) => {
40064
40098
  }
40065
40099
  }
40066
40100
  }
40067
- const stmnt = fromJson([statement], "postgresql");
40101
+ const stmnt = fromJson([statement], "postgresql", "push");
40068
40102
  if (typeof stmnt !== "undefined") {
40069
40103
  statementsToExecute.push(...stmnt);
40070
40104
  }
package/api.mjs CHANGED
@@ -7761,7 +7761,8 @@ var init_pgSchema = __esm({
7761
7761
  to: stringType().array().optional(),
7762
7762
  using: stringType().optional(),
7763
7763
  withCheck: stringType().optional(),
7764
- on: stringType().optional()
7764
+ on: stringType().optional(),
7765
+ schema: stringType().optional()
7765
7766
  }).strict();
7766
7767
  policySquashed = objectType({
7767
7768
  name: stringType(),
@@ -8096,6 +8097,16 @@ var init_pgSchema = __esm({
8096
8097
  squashPolicyPush: (policy4) => {
8097
8098
  return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.on}`;
8098
8099
  },
8100
+ unsquashPolicyPush: (policy4) => {
8101
+ const splitted = policy4.split("--");
8102
+ return {
8103
+ name: splitted[0],
8104
+ as: splitted[1],
8105
+ for: splitted[2],
8106
+ to: splitted[3].split(","),
8107
+ on: splitted[4] !== "undefined" ? splitted[4] : void 0
8108
+ };
8109
+ },
8099
8110
  squashPK: (pk) => {
8100
8111
  return `${pk.columns.join(",")};${pk.name}`;
8101
8112
  },
@@ -12058,9 +12069,9 @@ var init_sqlgenerator = __esm({
12058
12069
  can(statement, dialect4) {
12059
12070
  return statement.type === "alter_policy" && dialect4 === "postgresql";
12060
12071
  }
12061
- convert(statement) {
12062
- const newPolicy = PgSquasher.unsquashPolicy(statement.newData);
12063
- const oldPolicy = PgSquasher.unsquashPolicy(statement.oldData);
12072
+ convert(statement, _dialect, action) {
12073
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(statement.newData) : PgSquasher.unsquashPolicy(statement.newData);
12074
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(statement.oldData) : PgSquasher.unsquashPolicy(statement.oldData);
12064
12075
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12065
12076
  const usingPart = newPolicy.using ? ` USING (${newPolicy.using})` : oldPolicy.using ? ` USING (${oldPolicy.using})` : "";
12066
12077
  const withCheckPart = newPolicy.withCheck ? ` WITH CHECK (${newPolicy.withCheck})` : oldPolicy.withCheck ? ` WITH CHECK (${oldPolicy.withCheck})` : "";
@@ -12780,7 +12791,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
12780
12791
  can(statement, dialect4) {
12781
12792
  return statement.type === "drop_table" && dialect4 === "postgresql";
12782
12793
  }
12783
- convert(statement) {
12794
+ convert(statement, _d5, action) {
12784
12795
  const { tableName, schema: schema4, policies } = statement;
12785
12796
  const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
12786
12797
  const dropPolicyConvertor = new PgDropPolicyConvertor();
@@ -12788,7 +12799,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
12788
12799
  return dropPolicyConvertor.convert({
12789
12800
  type: "drop_policy",
12790
12801
  tableName,
12791
- data: PgSquasher.unsquashPolicy(p),
12802
+ data: action === "push" ? PgSquasher.unsquashPolicyPush(p) : PgSquasher.unsquashPolicy(p),
12792
12803
  schema: schema4
12793
12804
  });
12794
12805
  }) ?? [];
@@ -16775,8 +16786,10 @@ var init_snapshotsDiffer = __esm({
16775
16786
  const { renamed, created: created2, deleted: deleted2 } = await policyResolver2({
16776
16787
  tableName: entry.name,
16777
16788
  schema: entry.schema,
16778
- deleted: entry.policies.deleted.map(PgSquasher.unsquashPolicy),
16779
- created: entry.policies.added.map(PgSquasher.unsquashPolicy)
16789
+ deleted: entry.policies.deleted.map(
16790
+ action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy
16791
+ ),
16792
+ created: entry.policies.added.map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
16780
16793
  });
16781
16794
  if (created2.length > 0) {
16782
16795
  policyCreates.push({
@@ -16816,7 +16829,7 @@ var init_snapshotsDiffer = __esm({
16816
16829
  (policyKey, policy4) => {
16817
16830
  const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
16818
16831
  const newName = columnChangeFor(policyKey, rens);
16819
- const unsquashedPolicy = PgSquasher.unsquashPolicy(policy4);
16832
+ const unsquashedPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(policy4) : PgSquasher.unsquashPolicy(policy4);
16820
16833
  unsquashedPolicy.name = newName;
16821
16834
  policy4 = PgSquasher.squashPolicy(unsquashedPolicy);
16822
16835
  return newName;
@@ -16830,8 +16843,12 @@ var init_snapshotsDiffer = __esm({
16830
16843
  const indPolicyCreates = [];
16831
16844
  const indPolicyDeletes = [];
16832
16845
  const { renamed: indPolicyRenames, created, deleted } = await indPolicyResolver2({
16833
- deleted: indPolicyRes.deleted.map((t) => PgSquasher.unsquashPolicy(t.values)),
16834
- created: indPolicyRes.added.map((t) => PgSquasher.unsquashPolicy(t.values))
16846
+ deleted: indPolicyRes.deleted.map(
16847
+ (t) => action === "push" ? PgSquasher.unsquashPolicyPush(t.values) : PgSquasher.unsquashPolicy(t.values)
16848
+ ),
16849
+ created: indPolicyRes.added.map(
16850
+ (t) => action === "push" ? PgSquasher.unsquashPolicyPush(t.values) : PgSquasher.unsquashPolicy(t.values)
16851
+ )
16835
16852
  });
16836
16853
  if (created.length > 0) {
16837
16854
  indPolicyCreates.push({
@@ -17106,9 +17123,9 @@ var init_snapshotsDiffer = __esm({
17106
17123
  );
17107
17124
  }
17108
17125
  typedResult.alteredPolicies.forEach(({ values }) => {
17109
- const policy4 = PgSquasher.unsquashPolicy(values);
17110
- const newPolicy = PgSquasher.unsquashPolicy(json22.policies[policy4.name].values);
17111
- const oldPolicy = PgSquasher.unsquashPolicy(json1.policies[policy4.name].values);
17126
+ const policy4 = action === "push" ? PgSquasher.unsquashPolicyPush(values) : PgSquasher.unsquashPolicy(values);
17127
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json22.policies[policy4.name].values);
17128
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json1.policies[policy4.name].values);
17112
17129
  if (newPolicy.as !== oldPolicy.as) {
17113
17130
  jsonDropIndPoliciesStatements.push(
17114
17131
  ...prepareDropIndPolicyJsons(
@@ -17167,8 +17184,8 @@ var init_snapshotsDiffer = __esm({
17167
17184
  }
17168
17185
  alteredTables.forEach((it) => {
17169
17186
  Object.keys(it.alteredPolicies).forEach((policyName) => {
17170
- const newPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__new);
17171
- const oldPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__old);
17187
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(it.alteredPolicies[policyName].__new) : PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__new);
17188
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(it.alteredPolicies[policyName].__old) : PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__old);
17172
17189
  if (newPolicy.as !== oldPolicy.as) {
17173
17190
  jsonDropPoliciesStatements.push(
17174
17191
  ...prepareDropPolicyJsons(
@@ -17222,7 +17239,8 @@ var init_snapshotsDiffer = __esm({
17222
17239
  if (policiesInPreviousState.length > 0 && policiesInCurrentState.length === 0 && !table4.isRLSEnabled) {
17223
17240
  jsonDisableRLSStatements.push({ type: "disable_rls", tableName: table4.name, schema: table4.schema });
17224
17241
  }
17225
- if (table4.isRLSEnabled !== tableInPreviousState.isRLSEnabled) {
17242
+ const wasRlsEnabled = tableInPreviousState ? tableInPreviousState.isRLSEnabled : false;
17243
+ if (table4.isRLSEnabled !== wasRlsEnabled) {
17226
17244
  if (table4.isRLSEnabled) {
17227
17245
  jsonEnableRLSStatements.push({ type: "enable_rls", tableName: table4.name, schema: table4.schema });
17228
17246
  } else if (!table4.isRLSEnabled && policiesInCurrentState.length === 0) {
@@ -17349,7 +17367,11 @@ var init_snapshotsDiffer = __esm({
17349
17367
  });
17350
17368
  jsonCreatePoliciesStatements.push(...[].concat(
17351
17369
  ...createdTables.map(
17352
- (it) => prepareCreatePolicyJsons(it.name, it.schema, Object.values(it.policies).map(PgSquasher.unsquashPolicy))
17370
+ (it) => prepareCreatePolicyJsons(
17371
+ it.name,
17372
+ it.schema,
17373
+ Object.values(it.policies).map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
17374
+ )
17353
17375
  )
17354
17376
  ));
17355
17377
  const createViews = [];
@@ -17564,7 +17586,7 @@ var init_snapshotsDiffer = __esm({
17564
17586
  }
17565
17587
  return true;
17566
17588
  });
17567
- const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
17589
+ const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql", action);
17568
17590
  const uniqueSqlStatements = [];
17569
17591
  sqlStatements.forEach((ss) => {
17570
17592
  if (!uniqueSqlStatements.includes(ss)) {
@@ -28829,6 +28851,7 @@ ${withStyle.errorWarning(
28829
28851
  } else {
28830
28852
  policiesToReturn[policy4.name] = {
28831
28853
  ...mappedPolicy,
28854
+ schema: tableConfig.schema ?? "public",
28832
28855
  on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
28833
28856
  };
28834
28857
  }
@@ -29037,9 +29060,10 @@ ${withStyle.errorWarning(
29037
29060
  while (end > start && str[end - 1] === char3) --end;
29038
29061
  return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
29039
29062
  };
29040
- fromDatabase = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback) => {
29063
+ fromDatabase = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback, tsSchema) => {
29041
29064
  const result = {};
29042
29065
  const views = {};
29066
+ const policies = {};
29043
29067
  const internals = { tables: {} };
29044
29068
  const where = schemaFilters.map((t) => `n.nspname = '${t}'`).join(" or ");
29045
29069
  const allTables = await db.query(
@@ -29165,7 +29189,8 @@ WHERE
29165
29189
  }
29166
29190
  }
29167
29191
  }
29168
- const wherePolicies = schemaFilters.map((t) => `schemaname = '${t}'`).join(" or ");
29192
+ const schemasForLinkedPoliciesInSchema = Object.values(tsSchema?.policies ?? {}).map((it) => it.schema);
29193
+ const wherePolicies = [...schemaFilters, ...schemasForLinkedPoliciesInSchema].map((t) => `schemaname = '${t}'`).join(" or ");
29169
29194
  const policiesByTable = {};
29170
29195
  const allPolicies = await db.query(`SELECT schemaname, tablename, policyname as name, permissive as "as", roles as to, cmd as for, qual as using, with_check as "withCheck" FROM pg_policies${wherePolicies === "" ? "" : ` WHERE ${wherePolicies}`};`);
29171
29196
  for (const dbPolicy of allPolicies) {
@@ -29181,6 +29206,15 @@ WHERE
29181
29206
  [dbPolicy.name]: { ...rest, to: parsedTo, withCheck: parsedWithCheck, using: parsedUsing }
29182
29207
  };
29183
29208
  }
29209
+ if (tsSchema?.policies[dbPolicy.name]) {
29210
+ policies[dbPolicy.name] = {
29211
+ ...rest,
29212
+ to: parsedTo,
29213
+ withCheck: parsedWithCheck,
29214
+ using: parsedUsing,
29215
+ on: tsSchema?.policies[dbPolicy.name].on
29216
+ };
29217
+ }
29184
29218
  }
29185
29219
  if (progressCallback) {
29186
29220
  progressCallback(
@@ -29773,7 +29807,7 @@ WHERE
29773
29807
  schemas: schemasObject,
29774
29808
  sequences: sequencesToReturn,
29775
29809
  roles: rolesToReturn,
29776
- policies: {},
29810
+ policies,
29777
29811
  views,
29778
29812
  _meta: {
29779
29813
  schemas: {},
@@ -39859,7 +39893,7 @@ init_mjs();
39859
39893
  init_global();
39860
39894
  init_pgSerializer();
39861
39895
  init_views();
39862
- var pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
39896
+ var pgPushIntrospect = async (db, filters, schemaFilters, entities, tsSchema) => {
39863
39897
  const matchers = filters.map((it) => {
39864
39898
  return new Minimatch(it);
39865
39899
  });
@@ -39887,7 +39921,7 @@ var pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
39887
39921
  );
39888
39922
  const res = await (0, import_hanji3.renderWithTask)(
39889
39923
  progress,
39890
- fromDatabase(db, filter2, schemaFilters, entities)
39924
+ fromDatabase(db, filter2, schemaFilters, entities, void 0, tsSchema)
39891
39925
  );
39892
39926
  const schema4 = { id: originUUID, prevId: "", ...res };
39893
39927
  const { internal, ...schemaWithoutInternals } = schema4;
@@ -40055,7 +40089,7 @@ var pgSuggestions = async (db, statements) => {
40055
40089
  }
40056
40090
  }
40057
40091
  }
40058
- const stmnt = fromJson([statement], "postgresql");
40092
+ const stmnt = fromJson([statement], "postgresql", "push");
40059
40093
  if (typeof stmnt !== "undefined") {
40060
40094
  statementsToExecute.push(...stmnt);
40061
40095
  }
package/bin.cjs CHANGED
@@ -6044,7 +6044,8 @@ var init_pgSchema = __esm({
6044
6044
  to: stringType().array().optional(),
6045
6045
  using: stringType().optional(),
6046
6046
  withCheck: stringType().optional(),
6047
- on: stringType().optional()
6047
+ on: stringType().optional(),
6048
+ schema: stringType().optional()
6048
6049
  }).strict();
6049
6050
  policySquashed = objectType({
6050
6051
  name: stringType(),
@@ -6381,6 +6382,16 @@ var init_pgSchema = __esm({
6381
6382
  var _a;
6382
6383
  return `${policy4.name}--${policy4.as}--${policy4.for}--${(_a = policy4.to) == null ? void 0 : _a.join(",")}--${policy4.on}`;
6383
6384
  },
6385
+ unsquashPolicyPush: (policy4) => {
6386
+ const splitted = policy4.split("--");
6387
+ return {
6388
+ name: splitted[0],
6389
+ as: splitted[1],
6390
+ for: splitted[2],
6391
+ to: splitted[3].split(","),
6392
+ on: splitted[4] !== "undefined" ? splitted[4] : void 0
6393
+ };
6394
+ },
6384
6395
  squashPK: (pk) => {
6385
6396
  return `${pk.columns.join(",")};${pk.name}`;
6386
6397
  },
@@ -19590,6 +19601,7 @@ ${withStyle.errorWarning(
19590
19601
  } else {
19591
19602
  policiesToReturn[policy4.name] = {
19592
19603
  ...mappedPolicy,
19604
+ schema: tableConfig.schema ?? "public",
19593
19605
  on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
19594
19606
  };
19595
19607
  }
@@ -19800,9 +19812,10 @@ ${withStyle.errorWarning(
19800
19812
  --end;
19801
19813
  return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
19802
19814
  };
19803
- fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback) => {
19815
+ fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback, tsSchema) => {
19804
19816
  const result = {};
19805
19817
  const views = {};
19818
+ const policies = {};
19806
19819
  const internals = { tables: {} };
19807
19820
  const where = schemaFilters.map((t2) => `n.nspname = '${t2}'`).join(" or ");
19808
19821
  const allTables = await db.query(
@@ -19932,7 +19945,8 @@ WHERE
19932
19945
  }
19933
19946
  }
19934
19947
  }
19935
- const wherePolicies = schemaFilters.map((t2) => `schemaname = '${t2}'`).join(" or ");
19948
+ const schemasForLinkedPoliciesInSchema = Object.values((tsSchema == null ? void 0 : tsSchema.policies) ?? {}).map((it) => it.schema);
19949
+ const wherePolicies = [...schemaFilters, ...schemasForLinkedPoliciesInSchema].map((t2) => `schemaname = '${t2}'`).join(" or ");
19936
19950
  const policiesByTable = {};
19937
19951
  const allPolicies = await db.query(`SELECT schemaname, tablename, policyname as name, permissive as "as", roles as to, cmd as for, qual as using, with_check as "withCheck" FROM pg_policies${wherePolicies === "" ? "" : ` WHERE ${wherePolicies}`};`);
19938
19952
  for (const dbPolicy of allPolicies) {
@@ -19948,6 +19962,15 @@ WHERE
19948
19962
  [dbPolicy.name]: { ...rest, to: parsedTo, withCheck: parsedWithCheck, using: parsedUsing }
19949
19963
  };
19950
19964
  }
19965
+ if (tsSchema == null ? void 0 : tsSchema.policies[dbPolicy.name]) {
19966
+ policies[dbPolicy.name] = {
19967
+ ...rest,
19968
+ to: parsedTo,
19969
+ withCheck: parsedWithCheck,
19970
+ using: parsedUsing,
19971
+ on: tsSchema == null ? void 0 : tsSchema.policies[dbPolicy.name].on
19972
+ };
19973
+ }
19951
19974
  }
19952
19975
  if (progressCallback) {
19953
19976
  progressCallback(
@@ -20545,7 +20568,7 @@ WHERE
20545
20568
  schemas: schemasObject,
20546
20569
  sequences: sequencesToReturn,
20547
20570
  roles: rolesToReturn,
20548
- policies: {},
20571
+ policies,
20549
20572
  views,
20550
20573
  _meta: {
20551
20574
  schemas: {},
@@ -21488,7 +21511,7 @@ ${filenames.join("\n")}
21488
21511
  });
21489
21512
 
21490
21513
  // src/migrationPreparator.ts
21491
- var import_crypto, import_fs4, prepareMySqlDbPushSnapshot, prepareSQLiteDbPushSnapshot, preparePgDbPushSnapshot, prepareMySqlMigrationSnapshot, prepareSqliteMigrationSnapshot, fillPgSnapshot, preparePgMigrationSnapshot, preparePrevSnapshot;
21514
+ var import_crypto, import_fs4, prepareMySqlDbPushSnapshot, prepareSQLiteDbPushSnapshot, prepareMySqlMigrationSnapshot, prepareSqliteMigrationSnapshot, fillPgSnapshot, preparePgMigrationSnapshot, preparePrevSnapshot;
21492
21515
  var init_migrationPreparator = __esm({
21493
21516
  "src/migrationPreparator.ts"() {
21494
21517
  "use strict";
@@ -21520,14 +21543,6 @@ var init_migrationPreparator = __esm({
21520
21543
  };
21521
21544
  return { prev, cur: result };
21522
21545
  };
21523
- preparePgDbPushSnapshot = async (prev, schemaPath, casing2, schemaFilter = ["public"]) => {
21524
- const serialized = await serializePg(schemaPath, casing2, schemaFilter);
21525
- const id = (0, import_crypto.randomUUID)();
21526
- const idPrev = prev.id;
21527
- const { version: version3, dialect: dialect4, ...rest } = serialized;
21528
- const result = { version: version3, dialect: dialect4, id, prevId: idPrev, ...rest };
21529
- return { prev, cur: result };
21530
- };
21531
21546
  prepareMySqlMigrationSnapshot = async (migrationFolders, schemaPath, casing2) => {
21532
21547
  const prevSnapshot = mysqlSchema.parse(
21533
21548
  preparePrevSnapshot(migrationFolders, dryMySql)
@@ -24729,9 +24744,9 @@ var init_sqlgenerator = __esm({
24729
24744
  can(statement, dialect4) {
24730
24745
  return statement.type === "alter_policy" && dialect4 === "postgresql";
24731
24746
  }
24732
- convert(statement) {
24733
- const newPolicy = PgSquasher.unsquashPolicy(statement.newData);
24734
- const oldPolicy = PgSquasher.unsquashPolicy(statement.oldData);
24747
+ convert(statement, _dialect, action) {
24748
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(statement.newData) : PgSquasher.unsquashPolicy(statement.newData);
24749
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(statement.oldData) : PgSquasher.unsquashPolicy(statement.oldData);
24735
24750
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
24736
24751
  const usingPart = newPolicy.using ? ` USING (${newPolicy.using})` : oldPolicy.using ? ` USING (${oldPolicy.using})` : "";
24737
24752
  const withCheckPart = newPolicy.withCheck ? ` WITH CHECK (${newPolicy.withCheck})` : oldPolicy.withCheck ? ` WITH CHECK (${oldPolicy.withCheck})` : "";
@@ -25458,7 +25473,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
25458
25473
  can(statement, dialect4) {
25459
25474
  return statement.type === "drop_table" && dialect4 === "postgresql";
25460
25475
  }
25461
- convert(statement) {
25476
+ convert(statement, _d, action) {
25462
25477
  const { tableName, schema: schema5, policies } = statement;
25463
25478
  const tableNameWithSchema = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
25464
25479
  const dropPolicyConvertor = new PgDropPolicyConvertor();
@@ -25466,7 +25481,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
25466
25481
  return dropPolicyConvertor.convert({
25467
25482
  type: "drop_policy",
25468
25483
  tableName,
25469
- data: PgSquasher.unsquashPolicy(p2),
25484
+ data: action === "push" ? PgSquasher.unsquashPolicyPush(p2) : PgSquasher.unsquashPolicy(p2),
25470
25485
  schema: schema5
25471
25486
  });
25472
25487
  })) ?? [];
@@ -29434,8 +29449,10 @@ var init_snapshotsDiffer = __esm({
29434
29449
  const { renamed, created: created2, deleted: deleted2 } = await policyResolver2({
29435
29450
  tableName: entry.name,
29436
29451
  schema: entry.schema,
29437
- deleted: entry.policies.deleted.map(PgSquasher.unsquashPolicy),
29438
- created: entry.policies.added.map(PgSquasher.unsquashPolicy)
29452
+ deleted: entry.policies.deleted.map(
29453
+ action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy
29454
+ ),
29455
+ created: entry.policies.added.map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
29439
29456
  });
29440
29457
  if (created2.length > 0) {
29441
29458
  policyCreates.push({
@@ -29475,7 +29492,7 @@ var init_snapshotsDiffer = __esm({
29475
29492
  (policyKey, policy4) => {
29476
29493
  const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
29477
29494
  const newName = columnChangeFor(policyKey, rens);
29478
- const unsquashedPolicy = PgSquasher.unsquashPolicy(policy4);
29495
+ const unsquashedPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(policy4) : PgSquasher.unsquashPolicy(policy4);
29479
29496
  unsquashedPolicy.name = newName;
29480
29497
  policy4 = PgSquasher.squashPolicy(unsquashedPolicy);
29481
29498
  return newName;
@@ -29489,8 +29506,12 @@ var init_snapshotsDiffer = __esm({
29489
29506
  const indPolicyCreates = [];
29490
29507
  const indPolicyDeletes = [];
29491
29508
  const { renamed: indPolicyRenames, created, deleted } = await indPolicyResolver2({
29492
- deleted: indPolicyRes.deleted.map((t2) => PgSquasher.unsquashPolicy(t2.values)),
29493
- created: indPolicyRes.added.map((t2) => PgSquasher.unsquashPolicy(t2.values))
29509
+ deleted: indPolicyRes.deleted.map(
29510
+ (t2) => action === "push" ? PgSquasher.unsquashPolicyPush(t2.values) : PgSquasher.unsquashPolicy(t2.values)
29511
+ ),
29512
+ created: indPolicyRes.added.map(
29513
+ (t2) => action === "push" ? PgSquasher.unsquashPolicyPush(t2.values) : PgSquasher.unsquashPolicy(t2.values)
29514
+ )
29494
29515
  });
29495
29516
  if (created.length > 0) {
29496
29517
  indPolicyCreates.push({
@@ -29766,9 +29787,9 @@ var init_snapshotsDiffer = __esm({
29766
29787
  );
29767
29788
  }
29768
29789
  typedResult.alteredPolicies.forEach(({ values }) => {
29769
- const policy4 = PgSquasher.unsquashPolicy(values);
29770
- const newPolicy = PgSquasher.unsquashPolicy(json2.policies[policy4.name].values);
29771
- const oldPolicy = PgSquasher.unsquashPolicy(json1.policies[policy4.name].values);
29790
+ const policy4 = action === "push" ? PgSquasher.unsquashPolicyPush(values) : PgSquasher.unsquashPolicy(values);
29791
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json2.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json2.policies[policy4.name].values);
29792
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json2.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json1.policies[policy4.name].values);
29772
29793
  if (newPolicy.as !== oldPolicy.as) {
29773
29794
  jsonDropIndPoliciesStatements.push(
29774
29795
  ...prepareDropIndPolicyJsons(
@@ -29827,8 +29848,8 @@ var init_snapshotsDiffer = __esm({
29827
29848
  }
29828
29849
  alteredTables.forEach((it) => {
29829
29850
  Object.keys(it.alteredPolicies).forEach((policyName) => {
29830
- const newPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__new);
29831
- const oldPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__old);
29851
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(it.alteredPolicies[policyName].__new) : PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__new);
29852
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(it.alteredPolicies[policyName].__old) : PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__old);
29832
29853
  if (newPolicy.as !== oldPolicy.as) {
29833
29854
  jsonDropPoliciesStatements.push(
29834
29855
  ...prepareDropPolicyJsons(
@@ -29882,7 +29903,8 @@ var init_snapshotsDiffer = __esm({
29882
29903
  if (policiesInPreviousState.length > 0 && policiesInCurrentState.length === 0 && !table4.isRLSEnabled) {
29883
29904
  jsonDisableRLSStatements.push({ type: "disable_rls", tableName: table4.name, schema: table4.schema });
29884
29905
  }
29885
- if (table4.isRLSEnabled !== tableInPreviousState.isRLSEnabled) {
29906
+ const wasRlsEnabled = tableInPreviousState ? tableInPreviousState.isRLSEnabled : false;
29907
+ if (table4.isRLSEnabled !== wasRlsEnabled) {
29886
29908
  if (table4.isRLSEnabled) {
29887
29909
  jsonEnableRLSStatements.push({ type: "enable_rls", tableName: table4.name, schema: table4.schema });
29888
29910
  } else if (!table4.isRLSEnabled && policiesInCurrentState.length === 0) {
@@ -30009,7 +30031,11 @@ var init_snapshotsDiffer = __esm({
30009
30031
  });
30010
30032
  jsonCreatePoliciesStatements.push(...[].concat(
30011
30033
  ...createdTables.map(
30012
- (it) => prepareCreatePolicyJsons(it.name, it.schema, Object.values(it.policies).map(PgSquasher.unsquashPolicy))
30034
+ (it) => prepareCreatePolicyJsons(
30035
+ it.name,
30036
+ it.schema,
30037
+ Object.values(it.policies).map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
30038
+ )
30013
30039
  )
30014
30040
  ));
30015
30041
  const createViews = [];
@@ -30224,7 +30250,7 @@ var init_snapshotsDiffer = __esm({
30224
30250
  }
30225
30251
  return true;
30226
30252
  });
30227
- const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
30253
+ const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql", action);
30228
30254
  const uniqueSqlStatements = [];
30229
30255
  sqlStatements.forEach((ss) => {
30230
30256
  if (!uniqueSqlStatements.includes(ss)) {
@@ -33050,13 +33076,7 @@ var init_migrate = __esm({
33050
33076
  console.error(e2);
33051
33077
  }
33052
33078
  };
33053
- preparePgPush = async (schemaPath, snapshot, schemaFilter, casing2) => {
33054
- const { prev, cur } = await preparePgDbPushSnapshot(
33055
- snapshot,
33056
- schemaPath,
33057
- casing2,
33058
- schemaFilter
33059
- );
33079
+ preparePgPush = async (cur, prev) => {
33060
33080
  const validatedPrev = pgSchema.parse(prev);
33061
33081
  const validatedCur = pgSchema.parse(cur);
33062
33082
  const squashedPrev = squashPgScheme(validatedPrev, "push");
@@ -58697,7 +58717,7 @@ var require_dist_cjs42 = __commonJS({
58697
58717
  var import_util_buffer_from = require_dist_cjs23();
58698
58718
  var import_util_utf8 = require_dist_cjs24();
58699
58719
  var import_buffer2 = require("buffer");
58700
- var import_crypto9 = require("crypto");
58720
+ var import_crypto10 = require("crypto");
58701
58721
  var _Hash = class _Hash {
58702
58722
  constructor(algorithmIdentifier, secret) {
58703
58723
  this.algorithmIdentifier = algorithmIdentifier;
@@ -58711,7 +58731,7 @@ var require_dist_cjs42 = __commonJS({
58711
58731
  return Promise.resolve(this.hash.digest());
58712
58732
  }
58713
58733
  reset() {
58714
- this.hash = this.secret ? (0, import_crypto9.createHmac)(this.algorithmIdentifier, castSourceData(this.secret)) : (0, import_crypto9.createHash)(this.algorithmIdentifier);
58734
+ this.hash = this.secret ? (0, import_crypto10.createHmac)(this.algorithmIdentifier, castSourceData(this.secret)) : (0, import_crypto10.createHash)(this.algorithmIdentifier);
58715
58735
  }
58716
58736
  };
58717
58737
  __name(_Hash, "Hash");
@@ -81253,7 +81273,7 @@ var init_pgPushUtils = __esm({
81253
81273
  }
81254
81274
  }
81255
81275
  }
81256
- const stmnt = fromJson([statement], "postgresql");
81276
+ const stmnt = fromJson([statement], "postgresql", "push");
81257
81277
  if (typeof stmnt !== "undefined") {
81258
81278
  statementsToExecute.push(...stmnt);
81259
81279
  }
@@ -82407,7 +82427,7 @@ var init_pgIntrospect = __esm({
82407
82427
  init_global();
82408
82428
  init_pgSerializer();
82409
82429
  init_views();
82410
- pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
82430
+ pgPushIntrospect = async (db, filters, schemaFilters, entities, tsSchema) => {
82411
82431
  const matchers = filters.map((it) => {
82412
82432
  return new Minimatch(it);
82413
82433
  });
@@ -82436,7 +82456,7 @@ var init_pgIntrospect = __esm({
82436
82456
  );
82437
82457
  const res = await (0, import_hanji9.renderWithTask)(
82438
82458
  progress,
82439
- fromDatabase2(db, filter2, schemaFilters, entities)
82459
+ fromDatabase2(db, filter2, schemaFilters, entities, void 0, tsSchema)
82440
82460
  );
82441
82461
  const schema5 = { id: originUUID, prevId: "", ...res };
82442
82462
  const { internal, ...schemaWithoutInternals } = schema5;
@@ -82912,12 +82932,14 @@ __export(push_exports, {
82912
82932
  pgPush: () => pgPush,
82913
82933
  sqlitePush: () => sqlitePush
82914
82934
  });
82915
- var import_hanji11, mysqlPush, pgPush, sqlitePush, libSQLPush;
82935
+ var import_crypto9, import_hanji11, mysqlPush, pgPush, sqlitePush, libSQLPush;
82916
82936
  var init_push = __esm({
82917
82937
  "src/cli/commands/push.ts"() {
82918
82938
  "use strict";
82919
82939
  init_source();
82940
+ import_crypto9 = require("crypto");
82920
82941
  import_hanji11 = __toESM(require_hanji());
82942
+ init_serializer();
82921
82943
  init_sqlgenerator();
82922
82944
  init_selector_ui();
82923
82945
  init_outputs();
@@ -83030,9 +83052,13 @@ var init_push = __esm({
83030
83052
  const { preparePostgresDB: preparePostgresDB2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
83031
83053
  const { pgPushIntrospect: pgPushIntrospect2 } = await Promise.resolve().then(() => (init_pgIntrospect(), pgIntrospect_exports));
83032
83054
  const db = await preparePostgresDB2(credentials2);
83033
- const { schema: schema5 } = await pgPushIntrospect2(db, tablesFilter, schemasFilter, entities);
83055
+ const serialized = await serializePg(schemaPath, casing2, schemasFilter);
83056
+ const { schema: schema5 } = await pgPushIntrospect2(db, tablesFilter, schemasFilter, entities, serialized);
83034
83057
  const { preparePgPush: preparePgPush2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
83035
- const statements = await preparePgPush2(schemaPath, schema5, schemasFilter, casing2);
83058
+ const statements = await preparePgPush2(
83059
+ { id: (0, import_crypto9.randomUUID)(), prevId: schema5.id, ...serialized },
83060
+ schema5
83061
+ );
83036
83062
  try {
83037
83063
  if (statements.sqlStatements.length === 0) {
83038
83064
  (0, import_hanji11.render)(`[${source_default.blue("i")}] No changes detected`);
@@ -88963,7 +88989,7 @@ init_utils2();
88963
88989
  var version2 = async () => {
88964
88990
  const { npmVersion } = await ormCoreVersions();
88965
88991
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
88966
- const envVersion = "0.27.1";
88992
+ const envVersion = "0.27.2";
88967
88993
  const kitVersion = envVersion ? `v${envVersion}` : "--";
88968
88994
  const versions = `drizzle-kit: ${kitVersion}
88969
88995
  ${ormVersion}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.27.1",
3
+ "version": "0.27.2",
4
4
  "homepage": "https://orm.drizzle.team",
5
5
  "keywords": [
6
6
  "drizzle",
package/utils.js CHANGED
@@ -5252,7 +5252,8 @@ var policy = objectType({
5252
5252
  to: stringType().array().optional(),
5253
5253
  using: stringType().optional(),
5254
5254
  withCheck: stringType().optional(),
5255
- on: stringType().optional()
5255
+ on: stringType().optional(),
5256
+ schema: stringType().optional()
5256
5257
  }).strict();
5257
5258
  var policySquashed = objectType({
5258
5259
  name: stringType(),
package/utils.mjs CHANGED
@@ -5231,7 +5231,8 @@ var policy = objectType({
5231
5231
  to: stringType().array().optional(),
5232
5232
  using: stringType().optional(),
5233
5233
  withCheck: stringType().optional(),
5234
- on: stringType().optional()
5234
+ on: stringType().optional(),
5235
+ schema: stringType().optional()
5235
5236
  }).strict();
5236
5237
  var policySquashed = objectType({
5237
5238
  name: stringType(),