drizzle-kit 0.27.1-82368 → 0.27.1-93aad0e
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 +14 -0
- package/api.d.ts +14 -0
- package/api.js +57 -24
- package/api.mjs +57 -24
- package/bin.cjs +71 -46
- package/package.json +1 -1
- package/utils.js +2 -1
- package/utils.mjs +2 -1
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(
|
16774
|
-
|
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(
|
16829
|
-
|
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(
|
@@ -17345,7 +17362,11 @@ var init_snapshotsDiffer = __esm({
|
|
17345
17362
|
});
|
17346
17363
|
jsonCreatePoliciesStatements.push(...[].concat(
|
17347
17364
|
...createdTables.map(
|
17348
|
-
(it) => prepareCreatePolicyJsons(
|
17365
|
+
(it) => prepareCreatePolicyJsons(
|
17366
|
+
it.name,
|
17367
|
+
it.schema,
|
17368
|
+
Object.values(it.policies).map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
|
17369
|
+
)
|
17349
17370
|
)
|
17350
17371
|
));
|
17351
17372
|
const createViews = [];
|
@@ -17560,7 +17581,7 @@ var init_snapshotsDiffer = __esm({
|
|
17560
17581
|
}
|
17561
17582
|
return true;
|
17562
17583
|
});
|
17563
|
-
const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
|
17584
|
+
const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql", action);
|
17564
17585
|
const uniqueSqlStatements = [];
|
17565
17586
|
sqlStatements.forEach((ss) => {
|
17566
17587
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -28825,6 +28846,7 @@ ${withStyle.errorWarning(
|
|
28825
28846
|
} else {
|
28826
28847
|
policiesToReturn[policy4.name] = {
|
28827
28848
|
...mappedPolicy,
|
28849
|
+
schema: tableConfig.schema ?? "public",
|
28828
28850
|
on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
|
28829
28851
|
};
|
28830
28852
|
}
|
@@ -29033,9 +29055,10 @@ ${withStyle.errorWarning(
|
|
29033
29055
|
while (end > start && str[end - 1] === char3) --end;
|
29034
29056
|
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
29035
29057
|
};
|
29036
|
-
fromDatabase = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback) => {
|
29058
|
+
fromDatabase = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback, tsSchema) => {
|
29037
29059
|
const result = {};
|
29038
29060
|
const views = {};
|
29061
|
+
const policies = {};
|
29039
29062
|
const internals = { tables: {} };
|
29040
29063
|
const where = schemaFilters.map((t) => `n.nspname = '${t}'`).join(" or ");
|
29041
29064
|
const allTables = await db.query(
|
@@ -29161,7 +29184,8 @@ WHERE
|
|
29161
29184
|
}
|
29162
29185
|
}
|
29163
29186
|
}
|
29164
|
-
const
|
29187
|
+
const schemasForLinkedPoliciesInSchema = Object.values(tsSchema?.policies ?? {}).map((it) => it.schema);
|
29188
|
+
const wherePolicies = [...schemaFilters, ...schemasForLinkedPoliciesInSchema].map((t) => `schemaname = '${t}'`).join(" or ");
|
29165
29189
|
const policiesByTable = {};
|
29166
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}`};`);
|
29167
29191
|
for (const dbPolicy of allPolicies) {
|
@@ -29177,6 +29201,15 @@ WHERE
|
|
29177
29201
|
[dbPolicy.name]: { ...rest, to: parsedTo, withCheck: parsedWithCheck, using: parsedUsing }
|
29178
29202
|
};
|
29179
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
|
+
}
|
29180
29213
|
}
|
29181
29214
|
if (progressCallback) {
|
29182
29215
|
progressCallback(
|
@@ -29769,7 +29802,7 @@ WHERE
|
|
29769
29802
|
schemas: schemasObject,
|
29770
29803
|
sequences: sequencesToReturn,
|
29771
29804
|
roles: rolesToReturn,
|
29772
|
-
policies
|
29805
|
+
policies,
|
29773
29806
|
views,
|
29774
29807
|
_meta: {
|
29775
29808
|
schemas: {},
|
@@ -39869,7 +39902,7 @@ init_mjs();
|
|
39869
39902
|
init_global();
|
39870
39903
|
init_pgSerializer();
|
39871
39904
|
init_views();
|
39872
|
-
var pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
|
39905
|
+
var pgPushIntrospect = async (db, filters, schemaFilters, entities, tsSchema) => {
|
39873
39906
|
const matchers = filters.map((it) => {
|
39874
39907
|
return new Minimatch(it);
|
39875
39908
|
});
|
@@ -39897,7 +39930,7 @@ var pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
|
|
39897
39930
|
);
|
39898
39931
|
const res = await (0, import_hanji3.renderWithTask)(
|
39899
39932
|
progress,
|
39900
|
-
fromDatabase(db, filter2, schemaFilters, entities)
|
39933
|
+
fromDatabase(db, filter2, schemaFilters, entities, void 0, tsSchema)
|
39901
39934
|
);
|
39902
39935
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
39903
39936
|
const { internal, ...schemaWithoutInternals } = schema4;
|
@@ -40065,7 +40098,7 @@ var pgSuggestions = async (db, statements) => {
|
|
40065
40098
|
}
|
40066
40099
|
}
|
40067
40100
|
}
|
40068
|
-
const stmnt = fromJson([statement], "postgresql");
|
40101
|
+
const stmnt = fromJson([statement], "postgresql", "push");
|
40069
40102
|
if (typeof stmnt !== "undefined") {
|
40070
40103
|
statementsToExecute.push(...stmnt);
|
40071
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(
|
16779
|
-
|
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(
|
16834
|
-
|
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(
|
@@ -17350,7 +17367,11 @@ var init_snapshotsDiffer = __esm({
|
|
17350
17367
|
});
|
17351
17368
|
jsonCreatePoliciesStatements.push(...[].concat(
|
17352
17369
|
...createdTables.map(
|
17353
|
-
(it) => prepareCreatePolicyJsons(
|
17370
|
+
(it) => prepareCreatePolicyJsons(
|
17371
|
+
it.name,
|
17372
|
+
it.schema,
|
17373
|
+
Object.values(it.policies).map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
|
17374
|
+
)
|
17354
17375
|
)
|
17355
17376
|
));
|
17356
17377
|
const createViews = [];
|
@@ -17565,7 +17586,7 @@ var init_snapshotsDiffer = __esm({
|
|
17565
17586
|
}
|
17566
17587
|
return true;
|
17567
17588
|
});
|
17568
|
-
const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
|
17589
|
+
const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql", action);
|
17569
17590
|
const uniqueSqlStatements = [];
|
17570
17591
|
sqlStatements.forEach((ss) => {
|
17571
17592
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -28830,6 +28851,7 @@ ${withStyle.errorWarning(
|
|
28830
28851
|
} else {
|
28831
28852
|
policiesToReturn[policy4.name] = {
|
28832
28853
|
...mappedPolicy,
|
28854
|
+
schema: tableConfig.schema ?? "public",
|
28833
28855
|
on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
|
28834
28856
|
};
|
28835
28857
|
}
|
@@ -29038,9 +29060,10 @@ ${withStyle.errorWarning(
|
|
29038
29060
|
while (end > start && str[end - 1] === char3) --end;
|
29039
29061
|
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
29040
29062
|
};
|
29041
|
-
fromDatabase = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback) => {
|
29063
|
+
fromDatabase = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback, tsSchema) => {
|
29042
29064
|
const result = {};
|
29043
29065
|
const views = {};
|
29066
|
+
const policies = {};
|
29044
29067
|
const internals = { tables: {} };
|
29045
29068
|
const where = schemaFilters.map((t) => `n.nspname = '${t}'`).join(" or ");
|
29046
29069
|
const allTables = await db.query(
|
@@ -29166,7 +29189,8 @@ WHERE
|
|
29166
29189
|
}
|
29167
29190
|
}
|
29168
29191
|
}
|
29169
|
-
const
|
29192
|
+
const schemasForLinkedPoliciesInSchema = Object.values(tsSchema?.policies ?? {}).map((it) => it.schema);
|
29193
|
+
const wherePolicies = [...schemaFilters, ...schemasForLinkedPoliciesInSchema].map((t) => `schemaname = '${t}'`).join(" or ");
|
29170
29194
|
const policiesByTable = {};
|
29171
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}`};`);
|
29172
29196
|
for (const dbPolicy of allPolicies) {
|
@@ -29182,6 +29206,15 @@ WHERE
|
|
29182
29206
|
[dbPolicy.name]: { ...rest, to: parsedTo, withCheck: parsedWithCheck, using: parsedUsing }
|
29183
29207
|
};
|
29184
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
|
+
}
|
29185
29218
|
}
|
29186
29219
|
if (progressCallback) {
|
29187
29220
|
progressCallback(
|
@@ -29774,7 +29807,7 @@ WHERE
|
|
29774
29807
|
schemas: schemasObject,
|
29775
29808
|
sequences: sequencesToReturn,
|
29776
29809
|
roles: rolesToReturn,
|
29777
|
-
policies
|
29810
|
+
policies,
|
29778
29811
|
views,
|
29779
29812
|
_meta: {
|
29780
29813
|
schemas: {},
|
@@ -39860,7 +39893,7 @@ init_mjs();
|
|
39860
39893
|
init_global();
|
39861
39894
|
init_pgSerializer();
|
39862
39895
|
init_views();
|
39863
|
-
var pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
|
39896
|
+
var pgPushIntrospect = async (db, filters, schemaFilters, entities, tsSchema) => {
|
39864
39897
|
const matchers = filters.map((it) => {
|
39865
39898
|
return new Minimatch(it);
|
39866
39899
|
});
|
@@ -39888,7 +39921,7 @@ var pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
|
|
39888
39921
|
);
|
39889
39922
|
const res = await (0, import_hanji3.renderWithTask)(
|
39890
39923
|
progress,
|
39891
|
-
fromDatabase(db, filter2, schemaFilters, entities)
|
39924
|
+
fromDatabase(db, filter2, schemaFilters, entities, void 0, tsSchema)
|
39892
39925
|
);
|
39893
39926
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
39894
39927
|
const { internal, ...schemaWithoutInternals } = schema4;
|
@@ -40056,7 +40089,7 @@ var pgSuggestions = async (db, statements) => {
|
|
40056
40089
|
}
|
40057
40090
|
}
|
40058
40091
|
}
|
40059
|
-
const stmnt = fromJson([statement], "postgresql");
|
40092
|
+
const stmnt = fromJson([statement], "postgresql", "push");
|
40060
40093
|
if (typeof stmnt !== "undefined") {
|
40061
40094
|
statementsToExecute.push(...stmnt);
|
40062
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
|
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,
|
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(
|
29438
|
-
|
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(
|
29493
|
-
|
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(
|
@@ -30010,7 +30031,11 @@ var init_snapshotsDiffer = __esm({
|
|
30010
30031
|
});
|
30011
30032
|
jsonCreatePoliciesStatements.push(...[].concat(
|
30012
30033
|
...createdTables.map(
|
30013
|
-
(it) => prepareCreatePolicyJsons(
|
30034
|
+
(it) => prepareCreatePolicyJsons(
|
30035
|
+
it.name,
|
30036
|
+
it.schema,
|
30037
|
+
Object.values(it.policies).map(action === "push" ? PgSquasher.unsquashPolicyPush : PgSquasher.unsquashPolicy)
|
30038
|
+
)
|
30014
30039
|
)
|
30015
30040
|
));
|
30016
30041
|
const createViews = [];
|
@@ -30225,7 +30250,7 @@ var init_snapshotsDiffer = __esm({
|
|
30225
30250
|
}
|
30226
30251
|
return true;
|
30227
30252
|
});
|
30228
|
-
const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
|
30253
|
+
const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql", action);
|
30229
30254
|
const uniqueSqlStatements = [];
|
30230
30255
|
sqlStatements.forEach((ss) => {
|
30231
30256
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -33051,13 +33076,7 @@ var init_migrate = __esm({
|
|
33051
33076
|
console.error(e2);
|
33052
33077
|
}
|
33053
33078
|
};
|
33054
|
-
preparePgPush = async (
|
33055
|
-
const { prev, cur } = await preparePgDbPushSnapshot(
|
33056
|
-
snapshot,
|
33057
|
-
schemaPath,
|
33058
|
-
casing2,
|
33059
|
-
schemaFilter
|
33060
|
-
);
|
33079
|
+
preparePgPush = async (cur, prev) => {
|
33061
33080
|
const validatedPrev = pgSchema.parse(prev);
|
33062
33081
|
const validatedCur = pgSchema.parse(cur);
|
33063
33082
|
const squashedPrev = squashPgScheme(validatedPrev, "push");
|
@@ -58698,7 +58717,7 @@ var require_dist_cjs42 = __commonJS({
|
|
58698
58717
|
var import_util_buffer_from = require_dist_cjs23();
|
58699
58718
|
var import_util_utf8 = require_dist_cjs24();
|
58700
58719
|
var import_buffer2 = require("buffer");
|
58701
|
-
var
|
58720
|
+
var import_crypto10 = require("crypto");
|
58702
58721
|
var _Hash = class _Hash {
|
58703
58722
|
constructor(algorithmIdentifier, secret) {
|
58704
58723
|
this.algorithmIdentifier = algorithmIdentifier;
|
@@ -58712,7 +58731,7 @@ var require_dist_cjs42 = __commonJS({
|
|
58712
58731
|
return Promise.resolve(this.hash.digest());
|
58713
58732
|
}
|
58714
58733
|
reset() {
|
58715
|
-
this.hash = this.secret ? (0,
|
58734
|
+
this.hash = this.secret ? (0, import_crypto10.createHmac)(this.algorithmIdentifier, castSourceData(this.secret)) : (0, import_crypto10.createHash)(this.algorithmIdentifier);
|
58716
58735
|
}
|
58717
58736
|
};
|
58718
58737
|
__name(_Hash, "Hash");
|
@@ -81254,7 +81273,7 @@ var init_pgPushUtils = __esm({
|
|
81254
81273
|
}
|
81255
81274
|
}
|
81256
81275
|
}
|
81257
|
-
const stmnt = fromJson([statement], "postgresql");
|
81276
|
+
const stmnt = fromJson([statement], "postgresql", "push");
|
81258
81277
|
if (typeof stmnt !== "undefined") {
|
81259
81278
|
statementsToExecute.push(...stmnt);
|
81260
81279
|
}
|
@@ -82408,7 +82427,7 @@ var init_pgIntrospect = __esm({
|
|
82408
82427
|
init_global();
|
82409
82428
|
init_pgSerializer();
|
82410
82429
|
init_views();
|
82411
|
-
pgPushIntrospect = async (db, filters, schemaFilters, entities) => {
|
82430
|
+
pgPushIntrospect = async (db, filters, schemaFilters, entities, tsSchema) => {
|
82412
82431
|
const matchers = filters.map((it) => {
|
82413
82432
|
return new Minimatch(it);
|
82414
82433
|
});
|
@@ -82437,7 +82456,7 @@ var init_pgIntrospect = __esm({
|
|
82437
82456
|
);
|
82438
82457
|
const res = await (0, import_hanji9.renderWithTask)(
|
82439
82458
|
progress,
|
82440
|
-
fromDatabase2(db, filter2, schemaFilters, entities)
|
82459
|
+
fromDatabase2(db, filter2, schemaFilters, entities, void 0, tsSchema)
|
82441
82460
|
);
|
82442
82461
|
const schema5 = { id: originUUID, prevId: "", ...res };
|
82443
82462
|
const { internal, ...schemaWithoutInternals } = schema5;
|
@@ -82913,12 +82932,14 @@ __export(push_exports, {
|
|
82913
82932
|
pgPush: () => pgPush,
|
82914
82933
|
sqlitePush: () => sqlitePush
|
82915
82934
|
});
|
82916
|
-
var import_hanji11, mysqlPush, pgPush, sqlitePush, libSQLPush;
|
82935
|
+
var import_crypto9, import_hanji11, mysqlPush, pgPush, sqlitePush, libSQLPush;
|
82917
82936
|
var init_push = __esm({
|
82918
82937
|
"src/cli/commands/push.ts"() {
|
82919
82938
|
"use strict";
|
82920
82939
|
init_source();
|
82940
|
+
import_crypto9 = require("crypto");
|
82921
82941
|
import_hanji11 = __toESM(require_hanji());
|
82942
|
+
init_serializer();
|
82922
82943
|
init_sqlgenerator();
|
82923
82944
|
init_selector_ui();
|
82924
82945
|
init_outputs();
|
@@ -83031,9 +83052,13 @@ var init_push = __esm({
|
|
83031
83052
|
const { preparePostgresDB: preparePostgresDB2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
83032
83053
|
const { pgPushIntrospect: pgPushIntrospect2 } = await Promise.resolve().then(() => (init_pgIntrospect(), pgIntrospect_exports));
|
83033
83054
|
const db = await preparePostgresDB2(credentials2);
|
83034
|
-
const
|
83055
|
+
const serialized = await serializePg(schemaPath, casing2, schemasFilter);
|
83056
|
+
const { schema: schema5 } = await pgPushIntrospect2(db, tablesFilter, schemasFilter, entities, serialized);
|
83035
83057
|
const { preparePgPush: preparePgPush2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
83036
|
-
const statements = await preparePgPush2(
|
83058
|
+
const statements = await preparePgPush2(
|
83059
|
+
{ id: (0, import_crypto9.randomUUID)(), prevId: schema5.id, ...serialized },
|
83060
|
+
schema5
|
83061
|
+
);
|
83037
83062
|
try {
|
83038
83063
|
if (statements.sqlStatements.length === 0) {
|
83039
83064
|
(0, import_hanji11.render)(`[${source_default.blue("i")}] No changes detected`);
|
@@ -88964,7 +88989,7 @@ init_utils2();
|
|
88964
88989
|
var version2 = async () => {
|
88965
88990
|
const { npmVersion } = await ormCoreVersions();
|
88966
88991
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
88967
|
-
const envVersion = "0.27.1-
|
88992
|
+
const envVersion = "0.27.1-93aad0e";
|
88968
88993
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
88969
88994
|
const versions = `drizzle-kit: ${kitVersion}
|
88970
88995
|
${ormVersion}`;
|
package/package.json
CHANGED
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(),
|