drizzle-kit 0.25.0-8dece56 → 0.25.0-b4de377
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +474 -0
- package/api.d.ts +474 -0
- package/api.js +31749 -30079
- package/api.mjs +31748 -30078
- package/bin.cjs +1278 -162
- package/package.json +1 -1
- package/utils.js +51 -11
- package/utils.mjs +51 -11
package/bin.cjs
CHANGED
@@ -922,8 +922,8 @@ var require_hanji = __commonJS({
|
|
922
922
|
};
|
923
923
|
exports2.deferred = deferred;
|
924
924
|
var Terminal = class {
|
925
|
-
constructor(
|
926
|
-
this.view =
|
925
|
+
constructor(view2, stdin, stdout, closable) {
|
926
|
+
this.view = view2;
|
927
927
|
this.stdin = stdin;
|
928
928
|
this.stdout = stdout;
|
929
929
|
this.closable = closable;
|
@@ -961,7 +961,7 @@ var require_hanji = __commonJS({
|
|
961
961
|
this.resolve({ status: "submitted", data: this.view.result() });
|
962
962
|
return;
|
963
963
|
}
|
964
|
-
|
964
|
+
view2.input(str, key);
|
965
965
|
};
|
966
966
|
this.stdin.on("keypress", keypress);
|
967
967
|
this.view.attach(this);
|
@@ -1023,8 +1023,8 @@ var require_hanji = __commonJS({
|
|
1023
1023
|
};
|
1024
1024
|
exports2.TaskView = TaskView2;
|
1025
1025
|
var TaskTerminal = class {
|
1026
|
-
constructor(
|
1027
|
-
this.view =
|
1026
|
+
constructor(view2, stdout) {
|
1027
|
+
this.view = view2;
|
1028
1028
|
this.stdout = stdout;
|
1029
1029
|
this.text = "";
|
1030
1030
|
this.view.attach(this);
|
@@ -1043,22 +1043,22 @@ var require_hanji = __commonJS({
|
|
1043
1043
|
}
|
1044
1044
|
};
|
1045
1045
|
exports2.TaskTerminal = TaskTerminal;
|
1046
|
-
function render9(
|
1046
|
+
function render9(view2) {
|
1047
1047
|
const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
|
1048
|
-
if (
|
1049
|
-
const terminal = new Terminal(
|
1048
|
+
if (view2 instanceof Prompt3) {
|
1049
|
+
const terminal = new Terminal(view2, stdin, stdout, closable);
|
1050
1050
|
terminal.requestLayout();
|
1051
1051
|
return terminal.result();
|
1052
1052
|
}
|
1053
|
-
stdout.write(`${
|
1053
|
+
stdout.write(`${view2}
|
1054
1054
|
`);
|
1055
1055
|
closable.close();
|
1056
1056
|
return;
|
1057
1057
|
}
|
1058
1058
|
exports2.render = render9;
|
1059
|
-
function renderWithTask6(
|
1059
|
+
function renderWithTask6(view2, task) {
|
1060
1060
|
return __awaiter2(this, void 0, void 0, function* () {
|
1061
|
-
const terminal = new TaskTerminal(
|
1061
|
+
const terminal = new TaskTerminal(view2, process.stdout);
|
1062
1062
|
terminal.requestLayout();
|
1063
1063
|
const result = yield task;
|
1064
1064
|
terminal.clear();
|
@@ -5706,7 +5706,7 @@ var init_vector = __esm({
|
|
5706
5706
|
});
|
5707
5707
|
|
5708
5708
|
// 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;
|
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, viewWithOption, matViewWithOption, mergedViewWithOption, view, 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
5710
|
var init_pgSchema = __esm({
|
5711
5711
|
"src/serializer/pgSchema.ts"() {
|
5712
5712
|
"use strict";
|
@@ -5901,6 +5901,44 @@ var init_pgSchema = __esm({
|
|
5901
5901
|
columns: stringType().array(),
|
5902
5902
|
nullsNotDistinct: booleanType()
|
5903
5903
|
}).strict();
|
5904
|
+
viewWithOption = objectType({
|
5905
|
+
checkOption: enumType(["local", "cascaded"]).optional(),
|
5906
|
+
securityBarrier: booleanType().optional(),
|
5907
|
+
securityInvoker: booleanType().optional()
|
5908
|
+
}).strict();
|
5909
|
+
matViewWithOption = objectType({
|
5910
|
+
fillfactor: numberType().optional(),
|
5911
|
+
toastTupleTarget: numberType().optional(),
|
5912
|
+
parallelWorkers: numberType().optional(),
|
5913
|
+
autovacuumEnabled: booleanType().optional(),
|
5914
|
+
vacuumIndexCleanup: enumType(["auto", "off", "on"]).optional(),
|
5915
|
+
vacuumTruncate: booleanType().optional(),
|
5916
|
+
autovacuumVacuumThreshold: numberType().optional(),
|
5917
|
+
autovacuumVacuumScaleFactor: numberType().optional(),
|
5918
|
+
autovacuumVacuumCostDelay: numberType().optional(),
|
5919
|
+
autovacuumVacuumCostLimit: numberType().optional(),
|
5920
|
+
autovacuumFreezeMinAge: numberType().optional(),
|
5921
|
+
autovacuumFreezeMaxAge: numberType().optional(),
|
5922
|
+
autovacuumFreezeTableAge: numberType().optional(),
|
5923
|
+
autovacuumMultixactFreezeMinAge: numberType().optional(),
|
5924
|
+
autovacuumMultixactFreezeMaxAge: numberType().optional(),
|
5925
|
+
autovacuumMultixactFreezeTableAge: numberType().optional(),
|
5926
|
+
logAutovacuumMinDuration: numberType().optional(),
|
5927
|
+
userCatalogTable: booleanType().optional()
|
5928
|
+
}).strict();
|
5929
|
+
mergedViewWithOption = viewWithOption.merge(matViewWithOption);
|
5930
|
+
view = objectType({
|
5931
|
+
name: stringType(),
|
5932
|
+
schema: stringType(),
|
5933
|
+
columns: recordType(stringType(), column2),
|
5934
|
+
definition: stringType().optional(),
|
5935
|
+
materialized: booleanType(),
|
5936
|
+
with: mergedViewWithOption.optional(),
|
5937
|
+
isExisting: booleanType(),
|
5938
|
+
withNoData: booleanType().optional(),
|
5939
|
+
using: stringType().optional(),
|
5940
|
+
tablespace: stringType().optional()
|
5941
|
+
}).strict();
|
5904
5942
|
tableV42 = objectType({
|
5905
5943
|
name: stringType(),
|
5906
5944
|
schema: stringType(),
|
@@ -6035,6 +6073,7 @@ var init_pgSchema = __esm({
|
|
6035
6073
|
tables: recordType(stringType(), table2),
|
6036
6074
|
enums: recordType(stringType(), enumSchema),
|
6037
6075
|
schemas: recordType(stringType(), stringType()),
|
6076
|
+
views: recordType(stringType(), view).default({}),
|
6038
6077
|
sequences: recordType(stringType(), sequenceSchema).default({}),
|
6039
6078
|
_meta: objectType({
|
6040
6079
|
schemas: recordType(stringType(), stringType()),
|
@@ -6079,6 +6118,7 @@ var init_pgSchema = __esm({
|
|
6079
6118
|
tables: recordType(stringType(), tableSquashed2),
|
6080
6119
|
enums: recordType(stringType(), enumSchema),
|
6081
6120
|
schemas: recordType(stringType(), stringType()),
|
6121
|
+
views: recordType(stringType(), view),
|
6082
6122
|
sequences: recordType(stringType(), sequenceSquashed)
|
6083
6123
|
}).strict();
|
6084
6124
|
pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
|
@@ -6296,6 +6336,7 @@ var init_pgSchema = __esm({
|
|
6296
6336
|
tables: mappedTables,
|
6297
6337
|
enums: json.enums,
|
6298
6338
|
schemas: json.schemas,
|
6339
|
+
views: json.views,
|
6299
6340
|
sequences: mappedSequences
|
6300
6341
|
};
|
6301
6342
|
};
|
@@ -8811,6 +8852,9 @@ var init_utils3 = __esm({
|
|
8811
8852
|
String.prototype.concatIf = function(it, condition) {
|
8812
8853
|
return condition ? `${this}${it}` : String(this);
|
8813
8854
|
};
|
8855
|
+
String.prototype.snake_case = function() {
|
8856
|
+
return this && this.length > 0 ? `${this.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)}` : String(this);
|
8857
|
+
};
|
8814
8858
|
Array.prototype.random = function() {
|
8815
8859
|
return this[~~(Math.random() * this.length)];
|
8816
8860
|
};
|
@@ -12507,11 +12551,11 @@ var require_node2 = __commonJS({
|
|
12507
12551
|
};
|
12508
12552
|
var require_base64 = __commonJS3((exports3) => {
|
12509
12553
|
var intToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
12510
|
-
exports3.encode = function(
|
12511
|
-
if (0 <=
|
12512
|
-
return intToCharMap[
|
12554
|
+
exports3.encode = function(number2) {
|
12555
|
+
if (0 <= number2 && number2 < intToCharMap.length) {
|
12556
|
+
return intToCharMap[number2];
|
12513
12557
|
}
|
12514
|
-
throw new TypeError("Must be between 0 and 63: " +
|
12558
|
+
throw new TypeError("Must be between 0 and 63: " + number2);
|
12515
12559
|
};
|
12516
12560
|
exports3.decode = function(charCode) {
|
12517
12561
|
var bigA = 65;
|
@@ -18464,6 +18508,8 @@ var init_pgImports = __esm({
|
|
18464
18508
|
const enums = [];
|
18465
18509
|
const schemas = [];
|
18466
18510
|
const sequences = [];
|
18511
|
+
const views = [];
|
18512
|
+
const matViews = [];
|
18467
18513
|
const i0values = Object.values(exports2);
|
18468
18514
|
i0values.forEach((t2) => {
|
18469
18515
|
if ((0, import_pg_core.isPgEnum)(t2)) {
|
@@ -18476,17 +18522,25 @@ var init_pgImports = __esm({
|
|
18476
18522
|
if ((0, import_drizzle_orm4.is)(t2, import_pg_core.PgSchema)) {
|
18477
18523
|
schemas.push(t2);
|
18478
18524
|
}
|
18525
|
+
if ((0, import_pg_core.isPgView)(t2)) {
|
18526
|
+
views.push(t2);
|
18527
|
+
}
|
18528
|
+
if ((0, import_pg_core.isPgMaterializedView)(t2)) {
|
18529
|
+
matViews.push(t2);
|
18530
|
+
}
|
18479
18531
|
if ((0, import_pg_core.isPgSequence)(t2)) {
|
18480
18532
|
sequences.push(t2);
|
18481
18533
|
}
|
18482
18534
|
});
|
18483
|
-
return { tables, enums, schemas, sequences };
|
18535
|
+
return { tables, enums, schemas, sequences, views, matViews };
|
18484
18536
|
};
|
18485
18537
|
prepareFromPgImports = async (imports) => {
|
18486
|
-
|
18487
|
-
|
18488
|
-
|
18489
|
-
|
18538
|
+
const tables = [];
|
18539
|
+
const enums = [];
|
18540
|
+
const schemas = [];
|
18541
|
+
const sequences = [];
|
18542
|
+
const views = [];
|
18543
|
+
const matViews = [];
|
18490
18544
|
const { unregister } = await safeRegister();
|
18491
18545
|
for (let i2 = 0; i2 < imports.length; i2++) {
|
18492
18546
|
const it = imports[i2];
|
@@ -18496,9 +18550,11 @@ var init_pgImports = __esm({
|
|
18496
18550
|
enums.push(...prepared.enums);
|
18497
18551
|
schemas.push(...prepared.schemas);
|
18498
18552
|
sequences.push(...prepared.sequences);
|
18553
|
+
views.push(...prepared.views);
|
18554
|
+
matViews.push(...prepared.matViews);
|
18499
18555
|
}
|
18500
18556
|
unregister();
|
18501
|
-
return { tables: Array.from(new Set(tables)), enums, schemas, sequences };
|
18557
|
+
return { tables: Array.from(new Set(tables)), enums, schemas, sequences, views, matViews };
|
18502
18558
|
};
|
18503
18559
|
}
|
18504
18560
|
});
|
@@ -18562,9 +18618,10 @@ var init_pgSerializer = __esm({
|
|
18562
18618
|
indexName2 = (tableName, columns) => {
|
18563
18619
|
return `${tableName}_${columns.join("_")}_index`;
|
18564
18620
|
};
|
18565
|
-
generatePgSnapshot = (tables, enums, schemas, sequences, schemaFilter) => {
|
18566
|
-
var _a, _b, _c, _d, _e, _f;
|
18621
|
+
generatePgSnapshot = (tables, enums, schemas, sequences, views, matViews, schemaFilter) => {
|
18622
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
18567
18623
|
const result = {};
|
18624
|
+
const resultViews = {};
|
18568
18625
|
const sequencesToReturn = {};
|
18569
18626
|
const indexesInSchema = {};
|
18570
18627
|
for (const table4 of tables) {
|
@@ -18863,6 +18920,149 @@ ${withStyle.errorWarning(
|
|
18863
18920
|
} else {
|
18864
18921
|
}
|
18865
18922
|
}
|
18923
|
+
const combinedViews = [...views, ...matViews];
|
18924
|
+
for (const view2 of combinedViews) {
|
18925
|
+
let viewName;
|
18926
|
+
let schema5;
|
18927
|
+
let query;
|
18928
|
+
let selectedFields;
|
18929
|
+
let isExisting;
|
18930
|
+
let withOption;
|
18931
|
+
let tablespace;
|
18932
|
+
let using;
|
18933
|
+
let withNoData;
|
18934
|
+
let materialized = false;
|
18935
|
+
if ((0, import_drizzle_orm5.is)(view2, import_pg_core2.PgView)) {
|
18936
|
+
({ name: viewName, schema: schema5, query, selectedFields, isExisting, with: withOption } = (0, import_pg_core2.getViewConfig)(view2));
|
18937
|
+
} else {
|
18938
|
+
({ name: viewName, schema: schema5, query, selectedFields, isExisting, with: withOption, tablespace, using, withNoData } = (0, import_pg_core2.getMaterializedViewConfig)(
|
18939
|
+
view2
|
18940
|
+
));
|
18941
|
+
materialized = true;
|
18942
|
+
}
|
18943
|
+
const viewSchema = schema5 ?? "public";
|
18944
|
+
const viewKey = `${viewSchema}.${viewName}`;
|
18945
|
+
const columnsObject = {};
|
18946
|
+
const uniqueConstraintObject = {};
|
18947
|
+
const existingView = resultViews[viewKey];
|
18948
|
+
if (typeof existingView !== "undefined") {
|
18949
|
+
console.log(
|
18950
|
+
`
|
18951
|
+
${withStyle.errorWarning(
|
18952
|
+
`We've found duplicated view name across ${source_default.underline.blue(
|
18953
|
+
schema5 ?? "public"
|
18954
|
+
)} schema. Please rename your view`
|
18955
|
+
)}`
|
18956
|
+
);
|
18957
|
+
process.exit(1);
|
18958
|
+
}
|
18959
|
+
for (const key in selectedFields) {
|
18960
|
+
if ((0, import_drizzle_orm5.is)(selectedFields[key], import_pg_core2.PgColumn)) {
|
18961
|
+
const column7 = selectedFields[key];
|
18962
|
+
const notNull = column7.notNull;
|
18963
|
+
const primaryKey = column7.primary;
|
18964
|
+
const sqlTypeLowered = column7.getSQLType().toLowerCase();
|
18965
|
+
const typeSchema = (0, import_drizzle_orm5.is)(column7, import_pg_core2.PgEnumColumn) ? column7.enum.schema || "public" : void 0;
|
18966
|
+
const generated = column7.generated;
|
18967
|
+
const identity = column7.generatedIdentity;
|
18968
|
+
const increment = stringFromIdentityProperty((_g = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _g.increment) ?? "1";
|
18969
|
+
const minValue = stringFromIdentityProperty((_h = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _h.minValue) ?? (parseFloat(increment) < 0 ? minRangeForIdentityBasedOn(column7.columnType) : "1");
|
18970
|
+
const maxValue = stringFromIdentityProperty((_i = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _i.maxValue) ?? (parseFloat(increment) < 0 ? "-1" : maxRangeForIdentityBasedOn(column7.getSQLType()));
|
18971
|
+
const startWith = stringFromIdentityProperty((_j = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _j.startWith) ?? (parseFloat(increment) < 0 ? maxValue : minValue);
|
18972
|
+
const cache = stringFromIdentityProperty((_k = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _k.cache) ?? "1";
|
18973
|
+
const columnToSet = {
|
18974
|
+
name: column7.name,
|
18975
|
+
type: column7.getSQLType(),
|
18976
|
+
typeSchema,
|
18977
|
+
primaryKey,
|
18978
|
+
notNull,
|
18979
|
+
generated: generated ? {
|
18980
|
+
as: (0, import_drizzle_orm5.is)(generated.as, import_drizzle_orm5.SQL) ? dialect5.sqlToQuery(generated.as).sql : typeof generated.as === "function" ? dialect5.sqlToQuery(generated.as()).sql : generated.as,
|
18981
|
+
type: "stored"
|
18982
|
+
} : void 0,
|
18983
|
+
identity: identity ? {
|
18984
|
+
type: identity.type,
|
18985
|
+
name: identity.sequenceName ?? `${viewName}_${column7.name}_seq`,
|
18986
|
+
schema: schema5 ?? "public",
|
18987
|
+
increment,
|
18988
|
+
startWith,
|
18989
|
+
minValue,
|
18990
|
+
maxValue,
|
18991
|
+
cache,
|
18992
|
+
cycle: ((_l = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _l.cycle) ?? false
|
18993
|
+
} : void 0
|
18994
|
+
};
|
18995
|
+
if (column7.isUnique) {
|
18996
|
+
const existingUnique = uniqueConstraintObject[column7.uniqueName];
|
18997
|
+
if (typeof existingUnique !== "undefined") {
|
18998
|
+
console.log(
|
18999
|
+
`
|
19000
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
19001
|
+
viewName
|
19002
|
+
)} table.
|
19003
|
+
The unique constraint ${source_default.underline.blue(
|
19004
|
+
column7.uniqueName
|
19005
|
+
)} on the ${source_default.underline.blue(
|
19006
|
+
column7.name
|
19007
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
19008
|
+
existingUnique.columns.join(",")
|
19009
|
+
)} columns
|
19010
|
+
`)}`
|
19011
|
+
);
|
19012
|
+
process.exit(1);
|
19013
|
+
}
|
19014
|
+
uniqueConstraintObject[column7.uniqueName] = {
|
19015
|
+
name: column7.uniqueName,
|
19016
|
+
nullsNotDistinct: column7.uniqueType === "not distinct",
|
19017
|
+
columns: [columnToSet.name]
|
19018
|
+
};
|
19019
|
+
}
|
19020
|
+
if (column7.default !== void 0) {
|
19021
|
+
if ((0, import_drizzle_orm5.is)(column7.default, import_drizzle_orm5.SQL)) {
|
19022
|
+
columnToSet.default = sqlToStr(column7.default);
|
19023
|
+
} else {
|
19024
|
+
if (typeof column7.default === "string") {
|
19025
|
+
columnToSet.default = `'${column7.default}'`;
|
19026
|
+
} else {
|
19027
|
+
if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
|
19028
|
+
columnToSet.default = `'${JSON.stringify(
|
19029
|
+
column7.default
|
19030
|
+
)}'::${sqlTypeLowered}`;
|
19031
|
+
} else if (column7.default instanceof Date) {
|
19032
|
+
if (sqlTypeLowered === "date") {
|
19033
|
+
columnToSet.default = `'${column7.default.toISOString().split("T")[0]}'`;
|
19034
|
+
} else if (sqlTypeLowered === "timestamp") {
|
19035
|
+
columnToSet.default = `'${column7.default.toISOString().replace("T", " ").slice(0, 23)}'`;
|
19036
|
+
} else {
|
19037
|
+
columnToSet.default = `'${column7.default.toISOString()}'`;
|
19038
|
+
}
|
19039
|
+
} else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column7.default)) {
|
19040
|
+
columnToSet.default = `'${buildArrayString(
|
19041
|
+
column7.default,
|
19042
|
+
sqlTypeLowered
|
19043
|
+
)}'`;
|
19044
|
+
} else {
|
19045
|
+
columnToSet.default = column7.default;
|
19046
|
+
}
|
19047
|
+
}
|
19048
|
+
}
|
19049
|
+
}
|
19050
|
+
columnsObject[column7.name] = columnToSet;
|
19051
|
+
}
|
19052
|
+
}
|
19053
|
+
resultViews[viewKey] = {
|
19054
|
+
columns: columnsObject,
|
19055
|
+
definition: isExisting ? void 0 : dialect5.sqlToQuery(query).sql,
|
19056
|
+
name: viewName,
|
19057
|
+
schema: viewSchema,
|
19058
|
+
isExisting,
|
19059
|
+
with: withOption,
|
19060
|
+
withNoData,
|
19061
|
+
materialized,
|
19062
|
+
tablespace,
|
19063
|
+
using
|
19064
|
+
};
|
19065
|
+
}
|
18866
19066
|
const enumsToReturn = enums.reduce((map, obj) => {
|
18867
19067
|
const enumSchema3 = obj.schema || "public";
|
18868
19068
|
const key = `${enumSchema3}.${obj.enumName}`;
|
@@ -18889,6 +19089,7 @@ ${withStyle.errorWarning(
|
|
18889
19089
|
enums: enumsToReturn,
|
18890
19090
|
schemas: schemasObject,
|
18891
19091
|
sequences: sequencesToReturn,
|
19092
|
+
views: resultViews,
|
18892
19093
|
_meta: {
|
18893
19094
|
schemas: {},
|
18894
19095
|
tables: {},
|
@@ -18907,10 +19108,25 @@ ${withStyle.errorWarning(
|
|
18907
19108
|
};
|
18908
19109
|
fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, progressCallback) => {
|
18909
19110
|
const result = {};
|
19111
|
+
const views = {};
|
18910
19112
|
const internals = { tables: {} };
|
18911
|
-
const where = schemaFilters.map((t2) => `
|
19113
|
+
const where = schemaFilters.map((t2) => `n.nspname = '${t2}'`).join(" or ");
|
18912
19114
|
const allTables = await db.query(
|
18913
|
-
`SELECT
|
19115
|
+
`SELECT
|
19116
|
+
n.nspname AS table_schema,
|
19117
|
+
c.relname AS table_name,
|
19118
|
+
CASE
|
19119
|
+
WHEN c.relkind = 'r' THEN 'table'
|
19120
|
+
WHEN c.relkind = 'v' THEN 'view'
|
19121
|
+
WHEN c.relkind = 'm' THEN 'materialized_view'
|
19122
|
+
END AS type
|
19123
|
+
FROM
|
19124
|
+
pg_catalog.pg_class c
|
19125
|
+
JOIN
|
19126
|
+
pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
19127
|
+
WHERE
|
19128
|
+
c.relkind IN ('r', 'v', 'm')
|
19129
|
+
${where === "" ? "" : ` AND ${where}`};`
|
18914
19130
|
);
|
18915
19131
|
const schemas = new Set(allTables.map((it) => it.table_schema));
|
18916
19132
|
schemas.delete("public");
|
@@ -18988,7 +19204,7 @@ ${withStyle.errorWarning(
|
|
18988
19204
|
progressCallback("enums", Object.keys(enumsToReturn).length, "done");
|
18989
19205
|
}
|
18990
19206
|
const sequencesInColumns = [];
|
18991
|
-
const all = allTables.map((row) => {
|
19207
|
+
const all = allTables.filter((it) => it.type === "table").map((row) => {
|
18992
19208
|
return new Promise(async (res, rej) => {
|
18993
19209
|
var _a, _b, _c, _d, _e, _f;
|
18994
19210
|
const tableName = row.table_name;
|
@@ -19397,6 +19613,336 @@ ${withStyle.errorWarning(
|
|
19397
19613
|
}
|
19398
19614
|
for await (const _2 of all) {
|
19399
19615
|
}
|
19616
|
+
const allViews = allTables.filter((it) => it.type === "view" || it.type === "materialized_view").map((row) => {
|
19617
|
+
return new Promise(async (res, rej) => {
|
19618
|
+
var _a, _b, _c, _d;
|
19619
|
+
const viewName = row.table_name;
|
19620
|
+
if (!tablesFilter(viewName))
|
19621
|
+
return res("");
|
19622
|
+
tableCount += 1;
|
19623
|
+
const viewSchema = row.table_schema;
|
19624
|
+
try {
|
19625
|
+
const columnToReturn = {};
|
19626
|
+
const viewResponses = await db.query(`WITH view_columns AS (
|
19627
|
+
SELECT DISTINCT
|
19628
|
+
nv.nspname::information_schema.sql_identifier AS view_schema,
|
19629
|
+
v.relname::information_schema.sql_identifier AS view_name,
|
19630
|
+
nt.nspname::information_schema.sql_identifier AS table_schema,
|
19631
|
+
t.relname::information_schema.sql_identifier AS table_name,
|
19632
|
+
a.attname::information_schema.sql_identifier AS column_name
|
19633
|
+
FROM pg_namespace nv
|
19634
|
+
JOIN pg_class v ON nv.oid = v.relnamespace
|
19635
|
+
JOIN pg_depend dv ON v.oid = dv.refobjid
|
19636
|
+
JOIN pg_depend dt ON dv.objid = dt.objid
|
19637
|
+
JOIN pg_class t ON dt.refobjid = t.oid
|
19638
|
+
JOIN pg_namespace nt ON t.relnamespace = nt.oid
|
19639
|
+
JOIN pg_attribute a ON t.oid = a.attrelid
|
19640
|
+
WHERE (v.relkind = 'v'::"char" OR v.relkind = 'm'::"char")
|
19641
|
+
AND dv.refclassid = 'pg_class'::regclass::oid
|
19642
|
+
AND dv.classid = 'pg_rewrite'::regclass::oid
|
19643
|
+
AND dv.deptype = 'i'::"char"
|
19644
|
+
AND dv.objid = dt.objid
|
19645
|
+
AND dv.refobjid <> dt.refobjid
|
19646
|
+
AND dt.classid = 'pg_rewrite'::regclass::oid
|
19647
|
+
AND dt.refclassid = 'pg_class'::regclass::oid
|
19648
|
+
AND t.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'p'::"char"])
|
19649
|
+
AND dt.refobjsubid = a.attnum
|
19650
|
+
AND pg_has_role(t.relowner, 'USAGE'::text)
|
19651
|
+
AND nv.nspname::information_schema.sql_identifier = '${viewSchema}'
|
19652
|
+
AND v.relname::information_schema.sql_identifier = '${viewName}'
|
19653
|
+
),
|
19654
|
+
column_descriptions AS (
|
19655
|
+
SELECT DISTINCT
|
19656
|
+
a.attrelid::regclass::text AS table_name,
|
19657
|
+
a.attname AS column_name,
|
19658
|
+
c.is_nullable,
|
19659
|
+
a.attndims AS array_dimensions,
|
19660
|
+
CASE
|
19661
|
+
WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
|
19662
|
+
SELECT FROM pg_attrdef ad
|
19663
|
+
WHERE ad.adrelid = a.attrelid
|
19664
|
+
AND ad.adnum = a.attnum
|
19665
|
+
AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
|
19666
|
+
)
|
19667
|
+
THEN CASE a.atttypid
|
19668
|
+
WHEN 'int'::regtype THEN 'serial'
|
19669
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
19670
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
19671
|
+
END
|
19672
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
19673
|
+
END AS data_type,
|
19674
|
+
pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
|
19675
|
+
c.column_default,
|
19676
|
+
c.data_type AS additional_dt,
|
19677
|
+
c.udt_name AS enum_name,
|
19678
|
+
c.is_generated,
|
19679
|
+
c.generation_expression,
|
19680
|
+
c.is_identity,
|
19681
|
+
c.identity_generation,
|
19682
|
+
c.identity_start,
|
19683
|
+
c.identity_increment,
|
19684
|
+
c.identity_maximum,
|
19685
|
+
c.identity_minimum,
|
19686
|
+
c.identity_cycle
|
19687
|
+
FROM pg_attribute a
|
19688
|
+
JOIN information_schema.columns c ON c.column_name = a.attname
|
19689
|
+
JOIN pg_type t ON t.oid = a.atttypid
|
19690
|
+
LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
19691
|
+
WHERE a.attnum > 0
|
19692
|
+
AND NOT a.attisdropped
|
19693
|
+
),
|
19694
|
+
table_constraints AS (
|
19695
|
+
SELECT DISTINCT ON (ccu.column_name)
|
19696
|
+
ccu.column_name,
|
19697
|
+
c.data_type,
|
19698
|
+
tc.constraint_type,
|
19699
|
+
tc.constraint_name,
|
19700
|
+
tc.constraint_schema,
|
19701
|
+
tc.table_name
|
19702
|
+
FROM information_schema.table_constraints tc
|
19703
|
+
JOIN information_schema.constraint_column_usage ccu USING (constraint_schema, constraint_name)
|
19704
|
+
JOIN information_schema.columns c ON c.table_schema = tc.constraint_schema
|
19705
|
+
AND tc.table_name = c.table_name
|
19706
|
+
AND ccu.column_name = c.column_name
|
19707
|
+
),
|
19708
|
+
additional_column_info AS (
|
19709
|
+
SELECT DISTINCT
|
19710
|
+
a.attrelid::regclass::text AS table_name,
|
19711
|
+
a.attname AS column_name,
|
19712
|
+
is_nullable,
|
19713
|
+
a.attndims AS array_dimensions,
|
19714
|
+
CASE
|
19715
|
+
WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
|
19716
|
+
SELECT FROM pg_attrdef ad
|
19717
|
+
WHERE ad.adrelid = a.attrelid
|
19718
|
+
AND ad.adnum = a.attnum
|
19719
|
+
AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
|
19720
|
+
)
|
19721
|
+
THEN CASE a.atttypid
|
19722
|
+
WHEN 'int'::regtype THEN 'serial'
|
19723
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
19724
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
19725
|
+
END
|
19726
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
19727
|
+
END AS data_type,
|
19728
|
+
pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
|
19729
|
+
c.column_default,
|
19730
|
+
c.data_type AS additional_dt,
|
19731
|
+
c.udt_name AS enum_name,
|
19732
|
+
c.is_generated,
|
19733
|
+
generation_expression,
|
19734
|
+
is_identity,
|
19735
|
+
identity_generation,
|
19736
|
+
identity_start,
|
19737
|
+
identity_increment,
|
19738
|
+
identity_maximum,
|
19739
|
+
identity_minimum,
|
19740
|
+
identity_cycle
|
19741
|
+
FROM pg_attribute a
|
19742
|
+
JOIN information_schema.columns c ON c.column_name = a.attname
|
19743
|
+
LEFT JOIN pg_type t ON t.oid = a.atttypid
|
19744
|
+
LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
19745
|
+
WHERE a.attnum > 0
|
19746
|
+
AND NOT a.attisdropped
|
19747
|
+
)
|
19748
|
+
SELECT DISTINCT ON (vc.table_name, vc.column_name)
|
19749
|
+
vc.view_schema,
|
19750
|
+
vc.view_name,
|
19751
|
+
vc.table_schema,
|
19752
|
+
vc.table_name,
|
19753
|
+
vc.column_name,
|
19754
|
+
COALESCE(cd.data_type, aci.data_type) AS data_type,
|
19755
|
+
tc.constraint_type,
|
19756
|
+
tc.constraint_name,
|
19757
|
+
aci.is_nullable,
|
19758
|
+
aci.array_dimensions,
|
19759
|
+
aci.seq_name,
|
19760
|
+
aci.column_default,
|
19761
|
+
aci.additional_dt,
|
19762
|
+
aci.enum_name,
|
19763
|
+
aci.is_generated,
|
19764
|
+
aci.generation_expression,
|
19765
|
+
aci.is_identity,
|
19766
|
+
aci.identity_generation,
|
19767
|
+
aci.identity_start,
|
19768
|
+
aci.identity_increment,
|
19769
|
+
aci.identity_maximum,
|
19770
|
+
aci.identity_minimum,
|
19771
|
+
aci.identity_cycle
|
19772
|
+
FROM view_columns vc
|
19773
|
+
LEFT JOIN column_descriptions cd ON vc.table_name = cd.table_name AND vc.column_name = cd.column_name
|
19774
|
+
LEFT JOIN table_constraints tc ON vc.table_name = tc.table_name AND vc.column_name = tc.column_name
|
19775
|
+
LEFT JOIN additional_column_info aci ON vc.table_name = aci.table_name AND vc.column_name = aci.column_name
|
19776
|
+
ORDER BY vc.table_name, vc.column_name;`);
|
19777
|
+
for (const viewResponse of viewResponses) {
|
19778
|
+
const columnName = viewResponse.column_name;
|
19779
|
+
const columnAdditionalDT = viewResponse.additional_dt;
|
19780
|
+
const columnDimensions = viewResponse.array_dimensions;
|
19781
|
+
const enumType2 = viewResponse.enum_name;
|
19782
|
+
let columnType = viewResponse.data_type;
|
19783
|
+
const typeSchema = viewResponse.type_schema;
|
19784
|
+
const isGenerated = viewResponse.is_generated === "ALWAYS";
|
19785
|
+
const generationExpression = viewResponse.generation_expression;
|
19786
|
+
const isIdentity = viewResponse.is_identity === "YES";
|
19787
|
+
const identityGeneration = viewResponse.identity_generation === "ALWAYS" ? "always" : "byDefault";
|
19788
|
+
const identityStart = viewResponse.identity_start;
|
19789
|
+
const identityIncrement = viewResponse.identity_increment;
|
19790
|
+
const identityMaximum = viewResponse.identity_maximum;
|
19791
|
+
const identityMinimum = viewResponse.identity_minimum;
|
19792
|
+
const identityCycle = viewResponse.identity_cycle === "YES";
|
19793
|
+
const identityName = viewResponse.seq_name;
|
19794
|
+
const defaultValueRes = viewResponse.column_default;
|
19795
|
+
const primaryKey = viewResponse.constraint_type === "PRIMARY KEY";
|
19796
|
+
let columnTypeMapped = columnType;
|
19797
|
+
if (columnAdditionalDT === "ARRAY") {
|
19798
|
+
if (typeof internals.tables[viewName] === "undefined") {
|
19799
|
+
internals.tables[viewName] = {
|
19800
|
+
columns: {
|
19801
|
+
[columnName]: {
|
19802
|
+
isArray: true,
|
19803
|
+
dimensions: columnDimensions,
|
19804
|
+
rawType: columnTypeMapped.substring(
|
19805
|
+
0,
|
19806
|
+
columnTypeMapped.length - 2
|
19807
|
+
)
|
19808
|
+
}
|
19809
|
+
}
|
19810
|
+
};
|
19811
|
+
} else {
|
19812
|
+
if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
|
19813
|
+
internals.tables[viewName].columns[columnName] = {
|
19814
|
+
isArray: true,
|
19815
|
+
dimensions: columnDimensions,
|
19816
|
+
rawType: columnTypeMapped.substring(
|
19817
|
+
0,
|
19818
|
+
columnTypeMapped.length - 2
|
19819
|
+
)
|
19820
|
+
};
|
19821
|
+
}
|
19822
|
+
}
|
19823
|
+
}
|
19824
|
+
const defaultValue = defaultForColumn(
|
19825
|
+
viewResponse,
|
19826
|
+
internals,
|
19827
|
+
viewName
|
19828
|
+
);
|
19829
|
+
if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
|
19830
|
+
if (typeof internals.tables[viewName] === "undefined") {
|
19831
|
+
internals.tables[viewName] = {
|
19832
|
+
columns: {
|
19833
|
+
[columnName]: {
|
19834
|
+
isDefaultAnExpression: true
|
19835
|
+
}
|
19836
|
+
}
|
19837
|
+
};
|
19838
|
+
} else {
|
19839
|
+
if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
|
19840
|
+
internals.tables[viewName].columns[columnName] = {
|
19841
|
+
isDefaultAnExpression: true
|
19842
|
+
};
|
19843
|
+
} else {
|
19844
|
+
internals.tables[viewName].columns[columnName].isDefaultAnExpression = true;
|
19845
|
+
}
|
19846
|
+
}
|
19847
|
+
}
|
19848
|
+
const isSerial = columnType === "serial";
|
19849
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
19850
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
19851
|
+
}
|
19852
|
+
if (columnAdditionalDT === "ARRAY") {
|
19853
|
+
for (let i2 = 1; i2 < Number(columnDimensions); i2++) {
|
19854
|
+
columnTypeMapped += "[]";
|
19855
|
+
}
|
19856
|
+
}
|
19857
|
+
columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
|
19858
|
+
columnTypeMapped = trimChar(columnTypeMapped, '"');
|
19859
|
+
columnToReturn[columnName] = {
|
19860
|
+
name: columnName,
|
19861
|
+
type: (
|
19862
|
+
// filter vectors, but in future we should filter any extension that was installed by user
|
19863
|
+
columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
|
19864
|
+
),
|
19865
|
+
typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
|
19866
|
+
primaryKey,
|
19867
|
+
notNull: viewResponse.is_nullable === "NO",
|
19868
|
+
generated: isGenerated ? { as: generationExpression, type: "stored" } : void 0,
|
19869
|
+
identity: isIdentity ? {
|
19870
|
+
type: identityGeneration,
|
19871
|
+
name: identityName,
|
19872
|
+
increment: stringFromDatabaseIdentityProperty(identityIncrement),
|
19873
|
+
minValue: stringFromDatabaseIdentityProperty(identityMinimum),
|
19874
|
+
maxValue: stringFromDatabaseIdentityProperty(identityMaximum),
|
19875
|
+
startWith: stringFromDatabaseIdentityProperty(identityStart),
|
19876
|
+
cache: ((_a = sequencesToReturn[identityName]) == null ? void 0 : _a.cache) ? (_b = sequencesToReturn[identityName]) == null ? void 0 : _b.cache : ((_c = sequencesToReturn[`${viewSchema}.${identityName}`]) == null ? void 0 : _c.cache) ? (_d = sequencesToReturn[`${viewSchema}.${identityName}`]) == null ? void 0 : _d.cache : void 0,
|
19877
|
+
cycle: identityCycle,
|
19878
|
+
schema: viewSchema
|
19879
|
+
} : void 0
|
19880
|
+
};
|
19881
|
+
if (identityName) {
|
19882
|
+
delete sequencesToReturn[`${viewSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
|
19883
|
+
delete sequencesToReturn[identityName];
|
19884
|
+
}
|
19885
|
+
if (!isSerial && typeof defaultValue !== "undefined") {
|
19886
|
+
columnToReturn[columnName].default = defaultValue;
|
19887
|
+
}
|
19888
|
+
}
|
19889
|
+
const [viewInfo] = await db.query(`
|
19890
|
+
SELECT
|
19891
|
+
c.relname AS view_name,
|
19892
|
+
n.nspname AS schema_name,
|
19893
|
+
pg_get_viewdef(c.oid, true) AS definition,
|
19894
|
+
ts.spcname AS tablespace_name,
|
19895
|
+
c.reloptions AS options,
|
19896
|
+
pg_tablespace_location(ts.oid) AS location
|
19897
|
+
FROM
|
19898
|
+
pg_class c
|
19899
|
+
JOIN
|
19900
|
+
pg_namespace n ON c.relnamespace = n.oid
|
19901
|
+
LEFT JOIN
|
19902
|
+
pg_tablespace ts ON c.reltablespace = ts.oid
|
19903
|
+
WHERE
|
19904
|
+
(c.relkind = 'm' OR c.relkind = 'v')
|
19905
|
+
AND n.nspname = '${viewSchema}'
|
19906
|
+
AND c.relname = '${viewName}';`);
|
19907
|
+
const resultWith = {};
|
19908
|
+
if (viewInfo.options) {
|
19909
|
+
viewInfo.options.forEach((pair) => {
|
19910
|
+
const splitted = pair.split("=");
|
19911
|
+
const key = splitted[0];
|
19912
|
+
const value = splitted[1];
|
19913
|
+
if (value === "true") {
|
19914
|
+
resultWith[key] = true;
|
19915
|
+
} else if (value === "false") {
|
19916
|
+
resultWith[key] = false;
|
19917
|
+
} else if (!isNaN(Number(value))) {
|
19918
|
+
resultWith[key] = Number(value);
|
19919
|
+
} else {
|
19920
|
+
resultWith[key] = value;
|
19921
|
+
}
|
19922
|
+
});
|
19923
|
+
}
|
19924
|
+
const definition = viewInfo.definition.replace(/\s+/g, " ").replace(";", "").trim();
|
19925
|
+
const withOption = Object.values(resultWith).length ? Object.fromEntries(Object.entries(resultWith).map(([key, value]) => [key.camelCase(), value])) : void 0;
|
19926
|
+
const materialized = row.type === "materialized_view";
|
19927
|
+
views[`${viewSchema}.${viewName}`] = {
|
19928
|
+
name: viewName,
|
19929
|
+
schema: viewSchema,
|
19930
|
+
columns: columnToReturn,
|
19931
|
+
isExisting: false,
|
19932
|
+
definition,
|
19933
|
+
materialized,
|
19934
|
+
with: withOption,
|
19935
|
+
tablespace: viewInfo.tablespace_name ?? void 0
|
19936
|
+
};
|
19937
|
+
} catch (e2) {
|
19938
|
+
rej(e2);
|
19939
|
+
return;
|
19940
|
+
}
|
19941
|
+
res("");
|
19942
|
+
});
|
19943
|
+
});
|
19944
|
+
for await (const _2 of allViews) {
|
19945
|
+
}
|
19400
19946
|
if (progressCallback) {
|
19401
19947
|
progressCallback("columns", columnsCount, "done");
|
19402
19948
|
progressCallback("indexes", indexesCount, "done");
|
@@ -19410,6 +19956,7 @@ ${withStyle.errorWarning(
|
|
19410
19956
|
enums: enumsToReturn,
|
19411
19957
|
schemas: schemasObject,
|
19412
19958
|
sequences: sequencesToReturn,
|
19959
|
+
views,
|
19413
19960
|
_meta: {
|
19414
19961
|
schemas: {},
|
19415
19962
|
tables: {},
|
@@ -20052,10 +20599,10 @@ ${filenames.join("\n")}
|
|
20052
20599
|
const filenames = prepareFilenames(path5);
|
20053
20600
|
const { prepareFromPgImports: prepareFromPgImports2 } = await Promise.resolve().then(() => (init_pgImports(), pgImports_exports));
|
20054
20601
|
const { generatePgSnapshot: generatePgSnapshot2 } = await Promise.resolve().then(() => (init_pgSerializer(), pgSerializer_exports));
|
20055
|
-
const { tables, enums, schemas, sequences } = await prepareFromPgImports2(
|
20602
|
+
const { tables, enums, schemas, sequences, views, matViews } = await prepareFromPgImports2(
|
20056
20603
|
filenames
|
20057
20604
|
);
|
20058
|
-
return generatePgSnapshot2(tables, enums, schemas, sequences, schemaFilter);
|
20605
|
+
return generatePgSnapshot2(tables, enums, schemas, sequences, views, matViews, schemaFilter);
|
20059
20606
|
};
|
20060
20607
|
serializeSQLite = async (path5) => {
|
20061
20608
|
const filenames = prepareFilenames(path5);
|
@@ -22571,6 +23118,7 @@ function applyJsonDiff(json1, json2) {
|
|
22571
23118
|
difference.tables = difference.tables || {};
|
22572
23119
|
difference.enums = difference.enums || {};
|
22573
23120
|
difference.sequences = difference.sequences || {};
|
23121
|
+
difference.views = difference.views || {};
|
22574
23122
|
const schemaKeys = Object.keys(difference.schemas);
|
22575
23123
|
for (let key of schemaKeys) {
|
22576
23124
|
if (key.endsWith("__added") || key.endsWith("__deleted")) {
|
@@ -22626,6 +23174,71 @@ function applyJsonDiff(json1, json2) {
|
|
22626
23174
|
const alteredSequences = sequencesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted")) && "values" in it[1]).map((it) => {
|
22627
23175
|
return json2.sequences[it[0]];
|
22628
23176
|
});
|
23177
|
+
const viewsEntries = Object.entries(difference.views);
|
23178
|
+
const alteredViews = viewsEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map(
|
23179
|
+
([nameWithSchema, view2]) => {
|
23180
|
+
const deletedWithOption = view2.with__deleted;
|
23181
|
+
const addedWithOption = view2.with__added;
|
23182
|
+
const deletedWith = Object.fromEntries(
|
23183
|
+
Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__deleted")).map(([key, value]) => {
|
23184
|
+
return [key.replace("__deleted", ""), value];
|
23185
|
+
})
|
23186
|
+
);
|
23187
|
+
const addedWith = Object.fromEntries(
|
23188
|
+
Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__added")).map(([key, value]) => {
|
23189
|
+
return [key.replace("__added", ""), value];
|
23190
|
+
})
|
23191
|
+
);
|
23192
|
+
const alterWith = Object.fromEntries(
|
23193
|
+
Object.entries(view2.with || {}).filter(
|
23194
|
+
(it) => typeof it[1].__old !== "undefined" && typeof it[1].__new !== "undefined"
|
23195
|
+
).map(
|
23196
|
+
(it) => {
|
23197
|
+
return [it[0], it[1].__new];
|
23198
|
+
}
|
23199
|
+
)
|
23200
|
+
);
|
23201
|
+
const alteredSchema = view2.schema;
|
23202
|
+
const alteredDefinition = view2.definition;
|
23203
|
+
const alteredExisting = view2.isExisting;
|
23204
|
+
const addedTablespace = view2.tablespace__added;
|
23205
|
+
const droppedTablespace = view2.tablespace__deleted;
|
23206
|
+
const alterTablespaceTo = view2.tablespace;
|
23207
|
+
let alteredTablespace;
|
23208
|
+
if (addedTablespace)
|
23209
|
+
alteredTablespace = { __new: addedTablespace, __old: "pg_default" };
|
23210
|
+
if (droppedTablespace)
|
23211
|
+
alteredTablespace = { __new: "pg_default", __old: droppedTablespace };
|
23212
|
+
if (alterTablespaceTo)
|
23213
|
+
alteredTablespace = alterTablespaceTo;
|
23214
|
+
const addedUsing = view2.using__added;
|
23215
|
+
const droppedUsing = view2.using__deleted;
|
23216
|
+
const alterUsingTo = view2.using;
|
23217
|
+
let alteredUsing;
|
23218
|
+
if (addedUsing)
|
23219
|
+
alteredUsing = { __new: addedUsing, __old: "heap" };
|
23220
|
+
if (droppedUsing)
|
23221
|
+
alteredUsing = { __new: "heap", __old: droppedUsing };
|
23222
|
+
if (alterUsingTo)
|
23223
|
+
alteredUsing = alterUsingTo;
|
23224
|
+
return {
|
23225
|
+
name: json2.views[nameWithSchema].name,
|
23226
|
+
schema: json2.views[nameWithSchema].schema,
|
23227
|
+
deletedWithOption,
|
23228
|
+
addedWithOption,
|
23229
|
+
alteredWith: {
|
23230
|
+
deletedWith: Object.keys(deletedWith).length ? deletedWith : void 0,
|
23231
|
+
addedWith: Object.keys(addedWith).length ? addedWith : void 0,
|
23232
|
+
alterWith: Object.keys(alterWith).length ? alterWith : void 0
|
23233
|
+
},
|
23234
|
+
alteredSchema,
|
23235
|
+
alteredDefinition,
|
23236
|
+
alteredExisting,
|
23237
|
+
alteredTablespace,
|
23238
|
+
alteredUsing
|
23239
|
+
};
|
23240
|
+
}
|
23241
|
+
);
|
22629
23242
|
const alteredTablesWithColumns = Object.values(difference.tables).map(
|
22630
23243
|
(table4) => {
|
22631
23244
|
return findAlternationsInTable(table4);
|
@@ -22634,7 +23247,8 @@ function applyJsonDiff(json1, json2) {
|
|
22634
23247
|
return {
|
22635
23248
|
alteredTablesWithColumns,
|
22636
23249
|
alteredEnums,
|
22637
|
-
alteredSequences
|
23250
|
+
alteredSequences,
|
23251
|
+
alteredViews
|
22638
23252
|
};
|
22639
23253
|
}
|
22640
23254
|
var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
|
@@ -23029,7 +23643,7 @@ function fromJson(statements, dialect7, action, json2) {
|
|
23029
23643
|
}).filter((it) => it !== "");
|
23030
23644
|
return result;
|
23031
23645
|
}
|
23032
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
23646
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, PgDropViewConvertor, PgRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, 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;
|
23033
23647
|
var init_sqlgenerator = __esm({
|
23034
23648
|
"src/sqlgenerator.ts"() {
|
23035
23649
|
"use strict";
|
@@ -23245,6 +23859,118 @@ var init_sqlgenerator = __esm({
|
|
23245
23859
|
return statement;
|
23246
23860
|
}
|
23247
23861
|
};
|
23862
|
+
PgCreateViewConvertor = class extends Convertor {
|
23863
|
+
can(statement, dialect7) {
|
23864
|
+
return statement.type === "create_view" && dialect7 === "postgresql";
|
23865
|
+
}
|
23866
|
+
convert(st) {
|
23867
|
+
const { definition, name: viewName, schema: schema5, with: withOption, materialized, withNoData, tablespace, using } = st;
|
23868
|
+
const name = schema5 ? `"${schema5}"."${viewName}"` : `"${viewName}"`;
|
23869
|
+
let statement = materialized ? `CREATE MATERIALIZED VIEW ${name}` : `CREATE VIEW ${name}`;
|
23870
|
+
if (using)
|
23871
|
+
statement += ` USING "${using}"`;
|
23872
|
+
const options = [];
|
23873
|
+
if (withOption) {
|
23874
|
+
statement += ` WITH (`;
|
23875
|
+
Object.entries(withOption).forEach(([key, value]) => {
|
23876
|
+
if (typeof value === "undefined")
|
23877
|
+
return;
|
23878
|
+
options.push(`${key.snake_case()} = ${value}`);
|
23879
|
+
});
|
23880
|
+
statement += options.join(", ");
|
23881
|
+
statement += `)`;
|
23882
|
+
}
|
23883
|
+
if (tablespace)
|
23884
|
+
statement += ` TABLESPACE ${tablespace}`;
|
23885
|
+
statement += ` AS (${definition})`;
|
23886
|
+
if (withNoData)
|
23887
|
+
statement += ` WITH NO DATA`;
|
23888
|
+
statement += `;`;
|
23889
|
+
return statement;
|
23890
|
+
}
|
23891
|
+
};
|
23892
|
+
PgDropViewConvertor = class extends Convertor {
|
23893
|
+
can(statement, dialect7) {
|
23894
|
+
return statement.type === "drop_view" && dialect7 === "postgresql";
|
23895
|
+
}
|
23896
|
+
convert(st) {
|
23897
|
+
const { name: viewName, schema: schema5, materialized } = st;
|
23898
|
+
const name = schema5 ? `"${schema5}"."${viewName}"` : `"${viewName}"`;
|
23899
|
+
return `DROP${materialized ? " MATERIALIZED" : ""} VIEW ${name};`;
|
23900
|
+
}
|
23901
|
+
};
|
23902
|
+
PgRenameViewConvertor = class extends Convertor {
|
23903
|
+
can(statement, dialect7) {
|
23904
|
+
return statement.type === "rename_view" && dialect7 === "postgresql";
|
23905
|
+
}
|
23906
|
+
convert(st) {
|
23907
|
+
const { nameFrom: from, nameTo: to, schema: schema5, materialized } = st;
|
23908
|
+
const nameFrom = `"${schema5}"."${from}"`;
|
23909
|
+
return `ALTER${materialized ? " MATERIALIZED" : ""} VIEW ${nameFrom} RENAME TO "${to}";`;
|
23910
|
+
}
|
23911
|
+
};
|
23912
|
+
PgAlterViewSchemaConvertor = class extends Convertor {
|
23913
|
+
can(statement, dialect7) {
|
23914
|
+
return statement.type === "alter_view_alter_schema" && dialect7 === "postgresql";
|
23915
|
+
}
|
23916
|
+
convert(st) {
|
23917
|
+
const { fromSchema, toSchema, name, materialized } = st;
|
23918
|
+
const statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${fromSchema}"."${name}" SET SCHEMA "${toSchema}";`;
|
23919
|
+
return statement;
|
23920
|
+
}
|
23921
|
+
};
|
23922
|
+
PgAlterViewAddWithOptionConvertor = class extends Convertor {
|
23923
|
+
can(statement, dialect7) {
|
23924
|
+
return statement.type === "alter_view_add_with_option" && dialect7 === "postgresql";
|
23925
|
+
}
|
23926
|
+
convert(st) {
|
23927
|
+
const { schema: schema5, with: withOption, name, materialized } = st;
|
23928
|
+
let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema5}"."${name}" SET (`;
|
23929
|
+
const options = [];
|
23930
|
+
Object.entries(withOption).forEach(([key, value]) => {
|
23931
|
+
options.push(`${key.snake_case()} = ${value}`);
|
23932
|
+
});
|
23933
|
+
statement += options.join(", ");
|
23934
|
+
statement += `);`;
|
23935
|
+
return statement;
|
23936
|
+
}
|
23937
|
+
};
|
23938
|
+
PgAlterViewDropWithOptionConvertor = class extends Convertor {
|
23939
|
+
can(statement, dialect7) {
|
23940
|
+
return statement.type === "alter_view_drop_with_option" && dialect7 === "postgresql";
|
23941
|
+
}
|
23942
|
+
convert(st) {
|
23943
|
+
const { schema: schema5, name, materialized, with: withOptions } = st;
|
23944
|
+
let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema5}"."${name}" RESET (`;
|
23945
|
+
const options = [];
|
23946
|
+
Object.entries(withOptions).forEach(([key, value]) => {
|
23947
|
+
options.push(`${key.snake_case()}`);
|
23948
|
+
});
|
23949
|
+
statement += options.join(", ");
|
23950
|
+
statement += ");";
|
23951
|
+
return statement;
|
23952
|
+
}
|
23953
|
+
};
|
23954
|
+
PgAlterViewAlterTablespaceConvertor = class extends Convertor {
|
23955
|
+
can(statement, dialect7) {
|
23956
|
+
return statement.type === "alter_view_alter_tablespace" && dialect7 === "postgresql";
|
23957
|
+
}
|
23958
|
+
convert(st) {
|
23959
|
+
const { schema: schema5, name, toTablespace } = st;
|
23960
|
+
const statement = `ALTER MATERIALIZED VIEW "${schema5}"."${name}" SET TABLESPACE ${toTablespace};`;
|
23961
|
+
return statement;
|
23962
|
+
}
|
23963
|
+
};
|
23964
|
+
PgAlterViewAlterUsingConvertor = class extends Convertor {
|
23965
|
+
can(statement, dialect7) {
|
23966
|
+
return statement.type === "alter_view_alter_using" && dialect7 === "postgresql";
|
23967
|
+
}
|
23968
|
+
convert(st) {
|
23969
|
+
const { schema: schema5, name, toUsing } = st;
|
23970
|
+
const statement = `ALTER MATERIALIZED VIEW "${schema5}"."${name}" SET ACCESS METHOD "${toUsing}";`;
|
23971
|
+
return statement;
|
23972
|
+
}
|
23973
|
+
};
|
23248
23974
|
PgAlterTableAlterColumnSetGenerated = class extends Convertor {
|
23249
23975
|
can(statement, dialect7) {
|
23250
23976
|
return statement.type === "alter_table_alter_column_set_identity" && dialect7 === "postgresql";
|
@@ -24583,6 +25309,14 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24583
25309
|
convertors.push(new SQLiteCreateTableConvertor());
|
24584
25310
|
convertors.push(new SQLiteRecreateTableConvertor());
|
24585
25311
|
convertors.push(new LibSQLRecreateTableConvertor());
|
25312
|
+
convertors.push(new PgCreateViewConvertor());
|
25313
|
+
convertors.push(new PgDropViewConvertor());
|
25314
|
+
convertors.push(new PgRenameViewConvertor());
|
25315
|
+
convertors.push(new PgAlterViewSchemaConvertor());
|
25316
|
+
convertors.push(new PgAlterViewAddWithOptionConvertor());
|
25317
|
+
convertors.push(new PgAlterViewDropWithOptionConvertor());
|
25318
|
+
convertors.push(new PgAlterViewAlterTablespaceConvertor());
|
25319
|
+
convertors.push(new PgAlterViewAlterUsingConvertor());
|
24586
25320
|
convertors.push(new CreateTypeEnumConvertor());
|
24587
25321
|
convertors.push(new CreatePgSequenceConvertor());
|
24588
25322
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -24917,7 +25651,7 @@ var init_sqlitePushUtils = __esm({
|
|
24917
25651
|
});
|
24918
25652
|
|
24919
25653
|
// src/jsonStatements.ts
|
24920
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
25654
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql, preparePgCreateViewJson, preparePgDropViewJson, preparePgRenameViewJson, preparePgAlterViewAlterSchemaJson, preparePgAlterViewAddWithOptionJson, preparePgAlterViewDropWithOptionJson, preparePgAlterViewAlterTablespaceJson, preparePgAlterViewAlterUsingJson;
|
24921
25655
|
var init_jsonStatements = __esm({
|
24922
25656
|
"src/jsonStatements.ts"() {
|
24923
25657
|
"use strict";
|
@@ -26256,6 +26990,81 @@ var init_jsonStatements = __esm({
|
|
26256
26990
|
};
|
26257
26991
|
});
|
26258
26992
|
};
|
26993
|
+
preparePgCreateViewJson = (name, schema5, definition, materialized, withNoData = false, withOption, using, tablespace) => {
|
26994
|
+
return {
|
26995
|
+
type: "create_view",
|
26996
|
+
name,
|
26997
|
+
schema: schema5,
|
26998
|
+
definition,
|
26999
|
+
with: withOption,
|
27000
|
+
materialized,
|
27001
|
+
withNoData,
|
27002
|
+
using,
|
27003
|
+
tablespace
|
27004
|
+
};
|
27005
|
+
};
|
27006
|
+
preparePgDropViewJson = (name, schema5, materialized) => {
|
27007
|
+
return {
|
27008
|
+
type: "drop_view",
|
27009
|
+
name,
|
27010
|
+
schema: schema5,
|
27011
|
+
materialized
|
27012
|
+
};
|
27013
|
+
};
|
27014
|
+
preparePgRenameViewJson = (to, from, schema5, materialized) => {
|
27015
|
+
return {
|
27016
|
+
type: "rename_view",
|
27017
|
+
nameTo: to,
|
27018
|
+
nameFrom: from,
|
27019
|
+
schema: schema5,
|
27020
|
+
materialized
|
27021
|
+
};
|
27022
|
+
};
|
27023
|
+
preparePgAlterViewAlterSchemaJson = (to, from, name, materialized) => {
|
27024
|
+
return {
|
27025
|
+
type: "alter_view_alter_schema",
|
27026
|
+
fromSchema: from,
|
27027
|
+
toSchema: to,
|
27028
|
+
name,
|
27029
|
+
materialized
|
27030
|
+
};
|
27031
|
+
};
|
27032
|
+
preparePgAlterViewAddWithOptionJson = (name, schema5, materialized, withOption) => {
|
27033
|
+
return {
|
27034
|
+
type: "alter_view_add_with_option",
|
27035
|
+
name,
|
27036
|
+
schema: schema5,
|
27037
|
+
materialized,
|
27038
|
+
with: withOption
|
27039
|
+
};
|
27040
|
+
};
|
27041
|
+
preparePgAlterViewDropWithOptionJson = (name, schema5, materialized, withOption) => {
|
27042
|
+
return {
|
27043
|
+
type: "alter_view_drop_with_option",
|
27044
|
+
name,
|
27045
|
+
schema: schema5,
|
27046
|
+
materialized,
|
27047
|
+
with: withOption
|
27048
|
+
};
|
27049
|
+
};
|
27050
|
+
preparePgAlterViewAlterTablespaceJson = (name, schema5, materialized, to) => {
|
27051
|
+
return {
|
27052
|
+
type: "alter_view_alter_tablespace",
|
27053
|
+
name,
|
27054
|
+
schema: schema5,
|
27055
|
+
materialized,
|
27056
|
+
toTablespace: to
|
27057
|
+
};
|
27058
|
+
};
|
27059
|
+
preparePgAlterViewAlterUsingJson = (name, schema5, materialized, to) => {
|
27060
|
+
return {
|
27061
|
+
type: "alter_view_alter_using",
|
27062
|
+
name,
|
27063
|
+
schema: schema5,
|
27064
|
+
materialized,
|
27065
|
+
toUsing: to
|
27066
|
+
};
|
27067
|
+
};
|
26259
27068
|
}
|
26260
27069
|
});
|
26261
27070
|
|
@@ -26541,7 +27350,7 @@ var init_statementCombiner = __esm({
|
|
26541
27350
|
});
|
26542
27351
|
|
26543
27352
|
// src/snapshotsDiffer.ts
|
26544
|
-
var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
27353
|
+
var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, alteredViewSchema, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
26545
27354
|
var init_snapshotsDiffer = __esm({
|
26546
27355
|
"src/snapshotsDiffer.ts"() {
|
26547
27356
|
"use strict";
|
@@ -26689,10 +27498,42 @@ var init_snapshotsDiffer = __esm({
|
|
26689
27498
|
})
|
26690
27499
|
)
|
26691
27500
|
}).strict();
|
27501
|
+
alteredViewSchema = objectType({
|
27502
|
+
name: stringType(),
|
27503
|
+
schema: stringType(),
|
27504
|
+
deletedWithOption: mergedViewWithOption.optional(),
|
27505
|
+
addedWithOption: mergedViewWithOption.optional(),
|
27506
|
+
alteredWith: objectType({
|
27507
|
+
addedWith: mergedViewWithOption.optional(),
|
27508
|
+
deletedWith: mergedViewWithOption.optional(),
|
27509
|
+
alterWith: mergedViewWithOption.optional()
|
27510
|
+
}).strict(),
|
27511
|
+
alteredSchema: objectType({
|
27512
|
+
__old: stringType(),
|
27513
|
+
__new: stringType()
|
27514
|
+
}).strict().optional(),
|
27515
|
+
alteredDefinition: objectType({
|
27516
|
+
__old: stringType(),
|
27517
|
+
__new: stringType()
|
27518
|
+
}).strict().optional(),
|
27519
|
+
alteredExisting: objectType({
|
27520
|
+
__old: booleanType(),
|
27521
|
+
__new: booleanType()
|
27522
|
+
}).strict().optional(),
|
27523
|
+
alteredTablespace: objectType({
|
27524
|
+
__old: stringType(),
|
27525
|
+
__new: stringType()
|
27526
|
+
}).strict().optional(),
|
27527
|
+
alteredUsing: objectType({
|
27528
|
+
__old: stringType(),
|
27529
|
+
__new: stringType()
|
27530
|
+
}).strict().optional()
|
27531
|
+
}).strict();
|
26692
27532
|
diffResultScheme = objectType({
|
26693
27533
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
26694
27534
|
alteredEnums: changedEnumSchema.array(),
|
26695
|
-
alteredSequences: sequenceSquashed.array()
|
27535
|
+
alteredSequences: sequenceSquashed.array(),
|
27536
|
+
alteredViews: alteredViewSchema.array()
|
26696
27537
|
}).strict();
|
26697
27538
|
diffResultSchemeMysql = objectType({
|
26698
27539
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
@@ -26747,7 +27588,7 @@ var init_snapshotsDiffer = __esm({
|
|
26747
27588
|
}
|
26748
27589
|
return column7;
|
26749
27590
|
};
|
26750
|
-
applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
27591
|
+
applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
|
26751
27592
|
const schemasDiff = diffSchemasOrTables(json1.schemas, json2.schemas);
|
26752
27593
|
const {
|
26753
27594
|
created: createdSchemas,
|
@@ -26975,7 +27816,40 @@ var init_snapshotsDiffer = __esm({
|
|
26975
27816
|
return [tableKey2, tableValue];
|
26976
27817
|
}
|
26977
27818
|
);
|
26978
|
-
const
|
27819
|
+
const viewsDiff = diffSchemasOrTables(json1.views, json2.views);
|
27820
|
+
const {
|
27821
|
+
created: createdViews,
|
27822
|
+
deleted: deletedViews,
|
27823
|
+
renamed: renamedViews,
|
27824
|
+
moved: movedViews
|
27825
|
+
} = await viewsResolver2({
|
27826
|
+
created: viewsDiff.added,
|
27827
|
+
deleted: viewsDiff.deleted
|
27828
|
+
});
|
27829
|
+
const renamesViewDic = {};
|
27830
|
+
renamedViews.forEach((it) => {
|
27831
|
+
renamesViewDic[`${it.from.schema}.${it.from.name}`] = { to: it.to.name, from: it.from.name };
|
27832
|
+
});
|
27833
|
+
const movedViewDic = {};
|
27834
|
+
movedViews.forEach((it) => {
|
27835
|
+
movedViewDic[`${it.schemaFrom}.${it.name}`] = { to: it.schemaTo, from: it.schemaFrom };
|
27836
|
+
});
|
27837
|
+
const viewsPatchedSnap1 = copy(columnsPatchedSnap1);
|
27838
|
+
viewsPatchedSnap1.views = mapEntries(
|
27839
|
+
viewsPatchedSnap1.views,
|
27840
|
+
(viewKey, viewValue) => {
|
27841
|
+
const rename = renamesViewDic[`${viewValue.schema}.${viewValue.name}`];
|
27842
|
+
const moved = movedViewDic[`${viewValue.schema}.${viewValue.name}`];
|
27843
|
+
if (rename) {
|
27844
|
+
viewValue.name = rename.to;
|
27845
|
+
viewKey = `${viewValue.schema}.${viewValue.name}`;
|
27846
|
+
}
|
27847
|
+
if (moved)
|
27848
|
+
viewKey = `${moved.to}.${viewValue.name}`;
|
27849
|
+
return [viewKey, viewValue];
|
27850
|
+
}
|
27851
|
+
);
|
27852
|
+
const diffResult = applyJsonDiff(viewsPatchedSnap1, json2);
|
26979
27853
|
const typedResult = diffResultScheme.parse(diffResult);
|
26980
27854
|
const jsonStatements = [];
|
26981
27855
|
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
@@ -27227,6 +28101,137 @@ var init_snapshotsDiffer = __esm({
|
|
27227
28101
|
const createTables = createdTables.map((it) => {
|
27228
28102
|
return preparePgCreateTableJson(it, curFull);
|
27229
28103
|
});
|
28104
|
+
const createViews = [];
|
28105
|
+
const dropViews = [];
|
28106
|
+
const renameViews = [];
|
28107
|
+
const alterViews = [];
|
28108
|
+
createViews.push(
|
28109
|
+
...createdViews.filter((it) => !it.isExisting).map((it) => {
|
28110
|
+
return preparePgCreateViewJson(
|
28111
|
+
it.name,
|
28112
|
+
it.schema,
|
28113
|
+
it.definition,
|
28114
|
+
it.materialized,
|
28115
|
+
it.withNoData,
|
28116
|
+
it.with,
|
28117
|
+
it.using,
|
28118
|
+
it.tablespace
|
28119
|
+
);
|
28120
|
+
})
|
28121
|
+
);
|
28122
|
+
dropViews.push(
|
28123
|
+
...deletedViews.filter((it) => !it.isExisting).map((it) => {
|
28124
|
+
return preparePgDropViewJson(it.name, it.schema, it.materialized);
|
28125
|
+
})
|
28126
|
+
);
|
28127
|
+
renameViews.push(
|
28128
|
+
...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
|
28129
|
+
return preparePgRenameViewJson(it.to.name, it.from.name, it.to.schema, it.to.materialized);
|
28130
|
+
})
|
28131
|
+
);
|
28132
|
+
alterViews.push(
|
28133
|
+
...movedViews.filter((it) => !json2.views[`${it.schemaTo}.${it.name}`].isExisting).map((it) => {
|
28134
|
+
return preparePgAlterViewAlterSchemaJson(
|
28135
|
+
it.schemaTo,
|
28136
|
+
it.schemaFrom,
|
28137
|
+
it.name,
|
28138
|
+
json2.views[`${it.schemaTo}.${it.name}`].materialized
|
28139
|
+
);
|
28140
|
+
})
|
28141
|
+
);
|
28142
|
+
const alteredViews = typedResult.alteredViews.filter((it) => !json2.views[`${it.schema}.${it.name}`].isExisting);
|
28143
|
+
for (const alteredView of alteredViews) {
|
28144
|
+
const viewKey = `${alteredView.schema}.${alteredView.name}`;
|
28145
|
+
const { materialized, with: withOption, definition, withNoData, using, tablespace } = json2.views[viewKey];
|
28146
|
+
if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
|
28147
|
+
dropViews.push(preparePgDropViewJson(alteredView.name, alteredView.schema, materialized));
|
28148
|
+
createViews.push(
|
28149
|
+
preparePgCreateViewJson(
|
28150
|
+
alteredView.name,
|
28151
|
+
alteredView.schema,
|
28152
|
+
definition,
|
28153
|
+
materialized,
|
28154
|
+
withNoData,
|
28155
|
+
withOption,
|
28156
|
+
using,
|
28157
|
+
tablespace
|
28158
|
+
)
|
28159
|
+
);
|
28160
|
+
continue;
|
28161
|
+
}
|
28162
|
+
if (alteredView.addedWithOption) {
|
28163
|
+
alterViews.push(
|
28164
|
+
preparePgAlterViewAddWithOptionJson(
|
28165
|
+
alteredView.name,
|
28166
|
+
alteredView.schema,
|
28167
|
+
materialized,
|
28168
|
+
alteredView.addedWithOption
|
28169
|
+
)
|
28170
|
+
);
|
28171
|
+
}
|
28172
|
+
if (alteredView.deletedWithOption) {
|
28173
|
+
alterViews.push(
|
28174
|
+
preparePgAlterViewDropWithOptionJson(
|
28175
|
+
alteredView.name,
|
28176
|
+
alteredView.schema,
|
28177
|
+
materialized,
|
28178
|
+
alteredView.deletedWithOption
|
28179
|
+
)
|
28180
|
+
);
|
28181
|
+
}
|
28182
|
+
if (alteredView.alteredWith) {
|
28183
|
+
if (alteredView.alteredWith.addedWith) {
|
28184
|
+
alterViews.push(
|
28185
|
+
preparePgAlterViewAddWithOptionJson(
|
28186
|
+
alteredView.name,
|
28187
|
+
alteredView.schema,
|
28188
|
+
materialized,
|
28189
|
+
alteredView.alteredWith.addedWith
|
28190
|
+
)
|
28191
|
+
);
|
28192
|
+
}
|
28193
|
+
if (alteredView.alteredWith.deletedWith) {
|
28194
|
+
alterViews.push(
|
28195
|
+
preparePgAlterViewDropWithOptionJson(
|
28196
|
+
alteredView.name,
|
28197
|
+
alteredView.schema,
|
28198
|
+
materialized,
|
28199
|
+
alteredView.alteredWith.deletedWith
|
28200
|
+
)
|
28201
|
+
);
|
28202
|
+
}
|
28203
|
+
if (alteredView.alteredWith.alterWith) {
|
28204
|
+
alterViews.push(
|
28205
|
+
preparePgAlterViewAddWithOptionJson(
|
28206
|
+
alteredView.name,
|
28207
|
+
alteredView.schema,
|
28208
|
+
materialized,
|
28209
|
+
alteredView.alteredWith.alterWith
|
28210
|
+
)
|
28211
|
+
);
|
28212
|
+
}
|
28213
|
+
}
|
28214
|
+
if (alteredView.alteredTablespace) {
|
28215
|
+
alterViews.push(
|
28216
|
+
preparePgAlterViewAlterTablespaceJson(
|
28217
|
+
alteredView.name,
|
28218
|
+
alteredView.schema,
|
28219
|
+
materialized,
|
28220
|
+
alteredView.alteredTablespace.__new
|
28221
|
+
)
|
28222
|
+
);
|
28223
|
+
}
|
28224
|
+
if (alteredView.alteredUsing) {
|
28225
|
+
alterViews.push(
|
28226
|
+
preparePgAlterViewAlterUsingJson(
|
28227
|
+
alteredView.name,
|
28228
|
+
alteredView.schema,
|
28229
|
+
materialized,
|
28230
|
+
alteredView.alteredUsing.__new
|
28231
|
+
)
|
28232
|
+
);
|
28233
|
+
}
|
28234
|
+
}
|
27230
28235
|
jsonStatements.push(...createSchemas);
|
27231
28236
|
jsonStatements.push(...renameSchemas);
|
27232
28237
|
jsonStatements.push(...createEnums);
|
@@ -27238,6 +28243,9 @@ var init_snapshotsDiffer = __esm({
|
|
27238
28243
|
jsonStatements.push(...renameSequences);
|
27239
28244
|
jsonStatements.push(...jsonAlterSequences);
|
27240
28245
|
jsonStatements.push(...createTables);
|
28246
|
+
jsonStatements.push(...dropViews);
|
28247
|
+
jsonStatements.push(...renameViews);
|
28248
|
+
jsonStatements.push(...alterViews);
|
27241
28249
|
jsonStatements.push(...jsonDropTables);
|
27242
28250
|
jsonStatements.push(...jsonSetTableSchemas);
|
27243
28251
|
jsonStatements.push(...jsonRenameTables);
|
@@ -27257,6 +28265,7 @@ var init_snapshotsDiffer = __esm({
|
|
27257
28265
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
27258
28266
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
27259
28267
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
28268
|
+
jsonStatements.push(...createViews);
|
27260
28269
|
jsonStatements.push(...dropEnums);
|
27261
28270
|
jsonStatements.push(...dropSequences);
|
27262
28271
|
jsonStatements.push(...dropSchemas);
|
@@ -29535,9 +30544,10 @@ __export(migrate_exports, {
|
|
29535
30544
|
schemasResolver: () => schemasResolver,
|
29536
30545
|
sequencesResolver: () => sequencesResolver,
|
29537
30546
|
tablesResolver: () => tablesResolver,
|
30547
|
+
viewsResolver: () => viewsResolver,
|
29538
30548
|
writeResult: () => writeResult
|
29539
30549
|
});
|
29540
|
-
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;
|
30550
|
+
var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, viewsResolver, sequencesResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareAndMigrateLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
|
29541
30551
|
var init_migrate = __esm({
|
29542
30552
|
"src/cli/commands/migrate.ts"() {
|
29543
30553
|
"use strict";
|
@@ -29584,6 +30594,24 @@ var init_migrate = __esm({
|
|
29584
30594
|
throw e2;
|
29585
30595
|
}
|
29586
30596
|
};
|
30597
|
+
viewsResolver = async (input) => {
|
30598
|
+
try {
|
30599
|
+
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
30600
|
+
input.created,
|
30601
|
+
input.deleted,
|
30602
|
+
"view"
|
30603
|
+
);
|
30604
|
+
return {
|
30605
|
+
created,
|
30606
|
+
deleted,
|
30607
|
+
moved,
|
30608
|
+
renamed
|
30609
|
+
};
|
30610
|
+
} catch (e2) {
|
30611
|
+
console.error(e2);
|
30612
|
+
throw e2;
|
30613
|
+
}
|
30614
|
+
};
|
29587
30615
|
sequencesResolver = async (input) => {
|
29588
30616
|
try {
|
29589
30617
|
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
@@ -29672,6 +30700,7 @@ var init_migrate = __esm({
|
|
29672
30700
|
sequencesResolver,
|
29673
30701
|
tablesResolver,
|
29674
30702
|
columnsResolver,
|
30703
|
+
viewsResolver,
|
29675
30704
|
validatedPrev,
|
29676
30705
|
validatedCur
|
29677
30706
|
);
|
@@ -29706,6 +30735,7 @@ var init_migrate = __esm({
|
|
29706
30735
|
sequencesResolver,
|
29707
30736
|
tablesResolver,
|
29708
30737
|
columnsResolver,
|
30738
|
+
viewsResolver,
|
29709
30739
|
validatedPrev,
|
29710
30740
|
validatedCur,
|
29711
30741
|
"push"
|
@@ -34527,20 +35557,20 @@ var require_ponyfill_es2018 = __commonJS({
|
|
34527
35557
|
;
|
34528
35558
|
ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
|
34529
35559
|
}
|
34530
|
-
respondWithNewView(
|
35560
|
+
respondWithNewView(view2) {
|
34531
35561
|
if (!IsReadableStreamBYOBRequest(this)) {
|
34532
35562
|
throw byobRequestBrandCheckException("respondWithNewView");
|
34533
35563
|
}
|
34534
|
-
assertRequiredArgument(
|
34535
|
-
if (!ArrayBuffer.isView(
|
35564
|
+
assertRequiredArgument(view2, 1, "respondWithNewView");
|
35565
|
+
if (!ArrayBuffer.isView(view2)) {
|
34536
35566
|
throw new TypeError("You can only respond with array buffer views");
|
34537
35567
|
}
|
34538
35568
|
if (this._associatedReadableByteStreamController === void 0) {
|
34539
35569
|
throw new TypeError("This BYOB request has been invalidated");
|
34540
35570
|
}
|
34541
|
-
if (IsDetachedBuffer(
|
35571
|
+
if (IsDetachedBuffer(view2.buffer))
|
34542
35572
|
;
|
34543
|
-
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController,
|
35573
|
+
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view2);
|
34544
35574
|
}
|
34545
35575
|
}
|
34546
35576
|
Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
|
@@ -34641,8 +35671,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
34641
35671
|
const entry = this._queue.shift();
|
34642
35672
|
this._queueTotalSize -= entry.byteLength;
|
34643
35673
|
ReadableByteStreamControllerHandleQueueDrain(this);
|
34644
|
-
const
|
34645
|
-
readRequest._chunkSteps(
|
35674
|
+
const view2 = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
|
35675
|
+
readRequest._chunkSteps(view2);
|
34646
35676
|
return;
|
34647
35677
|
}
|
34648
35678
|
const autoAllocateChunkSize = this._autoAllocateChunkSize;
|
@@ -34808,19 +35838,19 @@ var require_ponyfill_es2018 = __commonJS({
|
|
34808
35838
|
}
|
34809
35839
|
}
|
34810
35840
|
}
|
34811
|
-
function ReadableByteStreamControllerPullInto(controller,
|
35841
|
+
function ReadableByteStreamControllerPullInto(controller, view2, readIntoRequest) {
|
34812
35842
|
const stream = controller._controlledReadableByteStream;
|
34813
35843
|
let elementSize = 1;
|
34814
|
-
if (
|
34815
|
-
elementSize =
|
35844
|
+
if (view2.constructor !== DataView) {
|
35845
|
+
elementSize = view2.constructor.BYTES_PER_ELEMENT;
|
34816
35846
|
}
|
34817
|
-
const ctor =
|
34818
|
-
const buffer = TransferArrayBuffer(
|
35847
|
+
const ctor = view2.constructor;
|
35848
|
+
const buffer = TransferArrayBuffer(view2.buffer);
|
34819
35849
|
const pullIntoDescriptor = {
|
34820
35850
|
buffer,
|
34821
35851
|
bufferByteLength: buffer.byteLength,
|
34822
|
-
byteOffset:
|
34823
|
-
byteLength:
|
35852
|
+
byteOffset: view2.byteOffset,
|
35853
|
+
byteLength: view2.byteLength,
|
34824
35854
|
bytesFilled: 0,
|
34825
35855
|
elementSize,
|
34826
35856
|
viewConstructor: ctor,
|
@@ -34988,9 +36018,9 @@ var require_ponyfill_es2018 = __commonJS({
|
|
34988
36018
|
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
34989
36019
|
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
34990
36020
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
34991
|
-
const
|
36021
|
+
const view2 = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
34992
36022
|
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
34993
|
-
SetUpReadableStreamBYOBRequest(byobRequest, controller,
|
36023
|
+
SetUpReadableStreamBYOBRequest(byobRequest, controller, view2);
|
34994
36024
|
controller._byobRequest = byobRequest;
|
34995
36025
|
}
|
34996
36026
|
return controller._byobRequest;
|
@@ -35023,29 +36053,29 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35023
36053
|
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
35024
36054
|
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
35025
36055
|
}
|
35026
|
-
function ReadableByteStreamControllerRespondWithNewView(controller,
|
36056
|
+
function ReadableByteStreamControllerRespondWithNewView(controller, view2) {
|
35027
36057
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
35028
36058
|
const state = controller._controlledReadableByteStream._state;
|
35029
36059
|
if (state === "closed") {
|
35030
|
-
if (
|
36060
|
+
if (view2.byteLength !== 0) {
|
35031
36061
|
throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
|
35032
36062
|
}
|
35033
36063
|
} else {
|
35034
|
-
if (
|
36064
|
+
if (view2.byteLength === 0) {
|
35035
36065
|
throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
|
35036
36066
|
}
|
35037
36067
|
}
|
35038
|
-
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !==
|
36068
|
+
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view2.byteOffset) {
|
35039
36069
|
throw new RangeError("The region specified by view does not match byobRequest");
|
35040
36070
|
}
|
35041
|
-
if (firstDescriptor.bufferByteLength !==
|
36071
|
+
if (firstDescriptor.bufferByteLength !== view2.buffer.byteLength) {
|
35042
36072
|
throw new RangeError("The buffer of view has different capacity than byobRequest");
|
35043
36073
|
}
|
35044
|
-
if (firstDescriptor.bytesFilled +
|
36074
|
+
if (firstDescriptor.bytesFilled + view2.byteLength > firstDescriptor.byteLength) {
|
35045
36075
|
throw new RangeError("The region specified by view is larger than byobRequest");
|
35046
36076
|
}
|
35047
|
-
const viewByteLength =
|
35048
|
-
firstDescriptor.buffer = TransferArrayBuffer(
|
36077
|
+
const viewByteLength = view2.byteLength;
|
36078
|
+
firstDescriptor.buffer = TransferArrayBuffer(view2.buffer);
|
35049
36079
|
ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
|
35050
36080
|
}
|
35051
36081
|
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
@@ -35091,9 +36121,9 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35091
36121
|
}
|
35092
36122
|
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
35093
36123
|
}
|
35094
|
-
function SetUpReadableStreamBYOBRequest(request, controller,
|
36124
|
+
function SetUpReadableStreamBYOBRequest(request, controller, view2) {
|
35095
36125
|
request._associatedReadableByteStreamController = controller;
|
35096
|
-
request._view =
|
36126
|
+
request._view = view2;
|
35097
36127
|
}
|
35098
36128
|
function byobRequestBrandCheckException(name) {
|
35099
36129
|
return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);
|
@@ -35169,20 +36199,20 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35169
36199
|
*
|
35170
36200
|
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
35171
36201
|
*/
|
35172
|
-
read(
|
36202
|
+
read(view2) {
|
35173
36203
|
if (!IsReadableStreamBYOBReader(this)) {
|
35174
36204
|
return promiseRejectedWith(byobReaderBrandCheckException("read"));
|
35175
36205
|
}
|
35176
|
-
if (!ArrayBuffer.isView(
|
36206
|
+
if (!ArrayBuffer.isView(view2)) {
|
35177
36207
|
return promiseRejectedWith(new TypeError("view must be an array buffer view"));
|
35178
36208
|
}
|
35179
|
-
if (
|
36209
|
+
if (view2.byteLength === 0) {
|
35180
36210
|
return promiseRejectedWith(new TypeError("view must have non-zero byteLength"));
|
35181
36211
|
}
|
35182
|
-
if (
|
36212
|
+
if (view2.buffer.byteLength === 0) {
|
35183
36213
|
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
35184
36214
|
}
|
35185
|
-
if (IsDetachedBuffer(
|
36215
|
+
if (IsDetachedBuffer(view2.buffer))
|
35186
36216
|
;
|
35187
36217
|
if (this._ownerReadableStream === void 0) {
|
35188
36218
|
return promiseRejectedWith(readerLockException("read from"));
|
@@ -35198,7 +36228,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35198
36228
|
_closeSteps: (chunk) => resolvePromise({ value: chunk, done: true }),
|
35199
36229
|
_errorSteps: (e2) => rejectPromise(e2)
|
35200
36230
|
};
|
35201
|
-
ReadableStreamBYOBReaderRead(this,
|
36231
|
+
ReadableStreamBYOBReaderRead(this, view2, readIntoRequest);
|
35202
36232
|
return promise;
|
35203
36233
|
}
|
35204
36234
|
/**
|
@@ -35244,13 +36274,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35244
36274
|
}
|
35245
36275
|
return x2 instanceof ReadableStreamBYOBReader;
|
35246
36276
|
}
|
35247
|
-
function ReadableStreamBYOBReaderRead(reader,
|
36277
|
+
function ReadableStreamBYOBReaderRead(reader, view2, readIntoRequest) {
|
35248
36278
|
const stream = reader._ownerReadableStream;
|
35249
36279
|
stream._disturbed = true;
|
35250
36280
|
if (stream._state === "errored") {
|
35251
36281
|
readIntoRequest._errorSteps(stream._storedError);
|
35252
36282
|
} else {
|
35253
|
-
ReadableByteStreamControllerPullInto(stream._readableStreamController,
|
36283
|
+
ReadableByteStreamControllerPullInto(stream._readableStreamController, view2, readIntoRequest);
|
35254
36284
|
}
|
35255
36285
|
}
|
35256
36286
|
function byobReaderBrandCheckException(name) {
|
@@ -36799,7 +37829,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
36799
37829
|
};
|
36800
37830
|
ReadableStreamDefaultReaderRead(reader, readRequest);
|
36801
37831
|
}
|
36802
|
-
function pullWithBYOBReader(
|
37832
|
+
function pullWithBYOBReader(view2, forBranch2) {
|
36803
37833
|
if (IsReadableStreamDefaultReader(reader)) {
|
36804
37834
|
ReadableStreamReaderGenericRelease(reader);
|
36805
37835
|
reader = AcquireReadableStreamBYOBReader(stream);
|
@@ -36865,7 +37895,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
36865
37895
|
reading = false;
|
36866
37896
|
}
|
36867
37897
|
};
|
36868
|
-
ReadableStreamBYOBReaderRead(reader,
|
37898
|
+
ReadableStreamBYOBReaderRead(reader, view2, readIntoRequest);
|
36869
37899
|
}
|
36870
37900
|
function pull1Algorithm() {
|
36871
37901
|
if (reading) {
|
@@ -51724,15 +52754,15 @@ var require_dist_cjs36 = __commonJS({
|
|
51724
52754
|
throw new Error("Int64 buffers must be exactly 8 bytes");
|
51725
52755
|
}
|
51726
52756
|
}
|
51727
|
-
static fromNumber(
|
51728
|
-
if (
|
51729
|
-
throw new Error(`${
|
52757
|
+
static fromNumber(number2) {
|
52758
|
+
if (number2 > 9223372036854776e3 || number2 < -9223372036854776e3) {
|
52759
|
+
throw new Error(`${number2} is too large (or, if negative, too small) to represent as an Int64`);
|
51730
52760
|
}
|
51731
52761
|
const bytes = new Uint8Array(8);
|
51732
|
-
for (let i2 = 7, remaining = Math.abs(Math.round(
|
52762
|
+
for (let i2 = 7, remaining = Math.abs(Math.round(number2)); i2 > -1 && remaining > 0; i2--, remaining /= 256) {
|
51733
52763
|
bytes[i2] = remaining;
|
51734
52764
|
}
|
51735
|
-
if (
|
52765
|
+
if (number2 < 0) {
|
51736
52766
|
negate(bytes);
|
51737
52767
|
}
|
51738
52768
|
return new _Int642(bytes);
|
@@ -63163,16 +64193,16 @@ var require_map_stream = __commonJS({
|
|
63163
64193
|
var writeQueue = {};
|
63164
64194
|
stream.writable = true;
|
63165
64195
|
stream.readable = true;
|
63166
|
-
function queueData(data,
|
64196
|
+
function queueData(data, number2) {
|
63167
64197
|
var nextToWrite = lastWritten + 1;
|
63168
|
-
if (
|
64198
|
+
if (number2 === nextToWrite) {
|
63169
64199
|
if (data !== void 0) {
|
63170
64200
|
stream.emit.apply(stream, ["data", data]);
|
63171
64201
|
}
|
63172
64202
|
lastWritten++;
|
63173
64203
|
nextToWrite++;
|
63174
64204
|
} else {
|
63175
|
-
writeQueue[
|
64205
|
+
writeQueue[number2] = data;
|
63176
64206
|
}
|
63177
64207
|
if (writeQueue.hasOwnProperty(nextToWrite)) {
|
63178
64208
|
var dataToWrite = writeQueue[nextToWrite];
|
@@ -63187,21 +64217,21 @@ var require_map_stream = __commonJS({
|
|
63187
64217
|
end();
|
63188
64218
|
}
|
63189
64219
|
}
|
63190
|
-
function next(err2, data,
|
64220
|
+
function next(err2, data, number2) {
|
63191
64221
|
if (destroyed)
|
63192
64222
|
return;
|
63193
64223
|
inNext = true;
|
63194
64224
|
if (!err2 || self2.opts.failures) {
|
63195
|
-
queueData(data,
|
64225
|
+
queueData(data, number2);
|
63196
64226
|
}
|
63197
64227
|
if (err2) {
|
63198
64228
|
stream.emit.apply(stream, [errorEventName, err2]);
|
63199
64229
|
}
|
63200
64230
|
inNext = false;
|
63201
64231
|
}
|
63202
|
-
function wrappedMapper(input,
|
64232
|
+
function wrappedMapper(input, number2, callback) {
|
63203
64233
|
return mapper.call(null, input, function(err2, data) {
|
63204
|
-
callback(err2, data,
|
64234
|
+
callback(err2, data, number2);
|
63205
64235
|
});
|
63206
64236
|
}
|
63207
64237
|
stream.write = function(data) {
|
@@ -77033,7 +78063,7 @@ var init_selector_ui = __esm({
|
|
77033
78063
|
});
|
77034
78064
|
|
77035
78065
|
// src/cli/commands/libSqlPushUtils.ts
|
77036
|
-
var
|
78066
|
+
var getOldTableName2, _moveDataStatements2, libSqlLogSuggestionsAndReturn;
|
77037
78067
|
var init_libSqlPushUtils = __esm({
|
77038
78068
|
"src/cli/commands/libSqlPushUtils.ts"() {
|
77039
78069
|
"use strict";
|
@@ -77041,7 +78071,7 @@ var init_libSqlPushUtils = __esm({
|
|
77041
78071
|
init_utils();
|
77042
78072
|
init_sqliteSchema();
|
77043
78073
|
init_sqlgenerator();
|
77044
|
-
|
78074
|
+
getOldTableName2 = (tableName, meta) => {
|
77045
78075
|
for (const key of Object.keys(meta.tables)) {
|
77046
78076
|
const value = meta.tables[key];
|
77047
78077
|
if (`"${tableName}"` === value) {
|
@@ -77196,7 +78226,7 @@ var init_libSqlPushUtils = __esm({
|
|
77196
78226
|
} else if (statement.type === "recreate_table") {
|
77197
78227
|
const tableName = statement.tableName;
|
77198
78228
|
let dataLoss = false;
|
77199
|
-
const oldTableName =
|
78229
|
+
const oldTableName = getOldTableName2(tableName, meta);
|
77200
78230
|
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
77201
78231
|
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
77202
78232
|
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
@@ -78956,11 +79986,13 @@ var init_pgIntrospect = __esm({
|
|
78956
79986
|
});
|
78957
79987
|
|
78958
79988
|
// src/introspect-sqlite.ts
|
78959
|
-
var sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
79989
|
+
var import_casing, sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, dbColumnName, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
78960
79990
|
var init_introspect_sqlite = __esm({
|
78961
79991
|
"src/introspect-sqlite.ts"() {
|
78962
79992
|
"use strict";
|
79993
|
+
import_casing = require("drizzle-orm/casing");
|
78963
79994
|
init_utils3();
|
79995
|
+
init_global();
|
78964
79996
|
sqliteImportsList = /* @__PURE__ */ new Set([
|
78965
79997
|
"sqliteTable",
|
78966
79998
|
"integer",
|
@@ -78998,6 +80030,15 @@ var init_introspect_sqlite = __esm({
|
|
78998
80030
|
}
|
78999
80031
|
return value;
|
79000
80032
|
};
|
80033
|
+
dbColumnName = ({ name, casing: casing2, withMode = false }) => {
|
80034
|
+
if (casing2 === "preserve") {
|
80035
|
+
return "";
|
80036
|
+
}
|
80037
|
+
if (casing2 === "camel") {
|
80038
|
+
return (0, import_casing.toCamelCase)(name) === name ? "" : withMode ? `"${name}", ` : `"${name}"`;
|
80039
|
+
}
|
80040
|
+
assertUnreachable(casing2);
|
80041
|
+
};
|
79001
80042
|
schemaToTypeScript = (schema5, casing2) => {
|
79002
80043
|
Object.values(schema5.tables).forEach((table4) => {
|
79003
80044
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
@@ -79117,13 +80158,14 @@ var init_introspect_sqlite = __esm({
|
|
79117
80158
|
};
|
79118
80159
|
column4 = (type, name, defaultValue, autoincrement, casing2) => {
|
79119
80160
|
let lowered = type;
|
80161
|
+
casing2 = casing2;
|
79120
80162
|
if (lowered === "integer") {
|
79121
|
-
let out = `${withCasing(name, casing2)}: integer(
|
80163
|
+
let out = `${withCasing(name, casing2)}: integer(${dbColumnName({ name, casing: casing2 })})`;
|
79122
80164
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
79123
80165
|
return out;
|
79124
80166
|
}
|
79125
80167
|
if (lowered === "real") {
|
79126
|
-
let out = `${withCasing(name, casing2)}: real(
|
80168
|
+
let out = `${withCasing(name, casing2)}: real(${dbColumnName({ name, casing: casing2 })})`;
|
79127
80169
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
79128
80170
|
return out;
|
79129
80171
|
}
|
@@ -79131,20 +80173,20 @@ var init_introspect_sqlite = __esm({
|
|
79131
80173
|
const match2 = lowered.match(/\d+/);
|
79132
80174
|
let out;
|
79133
80175
|
if (match2) {
|
79134
|
-
out = `${withCasing(name, casing2)}: text(
|
80176
|
+
out = `${withCasing(name, casing2)}: text(${dbColumnName({ name, casing: casing2, withMode: true })}{ length: ${match2[0]} })`;
|
79135
80177
|
} else {
|
79136
|
-
out = `${withCasing(name, casing2)}: text(
|
80178
|
+
out = `${withCasing(name, casing2)}: text(${dbColumnName({ name, casing: casing2 })})`;
|
79137
80179
|
}
|
79138
80180
|
out += defaultValue ? `.default("${mapColumnDefault(defaultValue)}")` : "";
|
79139
80181
|
return out;
|
79140
80182
|
}
|
79141
80183
|
if (lowered === "blob") {
|
79142
|
-
let out = `${withCasing(name, casing2)}: blob(
|
80184
|
+
let out = `${withCasing(name, casing2)}: blob(${dbColumnName({ name, casing: casing2 })})`;
|
79143
80185
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
79144
80186
|
return out;
|
79145
80187
|
}
|
79146
80188
|
if (lowered === "numeric") {
|
79147
|
-
let out = `${withCasing(name, casing2)}: numeric(
|
80189
|
+
let out = `${withCasing(name, casing2)}: numeric(${dbColumnName({ name, casing: casing2 })})`;
|
79148
80190
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
79149
80191
|
return out;
|
79150
80192
|
}
|
@@ -80067,11 +81109,13 @@ var require_pluralize = __commonJS({
|
|
80067
81109
|
});
|
80068
81110
|
|
80069
81111
|
// src/introspect-mysql.ts
|
80070
|
-
var mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, escapeColumnKey2, prepareCasing, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
|
81112
|
+
var import_casing2, mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, escapeColumnKey2, prepareCasing, dbColumnName2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
|
80071
81113
|
var init_introspect_mysql = __esm({
|
80072
81114
|
"src/introspect-mysql.ts"() {
|
80073
81115
|
"use strict";
|
81116
|
+
import_casing2 = require("drizzle-orm/casing");
|
80074
81117
|
init_utils3();
|
81118
|
+
init_global();
|
80075
81119
|
init_mysqlSerializer();
|
80076
81120
|
mysqlImportsList = /* @__PURE__ */ new Set([
|
80077
81121
|
"mysqlTable",
|
@@ -80151,7 +81195,16 @@ var init_introspect_mysql = __esm({
|
|
80151
81195
|
if (casing2 === "camel") {
|
80152
81196
|
return escapeColumnKey2(value.camelCase());
|
80153
81197
|
}
|
80154
|
-
|
81198
|
+
assertUnreachable(casing2);
|
81199
|
+
};
|
81200
|
+
dbColumnName2 = ({ name, casing: casing2, withMode = false }) => {
|
81201
|
+
if (casing2 === "preserve") {
|
81202
|
+
return "";
|
81203
|
+
}
|
81204
|
+
if (casing2 === "camel") {
|
81205
|
+
return (0, import_casing2.toCamelCase)(name) === name ? "" : withMode ? `"${name}", ` : `"${name}"`;
|
81206
|
+
}
|
81207
|
+
assertUnreachable(casing2);
|
80155
81208
|
};
|
80156
81209
|
schemaToTypeScript2 = (schema5, casing2) => {
|
80157
81210
|
const withCasing4 = prepareCasing(casing2);
|
@@ -80212,6 +81265,7 @@ var init_introspect_mysql = __esm({
|
|
80212
81265
|
Object.values(table4.columns),
|
80213
81266
|
Object.values(table4.foreignKeys),
|
80214
81267
|
withCasing4,
|
81268
|
+
casing2,
|
80215
81269
|
table4.name,
|
80216
81270
|
schema5
|
80217
81271
|
);
|
@@ -80291,51 +81345,51 @@ import { sql } from "drizzle-orm"
|
|
80291
81345
|
}
|
80292
81346
|
return defaultValue;
|
80293
81347
|
};
|
80294
|
-
column5 = (type, name, casing2, defaultValue, autoincrement, onUpdate, isExpression) => {
|
81348
|
+
column5 = (type, name, casing2, rawCasing, defaultValue, autoincrement, onUpdate, isExpression) => {
|
80295
81349
|
let lowered = type;
|
80296
81350
|
if (!type.startsWith("enum(")) {
|
80297
81351
|
lowered = type.toLowerCase();
|
80298
81352
|
}
|
80299
81353
|
if (lowered === "serial") {
|
80300
|
-
return `${casing2(name)}: serial(
|
81354
|
+
return `${casing2(name)}: serial(${dbColumnName2({ name, casing: rawCasing })})`;
|
80301
81355
|
}
|
80302
81356
|
if (lowered.startsWith("int")) {
|
80303
81357
|
const isUnsigned = lowered.startsWith("int unsigned");
|
80304
|
-
let out = `${casing2(name)}: int(
|
81358
|
+
let out = `${casing2(name)}: int(${dbColumnName2({ name, casing: rawCasing, withMode: isUnsigned })}${isUnsigned ? "{ unsigned: true }" : ""})`;
|
80305
81359
|
out += autoincrement ? `.autoincrement()` : "";
|
80306
81360
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80307
81361
|
return out;
|
80308
81362
|
}
|
80309
81363
|
if (lowered.startsWith("tinyint")) {
|
80310
81364
|
const isUnsigned = lowered.startsWith("tinyint unsigned");
|
80311
|
-
let out = `${casing2(name)}: tinyint(
|
81365
|
+
let out = `${casing2(name)}: tinyint(${dbColumnName2({ name, casing: rawCasing, withMode: isUnsigned })}${isUnsigned ? ", { unsigned: true }" : ""})`;
|
80312
81366
|
out += autoincrement ? `.autoincrement()` : "";
|
80313
81367
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80314
81368
|
return out;
|
80315
81369
|
}
|
80316
81370
|
if (lowered.startsWith("smallint")) {
|
80317
81371
|
const isUnsigned = lowered.startsWith("smallint unsigned");
|
80318
|
-
let out = `${casing2(name)}: smallint(
|
81372
|
+
let out = `${casing2(name)}: smallint(${dbColumnName2({ name, casing: rawCasing, withMode: isUnsigned })}${isUnsigned ? ", { unsigned: true }" : ""})`;
|
80319
81373
|
out += autoincrement ? `.autoincrement()` : "";
|
80320
81374
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80321
81375
|
return out;
|
80322
81376
|
}
|
80323
81377
|
if (lowered.startsWith("mediumint")) {
|
80324
81378
|
const isUnsigned = lowered.startsWith("mediumint unsigned");
|
80325
|
-
let out = `${casing2(name)}: mediumint(
|
81379
|
+
let out = `${casing2(name)}: mediumint(${dbColumnName2({ name, casing: rawCasing, withMode: isUnsigned })}${isUnsigned ? ", { unsigned: true }" : ""})`;
|
80326
81380
|
out += autoincrement ? `.autoincrement()` : "";
|
80327
81381
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80328
81382
|
return out;
|
80329
81383
|
}
|
80330
81384
|
if (lowered.startsWith("bigint")) {
|
80331
81385
|
const isUnsigned = lowered.startsWith("bigint unsigned");
|
80332
|
-
let out = `${casing2(name)}: bigint(
|
81386
|
+
let out = `${casing2(name)}: bigint(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ mode: "number"${isUnsigned ? ", unsigned: true" : ""} })`;
|
80333
81387
|
out += autoincrement ? `.autoincrement()` : "";
|
80334
81388
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80335
81389
|
return out;
|
80336
81390
|
}
|
80337
81391
|
if (lowered === "boolean") {
|
80338
|
-
let out = `${casing2(name)}: boolean(
|
81392
|
+
let out = `${casing2(name)}: boolean(${dbColumnName2({ name, casing: rawCasing })})`;
|
80339
81393
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80340
81394
|
return out;
|
80341
81395
|
}
|
@@ -80345,17 +81399,18 @@ import { sql } from "drizzle-orm"
|
|
80345
81399
|
const [precision, scale] = lowered.slice(7, lowered.length - 1).split(",");
|
80346
81400
|
params = { precision, scale };
|
80347
81401
|
}
|
80348
|
-
|
81402
|
+
const timeConfigParams = params ? timeConfig(params) : void 0;
|
81403
|
+
let out = params ? `${casing2(name)}: double(${dbColumnName2({ name, casing: rawCasing, withMode: timeConfigParams !== void 0 })}${timeConfig(params)})` : `${casing2(name)}: double(${dbColumnName2({ name, casing: rawCasing })})`;
|
80349
81404
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80350
81405
|
return out;
|
80351
81406
|
}
|
80352
81407
|
if (lowered === "float") {
|
80353
|
-
let out = `${casing2(name)}: float(
|
81408
|
+
let out = `${casing2(name)}: float(${dbColumnName2({ name, casing: rawCasing })})`;
|
80354
81409
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80355
81410
|
return out;
|
80356
81411
|
}
|
80357
81412
|
if (lowered === "real") {
|
80358
|
-
let out = `${casing2(name)}: real(
|
81413
|
+
let out = `${casing2(name)}: real(${dbColumnName2({ name, casing: rawCasing })})`;
|
80359
81414
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80360
81415
|
return out;
|
80361
81416
|
}
|
@@ -80364,7 +81419,7 @@ import { sql } from "drizzle-orm"
|
|
80364
81419
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
80365
81420
|
fsp = fsp ? fsp : null;
|
80366
81421
|
const params = timeConfig({ fsp, mode: "'string'" });
|
80367
|
-
let out = params ? `${casing2(name)}: timestamp(
|
81422
|
+
let out = params ? `${casing2(name)}: timestamp(${dbColumnName2({ name, casing: rawCasing, withMode: params !== void 0 })}${params})` : `${casing2(name)}: timestamp(${dbColumnName2({ name, casing: rawCasing })})`;
|
80368
81423
|
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80369
81424
|
out += defaultValue;
|
80370
81425
|
let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
|
@@ -80376,7 +81431,7 @@ import { sql } from "drizzle-orm"
|
|
80376
81431
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
80377
81432
|
fsp = fsp ? fsp : null;
|
80378
81433
|
const params = timeConfig({ fsp });
|
80379
|
-
let out = params ? `${casing2(name)}: time(
|
81434
|
+
let out = params ? `${casing2(name)}: time(${dbColumnName2({ name, casing: rawCasing, withMode: params !== void 0 })}${params})` : `${casing2(name)}: time(${dbColumnName2({ name, casing: rawCasing })})`;
|
80380
81435
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80381
81436
|
out += defaultValue;
|
80382
81437
|
return out;
|
@@ -80385,45 +81440,45 @@ import { sql } from "drizzle-orm"
|
|
80385
81440
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
80386
81441
|
${casing2(
|
80387
81442
|
name
|
80388
|
-
)}: date(
|
81443
|
+
)}: date(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ mode: 'string' })`;
|
80389
81444
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80390
81445
|
out += defaultValue;
|
80391
81446
|
return out;
|
80392
81447
|
}
|
80393
81448
|
if (lowered === "text") {
|
80394
|
-
let out = `${casing2(name)}: text(
|
81449
|
+
let out = `${casing2(name)}: text(${dbColumnName2({ name, casing: rawCasing })})`;
|
80395
81450
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80396
81451
|
return out;
|
80397
81452
|
}
|
80398
81453
|
if (lowered === "tinytext") {
|
80399
|
-
let out = `${casing2(name)}: tinytext(
|
81454
|
+
let out = `${casing2(name)}: tinytext(${dbColumnName2({ name, casing: rawCasing })})`;
|
80400
81455
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80401
81456
|
return out;
|
80402
81457
|
}
|
80403
81458
|
if (lowered === "mediumtext") {
|
80404
|
-
let out = `${casing2(name)}: mediumtext(
|
81459
|
+
let out = `${casing2(name)}: mediumtext(${dbColumnName2({ name, casing: rawCasing })})`;
|
80405
81460
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80406
81461
|
return out;
|
80407
81462
|
}
|
80408
81463
|
if (lowered === "longtext") {
|
80409
|
-
let out = `${casing2(name)}: longtext(
|
81464
|
+
let out = `${casing2(name)}: longtext(${dbColumnName2({ name, casing: rawCasing })})`;
|
80410
81465
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80411
81466
|
return out;
|
80412
81467
|
}
|
80413
81468
|
if (lowered === "year") {
|
80414
|
-
let out = `${casing2(name)}: year(
|
81469
|
+
let out = `${casing2(name)}: year(${dbColumnName2({ name, casing: rawCasing })})`;
|
80415
81470
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80416
81471
|
return out;
|
80417
81472
|
}
|
80418
81473
|
if (lowered === "json") {
|
80419
|
-
let out = `${casing2(name)}: json(
|
81474
|
+
let out = `${casing2(name)}: json(${dbColumnName2({ name, casing: rawCasing })})`;
|
80420
81475
|
out += defaultValue ? `.default(${mapColumnDefaultForJson(defaultValue)})` : "";
|
80421
81476
|
return out;
|
80422
81477
|
}
|
80423
81478
|
if (lowered.startsWith("varchar")) {
|
80424
81479
|
let out = `${casing2(
|
80425
81480
|
name
|
80426
|
-
)}: varchar(
|
81481
|
+
)}: varchar(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ length: ${lowered.substring(
|
80427
81482
|
"varchar".length + 1,
|
80428
81483
|
lowered.length - 1
|
80429
81484
|
)} })`;
|
@@ -80433,7 +81488,7 @@ import { sql } from "drizzle-orm"
|
|
80433
81488
|
if (lowered.startsWith("char")) {
|
80434
81489
|
let out = `${casing2(
|
80435
81490
|
name
|
80436
|
-
)}: char(
|
81491
|
+
)}: char(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ length: ${lowered.substring(
|
80437
81492
|
"char".length + 1,
|
80438
81493
|
lowered.length - 1
|
80439
81494
|
)} })`;
|
@@ -80446,10 +81501,10 @@ import { sql } from "drizzle-orm"
|
|
80446
81501
|
const fsp = lowered.startsWith("datetime(") ? lowered.substring("datetime".length + 1, lowered.length - 1) : void 0;
|
80447
81502
|
out = fsp ? `${casing2(
|
80448
81503
|
name
|
80449
|
-
)}: datetime(
|
81504
|
+
)}: datetime(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ mode: 'string', fsp: ${lowered.substring(
|
80450
81505
|
"datetime".length + 1,
|
80451
81506
|
lowered.length - 1
|
80452
|
-
)} })` : `${casing2(name)}: datetime(
|
81507
|
+
)} })` : `${casing2(name)}: datetime(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ mode: 'string'})`;
|
80453
81508
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80454
81509
|
out += defaultValue;
|
80455
81510
|
return out;
|
@@ -80460,7 +81515,8 @@ import { sql } from "drizzle-orm"
|
|
80460
81515
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
80461
81516
|
params = { precision, scale };
|
80462
81517
|
}
|
80463
|
-
|
81518
|
+
const timeConfigParams = params ? timeConfig(params) : void 0;
|
81519
|
+
let out = params ? `${casing2(name)}: decimal(${dbColumnName2({ name, casing: rawCasing, withMode: timeConfigParams !== void 0 })}${timeConfigParams})` : `${casing2(name)}: decimal(${dbColumnName2({ name, casing: rawCasing })})`;
|
80464
81520
|
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80465
81521
|
out += defaultValue;
|
80466
81522
|
return out;
|
@@ -80470,14 +81526,14 @@ import { sql } from "drizzle-orm"
|
|
80470
81526
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
80471
81527
|
length = length ? length : null;
|
80472
81528
|
const params = binaryConfig({ length });
|
80473
|
-
let out = params ? `${casing2(name)}: binary(
|
81529
|
+
let out = params ? `${casing2(name)}: binary(${dbColumnName2({ name, casing: rawCasing, withMode: params !== void 0 })}${params})` : `${casing2(name)}: binary(${dbColumnName2({ name, casing: rawCasing })})`;
|
80474
81530
|
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80475
81531
|
out += defaultValue;
|
80476
81532
|
return out;
|
80477
81533
|
}
|
80478
81534
|
if (lowered.startsWith("enum")) {
|
80479
81535
|
const values = lowered.substring("enum".length + 1, lowered.length - 1);
|
80480
|
-
let out = `${casing2(name)}: mysqlEnum(
|
81536
|
+
let out = `${casing2(name)}: mysqlEnum(${dbColumnName2({ name, casing: rawCasing, withMode: true })}[${values}])`;
|
80481
81537
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80482
81538
|
return out;
|
80483
81539
|
}
|
@@ -80486,7 +81542,7 @@ import { sql } from "drizzle-orm"
|
|
80486
81542
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
80487
81543
|
length = length ? length : null;
|
80488
81544
|
const params = binaryConfig({ length });
|
80489
|
-
let out = params ? `${casing2(name)}: varbinary(
|
81545
|
+
let out = params ? `${casing2(name)}: varbinary(${dbColumnName2({ name, casing: rawCasing, withMode: params !== void 0 })}${params})` : `${casing2(name)}: varbinary(${dbColumnName2({ name, casing: rawCasing })})`;
|
80490
81546
|
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80491
81547
|
out += defaultValue;
|
80492
81548
|
return out;
|
@@ -80495,7 +81551,7 @@ import { sql } from "drizzle-orm"
|
|
80495
81551
|
return `// Warning: Can't parse ${type} from database
|
80496
81552
|
// ${type}Type: ${type}("${name}")`;
|
80497
81553
|
};
|
80498
|
-
createTableColumns2 = (columns, fks, casing2, tableName, schema5) => {
|
81554
|
+
createTableColumns2 = (columns, fks, casing2, rawCasing, tableName, schema5) => {
|
80499
81555
|
let statement = "";
|
80500
81556
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
80501
81557
|
return !isSelf2(it);
|
@@ -80513,6 +81569,7 @@ import { sql } from "drizzle-orm"
|
|
80513
81569
|
it.type,
|
80514
81570
|
it.name,
|
80515
81571
|
casing2,
|
81572
|
+
rawCasing,
|
80516
81573
|
it.default,
|
80517
81574
|
it.autoincrement,
|
80518
81575
|
it.onUpdate,
|
@@ -80643,13 +81700,14 @@ function generateIdentityParams(identity) {
|
|
80643
81700
|
}
|
80644
81701
|
return `.generatedByDefaultAsIdentity(${paramsObj})`;
|
80645
81702
|
}
|
80646
|
-
var import_drizzle_orm9, import_relations, pgImportsList, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, mapColumnDefault3, importsPatch2, relations3, escapeColumnKey3, withCasing2, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, buildArrayDefault, mapDefault, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
81703
|
+
var import_drizzle_orm9, import_relations, import_casing3, pgImportsList, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, mapColumnDefault3, importsPatch2, relations3, escapeColumnKey3, withCasing2, dbColumnName3, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, buildArrayDefault, mapDefault, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
80647
81704
|
var init_introspect_pg = __esm({
|
80648
81705
|
"src/introspect-pg.ts"() {
|
80649
81706
|
"use strict";
|
80650
81707
|
import_drizzle_orm9 = require("drizzle-orm");
|
80651
81708
|
import_relations = require("drizzle-orm/relations");
|
80652
81709
|
init_utils3();
|
81710
|
+
import_casing3 = require("drizzle-orm/casing");
|
80653
81711
|
init_vector();
|
80654
81712
|
init_global();
|
80655
81713
|
init_pgSerializer();
|
@@ -80775,6 +81833,15 @@ var init_introspect_pg = __esm({
|
|
80775
81833
|
}
|
80776
81834
|
assertUnreachable(casing2);
|
80777
81835
|
};
|
81836
|
+
dbColumnName3 = ({ name, casing: casing2, withMode = false }) => {
|
81837
|
+
if (casing2 === "preserve") {
|
81838
|
+
return "";
|
81839
|
+
}
|
81840
|
+
if (casing2 === "camel") {
|
81841
|
+
return (0, import_casing3.toCamelCase)(name) === name ? "" : withMode ? `"${name}", ` : `"${name}"`;
|
81842
|
+
}
|
81843
|
+
assertUnreachable(casing2);
|
81844
|
+
};
|
80778
81845
|
paramNameFor = (name, schema5) => {
|
80779
81846
|
const schemaSuffix = schema5 && schema5 !== "public" ? `In${schema5.capitalise()}` : "";
|
80780
81847
|
return `${name}${schemaSuffix}`;
|
@@ -80837,6 +81904,30 @@ var init_introspect_pg = __esm({
|
|
80837
81904
|
},
|
80838
81905
|
{ pg: [] }
|
80839
81906
|
);
|
81907
|
+
Object.values(schema5.views).forEach((it) => {
|
81908
|
+
if (it.schema && it.schema !== "public" && it.schema !== "") {
|
81909
|
+
imports.pg.push("pgSchema");
|
81910
|
+
} else if (it.schema === "public") {
|
81911
|
+
it.materialized ? imports.pg.push("pgMaterializedView") : imports.pg.push("pgView");
|
81912
|
+
}
|
81913
|
+
Object.values(it.columns).forEach(() => {
|
81914
|
+
const columnImports = Object.values(it.columns).map((col) => {
|
81915
|
+
let patched = (importsPatch2[col.type] || col.type).replace("[]", "");
|
81916
|
+
patched = patched === "double precision" ? "doublePrecision" : patched;
|
81917
|
+
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
81918
|
+
patched = patched.startsWith("char(") ? "char" : patched;
|
81919
|
+
patched = patched.startsWith("numeric(") ? "numeric" : patched;
|
81920
|
+
patched = patched.startsWith("time(") ? "time" : patched;
|
81921
|
+
patched = patched.startsWith("timestamp(") ? "timestamp" : patched;
|
81922
|
+
patched = patched.startsWith("vector(") ? "vector" : patched;
|
81923
|
+
patched = patched.startsWith("geometry(") ? "geometry" : patched;
|
81924
|
+
return patched;
|
81925
|
+
}).filter((type) => {
|
81926
|
+
return pgImportsList.has(type);
|
81927
|
+
});
|
81928
|
+
imports.pg.push(...columnImports);
|
81929
|
+
});
|
81930
|
+
});
|
80840
81931
|
Object.values(schema5.sequences).forEach((it) => {
|
80841
81932
|
if (it.schema && it.schema !== "public" && it.schema !== "") {
|
80842
81933
|
imports.pg.push("pgSchema");
|
@@ -80931,6 +82022,28 @@ var init_introspect_pg = __esm({
|
|
80931
82022
|
statement += ");";
|
80932
82023
|
return statement;
|
80933
82024
|
});
|
82025
|
+
const viewsStatements = Object.values(schema5.views).map((it) => {
|
82026
|
+
const viewSchema = schemas[it.schema];
|
82027
|
+
const paramName = paramNameFor(it.name, viewSchema);
|
82028
|
+
const func = viewSchema ? it.materialized ? `${viewSchema}.materializedView` : `${viewSchema}.view` : it.materialized ? "pgMaterializedView" : "pgView";
|
82029
|
+
const withOption = it.with ?? "";
|
82030
|
+
const as = `sql\`${it.definition}\``;
|
82031
|
+
const tablespace = it.tablespace ?? "";
|
82032
|
+
const columns = createTableColumns3(
|
82033
|
+
"",
|
82034
|
+
Object.values(it.columns),
|
82035
|
+
[],
|
82036
|
+
enumTypes,
|
82037
|
+
schemas,
|
82038
|
+
casing2,
|
82039
|
+
schema5.internal
|
82040
|
+
);
|
82041
|
+
let statement = `export const ${withCasing2(paramName, casing2)} = ${func}("${it.name}", {${columns}})`;
|
82042
|
+
statement += tablespace ? `.tablespace("${tablespace}")` : "";
|
82043
|
+
statement += withOption ? `.with(${JSON.stringify(withOption)})` : "";
|
82044
|
+
statement += `.as(${as});`;
|
82045
|
+
return statement;
|
82046
|
+
}).join("\n\n");
|
80934
82047
|
const uniquePgImports = ["pgTable", ...new Set(imports.pg)];
|
80935
82048
|
const importsTs = `import { ${uniquePgImports.join(
|
80936
82049
|
", "
|
@@ -80943,6 +82056,8 @@ var init_introspect_pg = __esm({
|
|
80943
82056
|
decalrations += sequencesStatements;
|
80944
82057
|
decalrations += "\n";
|
80945
82058
|
decalrations += tableStatements.join("\n\n");
|
82059
|
+
decalrations += "\n";
|
82060
|
+
decalrations += viewsStatements;
|
80946
82061
|
const file = importsTs + decalrations;
|
80947
82062
|
const schemaEntry = `
|
80948
82063
|
{
|
@@ -81070,49 +82185,49 @@ var init_introspect_pg = __esm({
|
|
81070
82185
|
let out = `${withCasing2(name, casing2)}: ${withCasing2(
|
81071
82186
|
paramNameFor(type.replace("[]", ""), typeSchema),
|
81072
82187
|
casing2
|
81073
|
-
)}(
|
82188
|
+
)}(${dbColumnName3({ name, casing: casing2 })})`;
|
81074
82189
|
return out;
|
81075
82190
|
}
|
81076
82191
|
if (lowered.startsWith("serial")) {
|
81077
|
-
return `${withCasing2(name, casing2)}: serial(
|
82192
|
+
return `${withCasing2(name, casing2)}: serial(${dbColumnName3({ name, casing: casing2 })})`;
|
81078
82193
|
}
|
81079
82194
|
if (lowered.startsWith("smallserial")) {
|
81080
|
-
return `${withCasing2(name, casing2)}: smallserial(
|
82195
|
+
return `${withCasing2(name, casing2)}: smallserial(${dbColumnName3({ name, casing: casing2 })})`;
|
81081
82196
|
}
|
81082
82197
|
if (lowered.startsWith("bigserial")) {
|
81083
82198
|
return `${withCasing2(
|
81084
82199
|
name,
|
81085
82200
|
casing2
|
81086
|
-
)}: bigserial(
|
82201
|
+
)}: bigserial(${dbColumnName3({ name, casing: casing2, withMode: true })}{ mode: "bigint" })`;
|
81087
82202
|
}
|
81088
82203
|
if (lowered.startsWith("integer")) {
|
81089
|
-
let out = `${withCasing2(name, casing2)}: integer(
|
82204
|
+
let out = `${withCasing2(name, casing2)}: integer(${dbColumnName3({ name, casing: casing2 })})`;
|
81090
82205
|
return out;
|
81091
82206
|
}
|
81092
82207
|
if (lowered.startsWith("smallint")) {
|
81093
|
-
let out = `${withCasing2(name, casing2)}: smallint(
|
82208
|
+
let out = `${withCasing2(name, casing2)}: smallint(${dbColumnName3({ name, casing: casing2 })})`;
|
81094
82209
|
return out;
|
81095
82210
|
}
|
81096
82211
|
if (lowered.startsWith("bigint")) {
|
81097
82212
|
let out = `// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
81098
82213
|
`;
|
81099
|
-
out += `${withCasing2(name, casing2)}: bigint(
|
82214
|
+
out += `${withCasing2(name, casing2)}: bigint(${dbColumnName3({ name, casing: casing2, withMode: true })}{ mode: "number" })`;
|
81100
82215
|
return out;
|
81101
82216
|
}
|
81102
82217
|
if (lowered.startsWith("boolean")) {
|
81103
|
-
let out = `${withCasing2(name, casing2)}: boolean(
|
82218
|
+
let out = `${withCasing2(name, casing2)}: boolean(${dbColumnName3({ name, casing: casing2 })})`;
|
81104
82219
|
return out;
|
81105
82220
|
}
|
81106
82221
|
if (lowered.startsWith("double precision")) {
|
81107
|
-
let out = `${withCasing2(name, casing2)}: doublePrecision(
|
82222
|
+
let out = `${withCasing2(name, casing2)}: doublePrecision(${dbColumnName3({ name, casing: casing2 })})`;
|
81108
82223
|
return out;
|
81109
82224
|
}
|
81110
82225
|
if (lowered.startsWith("real")) {
|
81111
|
-
let out = `${withCasing2(name, casing2)}: real(
|
82226
|
+
let out = `${withCasing2(name, casing2)}: real(${dbColumnName3({ name, casing: casing2 })})`;
|
81112
82227
|
return out;
|
81113
82228
|
}
|
81114
82229
|
if (lowered.startsWith("uuid")) {
|
81115
|
-
let out = `${withCasing2(name, casing2)}: uuid(
|
82230
|
+
let out = `${withCasing2(name, casing2)}: uuid(${dbColumnName3({ name, casing: casing2 })})`;
|
81116
82231
|
return out;
|
81117
82232
|
}
|
81118
82233
|
if (lowered.startsWith("numeric")) {
|
@@ -81121,7 +82236,7 @@ var init_introspect_pg = __esm({
|
|
81121
82236
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
81122
82237
|
params = { precision, scale };
|
81123
82238
|
}
|
81124
|
-
let out = params ? `${withCasing2(name, casing2)}: numeric(
|
82239
|
+
let out = params ? `${withCasing2(name, casing2)}: numeric(${dbColumnName3({ name, casing: casing2, withMode: true })}${timeConfig2(params)})` : `${withCasing2(name, casing2)}: numeric(${dbColumnName3({ name, casing: casing2 })})`;
|
81125
82240
|
return out;
|
81126
82241
|
}
|
81127
82242
|
if (lowered.startsWith("timestamp")) {
|
@@ -81135,7 +82250,7 @@ var init_introspect_pg = __esm({
|
|
81135
82250
|
withTimezone,
|
81136
82251
|
mode: "'string'"
|
81137
82252
|
});
|
81138
|
-
let out = params ? `${withCasing2(name, casing2)}: timestamp(
|
82253
|
+
let out = params ? `${withCasing2(name, casing2)}: timestamp(${dbColumnName3({ name, casing: casing2, withMode: true })}${params})` : `${withCasing2(name, casing2)}: timestamp(${dbColumnName3({ name, casing: casing2 })})`;
|
81139
82254
|
return out;
|
81140
82255
|
}
|
81141
82256
|
if (lowered.startsWith("time")) {
|
@@ -81145,44 +82260,44 @@ var init_introspect_pg = __esm({
|
|
81145
82260
|
) : null;
|
81146
82261
|
precision = precision ? precision : null;
|
81147
82262
|
const params = timeConfig2({ precision, withTimezone });
|
81148
|
-
let out = params ? `${withCasing2(name, casing2)}: time(
|
82263
|
+
let out = params ? `${withCasing2(name, casing2)}: time(${dbColumnName3({ name, casing: casing2, withMode: true })}${params})` : `${withCasing2(name, casing2)}: time(${dbColumnName3({ name, casing: casing2 })})`;
|
81149
82264
|
return out;
|
81150
82265
|
}
|
81151
82266
|
if (lowered.startsWith("interval")) {
|
81152
82267
|
const params = intervalConfig(lowered);
|
81153
|
-
let out = params ? `${withCasing2(name, casing2)}: interval(
|
82268
|
+
let out = params ? `${withCasing2(name, casing2)}: interval(${dbColumnName3({ name, casing: casing2, withMode: true })}${params})` : `${withCasing2(name, casing2)}: interval(${dbColumnName3({ name, casing: casing2 })})`;
|
81154
82269
|
return out;
|
81155
82270
|
}
|
81156
82271
|
if (lowered === "date") {
|
81157
|
-
let out = `${withCasing2(name, casing2)}: date(
|
82272
|
+
let out = `${withCasing2(name, casing2)}: date(${dbColumnName3({ name, casing: casing2 })})`;
|
81158
82273
|
return out;
|
81159
82274
|
}
|
81160
82275
|
if (lowered.startsWith("text")) {
|
81161
|
-
let out = `${withCasing2(name, casing2)}: text(
|
82276
|
+
let out = `${withCasing2(name, casing2)}: text(${dbColumnName3({ name, casing: casing2 })})`;
|
81162
82277
|
return out;
|
81163
82278
|
}
|
81164
82279
|
if (lowered.startsWith("jsonb")) {
|
81165
|
-
let out = `${withCasing2(name, casing2)}: jsonb(
|
82280
|
+
let out = `${withCasing2(name, casing2)}: jsonb(${dbColumnName3({ name, casing: casing2 })})`;
|
81166
82281
|
return out;
|
81167
82282
|
}
|
81168
82283
|
if (lowered.startsWith("json")) {
|
81169
|
-
let out = `${withCasing2(name, casing2)}: json(
|
82284
|
+
let out = `${withCasing2(name, casing2)}: json(${dbColumnName3({ name, casing: casing2 })})`;
|
81170
82285
|
return out;
|
81171
82286
|
}
|
81172
82287
|
if (lowered.startsWith("inet")) {
|
81173
|
-
let out = `${withCasing2(name, casing2)}: inet(
|
82288
|
+
let out = `${withCasing2(name, casing2)}: inet(${dbColumnName3({ name, casing: casing2 })})`;
|
81174
82289
|
return out;
|
81175
82290
|
}
|
81176
82291
|
if (lowered.startsWith("cidr")) {
|
81177
|
-
let out = `${withCasing2(name, casing2)}: cidr(
|
82292
|
+
let out = `${withCasing2(name, casing2)}: cidr(${dbColumnName3({ name, casing: casing2 })})`;
|
81178
82293
|
return out;
|
81179
82294
|
}
|
81180
82295
|
if (lowered.startsWith("macaddr8")) {
|
81181
|
-
let out = `${withCasing2(name, casing2)}: macaddr8(
|
82296
|
+
let out = `${withCasing2(name, casing2)}: macaddr8(${dbColumnName3({ name, casing: casing2 })})`;
|
81182
82297
|
return out;
|
81183
82298
|
}
|
81184
82299
|
if (lowered.startsWith("macaddr")) {
|
81185
|
-
let out = `${withCasing2(name, casing2)}: macaddr(
|
82300
|
+
let out = `${withCasing2(name, casing2)}: macaddr(${dbColumnName3({ name, casing: casing2 })})`;
|
81186
82301
|
return out;
|
81187
82302
|
}
|
81188
82303
|
if (lowered.startsWith("varchar")) {
|
@@ -81191,21 +82306,21 @@ var init_introspect_pg = __esm({
|
|
81191
82306
|
out = `${withCasing2(
|
81192
82307
|
name,
|
81193
82308
|
casing2
|
81194
|
-
)}: varchar(
|
82309
|
+
)}: varchar(${dbColumnName3({ name, casing: casing2, withMode: true })}{ length: ${lowered.substring(
|
81195
82310
|
8,
|
81196
82311
|
lowered.length - 1
|
81197
82312
|
)} })`;
|
81198
82313
|
} else {
|
81199
|
-
out = `${withCasing2(name, casing2)}: varchar(
|
82314
|
+
out = `${withCasing2(name, casing2)}: varchar(${dbColumnName3({ name, casing: casing2 })})`;
|
81200
82315
|
}
|
81201
82316
|
return out;
|
81202
82317
|
}
|
81203
82318
|
if (lowered.startsWith("point")) {
|
81204
|
-
let out = `${withCasing2(name, casing2)}: point(
|
82319
|
+
let out = `${withCasing2(name, casing2)}: point(${dbColumnName3({ name, casing: casing2 })})`;
|
81205
82320
|
return out;
|
81206
82321
|
}
|
81207
82322
|
if (lowered.startsWith("line")) {
|
81208
|
-
let out = `${withCasing2(name, casing2)}: point(
|
82323
|
+
let out = `${withCasing2(name, casing2)}: point(${dbColumnName3({ name, casing: casing2 })})`;
|
81209
82324
|
return out;
|
81210
82325
|
}
|
81211
82326
|
if (lowered.startsWith("geometry")) {
|
@@ -81214,14 +82329,14 @@ var init_introspect_pg = __esm({
|
|
81214
82329
|
if (lowered.length !== 8) {
|
81215
82330
|
const geometryOptions = lowered.slice(9, -1).split(",");
|
81216
82331
|
if (geometryOptions.length === 1 && geometryOptions[0] !== "") {
|
81217
|
-
out = `${withCasing2(name, casing2)}: geometry(
|
82332
|
+
out = `${withCasing2(name, casing2)}: geometry(${dbColumnName3({ name, casing: casing2, withMode: true })}{ type: "${geometryOptions[0]}" })`;
|
81218
82333
|
} else if (geometryOptions.length === 2) {
|
81219
|
-
out = `${withCasing2(name, casing2)}: geometry(
|
82334
|
+
out = `${withCasing2(name, casing2)}: geometry(${dbColumnName3({ name, casing: casing2, withMode: true })}{ type: "${geometryOptions[0]}", srid: ${geometryOptions[1]} })`;
|
81220
82335
|
} else {
|
81221
82336
|
isGeoUnknown = true;
|
81222
82337
|
}
|
81223
82338
|
} else {
|
81224
|
-
out = `${withCasing2(name, casing2)}: geometry(
|
82339
|
+
out = `${withCasing2(name, casing2)}: geometry(${dbColumnName3({ name, casing: casing2 })})`;
|
81225
82340
|
}
|
81226
82341
|
if (isGeoUnknown) {
|
81227
82342
|
let unknown2 = `// TODO: failed to parse geometry type because found more than 2 options inside geometry function '${type}'
|
@@ -81238,12 +82353,12 @@ var init_introspect_pg = __esm({
|
|
81238
82353
|
out = `${withCasing2(
|
81239
82354
|
name,
|
81240
82355
|
casing2
|
81241
|
-
)}: vector(
|
82356
|
+
)}: vector(${dbColumnName3({ name, casing: casing2, withMode: true })}{ dimensions: ${lowered.substring(
|
81242
82357
|
7,
|
81243
82358
|
lowered.length - 1
|
81244
82359
|
)} })`;
|
81245
82360
|
} else {
|
81246
|
-
out = `${withCasing2(name, casing2)}: vector(
|
82361
|
+
out = `${withCasing2(name, casing2)}: vector(${dbColumnName3({ name, casing: casing2 })})`;
|
81247
82362
|
}
|
81248
82363
|
return out;
|
81249
82364
|
}
|
@@ -81253,12 +82368,12 @@ var init_introspect_pg = __esm({
|
|
81253
82368
|
out = `${withCasing2(
|
81254
82369
|
name,
|
81255
82370
|
casing2
|
81256
|
-
)}: char(
|
82371
|
+
)}: char(${dbColumnName3({ name, casing: casing2, withMode: true })}{ length: ${lowered.substring(
|
81257
82372
|
5,
|
81258
82373
|
lowered.length - 1
|
81259
82374
|
)} })`;
|
81260
82375
|
} else {
|
81261
|
-
out = `${withCasing2(name, casing2)}: char(
|
82376
|
+
out = `${withCasing2(name, casing2)}: char(${dbColumnName3({ name, casing: casing2 })})`;
|
81262
82377
|
}
|
81263
82378
|
return out;
|
81264
82379
|
}
|
@@ -81501,6 +82616,7 @@ var init_introspect = __esm({
|
|
81501
82616
|
sequencesResolver,
|
81502
82617
|
tablesResolver,
|
81503
82618
|
columnsResolver,
|
82619
|
+
viewsResolver,
|
81504
82620
|
dryPg,
|
81505
82621
|
schema5
|
81506
82622
|
);
|
@@ -85222,7 +86338,7 @@ init_utils2();
|
|
85222
86338
|
var version2 = async () => {
|
85223
86339
|
const { npmVersion } = await ormCoreVersions();
|
85224
86340
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
85225
|
-
const envVersion = "0.25.0-
|
86341
|
+
const envVersion = "0.25.0-b4de377";
|
85226
86342
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
85227
86343
|
const versions = `drizzle-kit: ${kitVersion}
|
85228
86344
|
${ormVersion}`;
|