drizzle-kit 0.25.0-1f15bfd → 0.25.0-225f91d
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 +1434 -643
- package/api.mjs +1434 -643
- package/bin.cjs +1021 -232
- 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 === "{}" ? [] : to.substring(1, to.length - 1).split(/\s*,\s*/g).sort();
|
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,
|
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, 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;
|
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,22 +23898,20 @@ var init_sqlgenerator = __esm({
|
|
23489
23898
|
}
|
23490
23899
|
convert(st) {
|
23491
23900
|
const { name, values, schema: schema5 } = st;
|
23492
|
-
const
|
23901
|
+
const tableNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
|
23493
23902
|
let valuesStatement = "(";
|
23494
23903
|
valuesStatement += values.map((it) => `'${it}'`).join(", ");
|
23495
23904
|
valuesStatement += ")";
|
23496
|
-
let statement =
|
23497
|
-
|
23498
|
-
|
23499
|
-
|
23500
|
-
|
23501
|
-
|
23502
|
-
|
23503
|
-
|
23504
|
-
|
23505
|
-
|
23506
|
-
const enumNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
|
23507
|
-
let statement = `DROP TYPE ${enumNameWithSchema} CASCADE;`;
|
23905
|
+
let statement = "DO $$ BEGIN";
|
23906
|
+
statement += "\n";
|
23907
|
+
statement += ` CREATE TYPE ${tableNameWithSchema} AS ENUM${valuesStatement};`;
|
23908
|
+
statement += "\n";
|
23909
|
+
statement += "EXCEPTION";
|
23910
|
+
statement += "\n";
|
23911
|
+
statement += " WHEN duplicate_object THEN null;";
|
23912
|
+
statement += "\n";
|
23913
|
+
statement += "END $$;";
|
23914
|
+
statement += "\n";
|
23508
23915
|
return statement;
|
23509
23916
|
}
|
23510
23917
|
};
|
@@ -23513,56 +23920,9 @@ var init_sqlgenerator = __esm({
|
|
23513
23920
|
return statement.type === "alter_type_add_value";
|
23514
23921
|
}
|
23515
23922
|
convert(st) {
|
23516
|
-
const { name, schema: schema5, value
|
23517
|
-
const
|
23518
|
-
return `ALTER TYPE ${
|
23519
|
-
}
|
23520
|
-
};
|
23521
|
-
AlterTypeSetSchemaConvertor = class extends Convertor {
|
23522
|
-
can(statement) {
|
23523
|
-
return statement.type === "move_type_enum";
|
23524
|
-
}
|
23525
|
-
convert(st) {
|
23526
|
-
const { name, schemaFrom, schemaTo } = st;
|
23527
|
-
const enumNameWithSchema = schemaFrom ? `"${schemaFrom}"."${name}"` : `"${name}"`;
|
23528
|
-
return `ALTER TYPE ${enumNameWithSchema} SET SCHEMA "${schemaTo}";`;
|
23529
|
-
}
|
23530
|
-
};
|
23531
|
-
AlterRenameTypeConvertor = class extends Convertor {
|
23532
|
-
can(statement) {
|
23533
|
-
return statement.type === "rename_type_enum";
|
23534
|
-
}
|
23535
|
-
convert(st) {
|
23536
|
-
const { nameTo, nameFrom, schema: schema5 } = st;
|
23537
|
-
const enumNameWithSchema = schema5 ? `"${schema5}"."${nameFrom}"` : `"${nameFrom}"`;
|
23538
|
-
return `ALTER TYPE ${enumNameWithSchema} RENAME TO "${nameTo}";`;
|
23539
|
-
}
|
23540
|
-
};
|
23541
|
-
AlterTypeDropValueConvertor = class extends Convertor {
|
23542
|
-
can(statement) {
|
23543
|
-
return statement.type === "alter_type_drop_value";
|
23544
|
-
}
|
23545
|
-
convert(st) {
|
23546
|
-
const { columnsWithEnum, name, newValues, schema: schema5 } = st;
|
23547
|
-
const statements = [];
|
23548
|
-
for (const withEnum of columnsWithEnum) {
|
23549
|
-
statements.push(
|
23550
|
-
`ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE text;`
|
23551
|
-
);
|
23552
|
-
}
|
23553
|
-
statements.push(new DropTypeEnumConvertor().convert({ name, schema: schema5, type: "drop_type_enum" }));
|
23554
|
-
statements.push(new CreateTypeEnumConvertor().convert({
|
23555
|
-
name,
|
23556
|
-
schema: schema5,
|
23557
|
-
values: newValues,
|
23558
|
-
type: "create_type_enum"
|
23559
|
-
}));
|
23560
|
-
for (const withEnum of columnsWithEnum) {
|
23561
|
-
statements.push(
|
23562
|
-
`ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE "${schema5}"."${name}" USING "${withEnum.column}"::"${schema5}"."${name}";`
|
23563
|
-
);
|
23564
|
-
}
|
23565
|
-
return statements;
|
23923
|
+
const { name, schema: schema5, value } = st;
|
23924
|
+
const schemaPrefix = schema5 && schema5 !== "public" ? `"${schema5}".` : "";
|
23925
|
+
return `ALTER TYPE ${schemaPrefix}"${name}" ADD VALUE '${value}';`;
|
23566
23926
|
}
|
23567
23927
|
};
|
23568
23928
|
PgDropTableConvertor = class extends Convertor {
|
@@ -23570,9 +23930,21 @@ var init_sqlgenerator = __esm({
|
|
23570
23930
|
return statement.type === "drop_table" && dialect4 === "postgresql";
|
23571
23931
|
}
|
23572
23932
|
convert(statement) {
|
23573
|
-
const { tableName, schema: schema5 } = statement;
|
23933
|
+
const { tableName, schema: schema5, policies } = statement;
|
23574
23934
|
const tableNameWithSchema = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
|
23575
|
-
|
23935
|
+
const dropPolicyConvertor = new PgDropPolicyConvertor();
|
23936
|
+
const droppedPolicies = (policies == null ? void 0 : policies.map((p2) => {
|
23937
|
+
return dropPolicyConvertor.convert({
|
23938
|
+
type: "drop_policy",
|
23939
|
+
tableName,
|
23940
|
+
data: PgSquasher.unsquashPolicy(p2),
|
23941
|
+
schema: schema5
|
23942
|
+
});
|
23943
|
+
})) ?? [];
|
23944
|
+
return [
|
23945
|
+
...droppedPolicies,
|
23946
|
+
`DROP TABLE ${tableNameWithSchema};`
|
23947
|
+
];
|
23576
23948
|
}
|
23577
23949
|
};
|
23578
23950
|
MySQLDropTableConvertor = class extends Convertor {
|
@@ -24709,11 +25081,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24709
25081
|
convertors.push(new SQLiteRecreateTableConvertor());
|
24710
25082
|
convertors.push(new LibSQLRecreateTableConvertor());
|
24711
25083
|
convertors.push(new CreateTypeEnumConvertor());
|
24712
|
-
convertors.push(new DropTypeEnumConvertor());
|
24713
|
-
convertors.push(new AlterTypeAddValueConvertor());
|
24714
|
-
convertors.push(new AlterTypeSetSchemaConvertor());
|
24715
|
-
convertors.push(new AlterRenameTypeConvertor());
|
24716
|
-
convertors.push(new AlterTypeDropValueConvertor());
|
24717
25084
|
convertors.push(new CreatePgSequenceConvertor());
|
24718
25085
|
convertors.push(new DropPgSequenceConvertor());
|
24719
25086
|
convertors.push(new RenamePgSequenceConvertor());
|
@@ -24745,12 +25112,23 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24745
25112
|
convertors.push(new PgDropIndexConvertor());
|
24746
25113
|
convertors.push(new SqliteDropIndexConvertor());
|
24747
25114
|
convertors.push(new MySqlDropIndexConvertor());
|
25115
|
+
convertors.push(new AlterTypeAddValueConvertor());
|
24748
25116
|
convertors.push(new PgAlterTableAlterColumnSetPrimaryKeyConvertor());
|
24749
25117
|
convertors.push(new PgAlterTableAlterColumnDropPrimaryKeyConvertor());
|
24750
25118
|
convertors.push(new PgAlterTableAlterColumnSetNotNullConvertor());
|
24751
25119
|
convertors.push(new PgAlterTableAlterColumnDropNotNullConvertor());
|
24752
25120
|
convertors.push(new PgAlterTableAlterColumnSetDefaultConvertor());
|
24753
25121
|
convertors.push(new PgAlterTableAlterColumnDropDefaultConvertor());
|
25122
|
+
convertors.push(new PgAlterPolicyConvertor());
|
25123
|
+
convertors.push(new PgCreatePolicyConvertor());
|
25124
|
+
convertors.push(new PgDropPolicyConvertor());
|
25125
|
+
convertors.push(new PgRenamePolicyConvertor());
|
25126
|
+
convertors.push(new PgEnableRlsConvertor());
|
25127
|
+
convertors.push(new PgDisableRlsConvertor());
|
25128
|
+
convertors.push(new PgDropRoleConvertor());
|
25129
|
+
convertors.push(new PgAlterRoleConvertor());
|
25130
|
+
convertors.push(new PgCreateRoleConvertor());
|
25131
|
+
convertors.push(new PgRenameRoleConvertor());
|
24754
25132
|
convertors.push(new PgAlterTableAlterColumnSetExpressionConvertor());
|
24755
25133
|
convertors.push(new PgAlterTableAlterColumnDropGeneratedConvertor());
|
24756
25134
|
convertors.push(new PgAlterTableAlterColumnAlterrGeneratedConvertor());
|
@@ -25046,7 +25424,7 @@ var init_sqlitePushUtils = __esm({
|
|
25046
25424
|
});
|
25047
25425
|
|
25048
25426
|
// src/jsonStatements.ts
|
25049
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson,
|
25427
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, 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;
|
25050
25428
|
var init_jsonStatements = __esm({
|
25051
25429
|
"src/jsonStatements.ts"() {
|
25052
25430
|
"use strict";
|
@@ -25057,7 +25435,7 @@ var init_jsonStatements = __esm({
|
|
25057
25435
|
init_pgSchema();
|
25058
25436
|
init_sqliteSchema();
|
25059
25437
|
preparePgCreateTableJson = (table4, json2) => {
|
25060
|
-
const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
25438
|
+
const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints, policies } = table4;
|
25061
25439
|
const tableKey2 = `${schema5 || "public"}.${name}`;
|
25062
25440
|
const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
|
25063
25441
|
return {
|
@@ -25067,7 +25445,8 @@ var init_jsonStatements = __esm({
|
|
25067
25445
|
columns: Object.values(columns),
|
25068
25446
|
compositePKs: Object.values(compositePrimaryKeys),
|
25069
25447
|
compositePkName,
|
25070
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
25448
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
25449
|
+
policies: Object.values(policies)
|
25071
25450
|
};
|
25072
25451
|
};
|
25073
25452
|
prepareMySqlCreateTableJson = (table4, json2, internals) => {
|
@@ -25105,7 +25484,8 @@ var init_jsonStatements = __esm({
|
|
25105
25484
|
return {
|
25106
25485
|
type: "drop_table",
|
25107
25486
|
tableName: table4.name,
|
25108
|
-
schema: table4.schema
|
25487
|
+
schema: table4.schema,
|
25488
|
+
policies: table4.policies ? Object.values(table4.policies) : []
|
25109
25489
|
};
|
25110
25490
|
};
|
25111
25491
|
prepareRenameTableJson = (tableFrom, tableTo) => {
|
@@ -25136,28 +25516,6 @@ var init_jsonStatements = __esm({
|
|
25136
25516
|
};
|
25137
25517
|
});
|
25138
25518
|
};
|
25139
|
-
prepareDropEnumValues = (name, schema5, removedValues, json2) => {
|
25140
|
-
if (!removedValues.length)
|
25141
|
-
return [];
|
25142
|
-
const affectedColumns = [];
|
25143
|
-
for (const tableKey2 in json2.tables) {
|
25144
|
-
const table4 = json2.tables[tableKey2];
|
25145
|
-
for (const columnKey in table4.columns) {
|
25146
|
-
const column7 = table4.columns[columnKey];
|
25147
|
-
if (column7.type === name && column7.typeSchema === schema5) {
|
25148
|
-
affectedColumns.push({ schema: table4.schema || "public", table: table4.name, column: column7.name });
|
25149
|
-
}
|
25150
|
-
}
|
25151
|
-
}
|
25152
|
-
return [{
|
25153
|
-
type: "alter_type_drop_value",
|
25154
|
-
name,
|
25155
|
-
schema: schema5,
|
25156
|
-
deletedValues: removedValues,
|
25157
|
-
newValues: json2.enums[`${schema5}.${name}`].values,
|
25158
|
-
columnsWithEnum: affectedColumns
|
25159
|
-
}];
|
25160
|
-
};
|
25161
25519
|
prepareDropEnumJson = (name, schema5) => {
|
25162
25520
|
return {
|
25163
25521
|
type: "drop_type_enum",
|
@@ -25224,6 +25582,41 @@ var init_jsonStatements = __esm({
|
|
25224
25582
|
schema: schema5
|
25225
25583
|
};
|
25226
25584
|
};
|
25585
|
+
prepareCreateRoleJson = (role) => {
|
25586
|
+
return {
|
25587
|
+
type: "create_role",
|
25588
|
+
name: role.name,
|
25589
|
+
values: {
|
25590
|
+
createDb: role.createDb,
|
25591
|
+
createRole: role.createRole,
|
25592
|
+
inherit: role.inherit
|
25593
|
+
}
|
25594
|
+
};
|
25595
|
+
};
|
25596
|
+
prepareAlterRoleJson = (role) => {
|
25597
|
+
return {
|
25598
|
+
type: "alter_role",
|
25599
|
+
name: role.name,
|
25600
|
+
values: {
|
25601
|
+
createDb: role.createDb,
|
25602
|
+
createRole: role.createRole,
|
25603
|
+
inherit: role.inherit
|
25604
|
+
}
|
25605
|
+
};
|
25606
|
+
};
|
25607
|
+
prepareDropRoleJson = (name) => {
|
25608
|
+
return {
|
25609
|
+
type: "drop_role",
|
25610
|
+
name
|
25611
|
+
};
|
25612
|
+
};
|
25613
|
+
prepareRenameRoleJson = (nameFrom, nameTo) => {
|
25614
|
+
return {
|
25615
|
+
type: "rename_role",
|
25616
|
+
nameFrom,
|
25617
|
+
nameTo
|
25618
|
+
};
|
25619
|
+
};
|
25227
25620
|
prepareCreateSchemasJson = (values) => {
|
25228
25621
|
return values.map((it) => {
|
25229
25622
|
return {
|
@@ -26124,6 +26517,46 @@ var init_jsonStatements = __esm({
|
|
26124
26517
|
}
|
26125
26518
|
return [...dropPkStatements, ...setPkStatements, ...statements];
|
26126
26519
|
};
|
26520
|
+
prepareRenamePolicyJsons = (tableName, schema5, renames) => {
|
26521
|
+
return renames.map((it) => {
|
26522
|
+
return {
|
26523
|
+
type: "rename_policy",
|
26524
|
+
tableName,
|
26525
|
+
oldName: it.from.name,
|
26526
|
+
newName: it.to.name,
|
26527
|
+
schema: schema5
|
26528
|
+
};
|
26529
|
+
});
|
26530
|
+
};
|
26531
|
+
prepareCreatePolicyJsons = (tableName, schema5, policies) => {
|
26532
|
+
return policies.map((it) => {
|
26533
|
+
return {
|
26534
|
+
type: "create_policy",
|
26535
|
+
tableName,
|
26536
|
+
data: it,
|
26537
|
+
schema: schema5
|
26538
|
+
};
|
26539
|
+
});
|
26540
|
+
};
|
26541
|
+
prepareDropPolicyJsons = (tableName, schema5, policies) => {
|
26542
|
+
return policies.map((it) => {
|
26543
|
+
return {
|
26544
|
+
type: "drop_policy",
|
26545
|
+
tableName,
|
26546
|
+
data: it,
|
26547
|
+
schema: schema5
|
26548
|
+
};
|
26549
|
+
});
|
26550
|
+
};
|
26551
|
+
prepareAlterPolicyJson = (tableName, schema5, oldPolicy, newPolicy) => {
|
26552
|
+
return {
|
26553
|
+
type: "alter_policy",
|
26554
|
+
tableName,
|
26555
|
+
oldData: oldPolicy,
|
26556
|
+
newData: newPolicy,
|
26557
|
+
schema: schema5
|
26558
|
+
};
|
26559
|
+
};
|
26127
26560
|
preparePgCreateIndexesJson = (tableName, schema5, indexes, fullSchema, action) => {
|
26128
26561
|
if (action === "push") {
|
26129
26562
|
return Object.values(indexes).map((indexData) => {
|
@@ -26797,7 +27230,8 @@ var init_snapshotsDiffer = __esm({
|
|
26797
27230
|
indexes: recordType(stringType(), stringType()),
|
26798
27231
|
foreignKeys: recordType(stringType(), stringType()),
|
26799
27232
|
compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
|
26800
|
-
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
27233
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({}),
|
27234
|
+
policies: recordType(stringType(), stringType()).default({})
|
26801
27235
|
}).strict();
|
26802
27236
|
alteredTableScheme = objectType({
|
26803
27237
|
name: stringType(),
|
@@ -26838,12 +27272,22 @@ var init_snapshotsDiffer = __esm({
|
|
26838
27272
|
__new: stringType(),
|
26839
27273
|
__old: stringType()
|
26840
27274
|
})
|
27275
|
+
),
|
27276
|
+
addedPolicies: recordType(stringType(), stringType()),
|
27277
|
+
deletedPolicies: recordType(stringType(), stringType()),
|
27278
|
+
alteredPolicies: recordType(
|
27279
|
+
stringType(),
|
27280
|
+
objectType({
|
27281
|
+
__new: stringType(),
|
27282
|
+
__old: stringType()
|
27283
|
+
})
|
26841
27284
|
)
|
26842
27285
|
}).strict();
|
26843
27286
|
diffResultScheme = objectType({
|
26844
27287
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
26845
27288
|
alteredEnums: changedEnumSchema.array(),
|
26846
|
-
alteredSequences: sequenceSquashed.array()
|
27289
|
+
alteredSequences: sequenceSquashed.array(),
|
27290
|
+
alteredRoles: roleSchema.array()
|
26847
27291
|
}).strict();
|
26848
27292
|
diffResultSchemeMysql = objectType({
|
26849
27293
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
@@ -26898,7 +27342,7 @@ var init_snapshotsDiffer = __esm({
|
|
26898
27342
|
}
|
26899
27343
|
return column7;
|
26900
27344
|
};
|
26901
|
-
applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
27345
|
+
applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, policyResolver2, roleResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
26902
27346
|
const schemasDiff = diffSchemasOrTables(json1.schemas, json2.schemas);
|
26903
27347
|
const {
|
26904
27348
|
created: createdSchemas,
|
@@ -27048,6 +27492,47 @@ var init_snapshotsDiffer = __esm({
|
|
27048
27492
|
return [tableKey2, tableValue];
|
27049
27493
|
}
|
27050
27494
|
);
|
27495
|
+
const rolesDiff = diffSchemasOrTables(
|
27496
|
+
schemasPatchedSnap1.roles,
|
27497
|
+
json2.roles
|
27498
|
+
);
|
27499
|
+
const {
|
27500
|
+
created: createdRoles,
|
27501
|
+
deleted: deletedRoles,
|
27502
|
+
renamed: renamedRoles
|
27503
|
+
} = await roleResolver2({
|
27504
|
+
created: rolesDiff.added,
|
27505
|
+
deleted: rolesDiff.deleted
|
27506
|
+
});
|
27507
|
+
schemasPatchedSnap1.roles = mapEntries(
|
27508
|
+
schemasPatchedSnap1.roles,
|
27509
|
+
(_2, it) => {
|
27510
|
+
const { name } = nameChangeFor(it, renamedRoles);
|
27511
|
+
it.name = name;
|
27512
|
+
return [name, it];
|
27513
|
+
}
|
27514
|
+
);
|
27515
|
+
const rolesChangeMap = renamedRoles.reduce(
|
27516
|
+
(acc, it) => {
|
27517
|
+
acc[it.from.name] = {
|
27518
|
+
nameFrom: it.from.name,
|
27519
|
+
nameTo: it.to.name
|
27520
|
+
};
|
27521
|
+
return acc;
|
27522
|
+
},
|
27523
|
+
{}
|
27524
|
+
);
|
27525
|
+
schemasPatchedSnap1.roles = mapEntries(
|
27526
|
+
schemasPatchedSnap1.roles,
|
27527
|
+
(roleKey, roleValue) => {
|
27528
|
+
const key = roleKey;
|
27529
|
+
const change = rolesChangeMap[key];
|
27530
|
+
if (change) {
|
27531
|
+
roleValue.name = change.nameTo;
|
27532
|
+
}
|
27533
|
+
return [roleKey, roleValue];
|
27534
|
+
}
|
27535
|
+
);
|
27051
27536
|
const tablesDiff = diffSchemasOrTables(
|
27052
27537
|
schemasPatchedSnap1.tables,
|
27053
27538
|
json2.tables
|
@@ -27126,6 +27611,65 @@ var init_snapshotsDiffer = __esm({
|
|
27126
27611
|
return [tableKey2, tableValue];
|
27127
27612
|
}
|
27128
27613
|
);
|
27614
|
+
const policyRes = diffPolicies(tablesPatchedSnap1.tables, json2.tables);
|
27615
|
+
const policyRenames = [];
|
27616
|
+
const policyCreates = [];
|
27617
|
+
const policyDeletes = [];
|
27618
|
+
for (let entry of Object.values(policyRes)) {
|
27619
|
+
const { renamed, created, deleted } = await policyResolver2({
|
27620
|
+
tableName: entry.name,
|
27621
|
+
schema: entry.schema,
|
27622
|
+
deleted: entry.policies.deleted.map(PgSquasher.unsquashPolicy),
|
27623
|
+
created: entry.policies.added.map(PgSquasher.unsquashPolicy)
|
27624
|
+
});
|
27625
|
+
if (created.length > 0) {
|
27626
|
+
policyCreates.push({
|
27627
|
+
table: entry.name,
|
27628
|
+
schema: entry.schema,
|
27629
|
+
columns: created
|
27630
|
+
});
|
27631
|
+
}
|
27632
|
+
if (deleted.length > 0) {
|
27633
|
+
policyDeletes.push({
|
27634
|
+
table: entry.name,
|
27635
|
+
schema: entry.schema,
|
27636
|
+
columns: deleted
|
27637
|
+
});
|
27638
|
+
}
|
27639
|
+
if (renamed.length > 0) {
|
27640
|
+
policyRenames.push({
|
27641
|
+
table: entry.name,
|
27642
|
+
schema: entry.schema,
|
27643
|
+
renames: renamed
|
27644
|
+
});
|
27645
|
+
}
|
27646
|
+
}
|
27647
|
+
const policyRenamesDict = columnRenames.reduce(
|
27648
|
+
(acc, it) => {
|
27649
|
+
acc[`${it.schema || "public"}.${it.table}`] = it.renames;
|
27650
|
+
return acc;
|
27651
|
+
},
|
27652
|
+
{}
|
27653
|
+
);
|
27654
|
+
const policyPatchedSnap1 = copy(tablesPatchedSnap1);
|
27655
|
+
policyPatchedSnap1.tables = mapEntries(
|
27656
|
+
policyPatchedSnap1.tables,
|
27657
|
+
(tableKey2, tableValue) => {
|
27658
|
+
const patchedPolicies = mapKeys(
|
27659
|
+
tableValue.policies,
|
27660
|
+
(policyKey, policy2) => {
|
27661
|
+
const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
|
27662
|
+
const newName = columnChangeFor(policyKey, rens);
|
27663
|
+
const unsquashedPolicy = PgSquasher.unsquashPolicy(policy2);
|
27664
|
+
unsquashedPolicy.name = newName;
|
27665
|
+
policy2 = PgSquasher.squashPolicy(unsquashedPolicy);
|
27666
|
+
return newName;
|
27667
|
+
}
|
27668
|
+
);
|
27669
|
+
tableValue.policies = patchedPolicies;
|
27670
|
+
return [tableKey2, tableValue];
|
27671
|
+
}
|
27672
|
+
);
|
27129
27673
|
const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
|
27130
27674
|
const typedResult = diffResultScheme.parse(diffResult);
|
27131
27675
|
const jsonStatements = [];
|
@@ -27170,13 +27714,15 @@ var init_snapshotsDiffer = __esm({
|
|
27170
27714
|
const jsonDeletedUniqueConstraints = [];
|
27171
27715
|
const jsonAlteredUniqueConstraints = [];
|
27172
27716
|
const jsonSetTableSchemas = [];
|
27173
|
-
|
27174
|
-
|
27175
|
-
|
27176
|
-
|
27177
|
-
|
27178
|
-
|
27179
|
-
|
27717
|
+
if (movedTables) {
|
27718
|
+
for (let it of movedTables) {
|
27719
|
+
jsonSetTableSchemas.push({
|
27720
|
+
type: "alter_table_set_schema",
|
27721
|
+
tableName: it.name,
|
27722
|
+
schemaFrom: it.schemaFrom || "public",
|
27723
|
+
schemaTo: it.schemaTo || "public"
|
27724
|
+
});
|
27725
|
+
}
|
27180
27726
|
}
|
27181
27727
|
for (let it of alteredTables) {
|
27182
27728
|
let addedColumns = [];
|
@@ -27281,7 +27827,99 @@ var init_snapshotsDiffer = __esm({
|
|
27281
27827
|
it.deletedIndexes || {}
|
27282
27828
|
);
|
27283
27829
|
}).flat();
|
27830
|
+
const jsonCreatePoliciesStatements = [];
|
27831
|
+
const jsonDropPoliciesStatements = [];
|
27832
|
+
const jsonAlterPoliciesStatements = [];
|
27833
|
+
const jsonRenamePoliciesStatements = [];
|
27834
|
+
const jsonEnableRLSStatements = [];
|
27835
|
+
const jsonDisableRLSStatements = [];
|
27836
|
+
for (let it of policyRenames) {
|
27837
|
+
jsonRenamePoliciesStatements.push(
|
27838
|
+
...prepareRenamePolicyJsons(it.table, it.schema, it.renames)
|
27839
|
+
);
|
27840
|
+
}
|
27841
|
+
for (const it of policyCreates) {
|
27842
|
+
jsonCreatePoliciesStatements.push(
|
27843
|
+
...prepareCreatePolicyJsons(
|
27844
|
+
it.table,
|
27845
|
+
it.schema,
|
27846
|
+
it.columns
|
27847
|
+
)
|
27848
|
+
);
|
27849
|
+
}
|
27850
|
+
for (const it of policyDeletes) {
|
27851
|
+
jsonDropPoliciesStatements.push(
|
27852
|
+
...prepareDropPolicyJsons(
|
27853
|
+
it.table,
|
27854
|
+
it.schema,
|
27855
|
+
it.columns
|
27856
|
+
)
|
27857
|
+
);
|
27858
|
+
}
|
27284
27859
|
alteredTables.forEach((it) => {
|
27860
|
+
Object.keys(it.alteredPolicies).forEach((policyName) => {
|
27861
|
+
const newPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__new);
|
27862
|
+
const oldPolicy = PgSquasher.unsquashPolicy(it.alteredPolicies[policyName].__old);
|
27863
|
+
if (newPolicy.as !== oldPolicy.as) {
|
27864
|
+
jsonDropPoliciesStatements.push(
|
27865
|
+
...prepareDropPolicyJsons(
|
27866
|
+
it.name,
|
27867
|
+
it.schema,
|
27868
|
+
[oldPolicy]
|
27869
|
+
)
|
27870
|
+
);
|
27871
|
+
jsonCreatePoliciesStatements.push(
|
27872
|
+
...prepareCreatePolicyJsons(
|
27873
|
+
it.name,
|
27874
|
+
it.schema,
|
27875
|
+
[newPolicy]
|
27876
|
+
)
|
27877
|
+
);
|
27878
|
+
return;
|
27879
|
+
}
|
27880
|
+
if (newPolicy.for !== oldPolicy.for) {
|
27881
|
+
jsonDropPoliciesStatements.push(
|
27882
|
+
...prepareDropPolicyJsons(
|
27883
|
+
it.name,
|
27884
|
+
it.schema,
|
27885
|
+
[oldPolicy]
|
27886
|
+
)
|
27887
|
+
);
|
27888
|
+
jsonCreatePoliciesStatements.push(
|
27889
|
+
...prepareCreatePolicyJsons(
|
27890
|
+
it.name,
|
27891
|
+
it.schema,
|
27892
|
+
[newPolicy]
|
27893
|
+
)
|
27894
|
+
);
|
27895
|
+
return;
|
27896
|
+
}
|
27897
|
+
jsonAlterPoliciesStatements.push(
|
27898
|
+
prepareAlterPolicyJson(
|
27899
|
+
it.name,
|
27900
|
+
it.schema,
|
27901
|
+
it.alteredPolicies[policyName].__old,
|
27902
|
+
it.alteredPolicies[policyName].__new
|
27903
|
+
)
|
27904
|
+
);
|
27905
|
+
});
|
27906
|
+
for (const table4 of Object.values(json2.tables)) {
|
27907
|
+
const policiesInCurrentState = Object.keys(table4.policies);
|
27908
|
+
const tableInPreviousState = columnsPatchedSnap1.tables[`${table4.schema === "" ? "public" : table4.schema}.${table4.name}`];
|
27909
|
+
const policiesInPreviousState = tableInPreviousState ? Object.keys(tableInPreviousState.policies) : [];
|
27910
|
+
if (policiesInPreviousState.length === 0 && policiesInCurrentState.length > 0) {
|
27911
|
+
jsonEnableRLSStatements.push({ type: "enable_rls", tableName: table4.name, schema: table4.schema });
|
27912
|
+
}
|
27913
|
+
if (policiesInPreviousState.length > 0 && policiesInCurrentState.length === 0) {
|
27914
|
+
jsonDisableRLSStatements.push({ type: "disable_rls", tableName: table4.name, schema: table4.schema });
|
27915
|
+
}
|
27916
|
+
}
|
27917
|
+
for (const table4 of Object.values(columnsPatchedSnap1.tables)) {
|
27918
|
+
const tableInCurrentState = json2.tables[`${table4.schema === "" ? "public" : table4.schema}.${table4.name}`];
|
27919
|
+
if (tableInCurrentState === void 0) {
|
27920
|
+
jsonDisableRLSStatements.push({ type: "disable_rls", tableName: table4.name, schema: table4.schema });
|
27921
|
+
}
|
27922
|
+
}
|
27285
27923
|
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
27286
27924
|
(current, item) => {
|
27287
27925
|
current[item] = it.alteredIndexes[item].__old;
|
@@ -27351,9 +27989,6 @@ var init_snapshotsDiffer = __esm({
|
|
27351
27989
|
const jsonAlterEnumsWithAddedValues = typedResult.alteredEnums.map((it) => {
|
27352
27990
|
return prepareAddValuesToEnumJson(it.name, it.schema, it.addedValues);
|
27353
27991
|
}).flat() ?? [];
|
27354
|
-
const jsonAlterEnumsWithDroppedValues = typedResult.alteredEnums.map((it) => {
|
27355
|
-
return prepareDropEnumValues(it.name, it.schema, it.deletedValues, curFull);
|
27356
|
-
}).flat() ?? [];
|
27357
27992
|
const createSequences = createdSequences.map((it) => {
|
27358
27993
|
return prepareCreateSequenceJson(it);
|
27359
27994
|
}) ?? [];
|
@@ -27369,6 +28004,18 @@ var init_snapshotsDiffer = __esm({
|
|
27369
28004
|
const jsonAlterSequences = typedResult.alteredSequences.map((it) => {
|
27370
28005
|
return prepareAlterSequenceJson(it);
|
27371
28006
|
}).flat() ?? [];
|
28007
|
+
const createRoles = createdRoles.map((it) => {
|
28008
|
+
return prepareCreateRoleJson(it);
|
28009
|
+
}) ?? [];
|
28010
|
+
const dropRoles = deletedRoles.map((it) => {
|
28011
|
+
return prepareDropRoleJson(it.name);
|
28012
|
+
});
|
28013
|
+
const renameRoles = renamedRoles.map((it) => {
|
28014
|
+
return prepareRenameRoleJson(it.from.name, it.to.name);
|
28015
|
+
});
|
28016
|
+
const jsonAlterRoles = typedResult.alteredRoles.map((it) => {
|
28017
|
+
return prepareAlterRoleJson(it);
|
28018
|
+
}).flat() ?? [];
|
27372
28019
|
const createSchemas = prepareCreateSchemasJson(
|
27373
28020
|
createdSchemas.map((it) => it.name)
|
27374
28021
|
);
|
@@ -27381,6 +28028,11 @@ var init_snapshotsDiffer = __esm({
|
|
27381
28028
|
const createTables = createdTables.map((it) => {
|
27382
28029
|
return preparePgCreateTableJson(it, curFull);
|
27383
28030
|
});
|
28031
|
+
jsonCreatePoliciesStatements.push(...[].concat(
|
28032
|
+
...createdTables.map(
|
28033
|
+
(it) => prepareCreatePolicyJsons(it.name, it.schema, Object.values(it.policies).map(PgSquasher.unsquashPolicy))
|
28034
|
+
)
|
28035
|
+
));
|
27384
28036
|
jsonStatements.push(...createSchemas);
|
27385
28037
|
jsonStatements.push(...renameSchemas);
|
27386
28038
|
jsonStatements.push(...createEnums);
|
@@ -27391,7 +28043,13 @@ var init_snapshotsDiffer = __esm({
|
|
27391
28043
|
jsonStatements.push(...moveSequences);
|
27392
28044
|
jsonStatements.push(...renameSequences);
|
27393
28045
|
jsonStatements.push(...jsonAlterSequences);
|
28046
|
+
jsonStatements.push(...renameRoles);
|
28047
|
+
jsonStatements.push(...dropRoles);
|
28048
|
+
jsonStatements.push(...createRoles);
|
28049
|
+
jsonStatements.push(...jsonAlterRoles);
|
27394
28050
|
jsonStatements.push(...createTables);
|
28051
|
+
jsonStatements.push(...jsonEnableRLSStatements);
|
28052
|
+
jsonStatements.push(...jsonDisableRLSStatements);
|
27395
28053
|
jsonStatements.push(...jsonDropTables);
|
27396
28054
|
jsonStatements.push(...jsonSetTableSchemas);
|
27397
28055
|
jsonStatements.push(...jsonRenameTables);
|
@@ -27411,7 +28069,10 @@ var init_snapshotsDiffer = __esm({
|
|
27411
28069
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
27412
28070
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
27413
28071
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
27414
|
-
jsonStatements.push(...
|
28072
|
+
jsonStatements.push(...jsonRenamePoliciesStatements);
|
28073
|
+
jsonStatements.push(...jsonDropPoliciesStatements);
|
28074
|
+
jsonStatements.push(...jsonCreatePoliciesStatements);
|
28075
|
+
jsonStatements.push(...jsonAlterPoliciesStatements);
|
27415
28076
|
jsonStatements.push(...dropEnums);
|
27416
28077
|
jsonStatements.push(...dropSequences);
|
27417
28078
|
jsonStatements.push(...dropSchemas);
|
@@ -29675,6 +30336,7 @@ __export(migrate_exports, {
|
|
29675
30336
|
columnsResolver: () => columnsResolver,
|
29676
30337
|
embeddedMigrations: () => embeddedMigrations,
|
29677
30338
|
enumsResolver: () => enumsResolver,
|
30339
|
+
policyResolver: () => policyResolver,
|
29678
30340
|
prepareAndMigrateLibSQL: () => prepareAndMigrateLibSQL,
|
29679
30341
|
prepareAndMigrateMysql: () => prepareAndMigrateMysql,
|
29680
30342
|
prepareAndMigratePg: () => prepareAndMigratePg,
|
@@ -29685,14 +30347,16 @@ __export(migrate_exports, {
|
|
29685
30347
|
prepareSQLitePush: () => prepareSQLitePush,
|
29686
30348
|
prepareSnapshotFolderName: () => prepareSnapshotFolderName,
|
29687
30349
|
promptColumnsConflicts: () => promptColumnsConflicts,
|
30350
|
+
promptNamedConflict: () => promptNamedConflict,
|
29688
30351
|
promptNamedWithSchemasConflict: () => promptNamedWithSchemasConflict,
|
29689
30352
|
promptSchemasConflict: () => promptSchemasConflict,
|
30353
|
+
roleResolver: () => roleResolver,
|
29690
30354
|
schemasResolver: () => schemasResolver,
|
29691
30355
|
sequencesResolver: () => sequencesResolver,
|
29692
30356
|
tablesResolver: () => tablesResolver,
|
29693
30357
|
writeResult: () => writeResult
|
29694
30358
|
});
|
29695
|
-
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;
|
30359
|
+
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;
|
29696
30360
|
var init_migrate = __esm({
|
29697
30361
|
"src/cli/commands/migrate.ts"() {
|
29698
30362
|
"use strict";
|
@@ -29757,6 +30421,32 @@ var init_migrate = __esm({
|
|
29757
30421
|
throw e2;
|
29758
30422
|
}
|
29759
30423
|
};
|
30424
|
+
roleResolver = async (input) => {
|
30425
|
+
const result = await promptNamedConflict(
|
30426
|
+
input.created,
|
30427
|
+
input.deleted,
|
30428
|
+
"role"
|
30429
|
+
);
|
30430
|
+
return {
|
30431
|
+
created: result.created,
|
30432
|
+
deleted: result.deleted,
|
30433
|
+
renamed: result.renamed
|
30434
|
+
};
|
30435
|
+
};
|
30436
|
+
policyResolver = async (input) => {
|
30437
|
+
const result = await promptColumnsConflicts(
|
30438
|
+
input.tableName,
|
30439
|
+
input.created,
|
30440
|
+
input.deleted
|
30441
|
+
);
|
30442
|
+
return {
|
30443
|
+
tableName: input.tableName,
|
30444
|
+
schema: input.schema,
|
30445
|
+
created: result.created,
|
30446
|
+
deleted: result.deleted,
|
30447
|
+
renamed: result.renamed
|
30448
|
+
};
|
30449
|
+
};
|
29760
30450
|
enumsResolver = async (input) => {
|
29761
30451
|
try {
|
29762
30452
|
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
@@ -29827,6 +30517,8 @@ var init_migrate = __esm({
|
|
29827
30517
|
schemasResolver,
|
29828
30518
|
enumsResolver,
|
29829
30519
|
sequencesResolver,
|
30520
|
+
policyResolver,
|
30521
|
+
roleResolver,
|
29830
30522
|
tablesResolver,
|
29831
30523
|
columnsResolver,
|
29832
30524
|
validatedPrev,
|
@@ -29862,6 +30554,8 @@ var init_migrate = __esm({
|
|
29862
30554
|
schemasResolver,
|
29863
30555
|
enumsResolver,
|
29864
30556
|
sequencesResolver,
|
30557
|
+
policyResolver,
|
30558
|
+
roleResolver,
|
29865
30559
|
tablesResolver,
|
29866
30560
|
columnsResolver,
|
29867
30561
|
validatedPrev,
|
@@ -30149,6 +30843,56 @@ var init_migrate = __esm({
|
|
30149
30843
|
result.deleted.push(...leftMissing);
|
30150
30844
|
return result;
|
30151
30845
|
};
|
30846
|
+
promptNamedConflict = async (newItems, missingItems, entity) => {
|
30847
|
+
if (missingItems.length === 0 || newItems.length === 0) {
|
30848
|
+
return {
|
30849
|
+
created: newItems,
|
30850
|
+
renamed: [],
|
30851
|
+
deleted: missingItems
|
30852
|
+
};
|
30853
|
+
}
|
30854
|
+
const result = { created: [], renamed: [], deleted: [] };
|
30855
|
+
let index4 = 0;
|
30856
|
+
let leftMissing = [...missingItems];
|
30857
|
+
do {
|
30858
|
+
const created = newItems[index4];
|
30859
|
+
const renames = leftMissing.map((it) => {
|
30860
|
+
return { from: it, to: created };
|
30861
|
+
});
|
30862
|
+
const promptData = [created, ...renames];
|
30863
|
+
const { status, data } = await (0, import_hanji3.render)(
|
30864
|
+
new ResolveSelectNamed(created, promptData, entity)
|
30865
|
+
);
|
30866
|
+
if (status === "aborted") {
|
30867
|
+
console.error("ERROR");
|
30868
|
+
process.exit(1);
|
30869
|
+
}
|
30870
|
+
if (isRenamePromptItem(data)) {
|
30871
|
+
console.log(
|
30872
|
+
`${source_default.yellow("~")} ${data.from.name} \u203A ${data.to.name} ${source_default.gray(
|
30873
|
+
`${entity} will be renamed/moved`
|
30874
|
+
)}`
|
30875
|
+
);
|
30876
|
+
if (data.from.name !== data.to.name) {
|
30877
|
+
result.renamed.push(data);
|
30878
|
+
}
|
30879
|
+
delete leftMissing[leftMissing.indexOf(data.from)];
|
30880
|
+
leftMissing = leftMissing.filter(Boolean);
|
30881
|
+
} else {
|
30882
|
+
console.log(
|
30883
|
+
`${source_default.green("+")} ${data.name} ${source_default.gray(
|
30884
|
+
`${entity} will be created`
|
30885
|
+
)}`
|
30886
|
+
);
|
30887
|
+
result.created.push(created);
|
30888
|
+
}
|
30889
|
+
index4 += 1;
|
30890
|
+
} while (index4 < newItems.length);
|
30891
|
+
console.log(source_default.gray(`--- all ${entity} conflicts resolved ---
|
30892
|
+
`));
|
30893
|
+
result.deleted.push(...leftMissing);
|
30894
|
+
return result;
|
30895
|
+
};
|
30152
30896
|
promptNamedWithSchemasConflict = async (newItems, missingItems, entity) => {
|
30153
30897
|
if (missingItems.length === 0 || newItems.length === 0) {
|
30154
30898
|
return {
|
@@ -38977,9 +39721,9 @@ var init_body2 = __esm({
|
|
38977
39721
|
// ../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/headers.js
|
38978
39722
|
function fromRawHeaders(headers = []) {
|
38979
39723
|
return new Headers2(
|
38980
|
-
headers.reduce((result, value, index4,
|
39724
|
+
headers.reduce((result, value, index4, array2) => {
|
38981
39725
|
if (index4 % 2 === 0) {
|
38982
|
-
result.push(
|
39726
|
+
result.push(array2.slice(index4, index4 + 2));
|
38983
39727
|
}
|
38984
39728
|
return result;
|
38985
39729
|
}, []).filter(([name, value]) => {
|
@@ -39377,7 +40121,7 @@ function determineRequestsReferrer(request, { referrerURLCallback, referrerOrigi
|
|
39377
40121
|
if (request.referrer === "no-referrer" || request.referrerPolicy === "") {
|
39378
40122
|
return null;
|
39379
40123
|
}
|
39380
|
-
const
|
40124
|
+
const policy2 = request.referrerPolicy;
|
39381
40125
|
if (request.referrer === "about:client") {
|
39382
40126
|
return "no-referrer";
|
39383
40127
|
}
|
@@ -39394,7 +40138,7 @@ function determineRequestsReferrer(request, { referrerURLCallback, referrerOrigi
|
|
39394
40138
|
referrerOrigin = referrerOriginCallback(referrerOrigin);
|
39395
40139
|
}
|
39396
40140
|
const currentURL = new URL(request.url);
|
39397
|
-
switch (
|
40141
|
+
switch (policy2) {
|
39398
40142
|
case "no-referrer":
|
39399
40143
|
return "no-referrer";
|
39400
40144
|
case "origin":
|
@@ -39430,18 +40174,18 @@ function determineRequestsReferrer(request, { referrerURLCallback, referrerOrigi
|
|
39430
40174
|
}
|
39431
40175
|
return referrerURL;
|
39432
40176
|
default:
|
39433
|
-
throw new TypeError(`Invalid referrerPolicy: ${
|
40177
|
+
throw new TypeError(`Invalid referrerPolicy: ${policy2}`);
|
39434
40178
|
}
|
39435
40179
|
}
|
39436
40180
|
function parseReferrerPolicyFromHeader(headers) {
|
39437
40181
|
const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
|
39438
|
-
let
|
40182
|
+
let policy2 = "";
|
39439
40183
|
for (const token of policyTokens) {
|
39440
40184
|
if (token && ReferrerPolicy.has(token)) {
|
39441
|
-
|
40185
|
+
policy2 = token;
|
39442
40186
|
}
|
39443
40187
|
}
|
39444
|
-
return
|
40188
|
+
return policy2;
|
39445
40189
|
}
|
39446
40190
|
var import_node_net, ReferrerPolicy, DEFAULT_REFERRER_POLICY;
|
39447
40191
|
var init_referrer = __esm({
|
@@ -60088,7 +60832,7 @@ var require_fromWebToken = __commonJS({
|
|
60088
60832
|
var fromWebToken2 = (init2) => async () => {
|
60089
60833
|
var _a;
|
60090
60834
|
(_a = init2.logger) == null ? void 0 : _a.debug("@aws-sdk/credential-provider-web-identity", "fromWebToken");
|
60091
|
-
const { roleArn, roleSessionName, webIdentityToken, providerId, policyArns, policy, durationSeconds } = init2;
|
60835
|
+
const { roleArn, roleSessionName, webIdentityToken, providerId, policyArns, policy: policy2, durationSeconds } = init2;
|
60092
60836
|
let { roleAssumerWithWebIdentity } = init2;
|
60093
60837
|
if (!roleAssumerWithWebIdentity) {
|
60094
60838
|
const { getDefaultRoleAssumerWithWebIdentity } = await Promise.resolve().then(() => __importStar2(require_dist_cjs50()));
|
@@ -60104,7 +60848,7 @@ var require_fromWebToken = __commonJS({
|
|
60104
60848
|
WebIdentityToken: webIdentityToken,
|
60105
60849
|
ProviderId: providerId,
|
60106
60850
|
PolicyArns: policyArns,
|
60107
|
-
Policy:
|
60851
|
+
Policy: policy2,
|
60108
60852
|
DurationSeconds: durationSeconds
|
60109
60853
|
});
|
60110
60854
|
};
|
@@ -63568,13 +64312,13 @@ var require_event_stream = __commonJS({
|
|
63568
64312
|
es.writeArray = function(done) {
|
63569
64313
|
if ("function" !== typeof done)
|
63570
64314
|
throw new Error("function writeArray (done): done must be function");
|
63571
|
-
var a = new Stream3(),
|
64315
|
+
var a = new Stream3(), array2 = [], isDone = false;
|
63572
64316
|
a.write = function(l) {
|
63573
|
-
|
64317
|
+
array2.push(l);
|
63574
64318
|
};
|
63575
64319
|
a.end = function() {
|
63576
64320
|
isDone = true;
|
63577
|
-
done(null,
|
64321
|
+
done(null, array2);
|
63578
64322
|
};
|
63579
64323
|
a.writable = true;
|
63580
64324
|
a.readable = false;
|
@@ -63582,23 +64326,23 @@ var require_event_stream = __commonJS({
|
|
63582
64326
|
a.writable = a.readable = false;
|
63583
64327
|
if (isDone)
|
63584
64328
|
return;
|
63585
|
-
done(new Error("destroyed before end"),
|
64329
|
+
done(new Error("destroyed before end"), array2);
|
63586
64330
|
};
|
63587
64331
|
return a;
|
63588
64332
|
};
|
63589
|
-
es.readArray = function(
|
64333
|
+
es.readArray = function(array2) {
|
63590
64334
|
var stream = new Stream3(), i2 = 0, paused = false, ended = false;
|
63591
64335
|
stream.readable = true;
|
63592
64336
|
stream.writable = false;
|
63593
|
-
if (!Array.isArray(
|
64337
|
+
if (!Array.isArray(array2))
|
63594
64338
|
throw new Error("event-stream.read expects an array");
|
63595
64339
|
stream.resume = function() {
|
63596
64340
|
if (ended)
|
63597
64341
|
return;
|
63598
64342
|
paused = false;
|
63599
|
-
var l =
|
64343
|
+
var l = array2.length;
|
63600
64344
|
while (i2 < l && !paused && !ended) {
|
63601
|
-
stream.emit("data",
|
64345
|
+
stream.emit("data", array2[i2++]);
|
63602
64346
|
}
|
63603
64347
|
if (i2 == l && !ended)
|
63604
64348
|
ended = true, stream.readable = false, stream.emit("end");
|
@@ -67223,8 +67967,8 @@ var require_utils4 = __commonJS({
|
|
67223
67967
|
"use strict";
|
67224
67968
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
67225
67969
|
exports2.string = exports2.stream = exports2.pattern = exports2.path = exports2.fs = exports2.errno = exports2.array = void 0;
|
67226
|
-
var
|
67227
|
-
exports2.array =
|
67970
|
+
var array2 = require_array();
|
67971
|
+
exports2.array = array2;
|
67228
67972
|
var errno = require_errno();
|
67229
67973
|
exports2.errno = errno;
|
67230
67974
|
var fs9 = require_fs2();
|
@@ -79082,7 +79826,7 @@ var init_pgIntrospect = __esm({
|
|
79082
79826
|
init_global();
|
79083
79827
|
init_pgSerializer();
|
79084
79828
|
init_views();
|
79085
|
-
pgPushIntrospect = async (db, filters, schemaFilters) => {
|
79829
|
+
pgPushIntrospect = async (db, filters, schemaFilters, entities = { roles: true }) => {
|
79086
79830
|
const matchers = filters.map((it) => {
|
79087
79831
|
return new Minimatch(it);
|
79088
79832
|
});
|
@@ -79111,7 +79855,7 @@ var init_pgIntrospect = __esm({
|
|
79111
79855
|
);
|
79112
79856
|
const res = await (0, import_hanji9.renderWithTask)(
|
79113
79857
|
progress,
|
79114
|
-
fromDatabase2(db, filter2, schemaFilters)
|
79858
|
+
fromDatabase2(db, filter2, schemaFilters, entities)
|
79115
79859
|
);
|
79116
79860
|
const schema5 = { id: originUUID, prevId: "", ...res };
|
79117
79861
|
const { internal, ...schemaWithoutInternals } = schema5;
|
@@ -79646,11 +80390,11 @@ var init_push = __esm({
|
|
79646
80390
|
console.log(e2);
|
79647
80391
|
}
|
79648
80392
|
};
|
79649
|
-
pgPush = async (schemaPath, verbose, strict, credentials2, tablesFilter, schemasFilter, force, casing2) => {
|
80393
|
+
pgPush = async (schemaPath, verbose, strict, credentials2, tablesFilter, schemasFilter, entities, force, casing2) => {
|
79650
80394
|
const { preparePostgresDB: preparePostgresDB2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
79651
80395
|
const { pgPushIntrospect: pgPushIntrospect2 } = await Promise.resolve().then(() => (init_pgIntrospect(), pgIntrospect_exports));
|
79652
80396
|
const db = await preparePostgresDB2(credentials2);
|
79653
|
-
const { schema: schema5 } = await pgPushIntrospect2(db, tablesFilter, schemasFilter);
|
80397
|
+
const { schema: schema5 } = await pgPushIntrospect2(db, tablesFilter, schemasFilter, entities);
|
79654
80398
|
const { preparePgPush: preparePgPush2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
79655
80399
|
const statements = await preparePgPush2(schemaPath, schema5, schemasFilter, casing2);
|
79656
80400
|
try {
|
@@ -80835,7 +81579,7 @@ function generateIdentityParams(identity) {
|
|
80835
81579
|
}
|
80836
81580
|
return `.generatedByDefaultAsIdentity(${paramsObj})`;
|
80837
81581
|
}
|
80838
|
-
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;
|
81582
|
+
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;
|
80839
81583
|
var init_introspect_pg = __esm({
|
80840
81584
|
"src/introspect-pg.ts"() {
|
80841
81585
|
"use strict";
|
@@ -81013,6 +81757,9 @@ var init_introspect_pg = __esm({
|
|
81013
81757
|
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
81014
81758
|
(it2) => "unique"
|
81015
81759
|
);
|
81760
|
+
const policiesImports = Object.values(it.policies).map(
|
81761
|
+
(it2) => "pgPolicy"
|
81762
|
+
);
|
81016
81763
|
if (it.schema && it.schema !== "public" && it.schema !== "") {
|
81017
81764
|
res.pg.push("pgSchema");
|
81018
81765
|
}
|
@@ -81020,6 +81767,7 @@ var init_introspect_pg = __esm({
|
|
81020
81767
|
res.pg.push(...fkImpots);
|
81021
81768
|
res.pg.push(...pkImports);
|
81022
81769
|
res.pg.push(...uniqueImports);
|
81770
|
+
res.pg.push(...policiesImports);
|
81023
81771
|
const columnImports = Object.values(it.columns).map((col) => {
|
81024
81772
|
let patched = (importsPatch2[col.type] || col.type).replace("[]", "");
|
81025
81773
|
patched = patched === "double precision" ? "doublePrecision" : patched;
|
@@ -81053,6 +81801,9 @@ var init_introspect_pg = __esm({
|
|
81053
81801
|
imports.pg.push("pgEnum");
|
81054
81802
|
}
|
81055
81803
|
});
|
81804
|
+
if (Object.keys(schema5.roles).length > 0) {
|
81805
|
+
imports.pg.push("pgRole");
|
81806
|
+
}
|
81056
81807
|
const enumStatements = Object.values(schema5.enums).map((it) => {
|
81057
81808
|
const enumSchema3 = schemas[it.schema];
|
81058
81809
|
const paramName = paramNameFor(it.name, enumSchema3);
|
@@ -81088,9 +81839,16 @@ var init_introspect_pg = __esm({
|
|
81088
81839
|
}
|
81089
81840
|
return `export const ${withCasing2(paramName, casing2)} = ${func}("${it.name}"${params ? `, { ${params.trimChar(",")} }` : ""})
|
81090
81841
|
`;
|
81091
|
-
}).join("").concat("
|
81842
|
+
}).join("").concat("");
|
81092
81843
|
const schemaStatements = Object.entries(schemas).map((it) => {
|
81093
81844
|
return `export const ${it[1]} = pgSchema("${it[0]}");
|
81845
|
+
`;
|
81846
|
+
}).join("");
|
81847
|
+
const rolesNameToTsKey = {};
|
81848
|
+
const rolesStatements = Object.entries(schema5.roles).map((it) => {
|
81849
|
+
const fields = it[1];
|
81850
|
+
rolesNameToTsKey[fields.name] = it[0];
|
81851
|
+
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(",")}}`} );
|
81094
81852
|
`;
|
81095
81853
|
}).join("");
|
81096
81854
|
const tableStatements = Object.values(schema5.tables).map((table4) => {
|
@@ -81109,8 +81867,8 @@ var init_introspect_pg = __esm({
|
|
81109
81867
|
schema5.internal
|
81110
81868
|
);
|
81111
81869
|
statement += "}";
|
81112
|
-
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) {
|
81113
|
-
statement += "
|
81870
|
+
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) {
|
81871
|
+
statement += ", ";
|
81114
81872
|
statement += "(table) => {\n";
|
81115
81873
|
statement += " return {\n";
|
81116
81874
|
statement += createTableIndexes3(
|
@@ -81127,6 +81885,11 @@ var init_introspect_pg = __esm({
|
|
81127
81885
|
Object.values(table4.uniqueConstraints),
|
81128
81886
|
casing2
|
81129
81887
|
);
|
81888
|
+
statement += createTablePolicies(
|
81889
|
+
Object.values(table4.policies),
|
81890
|
+
casing2,
|
81891
|
+
rolesNameToTsKey
|
81892
|
+
);
|
81130
81893
|
statement += " }\n";
|
81131
81894
|
statement += "}";
|
81132
81895
|
}
|
@@ -81137,14 +81900,14 @@ var init_introspect_pg = __esm({
|
|
81137
81900
|
const importsTs = `import { ${uniquePgImports.join(
|
81138
81901
|
", "
|
81139
81902
|
)} } from "drizzle-orm/pg-core"
|
81140
|
-
|
81903
|
+
import { sql } from "drizzle-orm"
|
81141
81904
|
|
81142
81905
|
`;
|
81143
81906
|
let decalrations = schemaStatements;
|
81907
|
+
decalrations += rolesStatements;
|
81144
81908
|
decalrations += enumStatements;
|
81145
81909
|
decalrations += sequencesStatements;
|
81146
|
-
decalrations += "\n";
|
81147
|
-
decalrations += tableStatements.join("\n\n");
|
81910
|
+
decalrations += tableStatements.join("\n");
|
81148
81911
|
const file = importsTs + decalrations;
|
81149
81912
|
const schemaEntry = `
|
81150
81913
|
{
|
@@ -81575,6 +82338,23 @@ var init_introspect_pg = __esm({
|
|
81575
82338
|
}).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
|
81576
82339
|
statement += ")";
|
81577
82340
|
statement += `,
|
82341
|
+
`;
|
82342
|
+
});
|
82343
|
+
return statement;
|
82344
|
+
};
|
82345
|
+
createTablePolicies = (policies, casing2, rolesNameToTsKey = {}) => {
|
82346
|
+
let statement = "";
|
82347
|
+
policies.forEach((it) => {
|
82348
|
+
var _a, _b, _c;
|
82349
|
+
const idxKey = withCasing2(it.name, casing2);
|
82350
|
+
const mappedItTo = (_a = it.to) == null ? void 0 : _a.map((v) => {
|
82351
|
+
return rolesNameToTsKey[v] ? withCasing2(rolesNameToTsKey[v], casing2) : `"${v}"`;
|
82352
|
+
});
|
82353
|
+
statement += ` ${idxKey}: `;
|
82354
|
+
statement += "pgPolicy(";
|
82355
|
+
statement += `"${it.name}", { `;
|
82356
|
+
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}\` ` : ""}`;
|
82357
|
+
statement += ` }),
|
81578
82358
|
`;
|
81579
82359
|
});
|
81580
82360
|
return statement;
|
@@ -81652,7 +82432,7 @@ var init_introspect = __esm({
|
|
81652
82432
|
init_utils();
|
81653
82433
|
init_views();
|
81654
82434
|
init_migrate();
|
81655
|
-
introspectPostgres = async (casing2, out, breakpoints, credentials2, tablesFilter, schemasFilter, prefix2) => {
|
82435
|
+
introspectPostgres = async (casing2, out, breakpoints, credentials2, tablesFilter, schemasFilter, prefix2, entities) => {
|
81656
82436
|
const { preparePostgresDB: preparePostgresDB2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
81657
82437
|
const db = await preparePostgresDB2(credentials2);
|
81658
82438
|
const matchers = tablesFilter.map((it) => {
|
@@ -81680,9 +82460,15 @@ var init_introspect = __esm({
|
|
81680
82460
|
const progress = new IntrospectProgress(true);
|
81681
82461
|
const res = await (0, import_hanji12.renderWithTask)(
|
81682
82462
|
progress,
|
81683
|
-
fromDatabase2(
|
81684
|
-
|
81685
|
-
|
82463
|
+
fromDatabase2(
|
82464
|
+
db,
|
82465
|
+
filter2,
|
82466
|
+
schemasFilter,
|
82467
|
+
entities,
|
82468
|
+
(stage, count, status) => {
|
82469
|
+
progress.update(stage, count, status);
|
82470
|
+
}
|
82471
|
+
)
|
81686
82472
|
);
|
81687
82473
|
const schema5 = { id: originUUID, prevId: "", ...res };
|
81688
82474
|
const ts = schemaToTypeScript3(schema5, casing2);
|
@@ -81701,6 +82487,7 @@ var init_introspect = __esm({
|
|
81701
82487
|
schemasResolver,
|
81702
82488
|
enumsResolver,
|
81703
82489
|
sequencesResolver,
|
82490
|
+
policyResolver,
|
81704
82491
|
tablesResolver,
|
81705
82492
|
columnsResolver,
|
81706
82493
|
dryPg,
|
@@ -85223,7 +86010,8 @@ var pull = command({
|
|
85223
86010
|
breakpoints,
|
85224
86011
|
tablesFilter,
|
85225
86012
|
schemasFilter,
|
85226
|
-
prefix: prefix2
|
86013
|
+
prefix: prefix2,
|
86014
|
+
entities
|
85227
86015
|
} = config;
|
85228
86016
|
(0, import_fs13.mkdirSync)(out, { recursive: true });
|
85229
86017
|
console.log(
|
@@ -85262,7 +86050,8 @@ var pull = command({
|
|
85262
86050
|
credentials2,
|
85263
86051
|
tablesFilter,
|
85264
86052
|
schemasFilter,
|
85265
|
-
prefix2
|
86053
|
+
prefix2,
|
86054
|
+
entities
|
85266
86055
|
);
|
85267
86056
|
} else if (dialect4 === "mysql") {
|
85268
86057
|
const { introspectMysql: introspectMysql2 } = await Promise.resolve().then(() => (init_introspect(), introspect_exports));
|
@@ -85433,7 +86222,7 @@ init_utils2();
|
|
85433
86222
|
var version2 = async () => {
|
85434
86223
|
const { npmVersion } = await ormCoreVersions();
|
85435
86224
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
85436
|
-
const envVersion = "0.25.0-
|
86225
|
+
const envVersion = "0.25.0-225f91d";
|
85437
86226
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
85438
86227
|
const versions = `drizzle-kit: ${kitVersion}
|
85439
86228
|
${ormVersion}`;
|