drizzle-kit 0.25.0-a345cb3 → 0.25.0-a5ec472
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +96 -0
- package/api.d.ts +96 -0
- package/api.js +1524 -567
- package/api.mjs +1524 -567
- package/bin.cjs +1112 -155
- package/index.d.mts +7 -0
- package/index.d.ts +7 -0
- package/package.json +2 -2
- package/utils.js +21 -3
- package/utils.mjs +21 -3
package/bin.cjs
CHANGED
@@ -1075,7 +1075,7 @@ var require_hanji = __commonJS({
|
|
1075
1075
|
});
|
1076
1076
|
|
1077
1077
|
// src/cli/views.ts
|
1078
|
-
var import_hanji, warning, err, info, grey, error, schema, isRenamePromptItem, ResolveColumnSelect, tableKey, ResolveSelect, ResolveSchemasSelect, Spinner, IntrospectProgress, MigrateProgress, ProgressView, DropMigrationView, trimmedRange;
|
1078
|
+
var import_hanji, warning, err, info, grey, error, schema, isRenamePromptItem, ResolveColumnSelect, tableKey, ResolveSelectNamed, ResolveSelect, ResolveSchemasSelect, Spinner, IntrospectProgress, MigrateProgress, ProgressView, DropMigrationView, trimmedRange;
|
1079
1079
|
var init_views = __esm({
|
1080
1080
|
"src/cli/views.ts"() {
|
1081
1081
|
"use strict";
|
@@ -1178,6 +1178,53 @@ Is ${source_default.bold.blue(
|
|
1178
1178
|
tableKey = (it) => {
|
1179
1179
|
return it.schema === "public" || !it.schema ? it.name : `${it.schema}.${it.name}`;
|
1180
1180
|
};
|
1181
|
+
ResolveSelectNamed = class extends import_hanji.Prompt {
|
1182
|
+
constructor(base, data, entityType) {
|
1183
|
+
super();
|
1184
|
+
this.base = base;
|
1185
|
+
this.entityType = entityType;
|
1186
|
+
this.on("attach", (terminal) => terminal.toggleCursor("hide"));
|
1187
|
+
this.state = new import_hanji.SelectState(data);
|
1188
|
+
this.state.bind(this);
|
1189
|
+
this.base = base;
|
1190
|
+
}
|
1191
|
+
render(status) {
|
1192
|
+
if (status === "submitted" || status === "aborted") {
|
1193
|
+
return "";
|
1194
|
+
}
|
1195
|
+
const key = this.base.name;
|
1196
|
+
let text = `
|
1197
|
+
Is ${source_default.bold.blue(key)} ${this.entityType} created or renamed from another ${this.entityType}?
|
1198
|
+
`;
|
1199
|
+
const isSelectedRenamed = isRenamePromptItem(
|
1200
|
+
this.state.items[this.state.selectedIdx]
|
1201
|
+
);
|
1202
|
+
const selectedPrefix = isSelectedRenamed ? source_default.yellow("\u276F ") : source_default.green("\u276F ");
|
1203
|
+
const labelLength = this.state.items.filter((it) => isRenamePromptItem(it)).map((_2) => {
|
1204
|
+
const it = _2;
|
1205
|
+
const keyFrom = it.from.name;
|
1206
|
+
return key.length + 3 + keyFrom.length;
|
1207
|
+
}).reduce((a, b) => {
|
1208
|
+
if (a > b) {
|
1209
|
+
return a;
|
1210
|
+
}
|
1211
|
+
return b;
|
1212
|
+
}, 0);
|
1213
|
+
const entityType = this.entityType;
|
1214
|
+
this.state.items.forEach((it, idx) => {
|
1215
|
+
const isSelected = idx === this.state.selectedIdx;
|
1216
|
+
const isRenamed = isRenamePromptItem(it);
|
1217
|
+
const title = isRenamed ? `${it.from.name} \u203A ${it.to.name}`.padEnd(labelLength, " ") : it.name.padEnd(labelLength, " ");
|
1218
|
+
const label = isRenamed ? `${source_default.yellow("~")} ${title} ${source_default.gray(`rename ${entityType}`)}` : `${source_default.green("+")} ${title} ${source_default.gray(`create ${entityType}`)}`;
|
1219
|
+
text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`;
|
1220
|
+
text += idx != this.state.items.length - 1 ? "\n" : "";
|
1221
|
+
});
|
1222
|
+
return text;
|
1223
|
+
}
|
1224
|
+
result() {
|
1225
|
+
return this.state.items[this.state.selectedIdx];
|
1226
|
+
}
|
1227
|
+
};
|
1181
1228
|
ResolveSelect = class extends import_hanji.Prompt {
|
1182
1229
|
constructor(base, data, entityType) {
|
1183
1230
|
super();
|
@@ -1315,6 +1362,11 @@ Is ${source_default.bold.blue(
|
|
1315
1362
|
count: 0,
|
1316
1363
|
name: "foreign keys",
|
1317
1364
|
status: "fetching"
|
1365
|
+
},
|
1366
|
+
policies: {
|
1367
|
+
count: 0,
|
1368
|
+
name: "policies",
|
1369
|
+
status: "fetching"
|
1318
1370
|
}
|
1319
1371
|
};
|
1320
1372
|
this.formatCount = (count) => {
|
@@ -1352,6 +1404,7 @@ Is ${source_default.bold.blue(
|
|
1352
1404
|
info2 += this.hasEnums ? this.statusText(spin, this.state.enums) : "";
|
1353
1405
|
info2 += this.statusText(spin, this.state.indexes);
|
1354
1406
|
info2 += this.statusText(spin, this.state.fks);
|
1407
|
+
info2 += this.statusText(spin, this.state.policies);
|
1355
1408
|
return info2;
|
1356
1409
|
}
|
1357
1410
|
};
|
@@ -1736,8 +1789,8 @@ var init_lib = __esm({
|
|
1736
1789
|
return void 0;
|
1737
1790
|
};
|
1738
1791
|
util2.isInteger = typeof Number.isInteger === "function" ? (val2) => Number.isInteger(val2) : (val2) => typeof val2 === "number" && isFinite(val2) && Math.floor(val2) === val2;
|
1739
|
-
function joinValues(
|
1740
|
-
return
|
1792
|
+
function joinValues(array2, separator = " | ") {
|
1793
|
+
return array2.map((val2) => typeof val2 === "string" ? `'${val2}'` : val2).join(separator);
|
1741
1794
|
}
|
1742
1795
|
util2.joinValues = joinValues;
|
1743
1796
|
util2.jsonStringifyReplacer = (_2, value) => {
|
@@ -5706,7 +5759,7 @@ var init_vector = __esm({
|
|
5706
5759
|
});
|
5707
5760
|
|
5708
5761
|
// src/serializer/pgSchema.ts
|
5709
|
-
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
5762
|
+
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, roleSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, policy, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
5710
5763
|
var init_pgSchema = __esm({
|
5711
5764
|
"src/serializer/pgSchema.ts"() {
|
5712
5765
|
"use strict";
|
@@ -5838,6 +5891,12 @@ var init_pgSchema = __esm({
|
|
5838
5891
|
cycle: booleanType().optional(),
|
5839
5892
|
schema: stringType()
|
5840
5893
|
}).strict();
|
5894
|
+
roleSchema = objectType({
|
5895
|
+
name: stringType(),
|
5896
|
+
createDb: booleanType().optional(),
|
5897
|
+
createRole: booleanType().optional(),
|
5898
|
+
inherit: booleanType().optional()
|
5899
|
+
}).strict();
|
5841
5900
|
sequenceSquashed = objectType({
|
5842
5901
|
name: stringType(),
|
5843
5902
|
schema: stringType(),
|
@@ -5901,6 +5960,14 @@ var init_pgSchema = __esm({
|
|
5901
5960
|
columns: stringType().array(),
|
5902
5961
|
nullsNotDistinct: booleanType()
|
5903
5962
|
}).strict();
|
5963
|
+
policy = objectType({
|
5964
|
+
name: stringType(),
|
5965
|
+
as: enumType(["PERMISSIVE", "RESTRICTIVE"]).optional(),
|
5966
|
+
for: enumType(["ALL", "SELECT", "INSERT", "UPDATE", "DELETE"]).optional(),
|
5967
|
+
to: stringType().array().optional(),
|
5968
|
+
using: stringType().optional(),
|
5969
|
+
withCheck: stringType().optional()
|
5970
|
+
}).strict();
|
5904
5971
|
tableV42 = objectType({
|
5905
5972
|
name: stringType(),
|
5906
5973
|
schema: stringType(),
|
@@ -5942,7 +6009,8 @@ var init_pgSchema = __esm({
|
|
5942
6009
|
indexes: recordType(stringType(), index2),
|
5943
6010
|
foreignKeys: recordType(stringType(), fk2),
|
5944
6011
|
compositePrimaryKeys: recordType(stringType(), compositePK2),
|
5945
|
-
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
|
6012
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({}),
|
6013
|
+
policies: recordType(stringType(), policy).default({})
|
5946
6014
|
}).strict();
|
5947
6015
|
schemaHash2 = objectType({
|
5948
6016
|
id: stringType(),
|
@@ -6036,6 +6104,7 @@ var init_pgSchema = __esm({
|
|
6036
6104
|
enums: recordType(stringType(), enumSchema),
|
6037
6105
|
schemas: recordType(stringType(), stringType()),
|
6038
6106
|
sequences: recordType(stringType(), sequenceSchema).default({}),
|
6107
|
+
roles: recordType(stringType(), roleSchema).default({}),
|
6039
6108
|
_meta: objectType({
|
6040
6109
|
schemas: recordType(stringType(), stringType()),
|
6041
6110
|
tables: recordType(stringType(), stringType()),
|
@@ -6050,7 +6119,8 @@ var init_pgSchema = __esm({
|
|
6050
6119
|
indexes: recordType(stringType(), stringType()),
|
6051
6120
|
foreignKeys: recordType(stringType(), stringType()),
|
6052
6121
|
compositePrimaryKeys: recordType(stringType(), stringType()),
|
6053
|
-
uniqueConstraints: recordType(stringType(), stringType())
|
6122
|
+
uniqueConstraints: recordType(stringType(), stringType()),
|
6123
|
+
policies: recordType(stringType(), stringType())
|
6054
6124
|
}).strict();
|
6055
6125
|
tableSquashedV42 = objectType({
|
6056
6126
|
name: stringType(),
|
@@ -6079,7 +6149,8 @@ var init_pgSchema = __esm({
|
|
6079
6149
|
tables: recordType(stringType(), tableSquashed2),
|
6080
6150
|
enums: recordType(stringType(), enumSchema),
|
6081
6151
|
schemas: recordType(stringType(), stringType()),
|
6082
|
-
sequences: recordType(stringType(), sequenceSquashed)
|
6152
|
+
sequences: recordType(stringType(), sequenceSquashed),
|
6153
|
+
roles: recordType(stringType(), roleSchema).default({})
|
6083
6154
|
}).strict();
|
6084
6155
|
pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
|
6085
6156
|
pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
|
@@ -6162,6 +6233,25 @@ var init_pgSchema = __esm({
|
|
6162
6233
|
squashFK: (fk4) => {
|
6163
6234
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo || "public"}`;
|
6164
6235
|
},
|
6236
|
+
squashPolicy: (policy2) => {
|
6237
|
+
var _a;
|
6238
|
+
return `${policy2.name}--${policy2.as}--${policy2.for}--${(_a = policy2.to) == null ? void 0 : _a.join(",")}--${policy2.using}--${policy2.withCheck}`;
|
6239
|
+
},
|
6240
|
+
unsquashPolicy: (policy2) => {
|
6241
|
+
const splitted = policy2.split("--");
|
6242
|
+
return {
|
6243
|
+
name: splitted[0],
|
6244
|
+
as: splitted[1],
|
6245
|
+
for: splitted[2],
|
6246
|
+
to: splitted[3].split(","),
|
6247
|
+
using: splitted[4] !== "undefined" ? splitted[4] : void 0,
|
6248
|
+
withCheck: splitted[5] !== "undefined" ? splitted[5] : void 0
|
6249
|
+
};
|
6250
|
+
},
|
6251
|
+
squashPolicyPush: (policy2) => {
|
6252
|
+
var _a;
|
6253
|
+
return `${policy2.name}--${policy2.as}--${policy2.for}--${(_a = policy2.to) == null ? void 0 : _a.join(",")}`;
|
6254
|
+
},
|
6165
6255
|
squashPK: (pk) => {
|
6166
6256
|
return `${pk.columns.join(",")};${pk.name}`;
|
6167
6257
|
},
|
@@ -6264,6 +6354,9 @@ var init_pgSchema = __esm({
|
|
6264
6354
|
return PgSquasher.squashUnique(unq);
|
6265
6355
|
}
|
6266
6356
|
);
|
6357
|
+
const squashedPolicies = mapValues(it[1].policies, (policy2) => {
|
6358
|
+
return action === "push" ? PgSquasher.squashPolicyPush(policy2) : PgSquasher.squashPolicy(policy2);
|
6359
|
+
});
|
6267
6360
|
return [
|
6268
6361
|
it[0],
|
6269
6362
|
{
|
@@ -6273,7 +6366,8 @@ var init_pgSchema = __esm({
|
|
6273
6366
|
indexes: squashedIndexes,
|
6274
6367
|
foreignKeys: squashedFKs,
|
6275
6368
|
compositePrimaryKeys: squashedPKs,
|
6276
|
-
uniqueConstraints: squashedUniqueConstraints
|
6369
|
+
uniqueConstraints: squashedUniqueConstraints,
|
6370
|
+
policies: squashedPolicies
|
6277
6371
|
}
|
6278
6372
|
];
|
6279
6373
|
})
|
@@ -6296,7 +6390,8 @@ var init_pgSchema = __esm({
|
|
6296
6390
|
tables: mappedTables,
|
6297
6391
|
enums: json.enums,
|
6298
6392
|
schemas: json.schemas,
|
6299
|
-
sequences: mappedSequences
|
6393
|
+
sequences: mappedSequences,
|
6394
|
+
roles: json.roles
|
6300
6395
|
};
|
6301
6396
|
};
|
6302
6397
|
dryPg = pgSchema.parse({
|
@@ -10596,10 +10691,10 @@ var require_inflight = __commonJS({
|
|
10596
10691
|
}
|
10597
10692
|
function slice(args) {
|
10598
10693
|
var length = args.length;
|
10599
|
-
var
|
10694
|
+
var array2 = [];
|
10600
10695
|
for (var i2 = 0; i2 < length; i2++)
|
10601
|
-
|
10602
|
-
return
|
10696
|
+
array2[i2] = args[i2];
|
10697
|
+
return array2;
|
10603
10698
|
}
|
10604
10699
|
}
|
10605
10700
|
});
|
@@ -11422,6 +11517,13 @@ var init_cli = __esm({
|
|
11422
11517
|
breakpoints: booleanType().optional().default(true),
|
11423
11518
|
migrations: objectType({
|
11424
11519
|
prefix: prefix.optional().default("index")
|
11520
|
+
}).optional(),
|
11521
|
+
entities: objectType({
|
11522
|
+
roles: booleanType().or(objectType({
|
11523
|
+
provider: stringType().optional(),
|
11524
|
+
include: stringType().array().optional(),
|
11525
|
+
exclude: stringType().array().optional()
|
11526
|
+
})).optional().default(false)
|
11425
11527
|
}).optional()
|
11426
11528
|
}).passthrough();
|
11427
11529
|
configCheck = objectType({
|
@@ -17609,7 +17711,8 @@ var init_utils4 = __esm({
|
|
17609
17711
|
credentials: parsed2.data,
|
17610
17712
|
tablesFilter,
|
17611
17713
|
schemasFilter,
|
17612
|
-
prefix: ((_a = config.migrations) == null ? void 0 : _a.prefix) || "index"
|
17714
|
+
prefix: ((_a = config.migrations) == null ? void 0 : _a.prefix) || "index",
|
17715
|
+
entities: config.entities
|
17613
17716
|
};
|
17614
17717
|
}
|
17615
17718
|
if (dialect4 === "mysql") {
|
@@ -17626,7 +17729,8 @@ var init_utils4 = __esm({
|
|
17626
17729
|
credentials: parsed2.data,
|
17627
17730
|
tablesFilter,
|
17628
17731
|
schemasFilter,
|
17629
|
-
prefix: ((_b = config.migrations) == null ? void 0 : _b.prefix) || "index"
|
17732
|
+
prefix: ((_b = config.migrations) == null ? void 0 : _b.prefix) || "index",
|
17733
|
+
entities: config.entities
|
17630
17734
|
};
|
17631
17735
|
}
|
17632
17736
|
if (dialect4 === "sqlite") {
|
@@ -17643,7 +17747,8 @@ var init_utils4 = __esm({
|
|
17643
17747
|
credentials: parsed2.data,
|
17644
17748
|
tablesFilter,
|
17645
17749
|
schemasFilter,
|
17646
|
-
prefix: ((_c = config.migrations) == null ? void 0 : _c.prefix) || "index"
|
17750
|
+
prefix: ((_c = config.migrations) == null ? void 0 : _c.prefix) || "index",
|
17751
|
+
entities: config.entities
|
17647
17752
|
};
|
17648
17753
|
}
|
17649
17754
|
if (dialect4 === "turso") {
|
@@ -18499,6 +18604,7 @@ var init_pgImports = __esm({
|
|
18499
18604
|
const enums = [];
|
18500
18605
|
const schemas = [];
|
18501
18606
|
const sequences = [];
|
18607
|
+
const roles = [];
|
18502
18608
|
const i0values = Object.values(exports2);
|
18503
18609
|
i0values.forEach((t2) => {
|
18504
18610
|
if ((0, import_pg_core.isPgEnum)(t2)) {
|
@@ -18514,14 +18620,18 @@ var init_pgImports = __esm({
|
|
18514
18620
|
if ((0, import_pg_core.isPgSequence)(t2)) {
|
18515
18621
|
sequences.push(t2);
|
18516
18622
|
}
|
18623
|
+
if ((0, import_drizzle_orm4.is)(t2, import_pg_core.PgRole)) {
|
18624
|
+
roles.push(t2);
|
18625
|
+
}
|
18517
18626
|
});
|
18518
|
-
return { tables, enums, schemas, sequences };
|
18627
|
+
return { tables, enums, schemas, sequences, roles };
|
18519
18628
|
};
|
18520
18629
|
prepareFromPgImports = async (imports) => {
|
18521
18630
|
let tables = [];
|
18522
18631
|
let enums = [];
|
18523
18632
|
let schemas = [];
|
18524
18633
|
let sequences = [];
|
18634
|
+
let roles = [];
|
18525
18635
|
const { unregister } = await safeRegister();
|
18526
18636
|
for (let i2 = 0; i2 < imports.length; i2++) {
|
18527
18637
|
const it = imports[i2];
|
@@ -18531,9 +18641,10 @@ var init_pgImports = __esm({
|
|
18531
18641
|
enums.push(...prepared.enums);
|
18532
18642
|
schemas.push(...prepared.schemas);
|
18533
18643
|
sequences.push(...prepared.sequences);
|
18644
|
+
roles.push(...prepared.roles);
|
18534
18645
|
}
|
18535
18646
|
unregister();
|
18536
|
-
return { tables: Array.from(new Set(tables)), enums, schemas, sequences };
|
18647
|
+
return { tables: Array.from(new Set(tables)), enums, schemas, sequences, roles };
|
18537
18648
|
};
|
18538
18649
|
}
|
18539
18650
|
});
|
@@ -18541,9 +18652,11 @@ var init_pgImports = __esm({
|
|
18541
18652
|
// src/serializer/pgSerializer.ts
|
18542
18653
|
var pgSerializer_exports = {};
|
18543
18654
|
__export(pgSerializer_exports, {
|
18655
|
+
buildArrayString: () => buildArrayString,
|
18544
18656
|
fromDatabase: () => fromDatabase2,
|
18545
18657
|
generatePgSnapshot: () => generatePgSnapshot,
|
18546
|
-
indexName: () => indexName2
|
18658
|
+
indexName: () => indexName2,
|
18659
|
+
minRangeForIdentityBasedOn: () => minRangeForIdentityBasedOn
|
18547
18660
|
});
|
18548
18661
|
function stringFromIdentityProperty(field) {
|
18549
18662
|
return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
|
@@ -18557,9 +18670,9 @@ function minRangeForIdentityBasedOn(columnType) {
|
|
18557
18670
|
function stringFromDatabaseIdentityProperty(field) {
|
18558
18671
|
return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : typeof field === "bigint" ? field.toString() : String(field);
|
18559
18672
|
}
|
18560
|
-
function buildArrayString(
|
18673
|
+
function buildArrayString(array2, sqlType) {
|
18561
18674
|
sqlType = sqlType.split("[")[0];
|
18562
|
-
const values =
|
18675
|
+
const values = array2.map((value) => {
|
18563
18676
|
if (typeof value === "number" || typeof value === "bigint") {
|
18564
18677
|
return value.toString();
|
18565
18678
|
} else if (typeof value === "boolean") {
|
@@ -18581,6 +18694,40 @@ function buildArrayString(array, sqlType) {
|
|
18581
18694
|
}).join(",");
|
18582
18695
|
return `{${values}}`;
|
18583
18696
|
}
|
18697
|
+
function prepareRoles(entities) {
|
18698
|
+
let useRoles = false;
|
18699
|
+
const includeRoles = [];
|
18700
|
+
const excludeRoles = [];
|
18701
|
+
if (entities && entities.roles) {
|
18702
|
+
if (typeof entities.roles === "object") {
|
18703
|
+
if (entities.roles.provider) {
|
18704
|
+
if (entities.roles.provider === "supabase") {
|
18705
|
+
excludeRoles.push(...[
|
18706
|
+
"anon",
|
18707
|
+
"authenticator",
|
18708
|
+
"authenticated",
|
18709
|
+
"service_role",
|
18710
|
+
"supabase_auth_admin",
|
18711
|
+
"supabase_storage_admin",
|
18712
|
+
"dashboard_user",
|
18713
|
+
"supabase_admin"
|
18714
|
+
]);
|
18715
|
+
} else if (entities.roles.provider === "neon") {
|
18716
|
+
excludeRoles.push(...["authenticated", "anonymous"]);
|
18717
|
+
}
|
18718
|
+
}
|
18719
|
+
if (entities.roles.include) {
|
18720
|
+
includeRoles.push(...entities.roles.include);
|
18721
|
+
}
|
18722
|
+
if (entities.roles.exclude) {
|
18723
|
+
excludeRoles.push(...entities.roles.exclude);
|
18724
|
+
}
|
18725
|
+
} else {
|
18726
|
+
useRoles = entities.roles;
|
18727
|
+
}
|
18728
|
+
}
|
18729
|
+
return { useRoles, includeRoles, excludeRoles };
|
18730
|
+
}
|
18584
18731
|
var import_drizzle_orm5, import_pg_core2, import_pg_core3, indexName2, generatePgSnapshot, trimChar, fromDatabase2, defaultForColumn;
|
18585
18732
|
var init_pgSerializer = __esm({
|
18586
18733
|
"src/serializer/pgSerializer.ts"() {
|
@@ -18596,11 +18743,12 @@ var init_pgSerializer = __esm({
|
|
18596
18743
|
indexName2 = (tableName, columns) => {
|
18597
18744
|
return `${tableName}_${columns.join("_")}_index`;
|
18598
18745
|
};
|
18599
|
-
generatePgSnapshot = (tables, enums, schemas, sequences, casing2, schemaFilter) => {
|
18746
|
+
generatePgSnapshot = (tables, enums, schemas, sequences, roles, casing2, schemaFilter) => {
|
18600
18747
|
var _a, _b, _c, _d, _e, _f;
|
18601
18748
|
const dialect4 = new import_pg_core2.PgDialect({ casing: casing2 });
|
18602
18749
|
const result = {};
|
18603
18750
|
const sequencesToReturn = {};
|
18751
|
+
const rolesToReturn = {};
|
18604
18752
|
const indexesInSchema = {};
|
18605
18753
|
for (const table4 of tables) {
|
18606
18754
|
const {
|
@@ -18611,7 +18759,8 @@ var init_pgSerializer = __esm({
|
|
18611
18759
|
checks,
|
18612
18760
|
schema: schema5,
|
18613
18761
|
primaryKeys,
|
18614
|
-
uniqueConstraints
|
18762
|
+
uniqueConstraints,
|
18763
|
+
policies
|
18615
18764
|
} = (0, import_pg_core3.getTableConfig)(table4);
|
18616
18765
|
if (schemaFilter && !schemaFilter.includes(schema5 ?? "public")) {
|
18617
18766
|
continue;
|
@@ -18621,6 +18770,7 @@ var init_pgSerializer = __esm({
|
|
18621
18770
|
const foreignKeysObject = {};
|
18622
18771
|
const primaryKeysObject = {};
|
18623
18772
|
const uniqueConstraintObject = {};
|
18773
|
+
const policiesObject = {};
|
18624
18774
|
columns.forEach((column7) => {
|
18625
18775
|
var _a2, _b2, _c2, _d2, _e2, _f2;
|
18626
18776
|
const name = getColumnCasing(column7, casing2);
|
@@ -18885,6 +19035,35 @@ ${withStyle.errorWarning(
|
|
18885
19035
|
with: value.config.with ?? {}
|
18886
19036
|
};
|
18887
19037
|
});
|
19038
|
+
policies.forEach((policy2) => {
|
19039
|
+
var _a2, _b2;
|
19040
|
+
const mappedTo = [];
|
19041
|
+
if (!policy2.to) {
|
19042
|
+
mappedTo.push("public");
|
19043
|
+
} else {
|
19044
|
+
if (policy2.to && typeof policy2.to === "string") {
|
19045
|
+
mappedTo.push(policy2.to);
|
19046
|
+
} else if (policy2.to && (0, import_drizzle_orm5.is)(policy2.to, import_pg_core2.PgRole)) {
|
19047
|
+
mappedTo.push(policy2.to.name);
|
19048
|
+
} else if (policy2.to && Array.isArray(policy2.to)) {
|
19049
|
+
policy2.to.forEach((it) => {
|
19050
|
+
if (typeof it === "string") {
|
19051
|
+
mappedTo.push(it);
|
19052
|
+
} else if ((0, import_drizzle_orm5.is)(it, import_pg_core2.PgRole)) {
|
19053
|
+
mappedTo.push(it.name);
|
19054
|
+
}
|
19055
|
+
});
|
19056
|
+
}
|
19057
|
+
}
|
19058
|
+
policiesObject[policy2.name] = {
|
19059
|
+
name: policy2.name,
|
19060
|
+
as: ((_a2 = policy2.as) == null ? void 0 : _a2.toUpperCase()) ?? "PERMISSIVE",
|
19061
|
+
for: ((_b2 = policy2.for) == null ? void 0 : _b2.toUpperCase()) ?? "ALL",
|
19062
|
+
to: mappedTo.sort(),
|
19063
|
+
using: (0, import_drizzle_orm5.is)(policy2.using, import_drizzle_orm5.SQL) ? dialect4.sqlToQuery(policy2.using).sql : void 0,
|
19064
|
+
withCheck: (0, import_drizzle_orm5.is)(policy2.withCheck, import_drizzle_orm5.SQL) ? dialect4.sqlToQuery(policy2.withCheck).sql : void 0
|
19065
|
+
};
|
19066
|
+
});
|
18888
19067
|
const tableKey2 = `${schema5 ?? "public"}.${tableName}`;
|
18889
19068
|
result[tableKey2] = {
|
18890
19069
|
name: tableName,
|
@@ -18893,7 +19072,8 @@ ${withStyle.errorWarning(
|
|
18893
19072
|
indexes: indexesObject,
|
18894
19073
|
foreignKeys: foreignKeysObject,
|
18895
19074
|
compositePrimaryKeys: primaryKeysObject,
|
18896
|
-
uniqueConstraints: uniqueConstraintObject
|
19075
|
+
uniqueConstraints: uniqueConstraintObject,
|
19076
|
+
policies: policiesObject
|
18897
19077
|
};
|
18898
19078
|
}
|
18899
19079
|
for (const sequence of sequences) {
|
@@ -18917,6 +19097,16 @@ ${withStyle.errorWarning(
|
|
18917
19097
|
} else {
|
18918
19098
|
}
|
18919
19099
|
}
|
19100
|
+
for (const role of roles) {
|
19101
|
+
if (!role._existing) {
|
19102
|
+
rolesToReturn[role.name] = {
|
19103
|
+
name: role.name,
|
19104
|
+
createDb: role.createDb === void 0 ? false : role.createDb,
|
19105
|
+
createRole: role.createRole === void 0 ? false : role.createRole,
|
19106
|
+
inherit: role.inherit === void 0 ? true : role.inherit
|
19107
|
+
};
|
19108
|
+
}
|
19109
|
+
}
|
18920
19110
|
const enumsToReturn = enums.reduce((map, obj) => {
|
18921
19111
|
const enumSchema3 = obj.schema || "public";
|
18922
19112
|
const key = `${enumSchema3}.${obj.enumName}`;
|
@@ -18943,6 +19133,7 @@ ${withStyle.errorWarning(
|
|
18943
19133
|
enums: enumsToReturn,
|
18944
19134
|
schemas: schemasObject,
|
18945
19135
|
sequences: sequencesToReturn,
|
19136
|
+
roles: rolesToReturn,
|
18946
19137
|
_meta: {
|
18947
19138
|
schemas: {},
|
18948
19139
|
tables: {},
|
@@ -18959,7 +19150,7 @@ ${withStyle.errorWarning(
|
|
18959
19150
|
--end;
|
18960
19151
|
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
18961
19152
|
};
|
18962
|
-
fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, progressCallback) => {
|
19153
|
+
fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, entities, progressCallback) => {
|
18963
19154
|
const result = {};
|
18964
19155
|
const internals = { tables: {} };
|
18965
19156
|
const where = schemaFilters.map((t2) => `table_schema = '${t2}'`).join(" or ");
|
@@ -19041,6 +19232,64 @@ ${withStyle.errorWarning(
|
|
19041
19232
|
if (progressCallback) {
|
19042
19233
|
progressCallback("enums", Object.keys(enumsToReturn).length, "done");
|
19043
19234
|
}
|
19235
|
+
const allRoles = await db.query(
|
19236
|
+
`SELECT rolname, rolinherit, rolcreatedb, rolcreaterole FROM pg_roles;`
|
19237
|
+
);
|
19238
|
+
const rolesToReturn = {};
|
19239
|
+
const preparedRoles = prepareRoles(entities);
|
19240
|
+
if (preparedRoles.useRoles || !(preparedRoles.includeRoles.length === 0 && preparedRoles.excludeRoles.length === 0)) {
|
19241
|
+
for (const dbRole of allRoles) {
|
19242
|
+
if (preparedRoles.useRoles) {
|
19243
|
+
rolesToReturn[dbRole.rolname] = {
|
19244
|
+
createDb: dbRole.rolcreatedb,
|
19245
|
+
createRole: dbRole.rolcreatedb,
|
19246
|
+
inherit: dbRole.rolinherit,
|
19247
|
+
name: dbRole.rolname
|
19248
|
+
};
|
19249
|
+
} else {
|
19250
|
+
if (preparedRoles.includeRoles.length === 0 && preparedRoles.excludeRoles.length === 0)
|
19251
|
+
continue;
|
19252
|
+
if (preparedRoles.includeRoles.includes(dbRole.rolname) && preparedRoles.excludeRoles.includes(dbRole.rolname))
|
19253
|
+
continue;
|
19254
|
+
if (preparedRoles.excludeRoles.includes(dbRole.rolname))
|
19255
|
+
continue;
|
19256
|
+
if (!preparedRoles.includeRoles.includes(dbRole.rolname))
|
19257
|
+
continue;
|
19258
|
+
rolesToReturn[dbRole.rolname] = {
|
19259
|
+
createDb: dbRole.rolcreatedb,
|
19260
|
+
createRole: dbRole.rolcreaterole,
|
19261
|
+
inherit: dbRole.rolinherit,
|
19262
|
+
name: dbRole.rolname
|
19263
|
+
};
|
19264
|
+
}
|
19265
|
+
}
|
19266
|
+
}
|
19267
|
+
const wherePolicies = schemaFilters.map((t2) => `schemaname = '${t2}'`).join(" or ");
|
19268
|
+
const policiesByTable = {};
|
19269
|
+
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}`};`);
|
19270
|
+
for (const dbPolicy of allPolicies) {
|
19271
|
+
const { tablename, schemaname, to, withCheck, using, ...rest } = dbPolicy;
|
19272
|
+
const tableForPolicy = policiesByTable[`${schemaname}.${tablename}`];
|
19273
|
+
const parsedTo = to;
|
19274
|
+
const parsedWithCheck = withCheck === null ? void 0 : withCheck;
|
19275
|
+
const parsedUsing = using === null ? void 0 : using;
|
19276
|
+
if (tableForPolicy) {
|
19277
|
+
tableForPolicy[dbPolicy.name] = { ...rest, to: parsedTo };
|
19278
|
+
} else {
|
19279
|
+
policiesByTable[`${schemaname}.${tablename}`] = {
|
19280
|
+
[dbPolicy.name]: { ...rest, to: parsedTo, withCheck: parsedWithCheck, using: parsedUsing }
|
19281
|
+
};
|
19282
|
+
}
|
19283
|
+
}
|
19284
|
+
if (progressCallback) {
|
19285
|
+
progressCallback(
|
19286
|
+
"policies",
|
19287
|
+
Object.values(policiesByTable).reduce((total, innerRecord) => {
|
19288
|
+
return total + Object.keys(innerRecord).length;
|
19289
|
+
}, 0),
|
19290
|
+
"done"
|
19291
|
+
);
|
19292
|
+
}
|
19044
19293
|
const sequencesInColumns = [];
|
19045
19294
|
const all = allTables.map((row) => {
|
19046
19295
|
return new Promise(async (res, rej) => {
|
@@ -19437,7 +19686,8 @@ ${withStyle.errorWarning(
|
|
19437
19686
|
indexes: indexToReturn,
|
19438
19687
|
foreignKeys: foreignKeysToReturn,
|
19439
19688
|
compositePrimaryKeys: primaryKeys,
|
19440
|
-
uniqueConstraints: uniqueConstrains
|
19689
|
+
uniqueConstraints: uniqueConstrains,
|
19690
|
+
policies: policiesByTable[`${tableSchema}.${tableName}`] ?? {}
|
19441
19691
|
};
|
19442
19692
|
} catch (e2) {
|
19443
19693
|
rej(e2);
|
@@ -19464,6 +19714,7 @@ ${withStyle.errorWarning(
|
|
19464
19714
|
enums: enumsToReturn,
|
19465
19715
|
schemas: schemasObject,
|
19466
19716
|
sequences: sequencesToReturn,
|
19717
|
+
roles: rolesToReturn,
|
19467
19718
|
_meta: {
|
19468
19719
|
schemas: {},
|
19469
19720
|
tables: {},
|
@@ -20128,10 +20379,10 @@ ${filenames.join("\n")}
|
|
20128
20379
|
const filenames = prepareFilenames(path5);
|
20129
20380
|
const { prepareFromPgImports: prepareFromPgImports2 } = await Promise.resolve().then(() => (init_pgImports(), pgImports_exports));
|
20130
20381
|
const { generatePgSnapshot: generatePgSnapshot2 } = await Promise.resolve().then(() => (init_pgSerializer(), pgSerializer_exports));
|
20131
|
-
const { tables, enums, schemas, sequences } = await prepareFromPgImports2(
|
20382
|
+
const { tables, enums, schemas, sequences, roles } = await prepareFromPgImports2(
|
20132
20383
|
filenames
|
20133
20384
|
);
|
20134
|
-
return generatePgSnapshot2(tables, enums, schemas, sequences, casing2, schemaFilter);
|
20385
|
+
return generatePgSnapshot2(tables, enums, schemas, sequences, roles, casing2, schemaFilter);
|
20135
20386
|
};
|
20136
20387
|
serializeSQLite = async (path5, casing2) => {
|
20137
20388
|
const filenames = prepareFilenames(path5);
|
@@ -20326,57 +20577,57 @@ var require_heap = __commonJS({
|
|
20326
20577
|
}
|
20327
20578
|
return [].splice.apply(a, [lo, lo - lo].concat(x2)), x2;
|
20328
20579
|
};
|
20329
|
-
heappush = function(
|
20580
|
+
heappush = function(array2, item, cmp) {
|
20330
20581
|
if (cmp == null) {
|
20331
20582
|
cmp = defaultCmp;
|
20332
20583
|
}
|
20333
|
-
|
20334
|
-
return _siftdown(
|
20584
|
+
array2.push(item);
|
20585
|
+
return _siftdown(array2, 0, array2.length - 1, cmp);
|
20335
20586
|
};
|
20336
|
-
heappop = function(
|
20587
|
+
heappop = function(array2, cmp) {
|
20337
20588
|
var lastelt, returnitem;
|
20338
20589
|
if (cmp == null) {
|
20339
20590
|
cmp = defaultCmp;
|
20340
20591
|
}
|
20341
|
-
lastelt =
|
20342
|
-
if (
|
20343
|
-
returnitem =
|
20344
|
-
|
20345
|
-
_siftup(
|
20592
|
+
lastelt = array2.pop();
|
20593
|
+
if (array2.length) {
|
20594
|
+
returnitem = array2[0];
|
20595
|
+
array2[0] = lastelt;
|
20596
|
+
_siftup(array2, 0, cmp);
|
20346
20597
|
} else {
|
20347
20598
|
returnitem = lastelt;
|
20348
20599
|
}
|
20349
20600
|
return returnitem;
|
20350
20601
|
};
|
20351
|
-
heapreplace = function(
|
20602
|
+
heapreplace = function(array2, item, cmp) {
|
20352
20603
|
var returnitem;
|
20353
20604
|
if (cmp == null) {
|
20354
20605
|
cmp = defaultCmp;
|
20355
20606
|
}
|
20356
|
-
returnitem =
|
20357
|
-
|
20358
|
-
_siftup(
|
20607
|
+
returnitem = array2[0];
|
20608
|
+
array2[0] = item;
|
20609
|
+
_siftup(array2, 0, cmp);
|
20359
20610
|
return returnitem;
|
20360
20611
|
};
|
20361
|
-
heappushpop = function(
|
20612
|
+
heappushpop = function(array2, item, cmp) {
|
20362
20613
|
var _ref;
|
20363
20614
|
if (cmp == null) {
|
20364
20615
|
cmp = defaultCmp;
|
20365
20616
|
}
|
20366
|
-
if (
|
20367
|
-
_ref = [
|
20368
|
-
_siftup(
|
20617
|
+
if (array2.length && cmp(array2[0], item) < 0) {
|
20618
|
+
_ref = [array2[0], item], item = _ref[0], array2[0] = _ref[1];
|
20619
|
+
_siftup(array2, 0, cmp);
|
20369
20620
|
}
|
20370
20621
|
return item;
|
20371
20622
|
};
|
20372
|
-
heapify = function(
|
20623
|
+
heapify = function(array2, cmp) {
|
20373
20624
|
var i2, _i, _j, _len, _ref, _ref1, _results, _results1;
|
20374
20625
|
if (cmp == null) {
|
20375
20626
|
cmp = defaultCmp;
|
20376
20627
|
}
|
20377
20628
|
_ref1 = function() {
|
20378
20629
|
_results1 = [];
|
20379
|
-
for (var _j2 = 0, _ref2 = floor(
|
20630
|
+
for (var _j2 = 0, _ref2 = floor(array2.length / 2); 0 <= _ref2 ? _j2 < _ref2 : _j2 > _ref2; 0 <= _ref2 ? _j2++ : _j2--) {
|
20380
20631
|
_results1.push(_j2);
|
20381
20632
|
}
|
20382
20633
|
return _results1;
|
@@ -20384,51 +20635,51 @@ var require_heap = __commonJS({
|
|
20384
20635
|
_results = [];
|
20385
20636
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
20386
20637
|
i2 = _ref1[_i];
|
20387
|
-
_results.push(_siftup(
|
20638
|
+
_results.push(_siftup(array2, i2, cmp));
|
20388
20639
|
}
|
20389
20640
|
return _results;
|
20390
20641
|
};
|
20391
|
-
updateItem = function(
|
20642
|
+
updateItem = function(array2, item, cmp) {
|
20392
20643
|
var pos;
|
20393
20644
|
if (cmp == null) {
|
20394
20645
|
cmp = defaultCmp;
|
20395
20646
|
}
|
20396
|
-
pos =
|
20647
|
+
pos = array2.indexOf(item);
|
20397
20648
|
if (pos === -1) {
|
20398
20649
|
return;
|
20399
20650
|
}
|
20400
|
-
_siftdown(
|
20401
|
-
return _siftup(
|
20651
|
+
_siftdown(array2, 0, pos, cmp);
|
20652
|
+
return _siftup(array2, pos, cmp);
|
20402
20653
|
};
|
20403
|
-
nlargest = function(
|
20654
|
+
nlargest = function(array2, n, cmp) {
|
20404
20655
|
var elem, result, _i, _len, _ref;
|
20405
20656
|
if (cmp == null) {
|
20406
20657
|
cmp = defaultCmp;
|
20407
20658
|
}
|
20408
|
-
result =
|
20659
|
+
result = array2.slice(0, n);
|
20409
20660
|
if (!result.length) {
|
20410
20661
|
return result;
|
20411
20662
|
}
|
20412
20663
|
heapify(result, cmp);
|
20413
|
-
_ref =
|
20664
|
+
_ref = array2.slice(n);
|
20414
20665
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
20415
20666
|
elem = _ref[_i];
|
20416
20667
|
heappushpop(result, elem, cmp);
|
20417
20668
|
}
|
20418
20669
|
return result.sort(cmp).reverse();
|
20419
20670
|
};
|
20420
|
-
nsmallest = function(
|
20671
|
+
nsmallest = function(array2, n, cmp) {
|
20421
20672
|
var elem, i2, los, result, _i, _j, _len, _ref, _ref1, _results;
|
20422
20673
|
if (cmp == null) {
|
20423
20674
|
cmp = defaultCmp;
|
20424
20675
|
}
|
20425
|
-
if (n * 10 <=
|
20426
|
-
result =
|
20676
|
+
if (n * 10 <= array2.length) {
|
20677
|
+
result = array2.slice(0, n).sort(cmp);
|
20427
20678
|
if (!result.length) {
|
20428
20679
|
return result;
|
20429
20680
|
}
|
20430
20681
|
los = result[result.length - 1];
|
20431
|
-
_ref =
|
20682
|
+
_ref = array2.slice(n);
|
20432
20683
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
20433
20684
|
elem = _ref[_i];
|
20434
20685
|
if (cmp(elem, los) < 0) {
|
@@ -20439,51 +20690,51 @@ var require_heap = __commonJS({
|
|
20439
20690
|
}
|
20440
20691
|
return result;
|
20441
20692
|
}
|
20442
|
-
heapify(
|
20693
|
+
heapify(array2, cmp);
|
20443
20694
|
_results = [];
|
20444
|
-
for (i2 = _j = 0, _ref1 = min(n,
|
20445
|
-
_results.push(heappop(
|
20695
|
+
for (i2 = _j = 0, _ref1 = min(n, array2.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i2 = 0 <= _ref1 ? ++_j : --_j) {
|
20696
|
+
_results.push(heappop(array2, cmp));
|
20446
20697
|
}
|
20447
20698
|
return _results;
|
20448
20699
|
};
|
20449
|
-
_siftdown = function(
|
20700
|
+
_siftdown = function(array2, startpos, pos, cmp) {
|
20450
20701
|
var newitem, parent, parentpos;
|
20451
20702
|
if (cmp == null) {
|
20452
20703
|
cmp = defaultCmp;
|
20453
20704
|
}
|
20454
|
-
newitem =
|
20705
|
+
newitem = array2[pos];
|
20455
20706
|
while (pos > startpos) {
|
20456
20707
|
parentpos = pos - 1 >> 1;
|
20457
|
-
parent =
|
20708
|
+
parent = array2[parentpos];
|
20458
20709
|
if (cmp(newitem, parent) < 0) {
|
20459
|
-
|
20710
|
+
array2[pos] = parent;
|
20460
20711
|
pos = parentpos;
|
20461
20712
|
continue;
|
20462
20713
|
}
|
20463
20714
|
break;
|
20464
20715
|
}
|
20465
|
-
return
|
20716
|
+
return array2[pos] = newitem;
|
20466
20717
|
};
|
20467
|
-
_siftup = function(
|
20718
|
+
_siftup = function(array2, pos, cmp) {
|
20468
20719
|
var childpos, endpos, newitem, rightpos, startpos;
|
20469
20720
|
if (cmp == null) {
|
20470
20721
|
cmp = defaultCmp;
|
20471
20722
|
}
|
20472
|
-
endpos =
|
20723
|
+
endpos = array2.length;
|
20473
20724
|
startpos = pos;
|
20474
|
-
newitem =
|
20725
|
+
newitem = array2[pos];
|
20475
20726
|
childpos = 2 * pos + 1;
|
20476
20727
|
while (childpos < endpos) {
|
20477
20728
|
rightpos = childpos + 1;
|
20478
|
-
if (rightpos < endpos && !(cmp(
|
20729
|
+
if (rightpos < endpos && !(cmp(array2[childpos], array2[rightpos]) < 0)) {
|
20479
20730
|
childpos = rightpos;
|
20480
20731
|
}
|
20481
|
-
|
20732
|
+
array2[pos] = array2[childpos];
|
20482
20733
|
pos = childpos;
|
20483
20734
|
childpos = 2 * pos + 1;
|
20484
20735
|
}
|
20485
|
-
|
20486
|
-
return _siftdown(
|
20736
|
+
array2[pos] = newitem;
|
20737
|
+
return _siftdown(array2, startpos, pos, cmp);
|
20487
20738
|
};
|
20488
20739
|
Heap = function() {
|
20489
20740
|
Heap2.push = heappush;
|
@@ -22396,12 +22647,12 @@ var require_lib = __commonJS({
|
|
22396
22647
|
}
|
22397
22648
|
return bestMatch;
|
22398
22649
|
}
|
22399
|
-
scalarize(
|
22650
|
+
scalarize(array2, originals, fuzzyOriginals) {
|
22400
22651
|
const fuzzyMatches = [];
|
22401
22652
|
if (fuzzyOriginals) {
|
22402
22653
|
const keyScores = {};
|
22403
|
-
for (let index4 = 0; index4 <
|
22404
|
-
const item =
|
22654
|
+
for (let index4 = 0; index4 < array2.length; index4++) {
|
22655
|
+
const item = array2[index4];
|
22405
22656
|
if (this.isScalar(item)) {
|
22406
22657
|
continue;
|
22407
22658
|
}
|
@@ -22415,8 +22666,8 @@ var require_lib = __commonJS({
|
|
22415
22666
|
}
|
22416
22667
|
}
|
22417
22668
|
const result = [];
|
22418
|
-
for (let index4 = 0; index4 <
|
22419
|
-
const item =
|
22669
|
+
for (let index4 = 0; index4 < array2.length; index4++) {
|
22670
|
+
const item = array2[index4];
|
22420
22671
|
if (this.isScalar(item)) {
|
22421
22672
|
result.push(item);
|
22422
22673
|
} else {
|
@@ -22638,6 +22889,37 @@ function diffColumns(left, right) {
|
|
22638
22889
|
);
|
22639
22890
|
return alteredTables;
|
22640
22891
|
}
|
22892
|
+
function diffPolicies(left, right) {
|
22893
|
+
left = JSON.parse(JSON.stringify(left));
|
22894
|
+
right = JSON.parse(JSON.stringify(right));
|
22895
|
+
const result = (0, import_json_diff.diff)(left, right) ?? {};
|
22896
|
+
const alteredTables = Object.fromEntries(
|
22897
|
+
Object.entries(result).filter((it) => {
|
22898
|
+
return !(it[0].includes("__added") || it[0].includes("__deleted"));
|
22899
|
+
}).map((tableEntry) => {
|
22900
|
+
const deletedPolicies = Object.entries(tableEntry[1].policies ?? {}).filter((it) => {
|
22901
|
+
return it[0].endsWith("__deleted");
|
22902
|
+
}).map((it) => {
|
22903
|
+
return it[1];
|
22904
|
+
});
|
22905
|
+
const addedPolicies = Object.entries(tableEntry[1].policies ?? {}).filter((it) => {
|
22906
|
+
return it[0].endsWith("__added");
|
22907
|
+
}).map((it) => {
|
22908
|
+
return it[1];
|
22909
|
+
});
|
22910
|
+
tableEntry[1].policies = {
|
22911
|
+
added: addedPolicies,
|
22912
|
+
deleted: deletedPolicies
|
22913
|
+
};
|
22914
|
+
const table4 = left[tableEntry[0]];
|
22915
|
+
return [
|
22916
|
+
tableEntry[0],
|
22917
|
+
{ name: table4.name, schema: table4.schema, ...tableEntry[1] }
|
22918
|
+
];
|
22919
|
+
})
|
22920
|
+
);
|
22921
|
+
return alteredTables;
|
22922
|
+
}
|
22641
22923
|
function applyJsonDiff(json1, json2) {
|
22642
22924
|
json1 = JSON.parse(JSON.stringify(json1));
|
22643
22925
|
json2 = JSON.parse(JSON.stringify(json2));
|
@@ -22647,6 +22929,7 @@ function applyJsonDiff(json1, json2) {
|
|
22647
22929
|
difference.tables = difference.tables || {};
|
22648
22930
|
difference.enums = difference.enums || {};
|
22649
22931
|
difference.sequences = difference.sequences || {};
|
22932
|
+
difference.roles = difference.roles || {};
|
22650
22933
|
const schemaKeys = Object.keys(difference.schemas);
|
22651
22934
|
for (let key of schemaKeys) {
|
22652
22935
|
if (key.endsWith("__added") || key.endsWith("__deleted")) {
|
@@ -22702,6 +22985,10 @@ function applyJsonDiff(json1, json2) {
|
|
22702
22985
|
const alteredSequences = sequencesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted")) && "values" in it[1]).map((it) => {
|
22703
22986
|
return json2.sequences[it[0]];
|
22704
22987
|
});
|
22988
|
+
const rolesEntries = Object.entries(difference.roles);
|
22989
|
+
const alteredRoles = rolesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map((it) => {
|
22990
|
+
return json2.roles[it[0]];
|
22991
|
+
});
|
22705
22992
|
const alteredTablesWithColumns = Object.values(difference.tables).map(
|
22706
22993
|
(table4) => {
|
22707
22994
|
return findAlternationsInTable(table4);
|
@@ -22710,7 +22997,8 @@ function applyJsonDiff(json1, json2) {
|
|
22710
22997
|
return {
|
22711
22998
|
alteredTablesWithColumns,
|
22712
22999
|
alteredEnums,
|
22713
|
-
alteredSequences
|
23000
|
+
alteredSequences,
|
23001
|
+
alteredRoles
|
22714
23002
|
};
|
22715
23003
|
}
|
22716
23004
|
var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
|
@@ -22770,6 +23058,21 @@ var init_jsonDiffer = __esm({
|
|
22770
23058
|
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
22771
23059
|
})
|
22772
23060
|
);
|
23061
|
+
const deletedPolicies = Object.fromEntries(
|
23062
|
+
Object.entries(table4.policies__deleted || {}).concat(
|
23063
|
+
Object.entries(table4.policies || {}).filter((it) => it[0].includes("__deleted"))
|
23064
|
+
).map((entry) => [entry[0].replace("__deleted", ""), entry[1]])
|
23065
|
+
);
|
23066
|
+
const addedPolicies = Object.fromEntries(
|
23067
|
+
Object.entries(table4.policies__added || {}).concat(
|
23068
|
+
Object.entries(table4.policies || {}).filter((it) => it[0].includes("__added"))
|
23069
|
+
).map((entry) => [entry[0].replace("__added", ""), entry[1]])
|
23070
|
+
);
|
23071
|
+
const alteredPolicies = Object.fromEntries(
|
23072
|
+
Object.entries(table4.policies || {}).filter((it) => {
|
23073
|
+
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
23074
|
+
})
|
23075
|
+
);
|
22773
23076
|
const deletedForeignKeys = Object.fromEntries(
|
22774
23077
|
Object.entries(table4.foreignKeys__deleted || {}).concat(
|
22775
23078
|
Object.entries(table4.foreignKeys || {}).filter((it) => it[0].includes("__deleted"))
|
@@ -22831,7 +23134,10 @@ var init_jsonDiffer = __esm({
|
|
22831
23134
|
alteredCompositePKs,
|
22832
23135
|
addedUniqueConstraints,
|
22833
23136
|
deletedUniqueConstraints,
|
22834
|
-
alteredUniqueConstraints
|
23137
|
+
alteredUniqueConstraints,
|
23138
|
+
deletedPolicies,
|
23139
|
+
addedPolicies,
|
23140
|
+
alteredPolicies
|
22835
23141
|
};
|
22836
23142
|
};
|
22837
23143
|
alternationsInColumn = (column7) => {
|
@@ -23105,7 +23411,7 @@ function fromJson(statements, dialect4, action, json2) {
|
|
23105
23411
|
}).filter((it) => it !== "");
|
23106
23412
|
return result;
|
23107
23413
|
}
|
23108
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
23414
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
23109
23415
|
var init_sqlgenerator = __esm({
|
23110
23416
|
"src/sqlgenerator.ts"() {
|
23111
23417
|
"use strict";
|
@@ -23162,12 +23468,110 @@ var init_sqlgenerator = __esm({
|
|
23162
23468
|
};
|
23163
23469
|
Convertor = class {
|
23164
23470
|
};
|
23471
|
+
PgCreateRoleConvertor = class extends Convertor {
|
23472
|
+
can(statement, dialect4) {
|
23473
|
+
return statement.type === "create_role" && dialect4 === "postgresql";
|
23474
|
+
}
|
23475
|
+
convert(statement) {
|
23476
|
+
return `CREATE ROLE "${statement.name}"${statement.values.createDb || statement.values.createRole || !statement.values.inherit ? ` WITH${statement.values.createDb ? " CREATEDB" : ""}${statement.values.createRole ? " CREATEROLE" : ""}${statement.values.inherit ? "" : " NOINHERIT"}` : ""};`;
|
23477
|
+
}
|
23478
|
+
};
|
23479
|
+
PgDropRoleConvertor = class extends Convertor {
|
23480
|
+
can(statement, dialect4) {
|
23481
|
+
return statement.type === "drop_role" && dialect4 === "postgresql";
|
23482
|
+
}
|
23483
|
+
convert(statement) {
|
23484
|
+
return `DROP ROLE "${statement.name}";`;
|
23485
|
+
}
|
23486
|
+
};
|
23487
|
+
PgRenameRoleConvertor = class extends Convertor {
|
23488
|
+
can(statement, dialect4) {
|
23489
|
+
return statement.type === "rename_role" && dialect4 === "postgresql";
|
23490
|
+
}
|
23491
|
+
convert(statement) {
|
23492
|
+
return `ALTER ROLE "${statement.nameFrom}" RENAME TO "${statement.nameTo}";`;
|
23493
|
+
}
|
23494
|
+
};
|
23495
|
+
PgAlterRoleConvertor = class extends Convertor {
|
23496
|
+
can(statement, dialect4) {
|
23497
|
+
return statement.type === "alter_role" && dialect4 === "postgresql";
|
23498
|
+
}
|
23499
|
+
convert(statement) {
|
23500
|
+
return `ALTER ROLE "${statement.name}"${` WITH${statement.values.createDb ? " CREATEDB" : " NOCREATEDB"}${statement.values.createRole ? " CREATEROLE" : " NOCREATEROLE"}${statement.values.inherit ? " INHERIT" : " NOINHERIT"}`};`;
|
23501
|
+
}
|
23502
|
+
};
|
23503
|
+
PgCreatePolicyConvertor = class extends Convertor {
|
23504
|
+
can(statement, dialect4) {
|
23505
|
+
return statement.type === "create_policy" && dialect4 === "postgresql";
|
23506
|
+
}
|
23507
|
+
convert(statement) {
|
23508
|
+
var _a, _b, _c;
|
23509
|
+
const policy2 = statement.data;
|
23510
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
23511
|
+
const usingPart = policy2.using ? ` USING (${policy2.using})` : "";
|
23512
|
+
const withCheckPart = policy2.withCheck ? ` WITH CHECK (${policy2.withCheck})` : "";
|
23513
|
+
const policyToPart = (_a = policy2.to) == null ? void 0 : _a.map(
|
23514
|
+
(v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
|
23515
|
+
).join(", ");
|
23516
|
+
return `CREATE POLICY "${policy2.name}" ON ${tableNameWithSchema} AS ${(_b = policy2.as) == null ? void 0 : _b.toUpperCase()} FOR ${(_c = policy2.for) == null ? void 0 : _c.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
|
23517
|
+
}
|
23518
|
+
};
|
23519
|
+
PgDropPolicyConvertor = class extends Convertor {
|
23520
|
+
can(statement, dialect4) {
|
23521
|
+
return statement.type === "drop_policy" && dialect4 === "postgresql";
|
23522
|
+
}
|
23523
|
+
convert(statement) {
|
23524
|
+
const policy2 = statement.data;
|
23525
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
23526
|
+
return `DROP POLICY "${policy2.name}" ON ${tableNameWithSchema} CASCADE;`;
|
23527
|
+
}
|
23528
|
+
};
|
23529
|
+
PgRenamePolicyConvertor = class extends Convertor {
|
23530
|
+
can(statement, dialect4) {
|
23531
|
+
return statement.type === "rename_policy" && dialect4 === "postgresql";
|
23532
|
+
}
|
23533
|
+
convert(statement) {
|
23534
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
23535
|
+
return `ALTER POLICY "${statement.oldName}" ON ${tableNameWithSchema} RENAME TO "${statement.newName}";`;
|
23536
|
+
}
|
23537
|
+
};
|
23538
|
+
PgAlterPolicyConvertor = class extends Convertor {
|
23539
|
+
can(statement, dialect4) {
|
23540
|
+
return statement.type === "alter_policy" && dialect4 === "postgresql";
|
23541
|
+
}
|
23542
|
+
convert(statement) {
|
23543
|
+
const newPolicy = PgSquasher.unsquashPolicy(statement.newData);
|
23544
|
+
const oldPolicy = PgSquasher.unsquashPolicy(statement.oldData);
|
23545
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
23546
|
+
const usingPart = newPolicy.using ? ` USING (${newPolicy.using})` : oldPolicy.using ? ` USING (${oldPolicy.using})` : "";
|
23547
|
+
const withCheckPart = newPolicy.withCheck ? ` WITH CHECK (${newPolicy.withCheck})` : oldPolicy.withCheck ? ` WITH CHECK (${oldPolicy.withCheck})` : "";
|
23548
|
+
return `ALTER POLICY "${oldPolicy.name}" ON ${tableNameWithSchema} TO ${newPolicy.to}${usingPart}${withCheckPart};`;
|
23549
|
+
}
|
23550
|
+
};
|
23551
|
+
PgEnableRlsConvertor = class extends Convertor {
|
23552
|
+
can(statement, dialect4) {
|
23553
|
+
return statement.type === "enable_rls" && dialect4 === "postgresql";
|
23554
|
+
}
|
23555
|
+
convert(statement) {
|
23556
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
23557
|
+
return `ALTER TABLE ${tableNameWithSchema} ENABLE ROW LEVEL SECURITY;`;
|
23558
|
+
}
|
23559
|
+
};
|
23560
|
+
PgDisableRlsConvertor = class extends Convertor {
|
23561
|
+
can(statement, dialect4) {
|
23562
|
+
return statement.type === "disable_rls" && dialect4 === "postgresql";
|
23563
|
+
}
|
23564
|
+
convert(statement) {
|
23565
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
23566
|
+
return `ALTER TABLE ${tableNameWithSchema} DISABLE ROW LEVEL SECURITY;`;
|
23567
|
+
}
|
23568
|
+
};
|
23165
23569
|
PgCreateTableConvertor = class extends Convertor {
|
23166
23570
|
can(statement, dialect4) {
|
23167
23571
|
return statement.type === "create_table" && dialect4 === "postgresql";
|
23168
23572
|
}
|
23169
23573
|
convert(st) {
|
23170
|
-
const { tableName, schema: schema5, columns, compositePKs, uniqueConstraints } = st;
|
23574
|
+
const { tableName, schema: schema5, columns, compositePKs, uniqueConstraints, policies } = st;
|
23171
23575
|
let statement = "";
|
23172
23576
|
const name = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
|
23173
23577
|
statement += `CREATE TABLE IF NOT EXISTS ${name} (
|
@@ -23204,7 +23608,12 @@ var init_sqlgenerator = __esm({
|
|
23204
23608
|
);`;
|
23205
23609
|
statement += `
|
23206
23610
|
`;
|
23207
|
-
|
23611
|
+
const enableRls = new PgEnableRlsConvertor().convert({
|
23612
|
+
type: "enable_rls",
|
23613
|
+
tableName,
|
23614
|
+
schema: schema5
|
23615
|
+
});
|
23616
|
+
return [statement, ...policies && policies.length > 0 ? [enableRls] : []];
|
23208
23617
|
}
|
23209
23618
|
};
|
23210
23619
|
MySqlCreateTableConvertor = class extends Convertor {
|
@@ -23489,20 +23898,22 @@ var init_sqlgenerator = __esm({
|
|
23489
23898
|
}
|
23490
23899
|
convert(st) {
|
23491
23900
|
const { name, values, schema: schema5 } = st;
|
23492
|
-
const
|
23901
|
+
const enumNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
|
23493
23902
|
let valuesStatement = "(";
|
23494
23903
|
valuesStatement += values.map((it) => `'${it}'`).join(", ");
|
23495
23904
|
valuesStatement += ")";
|
23496
|
-
let statement =
|
23497
|
-
statement
|
23498
|
-
|
23499
|
-
|
23500
|
-
|
23501
|
-
|
23502
|
-
statement
|
23503
|
-
|
23504
|
-
|
23505
|
-
|
23905
|
+
let statement = `CREATE TYPE ${enumNameWithSchema} AS ENUM${valuesStatement};`;
|
23906
|
+
return statement;
|
23907
|
+
}
|
23908
|
+
};
|
23909
|
+
DropTypeEnumConvertor = class extends Convertor {
|
23910
|
+
can(statement) {
|
23911
|
+
return statement.type === "drop_type_enum";
|
23912
|
+
}
|
23913
|
+
convert(st) {
|
23914
|
+
const { name, schema: schema5 } = st;
|
23915
|
+
const enumNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
|
23916
|
+
let statement = `DROP TYPE ${enumNameWithSchema};`;
|
23506
23917
|
return statement;
|
23507
23918
|
}
|
23508
23919
|
};
|
@@ -23511,9 +23922,56 @@ var init_sqlgenerator = __esm({
|
|
23511
23922
|
return statement.type === "alter_type_add_value";
|
23512
23923
|
}
|
23513
23924
|
convert(st) {
|
23514
|
-
const { name, schema: schema5, value } = st;
|
23515
|
-
const
|
23516
|
-
return `ALTER TYPE ${
|
23925
|
+
const { name, schema: schema5, value, before } = st;
|
23926
|
+
const enumNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
|
23927
|
+
return `ALTER TYPE ${enumNameWithSchema} ADD VALUE '${value}'${before.length ? ` BEFORE '${before}'` : ""};`;
|
23928
|
+
}
|
23929
|
+
};
|
23930
|
+
AlterTypeSetSchemaConvertor = class extends Convertor {
|
23931
|
+
can(statement) {
|
23932
|
+
return statement.type === "move_type_enum";
|
23933
|
+
}
|
23934
|
+
convert(st) {
|
23935
|
+
const { name, schemaFrom, schemaTo } = st;
|
23936
|
+
const enumNameWithSchema = schemaFrom ? `"${schemaFrom}"."${name}"` : `"${name}"`;
|
23937
|
+
return `ALTER TYPE ${enumNameWithSchema} SET SCHEMA "${schemaTo}";`;
|
23938
|
+
}
|
23939
|
+
};
|
23940
|
+
AlterRenameTypeConvertor = class extends Convertor {
|
23941
|
+
can(statement) {
|
23942
|
+
return statement.type === "rename_type_enum";
|
23943
|
+
}
|
23944
|
+
convert(st) {
|
23945
|
+
const { nameTo, nameFrom, schema: schema5 } = st;
|
23946
|
+
const enumNameWithSchema = schema5 ? `"${schema5}"."${nameFrom}"` : `"${nameFrom}"`;
|
23947
|
+
return `ALTER TYPE ${enumNameWithSchema} RENAME TO "${nameTo}";`;
|
23948
|
+
}
|
23949
|
+
};
|
23950
|
+
AlterTypeDropValueConvertor = class extends Convertor {
|
23951
|
+
can(statement) {
|
23952
|
+
return statement.type === "alter_type_drop_value";
|
23953
|
+
}
|
23954
|
+
convert(st) {
|
23955
|
+
const { columnsWithEnum, name, newValues, schema: schema5 } = st;
|
23956
|
+
const statements = [];
|
23957
|
+
for (const withEnum of columnsWithEnum) {
|
23958
|
+
statements.push(
|
23959
|
+
`ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE text;`
|
23960
|
+
);
|
23961
|
+
}
|
23962
|
+
statements.push(new DropTypeEnumConvertor().convert({ name, schema: schema5, type: "drop_type_enum" }));
|
23963
|
+
statements.push(new CreateTypeEnumConvertor().convert({
|
23964
|
+
name,
|
23965
|
+
schema: schema5,
|
23966
|
+
values: newValues,
|
23967
|
+
type: "create_type_enum"
|
23968
|
+
}));
|
23969
|
+
for (const withEnum of columnsWithEnum) {
|
23970
|
+
statements.push(
|
23971
|
+
`ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE "${schema5}"."${name}" USING "${withEnum.column}"::"${schema5}"."${name}";`
|
23972
|
+
);
|
23973
|
+
}
|
23974
|
+
return statements;
|
23517
23975
|
}
|
23518
23976
|
};
|
23519
23977
|
PgDropTableConvertor = class extends Convertor {
|
@@ -23521,9 +23979,21 @@ var init_sqlgenerator = __esm({
|
|
23521
23979
|
return statement.type === "drop_table" && dialect4 === "postgresql";
|
23522
23980
|
}
|
23523
23981
|
convert(statement) {
|
23524
|
-
const { tableName, schema: schema5 } = statement;
|
23982
|
+
const { tableName, schema: schema5, policies } = statement;
|
23525
23983
|
const tableNameWithSchema = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
|
23526
|
-
|
23984
|
+
const dropPolicyConvertor = new PgDropPolicyConvertor();
|
23985
|
+
const droppedPolicies = (policies == null ? void 0 : policies.map((p2) => {
|
23986
|
+
return dropPolicyConvertor.convert({
|
23987
|
+
type: "drop_policy",
|
23988
|
+
tableName,
|
23989
|
+
data: PgSquasher.unsquashPolicy(p2),
|
23990
|
+
schema: schema5
|
23991
|
+
});
|
23992
|
+
})) ?? [];
|
23993
|
+
return [
|
23994
|
+
...droppedPolicies,
|
23995
|
+
`DROP TABLE ${tableNameWithSchema};`
|
23996
|
+
];
|
23527
23997
|
}
|
23528
23998
|
};
|
23529
23999
|
MySQLDropTableConvertor = class extends Convertor {
|
@@ -24660,6 +25130,11 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24660
25130
|
convertors.push(new SQLiteRecreateTableConvertor());
|
24661
25131
|
convertors.push(new LibSQLRecreateTableConvertor());
|
24662
25132
|
convertors.push(new CreateTypeEnumConvertor());
|
25133
|
+
convertors.push(new DropTypeEnumConvertor());
|
25134
|
+
convertors.push(new AlterTypeAddValueConvertor());
|
25135
|
+
convertors.push(new AlterTypeSetSchemaConvertor());
|
25136
|
+
convertors.push(new AlterRenameTypeConvertor());
|
25137
|
+
convertors.push(new AlterTypeDropValueConvertor());
|
24663
25138
|
convertors.push(new CreatePgSequenceConvertor());
|
24664
25139
|
convertors.push(new DropPgSequenceConvertor());
|
24665
25140
|
convertors.push(new RenamePgSequenceConvertor());
|
@@ -24691,13 +25166,22 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24691
25166
|
convertors.push(new PgDropIndexConvertor());
|
24692
25167
|
convertors.push(new SqliteDropIndexConvertor());
|
24693
25168
|
convertors.push(new MySqlDropIndexConvertor());
|
24694
|
-
convertors.push(new AlterTypeAddValueConvertor());
|
24695
25169
|
convertors.push(new PgAlterTableAlterColumnSetPrimaryKeyConvertor());
|
24696
25170
|
convertors.push(new PgAlterTableAlterColumnDropPrimaryKeyConvertor());
|
24697
25171
|
convertors.push(new PgAlterTableAlterColumnSetNotNullConvertor());
|
24698
25172
|
convertors.push(new PgAlterTableAlterColumnDropNotNullConvertor());
|
24699
25173
|
convertors.push(new PgAlterTableAlterColumnSetDefaultConvertor());
|
24700
25174
|
convertors.push(new PgAlterTableAlterColumnDropDefaultConvertor());
|
25175
|
+
convertors.push(new PgAlterPolicyConvertor());
|
25176
|
+
convertors.push(new PgCreatePolicyConvertor());
|
25177
|
+
convertors.push(new PgDropPolicyConvertor());
|
25178
|
+
convertors.push(new PgRenamePolicyConvertor());
|
25179
|
+
convertors.push(new PgEnableRlsConvertor());
|
25180
|
+
convertors.push(new PgDisableRlsConvertor());
|
25181
|
+
convertors.push(new PgDropRoleConvertor());
|
25182
|
+
convertors.push(new PgAlterRoleConvertor());
|
25183
|
+
convertors.push(new PgCreateRoleConvertor());
|
25184
|
+
convertors.push(new PgRenameRoleConvertor());
|
24701
25185
|
convertors.push(new PgAlterTableAlterColumnSetExpressionConvertor());
|
24702
25186
|
convertors.push(new PgAlterTableAlterColumnDropGeneratedConvertor());
|
24703
25187
|
convertors.push(new PgAlterTableAlterColumnAlterrGeneratedConvertor());
|
@@ -24993,7 +25477,7 @@ var init_sqlitePushUtils = __esm({
|
|
24993
25477
|
});
|
24994
25478
|
|
24995
25479
|
// src/jsonStatements.ts
|
24996
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
25480
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateRoleJson, prepareAlterRoleJson, prepareDropRoleJson, prepareRenameRoleJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, prepareRenamePolicyJsons, prepareCreatePolicyJsons, prepareDropPolicyJsons, prepareAlterPolicyJson, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
24997
25481
|
var init_jsonStatements = __esm({
|
24998
25482
|
"src/jsonStatements.ts"() {
|
24999
25483
|
"use strict";
|
@@ -25004,7 +25488,7 @@ var init_jsonStatements = __esm({
|
|
25004
25488
|
init_pgSchema();
|
25005
25489
|
init_sqliteSchema();
|
25006
25490
|
preparePgCreateTableJson = (table4, json2) => {
|
25007
|
-
const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
25491
|
+
const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints, policies } = table4;
|
25008
25492
|
const tableKey2 = `${schema5 || "public"}.${name}`;
|
25009
25493
|
const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
|
25010
25494
|
return {
|
@@ -25014,7 +25498,8 @@ var init_jsonStatements = __esm({
|
|
25014
25498
|
columns: Object.values(columns),
|
25015
25499
|
compositePKs: Object.values(compositePrimaryKeys),
|
25016
25500
|
compositePkName,
|
25017
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
25501
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
25502
|
+
policies: Object.values(policies)
|
25018
25503
|
};
|
25019
25504
|
};
|
25020
25505
|
prepareMySqlCreateTableJson = (table4, json2, internals) => {
|
@@ -25052,7 +25537,8 @@ var init_jsonStatements = __esm({
|
|
25052
25537
|
return {
|
25053
25538
|
type: "drop_table",
|
25054
25539
|
tableName: table4.name,
|
25055
|
-
schema: table4.schema
|
25540
|
+
schema: table4.schema,
|
25541
|
+
policies: table4.policies ? Object.values(table4.policies) : []
|
25056
25542
|
};
|
25057
25543
|
};
|
25058
25544
|
prepareRenameTableJson = (tableFrom, tableTo) => {
|
@@ -25083,6 +25569,28 @@ var init_jsonStatements = __esm({
|
|
25083
25569
|
};
|
25084
25570
|
});
|
25085
25571
|
};
|
25572
|
+
prepareDropEnumValues = (name, schema5, removedValues, json2) => {
|
25573
|
+
if (!removedValues.length)
|
25574
|
+
return [];
|
25575
|
+
const affectedColumns = [];
|
25576
|
+
for (const tableKey2 in json2.tables) {
|
25577
|
+
const table4 = json2.tables[tableKey2];
|
25578
|
+
for (const columnKey in table4.columns) {
|
25579
|
+
const column7 = table4.columns[columnKey];
|
25580
|
+
if (column7.type === name && column7.typeSchema === schema5) {
|
25581
|
+
affectedColumns.push({ schema: table4.schema || "public", table: table4.name, column: column7.name });
|
25582
|
+
}
|
25583
|
+
}
|
25584
|
+
}
|
25585
|
+
return [{
|
25586
|
+
type: "alter_type_drop_value",
|
25587
|
+
name,
|
25588
|
+
schema: schema5,
|
25589
|
+
deletedValues: removedValues,
|
25590
|
+
newValues: json2.enums[`${schema5}.${name}`].values,
|
25591
|
+
columnsWithEnum: affectedColumns
|
25592
|
+
}];
|
25593
|
+
};
|
25086
25594
|
prepareDropEnumJson = (name, schema5) => {
|
25087
25595
|
return {
|
25088
25596
|
type: "drop_type_enum",
|
@@ -25149,6 +25657,41 @@ var init_jsonStatements = __esm({
|
|
25149
25657
|
schema: schema5
|
25150
25658
|
};
|
25151
25659
|
};
|
25660
|
+
prepareCreateRoleJson = (role) => {
|
25661
|
+
return {
|
25662
|
+
type: "create_role",
|
25663
|
+
name: role.name,
|
25664
|
+
values: {
|
25665
|
+
createDb: role.createDb,
|
25666
|
+
createRole: role.createRole,
|
25667
|
+
inherit: role.inherit
|
25668
|
+
}
|
25669
|
+
};
|
25670
|
+
};
|
25671
|
+
prepareAlterRoleJson = (role) => {
|
25672
|
+
return {
|
25673
|
+
type: "alter_role",
|
25674
|
+
name: role.name,
|
25675
|
+
values: {
|
25676
|
+
createDb: role.createDb,
|
25677
|
+
createRole: role.createRole,
|
25678
|
+
inherit: role.inherit
|
25679
|
+
}
|
25680
|
+
};
|
25681
|
+
};
|
25682
|
+
prepareDropRoleJson = (name) => {
|
25683
|
+
return {
|
25684
|
+
type: "drop_role",
|
25685
|
+
name
|
25686
|
+
};
|
25687
|
+
};
|
25688
|
+
prepareRenameRoleJson = (nameFrom, nameTo) => {
|
25689
|
+
return {
|
25690
|
+
type: "rename_role",
|
25691
|
+
nameFrom,
|
25692
|
+
nameTo
|
25693
|
+
};
|
25694
|
+
};
|
25152
25695
|
prepareCreateSchemasJson = (values) => {
|
25153
25696
|
return values.map((it) => {
|
25154
25697
|
return {
|
@@ -26049,6 +26592,46 @@ var init_jsonStatements = __esm({
|
|
26049
26592
|
}
|
26050
26593
|
return [...dropPkStatements, ...setPkStatements, ...statements];
|
26051
26594
|
};
|
26595
|
+
prepareRenamePolicyJsons = (tableName, schema5, renames) => {
|
26596
|
+
return renames.map((it) => {
|
26597
|
+
return {
|
26598
|
+
type: "rename_policy",
|
26599
|
+
tableName,
|
26600
|
+
oldName: it.from.name,
|
26601
|
+
newName: it.to.name,
|
26602
|
+
schema: schema5
|
26603
|
+
};
|
26604
|
+
});
|
26605
|
+
};
|
26606
|
+
prepareCreatePolicyJsons = (tableName, schema5, policies) => {
|
26607
|
+
return policies.map((it) => {
|
26608
|
+
return {
|
26609
|
+
type: "create_policy",
|
26610
|
+
tableName,
|
26611
|
+
data: it,
|
26612
|
+
schema: schema5
|
26613
|
+
};
|
26614
|
+
});
|
26615
|
+
};
|
26616
|
+
prepareDropPolicyJsons = (tableName, schema5, policies) => {
|
26617
|
+
return policies.map((it) => {
|
26618
|
+
return {
|
26619
|
+
type: "drop_policy",
|
26620
|
+
tableName,
|
26621
|
+
data: it,
|
26622
|
+
schema: schema5
|
26623
|
+
};
|
26624
|
+
});
|
26625
|
+
};
|
26626
|
+
prepareAlterPolicyJson = (tableName, schema5, oldPolicy, newPolicy) => {
|
26627
|
+
return {
|
26628
|
+
type: "alter_policy",
|
26629
|
+
tableName,
|
26630
|
+
oldData: oldPolicy,
|
26631
|
+
newData: newPolicy,
|
26632
|
+
schema: schema5
|
26633
|
+
};
|
26634
|
+
};
|
26052
26635
|
preparePgCreateIndexesJson = (tableName, schema5, indexes, fullSchema, action) => {
|
26053
26636
|
if (action === "push") {
|
26054
26637
|
return Object.values(indexes).map((indexData) => {
|
@@ -26722,7 +27305,8 @@ var init_snapshotsDiffer = __esm({
|
|
26722
27305
|
indexes: recordType(stringType(), stringType()),
|
26723
27306
|
foreignKeys: recordType(stringType(), stringType()),
|
26724
27307
|
compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
|
26725
|
-
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
27308
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({}),
|
27309
|
+
policies: recordType(stringType(), stringType()).default({})
|
26726
27310
|
}).strict();
|
26727
27311
|
alteredTableScheme = objectType({
|
26728
27312
|
name: stringType(),
|
@@ -26763,12 +27347,22 @@ var init_snapshotsDiffer = __esm({
|
|
26763
27347
|
__new: stringType(),
|
26764
27348
|
__old: stringType()
|
26765
27349
|
})
|
27350
|
+
),
|
27351
|
+
addedPolicies: recordType(stringType(), stringType()),
|
27352
|
+
deletedPolicies: recordType(stringType(), stringType()),
|
27353
|
+
alteredPolicies: recordType(
|
27354
|
+
stringType(),
|
27355
|
+
objectType({
|
27356
|
+
__new: stringType(),
|
27357
|
+
__old: stringType()
|
27358
|
+
})
|
26766
27359
|
)
|
26767
27360
|
}).strict();
|
26768
27361
|
diffResultScheme = objectType({
|
26769
27362
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
26770
27363
|
alteredEnums: changedEnumSchema.array(),
|
26771
|
-
alteredSequences: sequenceSquashed.array()
|
27364
|
+
alteredSequences: sequenceSquashed.array(),
|
27365
|
+
alteredRoles: roleSchema.array()
|
26772
27366
|
}).strict();
|
26773
27367
|
diffResultSchemeMysql = objectType({
|
26774
27368
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
@@ -26823,7 +27417,7 @@ var init_snapshotsDiffer = __esm({
|
|
26823
27417
|
}
|
26824
27418
|
return column7;
|
26825
27419
|
};
|
26826
|
-
applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
27420
|
+
applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, policyResolver2, roleResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
26827
27421
|
const schemasDiff = diffSchemasOrTables(json1.schemas, json2.schemas);
|
26828
27422
|
const {
|
26829
27423
|
created: createdSchemas,
|
@@ -26973,6 +27567,47 @@ var init_snapshotsDiffer = __esm({
|
|
26973
27567
|
return [tableKey2, tableValue];
|
26974
27568
|
}
|
26975
27569
|
);
|
27570
|
+
const rolesDiff = diffSchemasOrTables(
|
27571
|
+
schemasPatchedSnap1.roles,
|
27572
|
+
json2.roles
|
27573
|
+
);
|
27574
|
+
const {
|
27575
|
+
created: createdRoles,
|
27576
|
+
deleted: deletedRoles,
|
27577
|
+
renamed: renamedRoles
|
27578
|
+
} = await roleResolver2({
|
27579
|
+
created: rolesDiff.added,
|
27580
|
+
deleted: rolesDiff.deleted
|
27581
|
+
});
|
27582
|
+
schemasPatchedSnap1.roles = mapEntries(
|
27583
|
+
schemasPatchedSnap1.roles,
|
27584
|
+
(_2, it) => {
|
27585
|
+
const { name } = nameChangeFor(it, renamedRoles);
|
27586
|
+
it.name = name;
|
27587
|
+
return [name, it];
|
27588
|
+
}
|
27589
|
+
);
|
27590
|
+
const rolesChangeMap = renamedRoles.reduce(
|
27591
|
+
(acc, it) => {
|
27592
|
+
acc[it.from.name] = {
|
27593
|
+
nameFrom: it.from.name,
|
27594
|
+
nameTo: it.to.name
|
27595
|
+
};
|
27596
|
+
return acc;
|
27597
|
+
},
|
27598
|
+
{}
|
27599
|
+
);
|
27600
|
+
schemasPatchedSnap1.roles = mapEntries(
|
27601
|
+
schemasPatchedSnap1.roles,
|
27602
|
+
(roleKey, roleValue) => {
|
27603
|
+
const key = roleKey;
|
27604
|
+
const change = rolesChangeMap[key];
|
27605
|
+
if (change) {
|
27606
|
+
roleValue.name = change.nameTo;
|
27607
|
+
}
|
27608
|
+
return [roleKey, roleValue];
|
27609
|
+
}
|
27610
|
+
);
|
26976
27611
|
const tablesDiff = diffSchemasOrTables(
|
26977
27612
|
schemasPatchedSnap1.tables,
|
26978
27613
|
json2.tables
|
@@ -27051,6 +27686,65 @@ var init_snapshotsDiffer = __esm({
|
|
27051
27686
|
return [tableKey2, tableValue];
|
27052
27687
|
}
|
27053
27688
|
);
|
27689
|
+
const policyRes = diffPolicies(tablesPatchedSnap1.tables, json2.tables);
|
27690
|
+
const policyRenames = [];
|
27691
|
+
const policyCreates = [];
|
27692
|
+
const policyDeletes = [];
|
27693
|
+
for (let entry of Object.values(policyRes)) {
|
27694
|
+
const { renamed, created, deleted } = await policyResolver2({
|
27695
|
+
tableName: entry.name,
|
27696
|
+
schema: entry.schema,
|
27697
|
+
deleted: entry.policies.deleted.map(PgSquasher.unsquashPolicy),
|
27698
|
+
created: entry.policies.added.map(PgSquasher.unsquashPolicy)
|
27699
|
+
});
|
27700
|
+
if (created.length > 0) {
|
27701
|
+
policyCreates.push({
|
27702
|
+
table: entry.name,
|
27703
|
+
schema: entry.schema,
|
27704
|
+
columns: created
|
27705
|
+
});
|
27706
|
+
}
|
27707
|
+
if (deleted.length > 0) {
|
27708
|
+
policyDeletes.push({
|
27709
|
+
table: entry.name,
|
27710
|
+
schema: entry.schema,
|
27711
|
+
columns: deleted
|
27712
|
+
});
|
27713
|
+
}
|
27714
|
+
if (renamed.length > 0) {
|
27715
|
+
policyRenames.push({
|
27716
|
+
table: entry.name,
|
27717
|
+
schema: entry.schema,
|
27718
|
+
renames: renamed
|
27719
|
+
});
|
27720
|
+
}
|
27721
|
+
}
|
27722
|
+
const policyRenamesDict = columnRenames.reduce(
|
27723
|
+
(acc, it) => {
|
27724
|
+
acc[`${it.schema || "public"}.${it.table}`] = it.renames;
|
27725
|
+
return acc;
|
27726
|
+
},
|
27727
|
+
{}
|
27728
|
+
);
|
27729
|
+
const policyPatchedSnap1 = copy(tablesPatchedSnap1);
|
27730
|
+
policyPatchedSnap1.tables = mapEntries(
|
27731
|
+
policyPatchedSnap1.tables,
|
27732
|
+
(tableKey2, tableValue) => {
|
27733
|
+
const patchedPolicies = mapKeys(
|
27734
|
+
tableValue.policies,
|
27735
|
+
(policyKey, policy2) => {
|
27736
|
+
const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
|
27737
|
+
const newName = columnChangeFor(policyKey, rens);
|
27738
|
+
const unsquashedPolicy = PgSquasher.unsquashPolicy(policy2);
|
27739
|
+
unsquashedPolicy.name = newName;
|
27740
|
+
policy2 = PgSquasher.squashPolicy(unsquashedPolicy);
|
27741
|
+
return newName;
|
27742
|
+
}
|
27743
|
+
);
|
27744
|
+
tableValue.policies = patchedPolicies;
|
27745
|
+
return [tableKey2, tableValue];
|
27746
|
+
}
|
27747
|
+
);
|
27054
27748
|
const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
|
27055
27749
|
const typedResult = diffResultScheme.parse(diffResult);
|
27056
27750
|
const jsonStatements = [];
|
@@ -27095,13 +27789,15 @@ var init_snapshotsDiffer = __esm({
|
|
27095
27789
|
const jsonDeletedUniqueConstraints = [];
|
27096
27790
|
const jsonAlteredUniqueConstraints = [];
|
27097
27791
|
const jsonSetTableSchemas = [];
|
27098
|
-
|
27099
|
-
|
27100
|
-
|
27101
|
-
|
27102
|
-
|
27103
|
-
|
27104
|
-
|
27792
|
+
if (movedTables) {
|
27793
|
+
for (let it of movedTables) {
|
27794
|
+
jsonSetTableSchemas.push({
|
27795
|
+
type: "alter_table_set_schema",
|
27796
|
+
tableName: it.name,
|
27797
|
+
schemaFrom: it.schemaFrom || "public",
|
27798
|
+
schemaTo: it.schemaTo || "public"
|
27799
|
+
});
|
27800
|
+
}
|
27105
27801
|
}
|
27106
27802
|
for (let it of alteredTables) {
|
27107
27803
|
let addedColumns = [];
|
@@ -27206,7 +27902,99 @@ var init_snapshotsDiffer = __esm({
|
|
27206
27902
|
it.deletedIndexes || {}
|
27207
27903
|
);
|
27208
27904
|
}).flat();
|
27905
|
+
const jsonCreatePoliciesStatements = [];
|
27906
|
+
const jsonDropPoliciesStatements = [];
|
27907
|
+
const jsonAlterPoliciesStatements = [];
|
27908
|
+
const jsonRenamePoliciesStatements = [];
|
27909
|
+
const jsonEnableRLSStatements = [];
|
27910
|
+
const jsonDisableRLSStatements = [];
|
27911
|
+
for (let it of policyRenames) {
|
27912
|
+
jsonRenamePoliciesStatements.push(
|
27913
|
+
...prepareRenamePolicyJsons(it.table, it.schema, it.renames)
|
27914
|
+
);
|
27915
|
+
}
|
27916
|
+
for (const it of policyCreates) {
|
27917
|
+
jsonCreatePoliciesStatements.push(
|
27918
|
+
...prepareCreatePolicyJsons(
|
27919
|
+
it.table,
|
27920
|
+
it.schema,
|
27921
|
+
it.columns
|
27922
|
+
)
|
27923
|
+
);
|
27924
|
+
}
|
27925
|
+
for (const it of policyDeletes) {
|
27926
|
+
jsonDropPoliciesStatements.push(
|
27927
|
+
...prepareDropPolicyJsons(
|
27928
|
+
it.table,
|
27929
|
+
it.schema,
|
27930
|
+
it.columns
|
27931
|
+
)
|
27932
|
+
);
|
27933
|
+
}
|
27209
27934
|
alteredTables.forEach((it) => {
|
27935
|
+
Object.keys(it.alteredPolicies).forEach((policyName) => {
|
27936
|
+
const newPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__new);
|
27937
|
+
const oldPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__old);
|
27938
|
+
if (newPolicy.as !== oldPolicy.as) {
|
27939
|
+
jsonDropPoliciesStatements.push(
|
27940
|
+
...prepareDropPolicyJsons(
|
27941
|
+
it.name,
|
27942
|
+
it.schema,
|
27943
|
+
[oldPolicy]
|
27944
|
+
)
|
27945
|
+
);
|
27946
|
+
jsonCreatePoliciesStatements.push(
|
27947
|
+
...prepareCreatePolicyJsons(
|
27948
|
+
it.name,
|
27949
|
+
it.schema,
|
27950
|
+
[newPolicy]
|
27951
|
+
)
|
27952
|
+
);
|
27953
|
+
return;
|
27954
|
+
}
|
27955
|
+
if (newPolicy.for !== oldPolicy.for) {
|
27956
|
+
jsonDropPoliciesStatements.push(
|
27957
|
+
...prepareDropPolicyJsons(
|
27958
|
+
it.name,
|
27959
|
+
it.schema,
|
27960
|
+
[oldPolicy]
|
27961
|
+
)
|
27962
|
+
);
|
27963
|
+
jsonCreatePoliciesStatements.push(
|
27964
|
+
...prepareCreatePolicyJsons(
|
27965
|
+
it.name,
|
27966
|
+
it.schema,
|
27967
|
+
[newPolicy]
|
27968
|
+
)
|
27969
|
+
);
|
27970
|
+
return;
|
27971
|
+
}
|
27972
|
+
jsonAlterPoliciesStatements.push(
|
27973
|
+
prepareAlterPolicyJson(
|
27974
|
+
it.name,
|
27975
|
+
it.schema,
|
27976
|
+
it.alteredPolicies[policyName].__old,
|
27977
|
+
it.alteredPolicies[policyName].__new
|
27978
|
+
)
|
27979
|
+
);
|
27980
|
+
});
|
27981
|
+
for (const table4 of Object.values(json2.tables)) {
|
27982
|
+
const policiesInCurrentState = Object.keys(table4.policies);
|
27983
|
+
const tableInPreviousState = columnsPatchedSnap1.tables[`${table4.schema === "" ? "public" : table4.schema}.${table4.name}`];
|
27984
|
+
const policiesInPreviousState = tableInPreviousState ? Object.keys(tableInPreviousState.policies) : [];
|
27985
|
+
if (policiesInPreviousState.length === 0 && policiesInCurrentState.length > 0) {
|
27986
|
+
jsonEnableRLSStatements.push({ type: "enable_rls", tableName: table4.name, schema: table4.schema });
|
27987
|
+
}
|
27988
|
+
if (policiesInPreviousState.length > 0 && policiesInCurrentState.length === 0) {
|
27989
|
+
jsonDisableRLSStatements.push({ type: "disable_rls", tableName: table4.name, schema: table4.schema });
|
27990
|
+
}
|
27991
|
+
}
|
27992
|
+
for (const table4 of Object.values(columnsPatchedSnap1.tables)) {
|
27993
|
+
const tableInCurrentState = json2.tables[`${table4.schema === "" ? "public" : table4.schema}.${table4.name}`];
|
27994
|
+
if (tableInCurrentState === void 0) {
|
27995
|
+
jsonDisableRLSStatements.push({ type: "disable_rls", tableName: table4.name, schema: table4.schema });
|
27996
|
+
}
|
27997
|
+
}
|
27210
27998
|
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
27211
27999
|
(current, item) => {
|
27212
28000
|
current[item] = it.alteredIndexes[item].__old;
|
@@ -27276,6 +28064,9 @@ var init_snapshotsDiffer = __esm({
|
|
27276
28064
|
const jsonAlterEnumsWithAddedValues = typedResult.alteredEnums.map((it) => {
|
27277
28065
|
return prepareAddValuesToEnumJson(it.name, it.schema, it.addedValues);
|
27278
28066
|
}).flat() ?? [];
|
28067
|
+
const jsonAlterEnumsWithDroppedValues = typedResult.alteredEnums.map((it) => {
|
28068
|
+
return prepareDropEnumValues(it.name, it.schema, it.deletedValues, curFull);
|
28069
|
+
}).flat() ?? [];
|
27279
28070
|
const createSequences = createdSequences.map((it) => {
|
27280
28071
|
return prepareCreateSequenceJson(it);
|
27281
28072
|
}) ?? [];
|
@@ -27291,6 +28082,18 @@ var init_snapshotsDiffer = __esm({
|
|
27291
28082
|
const jsonAlterSequences = typedResult.alteredSequences.map((it) => {
|
27292
28083
|
return prepareAlterSequenceJson(it);
|
27293
28084
|
}).flat() ?? [];
|
28085
|
+
const createRoles = createdRoles.map((it) => {
|
28086
|
+
return prepareCreateRoleJson(it);
|
28087
|
+
}) ?? [];
|
28088
|
+
const dropRoles = deletedRoles.map((it) => {
|
28089
|
+
return prepareDropRoleJson(it.name);
|
28090
|
+
});
|
28091
|
+
const renameRoles = renamedRoles.map((it) => {
|
28092
|
+
return prepareRenameRoleJson(it.from.name, it.to.name);
|
28093
|
+
});
|
28094
|
+
const jsonAlterRoles = typedResult.alteredRoles.map((it) => {
|
28095
|
+
return prepareAlterRoleJson(it);
|
28096
|
+
}).flat() ?? [];
|
27294
28097
|
const createSchemas = prepareCreateSchemasJson(
|
27295
28098
|
createdSchemas.map((it) => it.name)
|
27296
28099
|
);
|
@@ -27303,6 +28106,11 @@ var init_snapshotsDiffer = __esm({
|
|
27303
28106
|
const createTables = createdTables.map((it) => {
|
27304
28107
|
return preparePgCreateTableJson(it, curFull);
|
27305
28108
|
});
|
28109
|
+
jsonCreatePoliciesStatements.push(...[].concat(
|
28110
|
+
...createdTables.map(
|
28111
|
+
(it) => prepareCreatePolicyJsons(it.name, it.schema, Object.values(it.policies).map(PgSquasher.unsquashPolicy))
|
28112
|
+
)
|
28113
|
+
));
|
27306
28114
|
jsonStatements.push(...createSchemas);
|
27307
28115
|
jsonStatements.push(...renameSchemas);
|
27308
28116
|
jsonStatements.push(...createEnums);
|
@@ -27313,7 +28121,13 @@ var init_snapshotsDiffer = __esm({
|
|
27313
28121
|
jsonStatements.push(...moveSequences);
|
27314
28122
|
jsonStatements.push(...renameSequences);
|
27315
28123
|
jsonStatements.push(...jsonAlterSequences);
|
28124
|
+
jsonStatements.push(...renameRoles);
|
28125
|
+
jsonStatements.push(...dropRoles);
|
28126
|
+
jsonStatements.push(...createRoles);
|
28127
|
+
jsonStatements.push(...jsonAlterRoles);
|
27316
28128
|
jsonStatements.push(...createTables);
|
28129
|
+
jsonStatements.push(...jsonEnableRLSStatements);
|
28130
|
+
jsonStatements.push(...jsonDisableRLSStatements);
|
27317
28131
|
jsonStatements.push(...jsonDropTables);
|
27318
28132
|
jsonStatements.push(...jsonSetTableSchemas);
|
27319
28133
|
jsonStatements.push(...jsonRenameTables);
|
@@ -27333,6 +28147,11 @@ var init_snapshotsDiffer = __esm({
|
|
27333
28147
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
27334
28148
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
27335
28149
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
28150
|
+
jsonStatements.push(...jsonAlterEnumsWithDroppedValues);
|
28151
|
+
jsonStatements.push(...jsonRenamePoliciesStatements);
|
28152
|
+
jsonStatements.push(...jsonDropPoliciesStatements);
|
28153
|
+
jsonStatements.push(...jsonCreatePoliciesStatements);
|
28154
|
+
jsonStatements.push(...jsonAlterPoliciesStatements);
|
27336
28155
|
jsonStatements.push(...dropEnums);
|
27337
28156
|
jsonStatements.push(...dropSequences);
|
27338
28157
|
jsonStatements.push(...dropSchemas);
|
@@ -27353,7 +28172,17 @@ var init_snapshotsDiffer = __esm({
|
|
27353
28172
|
}
|
27354
28173
|
return true;
|
27355
28174
|
});
|
27356
|
-
const
|
28175
|
+
const filteredEnumsJsonStatements = filteredJsonStatements.filter((st) => {
|
28176
|
+
if (st.type === "alter_type_add_value") {
|
28177
|
+
if (jsonStatements.find(
|
28178
|
+
(it) => it.type === "alter_type_drop_value" && it.name === st.name && it.schema === st.schema
|
28179
|
+
)) {
|
28180
|
+
return false;
|
28181
|
+
}
|
28182
|
+
}
|
28183
|
+
return true;
|
28184
|
+
});
|
28185
|
+
const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
|
27357
28186
|
const uniqueSqlStatements = [];
|
27358
28187
|
sqlStatements.forEach((ss) => {
|
27359
28188
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -27369,7 +28198,7 @@ var init_snapshotsDiffer = __esm({
|
|
27369
28198
|
});
|
27370
28199
|
const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
|
27371
28200
|
return {
|
27372
|
-
statements:
|
28201
|
+
statements: filteredEnumsJsonStatements,
|
27373
28202
|
sqlStatements: uniqueSqlStatements,
|
27374
28203
|
_meta
|
27375
28204
|
};
|
@@ -29596,6 +30425,7 @@ __export(migrate_exports, {
|
|
29596
30425
|
columnsResolver: () => columnsResolver,
|
29597
30426
|
embeddedMigrations: () => embeddedMigrations,
|
29598
30427
|
enumsResolver: () => enumsResolver,
|
30428
|
+
policyResolver: () => policyResolver,
|
29599
30429
|
prepareAndMigrateLibSQL: () => prepareAndMigrateLibSQL,
|
29600
30430
|
prepareAndMigrateMysql: () => prepareAndMigrateMysql,
|
29601
30431
|
prepareAndMigratePg: () => prepareAndMigratePg,
|
@@ -29606,14 +30436,16 @@ __export(migrate_exports, {
|
|
29606
30436
|
prepareSQLitePush: () => prepareSQLitePush,
|
29607
30437
|
prepareSnapshotFolderName: () => prepareSnapshotFolderName,
|
29608
30438
|
promptColumnsConflicts: () => promptColumnsConflicts,
|
30439
|
+
promptNamedConflict: () => promptNamedConflict,
|
29609
30440
|
promptNamedWithSchemasConflict: () => promptNamedWithSchemasConflict,
|
29610
30441
|
promptSchemasConflict: () => promptSchemasConflict,
|
30442
|
+
roleResolver: () => roleResolver,
|
29611
30443
|
schemasResolver: () => schemasResolver,
|
29612
30444
|
sequencesResolver: () => sequencesResolver,
|
29613
30445
|
tablesResolver: () => tablesResolver,
|
29614
30446
|
writeResult: () => writeResult
|
29615
30447
|
});
|
29616
|
-
var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, sequencesResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareAndMigrateLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
|
30448
|
+
var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, sequencesResolver, roleResolver, policyResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareAndMigrateLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedConflict, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
|
29617
30449
|
var init_migrate = __esm({
|
29618
30450
|
"src/cli/commands/migrate.ts"() {
|
29619
30451
|
"use strict";
|
@@ -29678,6 +30510,32 @@ var init_migrate = __esm({
|
|
29678
30510
|
throw e2;
|
29679
30511
|
}
|
29680
30512
|
};
|
30513
|
+
roleResolver = async (input) => {
|
30514
|
+
const result = await promptNamedConflict(
|
30515
|
+
input.created,
|
30516
|
+
input.deleted,
|
30517
|
+
"role"
|
30518
|
+
);
|
30519
|
+
return {
|
30520
|
+
created: result.created,
|
30521
|
+
deleted: result.deleted,
|
30522
|
+
renamed: result.renamed
|
30523
|
+
};
|
30524
|
+
};
|
30525
|
+
policyResolver = async (input) => {
|
30526
|
+
const result = await promptColumnsConflicts(
|
30527
|
+
input.tableName,
|
30528
|
+
input.created,
|
30529
|
+
input.deleted
|
30530
|
+
);
|
30531
|
+
return {
|
30532
|
+
tableName: input.tableName,
|
30533
|
+
schema: input.schema,
|
30534
|
+
created: result.created,
|
30535
|
+
deleted: result.deleted,
|
30536
|
+
renamed: result.renamed
|
30537
|
+
};
|
30538
|
+
};
|
29681
30539
|
enumsResolver = async (input) => {
|
29682
30540
|
try {
|
29683
30541
|
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
@@ -29748,6 +30606,8 @@ var init_migrate = __esm({
|
|
29748
30606
|
schemasResolver,
|
29749
30607
|
enumsResolver,
|
29750
30608
|
sequencesResolver,
|
30609
|
+
policyResolver,
|
30610
|
+
roleResolver,
|
29751
30611
|
tablesResolver,
|
29752
30612
|
columnsResolver,
|
29753
30613
|
validatedPrev,
|
@@ -29783,6 +30643,8 @@ var init_migrate = __esm({
|
|
29783
30643
|
schemasResolver,
|
29784
30644
|
enumsResolver,
|
29785
30645
|
sequencesResolver,
|
30646
|
+
policyResolver,
|
30647
|
+
roleResolver,
|
29786
30648
|
tablesResolver,
|
29787
30649
|
columnsResolver,
|
29788
30650
|
validatedPrev,
|
@@ -30070,6 +30932,56 @@ var init_migrate = __esm({
|
|
30070
30932
|
result.deleted.push(...leftMissing);
|
30071
30933
|
return result;
|
30072
30934
|
};
|
30935
|
+
promptNamedConflict = async (newItems, missingItems, entity) => {
|
30936
|
+
if (missingItems.length === 0 || newItems.length === 0) {
|
30937
|
+
return {
|
30938
|
+
created: newItems,
|
30939
|
+
renamed: [],
|
30940
|
+
deleted: missingItems
|
30941
|
+
};
|
30942
|
+
}
|
30943
|
+
const result = { created: [], renamed: [], deleted: [] };
|
30944
|
+
let index4 = 0;
|
30945
|
+
let leftMissing = [...missingItems];
|
30946
|
+
do {
|
30947
|
+
const created = newItems[index4];
|
30948
|
+
const renames = leftMissing.map((it) => {
|
30949
|
+
return { from: it, to: created };
|
30950
|
+
});
|
30951
|
+
const promptData = [created, ...renames];
|
30952
|
+
const { status, data } = await (0, import_hanji3.render)(
|
30953
|
+
new ResolveSelectNamed(created, promptData, entity)
|
30954
|
+
);
|
30955
|
+
if (status === "aborted") {
|
30956
|
+
console.error("ERROR");
|
30957
|
+
process.exit(1);
|
30958
|
+
}
|
30959
|
+
if (isRenamePromptItem(data)) {
|
30960
|
+
console.log(
|
30961
|
+
`${source_default.yellow("~")} ${data.from.name} \u203A ${data.to.name} ${source_default.gray(
|
30962
|
+
`${entity} will be renamed/moved`
|
30963
|
+
)}`
|
30964
|
+
);
|
30965
|
+
if (data.from.name !== data.to.name) {
|
30966
|
+
result.renamed.push(data);
|
30967
|
+
}
|
30968
|
+
delete leftMissing[leftMissing.indexOf(data.from)];
|
30969
|
+
leftMissing = leftMissing.filter(Boolean);
|
30970
|
+
} else {
|
30971
|
+
console.log(
|
30972
|
+
`${source_default.green("+")} ${data.name} ${source_default.gray(
|
30973
|
+
`${entity} will be created`
|
30974
|
+
)}`
|
30975
|
+
);
|
30976
|
+
result.created.push(created);
|
30977
|
+
}
|
30978
|
+
index4 += 1;
|
30979
|
+
} while (index4 < newItems.length);
|
30980
|
+
console.log(source_default.gray(`--- all ${entity} conflicts resolved ---
|
30981
|
+
`));
|
30982
|
+
result.deleted.push(...leftMissing);
|
30983
|
+
return result;
|
30984
|
+
};
|
30073
30985
|
promptNamedWithSchemasConflict = async (newItems, missingItems, entity) => {
|
30074
30986
|
if (missingItems.length === 0 || newItems.length === 0) {
|
30075
30987
|
return {
|
@@ -38898,9 +39810,9 @@ var init_body2 = __esm({
|
|
38898
39810
|
// ../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/headers.js
|
38899
39811
|
function fromRawHeaders(headers = []) {
|
38900
39812
|
return new Headers2(
|
38901
|
-
headers.reduce((result, value, index4,
|
39813
|
+
headers.reduce((result, value, index4, array2) => {
|
38902
39814
|
if (index4 % 2 === 0) {
|
38903
|
-
result.push(
|
39815
|
+
result.push(array2.slice(index4, index4 + 2));
|
38904
39816
|
}
|
38905
39817
|
return result;
|
38906
39818
|
}, []).filter(([name, value]) => {
|
@@ -39298,7 +40210,7 @@ function determineRequestsReferrer(request, { referrerURLCallback, referrerOrigi
|
|
39298
40210
|
if (request.referrer === "no-referrer" || request.referrerPolicy === "") {
|
39299
40211
|
return null;
|
39300
40212
|
}
|
39301
|
-
const
|
40213
|
+
const policy2 = request.referrerPolicy;
|
39302
40214
|
if (request.referrer === "about:client") {
|
39303
40215
|
return "no-referrer";
|
39304
40216
|
}
|
@@ -39315,7 +40227,7 @@ function determineRequestsReferrer(request, { referrerURLCallback, referrerOrigi
|
|
39315
40227
|
referrerOrigin = referrerOriginCallback(referrerOrigin);
|
39316
40228
|
}
|
39317
40229
|
const currentURL = new URL(request.url);
|
39318
|
-
switch (
|
40230
|
+
switch (policy2) {
|
39319
40231
|
case "no-referrer":
|
39320
40232
|
return "no-referrer";
|
39321
40233
|
case "origin":
|
@@ -39351,18 +40263,18 @@ function determineRequestsReferrer(request, { referrerURLCallback, referrerOrigi
|
|
39351
40263
|
}
|
39352
40264
|
return referrerURL;
|
39353
40265
|
default:
|
39354
|
-
throw new TypeError(`Invalid referrerPolicy: ${
|
40266
|
+
throw new TypeError(`Invalid referrerPolicy: ${policy2}`);
|
39355
40267
|
}
|
39356
40268
|
}
|
39357
40269
|
function parseReferrerPolicyFromHeader(headers) {
|
39358
40270
|
const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
|
39359
|
-
let
|
40271
|
+
let policy2 = "";
|
39360
40272
|
for (const token of policyTokens) {
|
39361
40273
|
if (token && ReferrerPolicy.has(token)) {
|
39362
|
-
|
40274
|
+
policy2 = token;
|
39363
40275
|
}
|
39364
40276
|
}
|
39365
|
-
return
|
40277
|
+
return policy2;
|
39366
40278
|
}
|
39367
40279
|
var import_node_net, ReferrerPolicy, DEFAULT_REFERRER_POLICY;
|
39368
40280
|
var init_referrer = __esm({
|
@@ -60009,7 +60921,7 @@ var require_fromWebToken = __commonJS({
|
|
60009
60921
|
var fromWebToken2 = (init2) => async () => {
|
60010
60922
|
var _a;
|
60011
60923
|
(_a = init2.logger) == null ? void 0 : _a.debug("@aws-sdk/credential-provider-web-identity", "fromWebToken");
|
60012
|
-
const { roleArn, roleSessionName, webIdentityToken, providerId, policyArns, policy, durationSeconds } = init2;
|
60924
|
+
const { roleArn, roleSessionName, webIdentityToken, providerId, policyArns, policy: policy2, durationSeconds } = init2;
|
60013
60925
|
let { roleAssumerWithWebIdentity } = init2;
|
60014
60926
|
if (!roleAssumerWithWebIdentity) {
|
60015
60927
|
const { getDefaultRoleAssumerWithWebIdentity } = await Promise.resolve().then(() => __importStar2(require_dist_cjs50()));
|
@@ -60025,7 +60937,7 @@ var require_fromWebToken = __commonJS({
|
|
60025
60937
|
WebIdentityToken: webIdentityToken,
|
60026
60938
|
ProviderId: providerId,
|
60027
60939
|
PolicyArns: policyArns,
|
60028
|
-
Policy:
|
60940
|
+
Policy: policy2,
|
60029
60941
|
DurationSeconds: durationSeconds
|
60030
60942
|
});
|
60031
60943
|
};
|
@@ -63489,13 +64401,13 @@ var require_event_stream = __commonJS({
|
|
63489
64401
|
es.writeArray = function(done) {
|
63490
64402
|
if ("function" !== typeof done)
|
63491
64403
|
throw new Error("function writeArray (done): done must be function");
|
63492
|
-
var a = new Stream3(),
|
64404
|
+
var a = new Stream3(), array2 = [], isDone = false;
|
63493
64405
|
a.write = function(l) {
|
63494
|
-
|
64406
|
+
array2.push(l);
|
63495
64407
|
};
|
63496
64408
|
a.end = function() {
|
63497
64409
|
isDone = true;
|
63498
|
-
done(null,
|
64410
|
+
done(null, array2);
|
63499
64411
|
};
|
63500
64412
|
a.writable = true;
|
63501
64413
|
a.readable = false;
|
@@ -63503,23 +64415,23 @@ var require_event_stream = __commonJS({
|
|
63503
64415
|
a.writable = a.readable = false;
|
63504
64416
|
if (isDone)
|
63505
64417
|
return;
|
63506
|
-
done(new Error("destroyed before end"),
|
64418
|
+
done(new Error("destroyed before end"), array2);
|
63507
64419
|
};
|
63508
64420
|
return a;
|
63509
64421
|
};
|
63510
|
-
es.readArray = function(
|
64422
|
+
es.readArray = function(array2) {
|
63511
64423
|
var stream = new Stream3(), i2 = 0, paused = false, ended = false;
|
63512
64424
|
stream.readable = true;
|
63513
64425
|
stream.writable = false;
|
63514
|
-
if (!Array.isArray(
|
64426
|
+
if (!Array.isArray(array2))
|
63515
64427
|
throw new Error("event-stream.read expects an array");
|
63516
64428
|
stream.resume = function() {
|
63517
64429
|
if (ended)
|
63518
64430
|
return;
|
63519
64431
|
paused = false;
|
63520
|
-
var l =
|
64432
|
+
var l = array2.length;
|
63521
64433
|
while (i2 < l && !paused && !ended) {
|
63522
|
-
stream.emit("data",
|
64434
|
+
stream.emit("data", array2[i2++]);
|
63523
64435
|
}
|
63524
64436
|
if (i2 == l && !ended)
|
63525
64437
|
ended = true, stream.readable = false, stream.emit("end");
|
@@ -67144,8 +68056,8 @@ var require_utils4 = __commonJS({
|
|
67144
68056
|
"use strict";
|
67145
68057
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
67146
68058
|
exports2.string = exports2.stream = exports2.pattern = exports2.path = exports2.fs = exports2.errno = exports2.array = void 0;
|
67147
|
-
var
|
67148
|
-
exports2.array =
|
68059
|
+
var array2 = require_array();
|
68060
|
+
exports2.array = array2;
|
67149
68061
|
var errno = require_errno();
|
67150
68062
|
exports2.errno = errno;
|
67151
68063
|
var fs9 = require_fs2();
|
@@ -79003,7 +79915,7 @@ var init_pgIntrospect = __esm({
|
|
79003
79915
|
init_global();
|
79004
79916
|
init_pgSerializer();
|
79005
79917
|
init_views();
|
79006
|
-
pgPushIntrospect = async (db, filters, schemaFilters) => {
|
79918
|
+
pgPushIntrospect = async (db, filters, schemaFilters, entities = { roles: true }) => {
|
79007
79919
|
const matchers = filters.map((it) => {
|
79008
79920
|
return new Minimatch(it);
|
79009
79921
|
});
|
@@ -79032,7 +79944,7 @@ var init_pgIntrospect = __esm({
|
|
79032
79944
|
);
|
79033
79945
|
const res = await (0, import_hanji9.renderWithTask)(
|
79034
79946
|
progress,
|
79035
|
-
fromDatabase2(db, filter2, schemaFilters)
|
79947
|
+
fromDatabase2(db, filter2, schemaFilters, entities)
|
79036
79948
|
);
|
79037
79949
|
const schema5 = { id: originUUID, prevId: "", ...res };
|
79038
79950
|
const { internal, ...schemaWithoutInternals } = schema5;
|
@@ -79567,11 +80479,11 @@ var init_push = __esm({
|
|
79567
80479
|
console.log(e2);
|
79568
80480
|
}
|
79569
80481
|
};
|
79570
|
-
pgPush = async (schemaPath, verbose, strict, credentials2, tablesFilter, schemasFilter, force, casing2) => {
|
80482
|
+
pgPush = async (schemaPath, verbose, strict, credentials2, tablesFilter, schemasFilter, entities, force, casing2) => {
|
79571
80483
|
const { preparePostgresDB: preparePostgresDB2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
79572
80484
|
const { pgPushIntrospect: pgPushIntrospect2 } = await Promise.resolve().then(() => (init_pgIntrospect(), pgIntrospect_exports));
|
79573
80485
|
const db = await preparePostgresDB2(credentials2);
|
79574
|
-
const { schema: schema5 } = await pgPushIntrospect2(db, tablesFilter, schemasFilter);
|
80486
|
+
const { schema: schema5 } = await pgPushIntrospect2(db, tablesFilter, schemasFilter, entities);
|
79575
80487
|
const { preparePgPush: preparePgPush2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
79576
80488
|
const statements = await preparePgPush2(schemaPath, schema5, schemasFilter, casing2);
|
79577
80489
|
try {
|
@@ -80756,7 +81668,7 @@ function generateIdentityParams(identity) {
|
|
80756
81668
|
}
|
80757
81669
|
return `.generatedByDefaultAsIdentity(${paramsObj})`;
|
80758
81670
|
}
|
80759
|
-
var import_drizzle_orm9, import_relations, import_casing5, pgImportsList, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, mapColumnDefault3, importsPatch2, relations3, escapeColumnKey3, withCasing2, dbColumnName3, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, buildArrayDefault, mapDefault, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
81671
|
+
var import_drizzle_orm9, import_relations, import_casing5, pgImportsList, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, mapColumnDefault3, importsPatch2, relations3, escapeColumnKey3, withCasing2, dbColumnName3, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, buildArrayDefault, mapDefault, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTablePolicies, createTableUniques3, createTableFKs3;
|
80760
81672
|
var init_introspect_pg = __esm({
|
80761
81673
|
"src/introspect-pg.ts"() {
|
80762
81674
|
"use strict";
|
@@ -80934,6 +81846,9 @@ var init_introspect_pg = __esm({
|
|
80934
81846
|
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
80935
81847
|
(it2) => "unique"
|
80936
81848
|
);
|
81849
|
+
const policiesImports = Object.values(it.policies).map(
|
81850
|
+
(it2) => "pgPolicy"
|
81851
|
+
);
|
80937
81852
|
if (it.schema && it.schema !== "public" && it.schema !== "") {
|
80938
81853
|
res.pg.push("pgSchema");
|
80939
81854
|
}
|
@@ -80941,6 +81856,7 @@ var init_introspect_pg = __esm({
|
|
80941
81856
|
res.pg.push(...fkImpots);
|
80942
81857
|
res.pg.push(...pkImports);
|
80943
81858
|
res.pg.push(...uniqueImports);
|
81859
|
+
res.pg.push(...policiesImports);
|
80944
81860
|
const columnImports = Object.values(it.columns).map((col) => {
|
80945
81861
|
let patched = (importsPatch2[col.type] || col.type).replace("[]", "");
|
80946
81862
|
patched = patched === "double precision" ? "doublePrecision" : patched;
|
@@ -80974,6 +81890,9 @@ var init_introspect_pg = __esm({
|
|
80974
81890
|
imports.pg.push("pgEnum");
|
80975
81891
|
}
|
80976
81892
|
});
|
81893
|
+
if (Object.keys(schema5.roles).length > 0) {
|
81894
|
+
imports.pg.push("pgRole");
|
81895
|
+
}
|
80977
81896
|
const enumStatements = Object.values(schema5.enums).map((it) => {
|
80978
81897
|
const enumSchema3 = schemas[it.schema];
|
80979
81898
|
const paramName = paramNameFor(it.name, enumSchema3);
|
@@ -81009,9 +81928,16 @@ var init_introspect_pg = __esm({
|
|
81009
81928
|
}
|
81010
81929
|
return `export const ${withCasing2(paramName, casing2)} = ${func}("${it.name}"${params ? `, { ${params.trimChar(",")} }` : ""})
|
81011
81930
|
`;
|
81012
|
-
}).join("").concat("
|
81931
|
+
}).join("").concat("");
|
81013
81932
|
const schemaStatements = Object.entries(schemas).map((it) => {
|
81014
81933
|
return `export const ${it[1]} = pgSchema("${it[0]}");
|
81934
|
+
`;
|
81935
|
+
}).join("");
|
81936
|
+
const rolesNameToTsKey = {};
|
81937
|
+
const rolesStatements = Object.entries(schema5.roles).map((it) => {
|
81938
|
+
const fields = it[1];
|
81939
|
+
rolesNameToTsKey[fields.name] = it[0];
|
81940
|
+
return `export const ${withCasing2(it[0], casing2)} = pgRole("${fields.name}", ${!fields.createDb && !fields.createRole && fields.inherit ? "" : `${`, { ${fields.createDb ? `createDb: true,` : ""}${fields.createRole ? ` createRole: true,` : ""}${!fields.inherit ? ` inherit: false ` : ""}`.trimChar(",")}}`} );
|
81015
81941
|
`;
|
81016
81942
|
}).join("");
|
81017
81943
|
const tableStatements = Object.values(schema5.tables).map((table4) => {
|
@@ -81030,8 +81956,8 @@ var init_introspect_pg = __esm({
|
|
81030
81956
|
schema5.internal
|
81031
81957
|
);
|
81032
81958
|
statement += "}";
|
81033
|
-
if (Object.keys(table4.indexes).length > 0 || Object.values(table4.foreignKeys).length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
81034
|
-
statement += "
|
81959
|
+
if (Object.keys(table4.indexes).length > 0 || Object.values(table4.foreignKeys).length > 0 || Object.values(table4.policies).length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
81960
|
+
statement += ", ";
|
81035
81961
|
statement += "(table) => {\n";
|
81036
81962
|
statement += " return {\n";
|
81037
81963
|
statement += createTableIndexes3(
|
@@ -81048,6 +81974,11 @@ var init_introspect_pg = __esm({
|
|
81048
81974
|
Object.values(table4.uniqueConstraints),
|
81049
81975
|
casing2
|
81050
81976
|
);
|
81977
|
+
statement += createTablePolicies(
|
81978
|
+
Object.values(table4.policies),
|
81979
|
+
casing2,
|
81980
|
+
rolesNameToTsKey
|
81981
|
+
);
|
81051
81982
|
statement += " }\n";
|
81052
81983
|
statement += "}";
|
81053
81984
|
}
|
@@ -81058,14 +81989,14 @@ var init_introspect_pg = __esm({
|
|
81058
81989
|
const importsTs = `import { ${uniquePgImports.join(
|
81059
81990
|
", "
|
81060
81991
|
)} } from "drizzle-orm/pg-core"
|
81061
|
-
|
81992
|
+
import { sql } from "drizzle-orm"
|
81062
81993
|
|
81063
81994
|
`;
|
81064
81995
|
let decalrations = schemaStatements;
|
81996
|
+
decalrations += rolesStatements;
|
81065
81997
|
decalrations += enumStatements;
|
81066
81998
|
decalrations += sequencesStatements;
|
81067
|
-
decalrations += "\n";
|
81068
|
-
decalrations += tableStatements.join("\n\n");
|
81999
|
+
decalrations += tableStatements.join("\n");
|
81069
82000
|
const file = importsTs + decalrations;
|
81070
82001
|
const schemaEntry = `
|
81071
82002
|
{
|
@@ -81496,6 +82427,23 @@ var init_introspect_pg = __esm({
|
|
81496
82427
|
}).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
|
81497
82428
|
statement += ")";
|
81498
82429
|
statement += `,
|
82430
|
+
`;
|
82431
|
+
});
|
82432
|
+
return statement;
|
82433
|
+
};
|
82434
|
+
createTablePolicies = (policies, casing2, rolesNameToTsKey = {}) => {
|
82435
|
+
let statement = "";
|
82436
|
+
policies.forEach((it) => {
|
82437
|
+
var _a, _b, _c;
|
82438
|
+
const idxKey = withCasing2(it.name, casing2);
|
82439
|
+
const mappedItTo = (_a = it.to) == null ? void 0 : _a.map((v) => {
|
82440
|
+
return rolesNameToTsKey[v] ? withCasing2(rolesNameToTsKey[v], casing2) : `"${v}"`;
|
82441
|
+
});
|
82442
|
+
statement += ` ${idxKey}: `;
|
82443
|
+
statement += "pgPolicy(";
|
82444
|
+
statement += `"${it.name}", { `;
|
82445
|
+
statement += `as: "${(_b = it.as) == null ? void 0 : _b.toLowerCase()}", for: "${(_c = it.for) == null ? void 0 : _c.toLowerCase()}", to: [${mappedItTo == null ? void 0 : mappedItTo.join(", ")}]${it.using ? `, using: sql\`${it.using}\`` : ""}${it.withCheck ? `, withCheck: sql\`${it.withCheck}\` ` : ""}`;
|
82446
|
+
statement += ` }),
|
81499
82447
|
`;
|
81500
82448
|
});
|
81501
82449
|
return statement;
|
@@ -81573,7 +82521,7 @@ var init_introspect = __esm({
|
|
81573
82521
|
init_utils();
|
81574
82522
|
init_views();
|
81575
82523
|
init_migrate();
|
81576
|
-
introspectPostgres = async (casing2, out, breakpoints, credentials2, tablesFilter, schemasFilter, prefix2) => {
|
82524
|
+
introspectPostgres = async (casing2, out, breakpoints, credentials2, tablesFilter, schemasFilter, prefix2, entities) => {
|
81577
82525
|
const { preparePostgresDB: preparePostgresDB2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
81578
82526
|
const db = await preparePostgresDB2(credentials2);
|
81579
82527
|
const matchers = tablesFilter.map((it) => {
|
@@ -81601,9 +82549,15 @@ var init_introspect = __esm({
|
|
81601
82549
|
const progress = new IntrospectProgress(true);
|
81602
82550
|
const res = await (0, import_hanji12.renderWithTask)(
|
81603
82551
|
progress,
|
81604
|
-
fromDatabase2(
|
81605
|
-
|
81606
|
-
|
82552
|
+
fromDatabase2(
|
82553
|
+
db,
|
82554
|
+
filter2,
|
82555
|
+
schemasFilter,
|
82556
|
+
entities,
|
82557
|
+
(stage, count, status) => {
|
82558
|
+
progress.update(stage, count, status);
|
82559
|
+
}
|
82560
|
+
)
|
81607
82561
|
);
|
81608
82562
|
const schema5 = { id: originUUID, prevId: "", ...res };
|
81609
82563
|
const ts = schemaToTypeScript3(schema5, casing2);
|
@@ -81622,6 +82576,7 @@ var init_introspect = __esm({
|
|
81622
82576
|
schemasResolver,
|
81623
82577
|
enumsResolver,
|
81624
82578
|
sequencesResolver,
|
82579
|
+
policyResolver,
|
81625
82580
|
tablesResolver,
|
81626
82581
|
columnsResolver,
|
81627
82582
|
dryPg,
|
@@ -85144,7 +86099,8 @@ var pull = command({
|
|
85144
86099
|
breakpoints,
|
85145
86100
|
tablesFilter,
|
85146
86101
|
schemasFilter,
|
85147
|
-
prefix: prefix2
|
86102
|
+
prefix: prefix2,
|
86103
|
+
entities
|
85148
86104
|
} = config;
|
85149
86105
|
(0, import_fs13.mkdirSync)(out, { recursive: true });
|
85150
86106
|
console.log(
|
@@ -85183,7 +86139,8 @@ var pull = command({
|
|
85183
86139
|
credentials2,
|
85184
86140
|
tablesFilter,
|
85185
86141
|
schemasFilter,
|
85186
|
-
prefix2
|
86142
|
+
prefix2,
|
86143
|
+
entities
|
85187
86144
|
);
|
85188
86145
|
} else if (dialect4 === "mysql") {
|
85189
86146
|
const { introspectMysql: introspectMysql2 } = await Promise.resolve().then(() => (init_introspect(), introspect_exports));
|
@@ -85354,7 +86311,7 @@ init_utils2();
|
|
85354
86311
|
var version2 = async () => {
|
85355
86312
|
const { npmVersion } = await ormCoreVersions();
|
85356
86313
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
85357
|
-
const envVersion = "0.25.0-
|
86314
|
+
const envVersion = "0.25.0-a5ec472";
|
85358
86315
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
85359
86316
|
const versions = `drizzle-kit: ${kitVersion}
|
85360
86317
|
${ormVersion}`;
|