drizzle-kit 0.25.0-8dece56 → 0.25.0-a5a41e0
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 +31727 -30079
- package/api.mjs +31726 -30078
- package/bin.cjs +1254 -161
- 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,6 +27816,16 @@ var init_snapshotsDiffer = __esm({
|
|
26975
27816
|
return [tableKey2, tableValue];
|
26976
27817
|
}
|
26977
27818
|
);
|
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
|
+
});
|
26978
27829
|
const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
|
26979
27830
|
const typedResult = diffResultScheme.parse(diffResult);
|
26980
27831
|
const jsonStatements = [];
|
@@ -27227,6 +28078,137 @@ var init_snapshotsDiffer = __esm({
|
|
27227
28078
|
const createTables = createdTables.map((it) => {
|
27228
28079
|
return preparePgCreateTableJson(it, curFull);
|
27229
28080
|
});
|
28081
|
+
const createViews = [];
|
28082
|
+
const dropViews = [];
|
28083
|
+
const renameViews = [];
|
28084
|
+
const alterViews = [];
|
28085
|
+
createViews.push(
|
28086
|
+
...createdViews.filter((it) => !it.isExisting).map((it) => {
|
28087
|
+
return preparePgCreateViewJson(
|
28088
|
+
it.name,
|
28089
|
+
it.schema,
|
28090
|
+
it.definition,
|
28091
|
+
it.materialized,
|
28092
|
+
it.withNoData,
|
28093
|
+
it.with,
|
28094
|
+
it.using,
|
28095
|
+
it.tablespace
|
28096
|
+
);
|
28097
|
+
})
|
28098
|
+
);
|
28099
|
+
dropViews.push(
|
28100
|
+
...deletedViews.filter((it) => !it.isExisting).map((it) => {
|
28101
|
+
return preparePgDropViewJson(it.name, it.schema, it.materialized);
|
28102
|
+
})
|
28103
|
+
);
|
28104
|
+
renameViews.push(
|
28105
|
+
...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
|
28106
|
+
return preparePgRenameViewJson(it.to.name, it.from.name, it.to.schema, it.to.materialized);
|
28107
|
+
})
|
28108
|
+
);
|
28109
|
+
alterViews.push(
|
28110
|
+
...movedViews.filter((it) => !json2.views[`${it.schemaTo}.${it.name}`].isExisting).map((it) => {
|
28111
|
+
return preparePgAlterViewAlterSchemaJson(
|
28112
|
+
it.schemaTo,
|
28113
|
+
it.schemaFrom,
|
28114
|
+
it.name,
|
28115
|
+
json2.views[`${it.schemaTo}.${it.name}`].materialized
|
28116
|
+
);
|
28117
|
+
})
|
28118
|
+
);
|
28119
|
+
const alteredViews = typedResult.alteredViews.filter((it) => !json2.views[`${it.schema}.${it.name}`].isExisting);
|
28120
|
+
for (const alteredView of alteredViews) {
|
28121
|
+
const viewKey = `${alteredView.schema}.${alteredView.name}`;
|
28122
|
+
const { materialized, with: withOption, definition, withNoData, using, tablespace } = json2.views[viewKey];
|
28123
|
+
if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
|
28124
|
+
dropViews.push(preparePgDropViewJson(alteredView.name, alteredView.schema, materialized));
|
28125
|
+
createViews.push(
|
28126
|
+
preparePgCreateViewJson(
|
28127
|
+
alteredView.name,
|
28128
|
+
alteredView.schema,
|
28129
|
+
definition,
|
28130
|
+
materialized,
|
28131
|
+
withNoData,
|
28132
|
+
withOption,
|
28133
|
+
using,
|
28134
|
+
tablespace
|
28135
|
+
)
|
28136
|
+
);
|
28137
|
+
continue;
|
28138
|
+
}
|
28139
|
+
if (alteredView.addedWithOption) {
|
28140
|
+
alterViews.push(
|
28141
|
+
preparePgAlterViewAddWithOptionJson(
|
28142
|
+
alteredView.name,
|
28143
|
+
alteredView.schema,
|
28144
|
+
materialized,
|
28145
|
+
alteredView.addedWithOption
|
28146
|
+
)
|
28147
|
+
);
|
28148
|
+
}
|
28149
|
+
if (alteredView.deletedWithOption) {
|
28150
|
+
alterViews.push(
|
28151
|
+
preparePgAlterViewDropWithOptionJson(
|
28152
|
+
alteredView.name,
|
28153
|
+
alteredView.schema,
|
28154
|
+
materialized,
|
28155
|
+
alteredView.deletedWithOption
|
28156
|
+
)
|
28157
|
+
);
|
28158
|
+
}
|
28159
|
+
if (alteredView.alteredWith) {
|
28160
|
+
if (alteredView.alteredWith.addedWith) {
|
28161
|
+
alterViews.push(
|
28162
|
+
preparePgAlterViewAddWithOptionJson(
|
28163
|
+
alteredView.name,
|
28164
|
+
alteredView.schema,
|
28165
|
+
materialized,
|
28166
|
+
alteredView.alteredWith.addedWith
|
28167
|
+
)
|
28168
|
+
);
|
28169
|
+
}
|
28170
|
+
if (alteredView.alteredWith.deletedWith) {
|
28171
|
+
alterViews.push(
|
28172
|
+
preparePgAlterViewDropWithOptionJson(
|
28173
|
+
alteredView.name,
|
28174
|
+
alteredView.schema,
|
28175
|
+
materialized,
|
28176
|
+
alteredView.alteredWith.deletedWith
|
28177
|
+
)
|
28178
|
+
);
|
28179
|
+
}
|
28180
|
+
if (alteredView.alteredWith.alterWith) {
|
28181
|
+
alterViews.push(
|
28182
|
+
preparePgAlterViewAddWithOptionJson(
|
28183
|
+
alteredView.name,
|
28184
|
+
alteredView.schema,
|
28185
|
+
materialized,
|
28186
|
+
alteredView.alteredWith.alterWith
|
28187
|
+
)
|
28188
|
+
);
|
28189
|
+
}
|
28190
|
+
}
|
28191
|
+
if (alteredView.alteredTablespace) {
|
28192
|
+
alterViews.push(
|
28193
|
+
preparePgAlterViewAlterTablespaceJson(
|
28194
|
+
alteredView.name,
|
28195
|
+
alteredView.schema,
|
28196
|
+
materialized,
|
28197
|
+
alteredView.alteredTablespace.__new
|
28198
|
+
)
|
28199
|
+
);
|
28200
|
+
}
|
28201
|
+
if (alteredView.alteredUsing) {
|
28202
|
+
alterViews.push(
|
28203
|
+
preparePgAlterViewAlterUsingJson(
|
28204
|
+
alteredView.name,
|
28205
|
+
alteredView.schema,
|
28206
|
+
materialized,
|
28207
|
+
alteredView.alteredUsing.__new
|
28208
|
+
)
|
28209
|
+
);
|
28210
|
+
}
|
28211
|
+
}
|
27230
28212
|
jsonStatements.push(...createSchemas);
|
27231
28213
|
jsonStatements.push(...renameSchemas);
|
27232
28214
|
jsonStatements.push(...createEnums);
|
@@ -27238,6 +28220,9 @@ var init_snapshotsDiffer = __esm({
|
|
27238
28220
|
jsonStatements.push(...renameSequences);
|
27239
28221
|
jsonStatements.push(...jsonAlterSequences);
|
27240
28222
|
jsonStatements.push(...createTables);
|
28223
|
+
jsonStatements.push(...dropViews);
|
28224
|
+
jsonStatements.push(...renameViews);
|
28225
|
+
jsonStatements.push(...alterViews);
|
27241
28226
|
jsonStatements.push(...jsonDropTables);
|
27242
28227
|
jsonStatements.push(...jsonSetTableSchemas);
|
27243
28228
|
jsonStatements.push(...jsonRenameTables);
|
@@ -27257,6 +28242,7 @@ var init_snapshotsDiffer = __esm({
|
|
27257
28242
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
27258
28243
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
27259
28244
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
28245
|
+
jsonStatements.push(...createViews);
|
27260
28246
|
jsonStatements.push(...dropEnums);
|
27261
28247
|
jsonStatements.push(...dropSequences);
|
27262
28248
|
jsonStatements.push(...dropSchemas);
|
@@ -29535,9 +30521,10 @@ __export(migrate_exports, {
|
|
29535
30521
|
schemasResolver: () => schemasResolver,
|
29536
30522
|
sequencesResolver: () => sequencesResolver,
|
29537
30523
|
tablesResolver: () => tablesResolver,
|
30524
|
+
viewsResolver: () => viewsResolver,
|
29538
30525
|
writeResult: () => writeResult
|
29539
30526
|
});
|
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;
|
30527
|
+
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
30528
|
var init_migrate = __esm({
|
29542
30529
|
"src/cli/commands/migrate.ts"() {
|
29543
30530
|
"use strict";
|
@@ -29584,6 +30571,24 @@ var init_migrate = __esm({
|
|
29584
30571
|
throw e2;
|
29585
30572
|
}
|
29586
30573
|
};
|
30574
|
+
viewsResolver = async (input) => {
|
30575
|
+
try {
|
30576
|
+
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
30577
|
+
input.created,
|
30578
|
+
input.deleted,
|
30579
|
+
"view"
|
30580
|
+
);
|
30581
|
+
return {
|
30582
|
+
created,
|
30583
|
+
deleted,
|
30584
|
+
moved,
|
30585
|
+
renamed
|
30586
|
+
};
|
30587
|
+
} catch (e2) {
|
30588
|
+
console.error(e2);
|
30589
|
+
throw e2;
|
30590
|
+
}
|
30591
|
+
};
|
29587
30592
|
sequencesResolver = async (input) => {
|
29588
30593
|
try {
|
29589
30594
|
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
@@ -29672,6 +30677,7 @@ var init_migrate = __esm({
|
|
29672
30677
|
sequencesResolver,
|
29673
30678
|
tablesResolver,
|
29674
30679
|
columnsResolver,
|
30680
|
+
viewsResolver,
|
29675
30681
|
validatedPrev,
|
29676
30682
|
validatedCur
|
29677
30683
|
);
|
@@ -29706,6 +30712,7 @@ var init_migrate = __esm({
|
|
29706
30712
|
sequencesResolver,
|
29707
30713
|
tablesResolver,
|
29708
30714
|
columnsResolver,
|
30715
|
+
viewsResolver,
|
29709
30716
|
validatedPrev,
|
29710
30717
|
validatedCur,
|
29711
30718
|
"push"
|
@@ -34527,20 +35534,20 @@ var require_ponyfill_es2018 = __commonJS({
|
|
34527
35534
|
;
|
34528
35535
|
ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
|
34529
35536
|
}
|
34530
|
-
respondWithNewView(
|
35537
|
+
respondWithNewView(view2) {
|
34531
35538
|
if (!IsReadableStreamBYOBRequest(this)) {
|
34532
35539
|
throw byobRequestBrandCheckException("respondWithNewView");
|
34533
35540
|
}
|
34534
|
-
assertRequiredArgument(
|
34535
|
-
if (!ArrayBuffer.isView(
|
35541
|
+
assertRequiredArgument(view2, 1, "respondWithNewView");
|
35542
|
+
if (!ArrayBuffer.isView(view2)) {
|
34536
35543
|
throw new TypeError("You can only respond with array buffer views");
|
34537
35544
|
}
|
34538
35545
|
if (this._associatedReadableByteStreamController === void 0) {
|
34539
35546
|
throw new TypeError("This BYOB request has been invalidated");
|
34540
35547
|
}
|
34541
|
-
if (IsDetachedBuffer(
|
35548
|
+
if (IsDetachedBuffer(view2.buffer))
|
34542
35549
|
;
|
34543
|
-
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController,
|
35550
|
+
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view2);
|
34544
35551
|
}
|
34545
35552
|
}
|
34546
35553
|
Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
|
@@ -34641,8 +35648,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
34641
35648
|
const entry = this._queue.shift();
|
34642
35649
|
this._queueTotalSize -= entry.byteLength;
|
34643
35650
|
ReadableByteStreamControllerHandleQueueDrain(this);
|
34644
|
-
const
|
34645
|
-
readRequest._chunkSteps(
|
35651
|
+
const view2 = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
|
35652
|
+
readRequest._chunkSteps(view2);
|
34646
35653
|
return;
|
34647
35654
|
}
|
34648
35655
|
const autoAllocateChunkSize = this._autoAllocateChunkSize;
|
@@ -34808,19 +35815,19 @@ var require_ponyfill_es2018 = __commonJS({
|
|
34808
35815
|
}
|
34809
35816
|
}
|
34810
35817
|
}
|
34811
|
-
function ReadableByteStreamControllerPullInto(controller,
|
35818
|
+
function ReadableByteStreamControllerPullInto(controller, view2, readIntoRequest) {
|
34812
35819
|
const stream = controller._controlledReadableByteStream;
|
34813
35820
|
let elementSize = 1;
|
34814
|
-
if (
|
34815
|
-
elementSize =
|
35821
|
+
if (view2.constructor !== DataView) {
|
35822
|
+
elementSize = view2.constructor.BYTES_PER_ELEMENT;
|
34816
35823
|
}
|
34817
|
-
const ctor =
|
34818
|
-
const buffer = TransferArrayBuffer(
|
35824
|
+
const ctor = view2.constructor;
|
35825
|
+
const buffer = TransferArrayBuffer(view2.buffer);
|
34819
35826
|
const pullIntoDescriptor = {
|
34820
35827
|
buffer,
|
34821
35828
|
bufferByteLength: buffer.byteLength,
|
34822
|
-
byteOffset:
|
34823
|
-
byteLength:
|
35829
|
+
byteOffset: view2.byteOffset,
|
35830
|
+
byteLength: view2.byteLength,
|
34824
35831
|
bytesFilled: 0,
|
34825
35832
|
elementSize,
|
34826
35833
|
viewConstructor: ctor,
|
@@ -34988,9 +35995,9 @@ var require_ponyfill_es2018 = __commonJS({
|
|
34988
35995
|
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
34989
35996
|
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
34990
35997
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
34991
|
-
const
|
35998
|
+
const view2 = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
34992
35999
|
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
34993
|
-
SetUpReadableStreamBYOBRequest(byobRequest, controller,
|
36000
|
+
SetUpReadableStreamBYOBRequest(byobRequest, controller, view2);
|
34994
36001
|
controller._byobRequest = byobRequest;
|
34995
36002
|
}
|
34996
36003
|
return controller._byobRequest;
|
@@ -35023,29 +36030,29 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35023
36030
|
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
35024
36031
|
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
35025
36032
|
}
|
35026
|
-
function ReadableByteStreamControllerRespondWithNewView(controller,
|
36033
|
+
function ReadableByteStreamControllerRespondWithNewView(controller, view2) {
|
35027
36034
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
35028
36035
|
const state = controller._controlledReadableByteStream._state;
|
35029
36036
|
if (state === "closed") {
|
35030
|
-
if (
|
36037
|
+
if (view2.byteLength !== 0) {
|
35031
36038
|
throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
|
35032
36039
|
}
|
35033
36040
|
} else {
|
35034
|
-
if (
|
36041
|
+
if (view2.byteLength === 0) {
|
35035
36042
|
throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
|
35036
36043
|
}
|
35037
36044
|
}
|
35038
|
-
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !==
|
36045
|
+
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view2.byteOffset) {
|
35039
36046
|
throw new RangeError("The region specified by view does not match byobRequest");
|
35040
36047
|
}
|
35041
|
-
if (firstDescriptor.bufferByteLength !==
|
36048
|
+
if (firstDescriptor.bufferByteLength !== view2.buffer.byteLength) {
|
35042
36049
|
throw new RangeError("The buffer of view has different capacity than byobRequest");
|
35043
36050
|
}
|
35044
|
-
if (firstDescriptor.bytesFilled +
|
36051
|
+
if (firstDescriptor.bytesFilled + view2.byteLength > firstDescriptor.byteLength) {
|
35045
36052
|
throw new RangeError("The region specified by view is larger than byobRequest");
|
35046
36053
|
}
|
35047
|
-
const viewByteLength =
|
35048
|
-
firstDescriptor.buffer = TransferArrayBuffer(
|
36054
|
+
const viewByteLength = view2.byteLength;
|
36055
|
+
firstDescriptor.buffer = TransferArrayBuffer(view2.buffer);
|
35049
36056
|
ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
|
35050
36057
|
}
|
35051
36058
|
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
@@ -35091,9 +36098,9 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35091
36098
|
}
|
35092
36099
|
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
35093
36100
|
}
|
35094
|
-
function SetUpReadableStreamBYOBRequest(request, controller,
|
36101
|
+
function SetUpReadableStreamBYOBRequest(request, controller, view2) {
|
35095
36102
|
request._associatedReadableByteStreamController = controller;
|
35096
|
-
request._view =
|
36103
|
+
request._view = view2;
|
35097
36104
|
}
|
35098
36105
|
function byobRequestBrandCheckException(name) {
|
35099
36106
|
return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);
|
@@ -35169,20 +36176,20 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35169
36176
|
*
|
35170
36177
|
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
35171
36178
|
*/
|
35172
|
-
read(
|
36179
|
+
read(view2) {
|
35173
36180
|
if (!IsReadableStreamBYOBReader(this)) {
|
35174
36181
|
return promiseRejectedWith(byobReaderBrandCheckException("read"));
|
35175
36182
|
}
|
35176
|
-
if (!ArrayBuffer.isView(
|
36183
|
+
if (!ArrayBuffer.isView(view2)) {
|
35177
36184
|
return promiseRejectedWith(new TypeError("view must be an array buffer view"));
|
35178
36185
|
}
|
35179
|
-
if (
|
36186
|
+
if (view2.byteLength === 0) {
|
35180
36187
|
return promiseRejectedWith(new TypeError("view must have non-zero byteLength"));
|
35181
36188
|
}
|
35182
|
-
if (
|
36189
|
+
if (view2.buffer.byteLength === 0) {
|
35183
36190
|
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
35184
36191
|
}
|
35185
|
-
if (IsDetachedBuffer(
|
36192
|
+
if (IsDetachedBuffer(view2.buffer))
|
35186
36193
|
;
|
35187
36194
|
if (this._ownerReadableStream === void 0) {
|
35188
36195
|
return promiseRejectedWith(readerLockException("read from"));
|
@@ -35198,7 +36205,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35198
36205
|
_closeSteps: (chunk) => resolvePromise({ value: chunk, done: true }),
|
35199
36206
|
_errorSteps: (e2) => rejectPromise(e2)
|
35200
36207
|
};
|
35201
|
-
ReadableStreamBYOBReaderRead(this,
|
36208
|
+
ReadableStreamBYOBReaderRead(this, view2, readIntoRequest);
|
35202
36209
|
return promise;
|
35203
36210
|
}
|
35204
36211
|
/**
|
@@ -35244,13 +36251,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
35244
36251
|
}
|
35245
36252
|
return x2 instanceof ReadableStreamBYOBReader;
|
35246
36253
|
}
|
35247
|
-
function ReadableStreamBYOBReaderRead(reader,
|
36254
|
+
function ReadableStreamBYOBReaderRead(reader, view2, readIntoRequest) {
|
35248
36255
|
const stream = reader._ownerReadableStream;
|
35249
36256
|
stream._disturbed = true;
|
35250
36257
|
if (stream._state === "errored") {
|
35251
36258
|
readIntoRequest._errorSteps(stream._storedError);
|
35252
36259
|
} else {
|
35253
|
-
ReadableByteStreamControllerPullInto(stream._readableStreamController,
|
36260
|
+
ReadableByteStreamControllerPullInto(stream._readableStreamController, view2, readIntoRequest);
|
35254
36261
|
}
|
35255
36262
|
}
|
35256
36263
|
function byobReaderBrandCheckException(name) {
|
@@ -36799,7 +37806,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
36799
37806
|
};
|
36800
37807
|
ReadableStreamDefaultReaderRead(reader, readRequest);
|
36801
37808
|
}
|
36802
|
-
function pullWithBYOBReader(
|
37809
|
+
function pullWithBYOBReader(view2, forBranch2) {
|
36803
37810
|
if (IsReadableStreamDefaultReader(reader)) {
|
36804
37811
|
ReadableStreamReaderGenericRelease(reader);
|
36805
37812
|
reader = AcquireReadableStreamBYOBReader(stream);
|
@@ -36865,7 +37872,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
36865
37872
|
reading = false;
|
36866
37873
|
}
|
36867
37874
|
};
|
36868
|
-
ReadableStreamBYOBReaderRead(reader,
|
37875
|
+
ReadableStreamBYOBReaderRead(reader, view2, readIntoRequest);
|
36869
37876
|
}
|
36870
37877
|
function pull1Algorithm() {
|
36871
37878
|
if (reading) {
|
@@ -51724,15 +52731,15 @@ var require_dist_cjs36 = __commonJS({
|
|
51724
52731
|
throw new Error("Int64 buffers must be exactly 8 bytes");
|
51725
52732
|
}
|
51726
52733
|
}
|
51727
|
-
static fromNumber(
|
51728
|
-
if (
|
51729
|
-
throw new Error(`${
|
52734
|
+
static fromNumber(number2) {
|
52735
|
+
if (number2 > 9223372036854776e3 || number2 < -9223372036854776e3) {
|
52736
|
+
throw new Error(`${number2} is too large (or, if negative, too small) to represent as an Int64`);
|
51730
52737
|
}
|
51731
52738
|
const bytes = new Uint8Array(8);
|
51732
|
-
for (let i2 = 7, remaining = Math.abs(Math.round(
|
52739
|
+
for (let i2 = 7, remaining = Math.abs(Math.round(number2)); i2 > -1 && remaining > 0; i2--, remaining /= 256) {
|
51733
52740
|
bytes[i2] = remaining;
|
51734
52741
|
}
|
51735
|
-
if (
|
52742
|
+
if (number2 < 0) {
|
51736
52743
|
negate(bytes);
|
51737
52744
|
}
|
51738
52745
|
return new _Int642(bytes);
|
@@ -63163,16 +64170,16 @@ var require_map_stream = __commonJS({
|
|
63163
64170
|
var writeQueue = {};
|
63164
64171
|
stream.writable = true;
|
63165
64172
|
stream.readable = true;
|
63166
|
-
function queueData(data,
|
64173
|
+
function queueData(data, number2) {
|
63167
64174
|
var nextToWrite = lastWritten + 1;
|
63168
|
-
if (
|
64175
|
+
if (number2 === nextToWrite) {
|
63169
64176
|
if (data !== void 0) {
|
63170
64177
|
stream.emit.apply(stream, ["data", data]);
|
63171
64178
|
}
|
63172
64179
|
lastWritten++;
|
63173
64180
|
nextToWrite++;
|
63174
64181
|
} else {
|
63175
|
-
writeQueue[
|
64182
|
+
writeQueue[number2] = data;
|
63176
64183
|
}
|
63177
64184
|
if (writeQueue.hasOwnProperty(nextToWrite)) {
|
63178
64185
|
var dataToWrite = writeQueue[nextToWrite];
|
@@ -63187,21 +64194,21 @@ var require_map_stream = __commonJS({
|
|
63187
64194
|
end();
|
63188
64195
|
}
|
63189
64196
|
}
|
63190
|
-
function next(err2, data,
|
64197
|
+
function next(err2, data, number2) {
|
63191
64198
|
if (destroyed)
|
63192
64199
|
return;
|
63193
64200
|
inNext = true;
|
63194
64201
|
if (!err2 || self2.opts.failures) {
|
63195
|
-
queueData(data,
|
64202
|
+
queueData(data, number2);
|
63196
64203
|
}
|
63197
64204
|
if (err2) {
|
63198
64205
|
stream.emit.apply(stream, [errorEventName, err2]);
|
63199
64206
|
}
|
63200
64207
|
inNext = false;
|
63201
64208
|
}
|
63202
|
-
function wrappedMapper(input,
|
64209
|
+
function wrappedMapper(input, number2, callback) {
|
63203
64210
|
return mapper.call(null, input, function(err2, data) {
|
63204
|
-
callback(err2, data,
|
64211
|
+
callback(err2, data, number2);
|
63205
64212
|
});
|
63206
64213
|
}
|
63207
64214
|
stream.write = function(data) {
|
@@ -77033,7 +78040,7 @@ var init_selector_ui = __esm({
|
|
77033
78040
|
});
|
77034
78041
|
|
77035
78042
|
// src/cli/commands/libSqlPushUtils.ts
|
77036
|
-
var
|
78043
|
+
var getOldTableName2, _moveDataStatements2, libSqlLogSuggestionsAndReturn;
|
77037
78044
|
var init_libSqlPushUtils = __esm({
|
77038
78045
|
"src/cli/commands/libSqlPushUtils.ts"() {
|
77039
78046
|
"use strict";
|
@@ -77041,7 +78048,7 @@ var init_libSqlPushUtils = __esm({
|
|
77041
78048
|
init_utils();
|
77042
78049
|
init_sqliteSchema();
|
77043
78050
|
init_sqlgenerator();
|
77044
|
-
|
78051
|
+
getOldTableName2 = (tableName, meta) => {
|
77045
78052
|
for (const key of Object.keys(meta.tables)) {
|
77046
78053
|
const value = meta.tables[key];
|
77047
78054
|
if (`"${tableName}"` === value) {
|
@@ -77196,7 +78203,7 @@ var init_libSqlPushUtils = __esm({
|
|
77196
78203
|
} else if (statement.type === "recreate_table") {
|
77197
78204
|
const tableName = statement.tableName;
|
77198
78205
|
let dataLoss = false;
|
77199
|
-
const oldTableName =
|
78206
|
+
const oldTableName = getOldTableName2(tableName, meta);
|
77200
78207
|
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
77201
78208
|
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
77202
78209
|
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
@@ -78956,11 +79963,13 @@ var init_pgIntrospect = __esm({
|
|
78956
79963
|
});
|
78957
79964
|
|
78958
79965
|
// src/introspect-sqlite.ts
|
78959
|
-
var sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
79966
|
+
var import_casing, sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, dbColumnName, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
78960
79967
|
var init_introspect_sqlite = __esm({
|
78961
79968
|
"src/introspect-sqlite.ts"() {
|
78962
79969
|
"use strict";
|
79970
|
+
import_casing = require("drizzle-orm/casing");
|
78963
79971
|
init_utils3();
|
79972
|
+
init_global();
|
78964
79973
|
sqliteImportsList = /* @__PURE__ */ new Set([
|
78965
79974
|
"sqliteTable",
|
78966
79975
|
"integer",
|
@@ -78998,6 +80007,15 @@ var init_introspect_sqlite = __esm({
|
|
78998
80007
|
}
|
78999
80008
|
return value;
|
79000
80009
|
};
|
80010
|
+
dbColumnName = ({ name, casing: casing2, withMode = false }) => {
|
80011
|
+
if (casing2 === "preserve") {
|
80012
|
+
return "";
|
80013
|
+
}
|
80014
|
+
if (casing2 === "camel") {
|
80015
|
+
return (0, import_casing.toCamelCase)(name) === name ? "" : withMode ? `"${name}", ` : `"${name}"`;
|
80016
|
+
}
|
80017
|
+
assertUnreachable(casing2);
|
80018
|
+
};
|
79001
80019
|
schemaToTypeScript = (schema5, casing2) => {
|
79002
80020
|
Object.values(schema5.tables).forEach((table4) => {
|
79003
80021
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
@@ -79117,13 +80135,14 @@ var init_introspect_sqlite = __esm({
|
|
79117
80135
|
};
|
79118
80136
|
column4 = (type, name, defaultValue, autoincrement, casing2) => {
|
79119
80137
|
let lowered = type;
|
80138
|
+
casing2 = casing2;
|
79120
80139
|
if (lowered === "integer") {
|
79121
|
-
let out = `${withCasing(name, casing2)}: integer(
|
80140
|
+
let out = `${withCasing(name, casing2)}: integer(${dbColumnName({ name, casing: casing2 })})`;
|
79122
80141
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
79123
80142
|
return out;
|
79124
80143
|
}
|
79125
80144
|
if (lowered === "real") {
|
79126
|
-
let out = `${withCasing(name, casing2)}: real(
|
80145
|
+
let out = `${withCasing(name, casing2)}: real(${dbColumnName({ name, casing: casing2 })})`;
|
79127
80146
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
79128
80147
|
return out;
|
79129
80148
|
}
|
@@ -79131,20 +80150,20 @@ var init_introspect_sqlite = __esm({
|
|
79131
80150
|
const match2 = lowered.match(/\d+/);
|
79132
80151
|
let out;
|
79133
80152
|
if (match2) {
|
79134
|
-
out = `${withCasing(name, casing2)}: text(
|
80153
|
+
out = `${withCasing(name, casing2)}: text(${dbColumnName({ name, casing: casing2, withMode: true })}{ length: ${match2[0]} })`;
|
79135
80154
|
} else {
|
79136
|
-
out = `${withCasing(name, casing2)}: text(
|
80155
|
+
out = `${withCasing(name, casing2)}: text(${dbColumnName({ name, casing: casing2 })})`;
|
79137
80156
|
}
|
79138
80157
|
out += defaultValue ? `.default("${mapColumnDefault(defaultValue)}")` : "";
|
79139
80158
|
return out;
|
79140
80159
|
}
|
79141
80160
|
if (lowered === "blob") {
|
79142
|
-
let out = `${withCasing(name, casing2)}: blob(
|
80161
|
+
let out = `${withCasing(name, casing2)}: blob(${dbColumnName({ name, casing: casing2 })})`;
|
79143
80162
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
79144
80163
|
return out;
|
79145
80164
|
}
|
79146
80165
|
if (lowered === "numeric") {
|
79147
|
-
let out = `${withCasing(name, casing2)}: numeric(
|
80166
|
+
let out = `${withCasing(name, casing2)}: numeric(${dbColumnName({ name, casing: casing2 })})`;
|
79148
80167
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
79149
80168
|
return out;
|
79150
80169
|
}
|
@@ -80067,11 +81086,13 @@ var require_pluralize = __commonJS({
|
|
80067
81086
|
});
|
80068
81087
|
|
80069
81088
|
// 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;
|
81089
|
+
var import_casing2, mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, escapeColumnKey2, prepareCasing, dbColumnName2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
|
80071
81090
|
var init_introspect_mysql = __esm({
|
80072
81091
|
"src/introspect-mysql.ts"() {
|
80073
81092
|
"use strict";
|
81093
|
+
import_casing2 = require("drizzle-orm/casing");
|
80074
81094
|
init_utils3();
|
81095
|
+
init_global();
|
80075
81096
|
init_mysqlSerializer();
|
80076
81097
|
mysqlImportsList = /* @__PURE__ */ new Set([
|
80077
81098
|
"mysqlTable",
|
@@ -80151,7 +81172,16 @@ var init_introspect_mysql = __esm({
|
|
80151
81172
|
if (casing2 === "camel") {
|
80152
81173
|
return escapeColumnKey2(value.camelCase());
|
80153
81174
|
}
|
80154
|
-
|
81175
|
+
assertUnreachable(casing2);
|
81176
|
+
};
|
81177
|
+
dbColumnName2 = ({ name, casing: casing2, withMode = false }) => {
|
81178
|
+
if (casing2 === "preserve") {
|
81179
|
+
return "";
|
81180
|
+
}
|
81181
|
+
if (casing2 === "camel") {
|
81182
|
+
return (0, import_casing2.toCamelCase)(name) === name ? "" : withMode ? `"${name}", ` : `"${name}"`;
|
81183
|
+
}
|
81184
|
+
assertUnreachable(casing2);
|
80155
81185
|
};
|
80156
81186
|
schemaToTypeScript2 = (schema5, casing2) => {
|
80157
81187
|
const withCasing4 = prepareCasing(casing2);
|
@@ -80212,6 +81242,7 @@ var init_introspect_mysql = __esm({
|
|
80212
81242
|
Object.values(table4.columns),
|
80213
81243
|
Object.values(table4.foreignKeys),
|
80214
81244
|
withCasing4,
|
81245
|
+
casing2,
|
80215
81246
|
table4.name,
|
80216
81247
|
schema5
|
80217
81248
|
);
|
@@ -80291,51 +81322,51 @@ import { sql } from "drizzle-orm"
|
|
80291
81322
|
}
|
80292
81323
|
return defaultValue;
|
80293
81324
|
};
|
80294
|
-
column5 = (type, name, casing2, defaultValue, autoincrement, onUpdate, isExpression) => {
|
81325
|
+
column5 = (type, name, casing2, rawCasing, defaultValue, autoincrement, onUpdate, isExpression) => {
|
80295
81326
|
let lowered = type;
|
80296
81327
|
if (!type.startsWith("enum(")) {
|
80297
81328
|
lowered = type.toLowerCase();
|
80298
81329
|
}
|
80299
81330
|
if (lowered === "serial") {
|
80300
|
-
return `${casing2(name)}: serial(
|
81331
|
+
return `${casing2(name)}: serial(${dbColumnName2({ name, casing: rawCasing })})`;
|
80301
81332
|
}
|
80302
81333
|
if (lowered.startsWith("int")) {
|
80303
81334
|
const isUnsigned = lowered.startsWith("int unsigned");
|
80304
|
-
let out = `${casing2(name)}: int(
|
81335
|
+
let out = `${casing2(name)}: int(${dbColumnName2({ name, casing: rawCasing, withMode: isUnsigned })}${isUnsigned ? "{ unsigned: true }" : ""})`;
|
80305
81336
|
out += autoincrement ? `.autoincrement()` : "";
|
80306
81337
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80307
81338
|
return out;
|
80308
81339
|
}
|
80309
81340
|
if (lowered.startsWith("tinyint")) {
|
80310
81341
|
const isUnsigned = lowered.startsWith("tinyint unsigned");
|
80311
|
-
let out = `${casing2(name)}: tinyint(
|
81342
|
+
let out = `${casing2(name)}: tinyint(${dbColumnName2({ name, casing: rawCasing, withMode: isUnsigned })}${isUnsigned ? ", { unsigned: true }" : ""})`;
|
80312
81343
|
out += autoincrement ? `.autoincrement()` : "";
|
80313
81344
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80314
81345
|
return out;
|
80315
81346
|
}
|
80316
81347
|
if (lowered.startsWith("smallint")) {
|
80317
81348
|
const isUnsigned = lowered.startsWith("smallint unsigned");
|
80318
|
-
let out = `${casing2(name)}: smallint(
|
81349
|
+
let out = `${casing2(name)}: smallint(${dbColumnName2({ name, casing: rawCasing, withMode: isUnsigned })}${isUnsigned ? ", { unsigned: true }" : ""})`;
|
80319
81350
|
out += autoincrement ? `.autoincrement()` : "";
|
80320
81351
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80321
81352
|
return out;
|
80322
81353
|
}
|
80323
81354
|
if (lowered.startsWith("mediumint")) {
|
80324
81355
|
const isUnsigned = lowered.startsWith("mediumint unsigned");
|
80325
|
-
let out = `${casing2(name)}: mediumint(
|
81356
|
+
let out = `${casing2(name)}: mediumint(${dbColumnName2({ name, casing: rawCasing, withMode: isUnsigned })}${isUnsigned ? ", { unsigned: true }" : ""})`;
|
80326
81357
|
out += autoincrement ? `.autoincrement()` : "";
|
80327
81358
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80328
81359
|
return out;
|
80329
81360
|
}
|
80330
81361
|
if (lowered.startsWith("bigint")) {
|
80331
81362
|
const isUnsigned = lowered.startsWith("bigint unsigned");
|
80332
|
-
let out = `${casing2(name)}: bigint(
|
81363
|
+
let out = `${casing2(name)}: bigint(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ mode: "number"${isUnsigned ? ", unsigned: true" : ""} })`;
|
80333
81364
|
out += autoincrement ? `.autoincrement()` : "";
|
80334
81365
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80335
81366
|
return out;
|
80336
81367
|
}
|
80337
81368
|
if (lowered === "boolean") {
|
80338
|
-
let out = `${casing2(name)}: boolean(
|
81369
|
+
let out = `${casing2(name)}: boolean(${dbColumnName2({ name, casing: rawCasing })})`;
|
80339
81370
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80340
81371
|
return out;
|
80341
81372
|
}
|
@@ -80345,17 +81376,18 @@ import { sql } from "drizzle-orm"
|
|
80345
81376
|
const [precision, scale] = lowered.slice(7, lowered.length - 1).split(",");
|
80346
81377
|
params = { precision, scale };
|
80347
81378
|
}
|
80348
|
-
|
81379
|
+
const timeConfigParams = params ? timeConfig(params) : void 0;
|
81380
|
+
let out = params ? `${casing2(name)}: double(${dbColumnName2({ name, casing: rawCasing, withMode: timeConfigParams !== void 0 })}${timeConfig(params)})` : `${casing2(name)}: double(${dbColumnName2({ name, casing: rawCasing })})`;
|
80349
81381
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80350
81382
|
return out;
|
80351
81383
|
}
|
80352
81384
|
if (lowered === "float") {
|
80353
|
-
let out = `${casing2(name)}: float(
|
81385
|
+
let out = `${casing2(name)}: float(${dbColumnName2({ name, casing: rawCasing })})`;
|
80354
81386
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80355
81387
|
return out;
|
80356
81388
|
}
|
80357
81389
|
if (lowered === "real") {
|
80358
|
-
let out = `${casing2(name)}: real(
|
81390
|
+
let out = `${casing2(name)}: real(${dbColumnName2({ name, casing: rawCasing })})`;
|
80359
81391
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80360
81392
|
return out;
|
80361
81393
|
}
|
@@ -80364,7 +81396,7 @@ import { sql } from "drizzle-orm"
|
|
80364
81396
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
80365
81397
|
fsp = fsp ? fsp : null;
|
80366
81398
|
const params = timeConfig({ fsp, mode: "'string'" });
|
80367
|
-
let out = params ? `${casing2(name)}: timestamp(
|
81399
|
+
let out = params ? `${casing2(name)}: timestamp(${dbColumnName2({ name, casing: rawCasing, withMode: params !== void 0 })}${params})` : `${casing2(name)}: timestamp(${dbColumnName2({ name, casing: rawCasing })})`;
|
80368
81400
|
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80369
81401
|
out += defaultValue;
|
80370
81402
|
let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
|
@@ -80376,7 +81408,7 @@ import { sql } from "drizzle-orm"
|
|
80376
81408
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
80377
81409
|
fsp = fsp ? fsp : null;
|
80378
81410
|
const params = timeConfig({ fsp });
|
80379
|
-
let out = params ? `${casing2(name)}: time(
|
81411
|
+
let out = params ? `${casing2(name)}: time(${dbColumnName2({ name, casing: rawCasing, withMode: params !== void 0 })}${params})` : `${casing2(name)}: time(${dbColumnName2({ name, casing: rawCasing })})`;
|
80380
81412
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80381
81413
|
out += defaultValue;
|
80382
81414
|
return out;
|
@@ -80385,45 +81417,45 @@ import { sql } from "drizzle-orm"
|
|
80385
81417
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
80386
81418
|
${casing2(
|
80387
81419
|
name
|
80388
|
-
)}: date(
|
81420
|
+
)}: date(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ mode: 'string' })`;
|
80389
81421
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80390
81422
|
out += defaultValue;
|
80391
81423
|
return out;
|
80392
81424
|
}
|
80393
81425
|
if (lowered === "text") {
|
80394
|
-
let out = `${casing2(name)}: text(
|
81426
|
+
let out = `${casing2(name)}: text(${dbColumnName2({ name, casing: rawCasing })})`;
|
80395
81427
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80396
81428
|
return out;
|
80397
81429
|
}
|
80398
81430
|
if (lowered === "tinytext") {
|
80399
|
-
let out = `${casing2(name)}: tinytext(
|
81431
|
+
let out = `${casing2(name)}: tinytext(${dbColumnName2({ name, casing: rawCasing })})`;
|
80400
81432
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80401
81433
|
return out;
|
80402
81434
|
}
|
80403
81435
|
if (lowered === "mediumtext") {
|
80404
|
-
let out = `${casing2(name)}: mediumtext(
|
81436
|
+
let out = `${casing2(name)}: mediumtext(${dbColumnName2({ name, casing: rawCasing })})`;
|
80405
81437
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80406
81438
|
return out;
|
80407
81439
|
}
|
80408
81440
|
if (lowered === "longtext") {
|
80409
|
-
let out = `${casing2(name)}: longtext(
|
81441
|
+
let out = `${casing2(name)}: longtext(${dbColumnName2({ name, casing: rawCasing })})`;
|
80410
81442
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80411
81443
|
return out;
|
80412
81444
|
}
|
80413
81445
|
if (lowered === "year") {
|
80414
|
-
let out = `${casing2(name)}: year(
|
81446
|
+
let out = `${casing2(name)}: year(${dbColumnName2({ name, casing: rawCasing })})`;
|
80415
81447
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80416
81448
|
return out;
|
80417
81449
|
}
|
80418
81450
|
if (lowered === "json") {
|
80419
|
-
let out = `${casing2(name)}: json(
|
81451
|
+
let out = `${casing2(name)}: json(${dbColumnName2({ name, casing: rawCasing })})`;
|
80420
81452
|
out += defaultValue ? `.default(${mapColumnDefaultForJson(defaultValue)})` : "";
|
80421
81453
|
return out;
|
80422
81454
|
}
|
80423
81455
|
if (lowered.startsWith("varchar")) {
|
80424
81456
|
let out = `${casing2(
|
80425
81457
|
name
|
80426
|
-
)}: varchar(
|
81458
|
+
)}: varchar(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ length: ${lowered.substring(
|
80427
81459
|
"varchar".length + 1,
|
80428
81460
|
lowered.length - 1
|
80429
81461
|
)} })`;
|
@@ -80433,7 +81465,7 @@ import { sql } from "drizzle-orm"
|
|
80433
81465
|
if (lowered.startsWith("char")) {
|
80434
81466
|
let out = `${casing2(
|
80435
81467
|
name
|
80436
|
-
)}: char(
|
81468
|
+
)}: char(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ length: ${lowered.substring(
|
80437
81469
|
"char".length + 1,
|
80438
81470
|
lowered.length - 1
|
80439
81471
|
)} })`;
|
@@ -80446,10 +81478,10 @@ import { sql } from "drizzle-orm"
|
|
80446
81478
|
const fsp = lowered.startsWith("datetime(") ? lowered.substring("datetime".length + 1, lowered.length - 1) : void 0;
|
80447
81479
|
out = fsp ? `${casing2(
|
80448
81480
|
name
|
80449
|
-
)}: datetime(
|
81481
|
+
)}: datetime(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ mode: 'string', fsp: ${lowered.substring(
|
80450
81482
|
"datetime".length + 1,
|
80451
81483
|
lowered.length - 1
|
80452
|
-
)} })` : `${casing2(name)}: datetime(
|
81484
|
+
)} })` : `${casing2(name)}: datetime(${dbColumnName2({ name, casing: rawCasing, withMode: true })}{ mode: 'string'})`;
|
80453
81485
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80454
81486
|
out += defaultValue;
|
80455
81487
|
return out;
|
@@ -80460,7 +81492,8 @@ import { sql } from "drizzle-orm"
|
|
80460
81492
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
80461
81493
|
params = { precision, scale };
|
80462
81494
|
}
|
80463
|
-
|
81495
|
+
const timeConfigParams = params ? timeConfig(params) : void 0;
|
81496
|
+
let out = params ? `${casing2(name)}: decimal(${dbColumnName2({ name, casing: rawCasing, withMode: timeConfigParams !== void 0 })}${timeConfigParams})` : `${casing2(name)}: decimal(${dbColumnName2({ name, casing: rawCasing })})`;
|
80464
81497
|
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80465
81498
|
out += defaultValue;
|
80466
81499
|
return out;
|
@@ -80470,14 +81503,14 @@ import { sql } from "drizzle-orm"
|
|
80470
81503
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
80471
81504
|
length = length ? length : null;
|
80472
81505
|
const params = binaryConfig({ length });
|
80473
|
-
let out = params ? `${casing2(name)}: binary(
|
81506
|
+
let out = params ? `${casing2(name)}: binary(${dbColumnName2({ name, casing: rawCasing, withMode: params !== void 0 })}${params})` : `${casing2(name)}: binary(${dbColumnName2({ name, casing: rawCasing })})`;
|
80474
81507
|
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80475
81508
|
out += defaultValue;
|
80476
81509
|
return out;
|
80477
81510
|
}
|
80478
81511
|
if (lowered.startsWith("enum")) {
|
80479
81512
|
const values = lowered.substring("enum".length + 1, lowered.length - 1);
|
80480
|
-
let out = `${casing2(name)}: mysqlEnum(
|
81513
|
+
let out = `${casing2(name)}: mysqlEnum(${dbColumnName2({ name, casing: rawCasing, withMode: true })}[${values}])`;
|
80481
81514
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80482
81515
|
return out;
|
80483
81516
|
}
|
@@ -80486,7 +81519,7 @@ import { sql } from "drizzle-orm"
|
|
80486
81519
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
80487
81520
|
length = length ? length : null;
|
80488
81521
|
const params = binaryConfig({ length });
|
80489
|
-
let out = params ? `${casing2(name)}: varbinary(
|
81522
|
+
let out = params ? `${casing2(name)}: varbinary(${dbColumnName2({ name, casing: rawCasing, withMode: params !== void 0 })}${params})` : `${casing2(name)}: varbinary(${dbColumnName2({ name, casing: rawCasing })})`;
|
80490
81523
|
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
80491
81524
|
out += defaultValue;
|
80492
81525
|
return out;
|
@@ -80495,7 +81528,7 @@ import { sql } from "drizzle-orm"
|
|
80495
81528
|
return `// Warning: Can't parse ${type} from database
|
80496
81529
|
// ${type}Type: ${type}("${name}")`;
|
80497
81530
|
};
|
80498
|
-
createTableColumns2 = (columns, fks, casing2, tableName, schema5) => {
|
81531
|
+
createTableColumns2 = (columns, fks, casing2, rawCasing, tableName, schema5) => {
|
80499
81532
|
let statement = "";
|
80500
81533
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
80501
81534
|
return !isSelf2(it);
|
@@ -80513,6 +81546,7 @@ import { sql } from "drizzle-orm"
|
|
80513
81546
|
it.type,
|
80514
81547
|
it.name,
|
80515
81548
|
casing2,
|
81549
|
+
rawCasing,
|
80516
81550
|
it.default,
|
80517
81551
|
it.autoincrement,
|
80518
81552
|
it.onUpdate,
|
@@ -80643,13 +81677,14 @@ function generateIdentityParams(identity) {
|
|
80643
81677
|
}
|
80644
81678
|
return `.generatedByDefaultAsIdentity(${paramsObj})`;
|
80645
81679
|
}
|
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;
|
81680
|
+
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
81681
|
var init_introspect_pg = __esm({
|
80648
81682
|
"src/introspect-pg.ts"() {
|
80649
81683
|
"use strict";
|
80650
81684
|
import_drizzle_orm9 = require("drizzle-orm");
|
80651
81685
|
import_relations = require("drizzle-orm/relations");
|
80652
81686
|
init_utils3();
|
81687
|
+
import_casing3 = require("drizzle-orm/casing");
|
80653
81688
|
init_vector();
|
80654
81689
|
init_global();
|
80655
81690
|
init_pgSerializer();
|
@@ -80775,6 +81810,15 @@ var init_introspect_pg = __esm({
|
|
80775
81810
|
}
|
80776
81811
|
assertUnreachable(casing2);
|
80777
81812
|
};
|
81813
|
+
dbColumnName3 = ({ name, casing: casing2, withMode = false }) => {
|
81814
|
+
if (casing2 === "preserve") {
|
81815
|
+
return "";
|
81816
|
+
}
|
81817
|
+
if (casing2 === "camel") {
|
81818
|
+
return (0, import_casing3.toCamelCase)(name) === name ? "" : withMode ? `"${name}", ` : `"${name}"`;
|
81819
|
+
}
|
81820
|
+
assertUnreachable(casing2);
|
81821
|
+
};
|
80778
81822
|
paramNameFor = (name, schema5) => {
|
80779
81823
|
const schemaSuffix = schema5 && schema5 !== "public" ? `In${schema5.capitalise()}` : "";
|
80780
81824
|
return `${name}${schemaSuffix}`;
|
@@ -80837,6 +81881,30 @@ var init_introspect_pg = __esm({
|
|
80837
81881
|
},
|
80838
81882
|
{ pg: [] }
|
80839
81883
|
);
|
81884
|
+
Object.values(schema5.views).forEach((it) => {
|
81885
|
+
if (it.schema && it.schema !== "public" && it.schema !== "") {
|
81886
|
+
imports.pg.push("pgSchema");
|
81887
|
+
} else if (it.schema === "public") {
|
81888
|
+
it.materialized ? imports.pg.push("pgMaterializedView") : imports.pg.push("pgView");
|
81889
|
+
}
|
81890
|
+
Object.values(it.columns).forEach(() => {
|
81891
|
+
const columnImports = Object.values(it.columns).map((col) => {
|
81892
|
+
let patched = (importsPatch2[col.type] || col.type).replace("[]", "");
|
81893
|
+
patched = patched === "double precision" ? "doublePrecision" : patched;
|
81894
|
+
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
81895
|
+
patched = patched.startsWith("char(") ? "char" : patched;
|
81896
|
+
patched = patched.startsWith("numeric(") ? "numeric" : patched;
|
81897
|
+
patched = patched.startsWith("time(") ? "time" : patched;
|
81898
|
+
patched = patched.startsWith("timestamp(") ? "timestamp" : patched;
|
81899
|
+
patched = patched.startsWith("vector(") ? "vector" : patched;
|
81900
|
+
patched = patched.startsWith("geometry(") ? "geometry" : patched;
|
81901
|
+
return patched;
|
81902
|
+
}).filter((type) => {
|
81903
|
+
return pgImportsList.has(type);
|
81904
|
+
});
|
81905
|
+
imports.pg.push(...columnImports);
|
81906
|
+
});
|
81907
|
+
});
|
80840
81908
|
Object.values(schema5.sequences).forEach((it) => {
|
80841
81909
|
if (it.schema && it.schema !== "public" && it.schema !== "") {
|
80842
81910
|
imports.pg.push("pgSchema");
|
@@ -80931,6 +81999,28 @@ var init_introspect_pg = __esm({
|
|
80931
81999
|
statement += ");";
|
80932
82000
|
return statement;
|
80933
82001
|
});
|
82002
|
+
const viewsStatements = Object.values(schema5.views).map((it) => {
|
82003
|
+
const viewSchema = schemas[it.schema];
|
82004
|
+
const paramName = paramNameFor(it.name, viewSchema);
|
82005
|
+
const func = viewSchema ? it.materialized ? `${viewSchema}.materializedView` : `${viewSchema}.view` : it.materialized ? "pgMaterializedView" : "pgView";
|
82006
|
+
const withOption = it.with ?? "";
|
82007
|
+
const as = `sql\`${it.definition}\``;
|
82008
|
+
const tablespace = it.tablespace ?? "";
|
82009
|
+
const columns = createTableColumns3(
|
82010
|
+
"",
|
82011
|
+
Object.values(it.columns),
|
82012
|
+
[],
|
82013
|
+
enumTypes,
|
82014
|
+
schemas,
|
82015
|
+
casing2,
|
82016
|
+
schema5.internal
|
82017
|
+
);
|
82018
|
+
let statement = `export const ${withCasing2(paramName, casing2)} = ${func}("${it.name}", {${columns}})`;
|
82019
|
+
statement += tablespace ? `.tablespace("${tablespace}")` : "";
|
82020
|
+
statement += withOption ? `.with(${JSON.stringify(withOption)})` : "";
|
82021
|
+
statement += `.as(${as});`;
|
82022
|
+
return statement;
|
82023
|
+
}).join("\n\n");
|
80934
82024
|
const uniquePgImports = ["pgTable", ...new Set(imports.pg)];
|
80935
82025
|
const importsTs = `import { ${uniquePgImports.join(
|
80936
82026
|
", "
|
@@ -80943,6 +82033,8 @@ var init_introspect_pg = __esm({
|
|
80943
82033
|
decalrations += sequencesStatements;
|
80944
82034
|
decalrations += "\n";
|
80945
82035
|
decalrations += tableStatements.join("\n\n");
|
82036
|
+
decalrations += "\n";
|
82037
|
+
decalrations += viewsStatements;
|
80946
82038
|
const file = importsTs + decalrations;
|
80947
82039
|
const schemaEntry = `
|
80948
82040
|
{
|
@@ -81070,49 +82162,49 @@ var init_introspect_pg = __esm({
|
|
81070
82162
|
let out = `${withCasing2(name, casing2)}: ${withCasing2(
|
81071
82163
|
paramNameFor(type.replace("[]", ""), typeSchema),
|
81072
82164
|
casing2
|
81073
|
-
)}(
|
82165
|
+
)}(${dbColumnName3({ name, casing: casing2 })})`;
|
81074
82166
|
return out;
|
81075
82167
|
}
|
81076
82168
|
if (lowered.startsWith("serial")) {
|
81077
|
-
return `${withCasing2(name, casing2)}: serial(
|
82169
|
+
return `${withCasing2(name, casing2)}: serial(${dbColumnName3({ name, casing: casing2 })})`;
|
81078
82170
|
}
|
81079
82171
|
if (lowered.startsWith("smallserial")) {
|
81080
|
-
return `${withCasing2(name, casing2)}: smallserial(
|
82172
|
+
return `${withCasing2(name, casing2)}: smallserial(${dbColumnName3({ name, casing: casing2 })})`;
|
81081
82173
|
}
|
81082
82174
|
if (lowered.startsWith("bigserial")) {
|
81083
82175
|
return `${withCasing2(
|
81084
82176
|
name,
|
81085
82177
|
casing2
|
81086
|
-
)}: bigserial(
|
82178
|
+
)}: bigserial(${dbColumnName3({ name, casing: casing2, withMode: true })}{ mode: "bigint" })`;
|
81087
82179
|
}
|
81088
82180
|
if (lowered.startsWith("integer")) {
|
81089
|
-
let out = `${withCasing2(name, casing2)}: integer(
|
82181
|
+
let out = `${withCasing2(name, casing2)}: integer(${dbColumnName3({ name, casing: casing2 })})`;
|
81090
82182
|
return out;
|
81091
82183
|
}
|
81092
82184
|
if (lowered.startsWith("smallint")) {
|
81093
|
-
let out = `${withCasing2(name, casing2)}: smallint(
|
82185
|
+
let out = `${withCasing2(name, casing2)}: smallint(${dbColumnName3({ name, casing: casing2 })})`;
|
81094
82186
|
return out;
|
81095
82187
|
}
|
81096
82188
|
if (lowered.startsWith("bigint")) {
|
81097
82189
|
let out = `// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
81098
82190
|
`;
|
81099
|
-
out += `${withCasing2(name, casing2)}: bigint(
|
82191
|
+
out += `${withCasing2(name, casing2)}: bigint(${dbColumnName3({ name, casing: casing2, withMode: true })}{ mode: "number" })`;
|
81100
82192
|
return out;
|
81101
82193
|
}
|
81102
82194
|
if (lowered.startsWith("boolean")) {
|
81103
|
-
let out = `${withCasing2(name, casing2)}: boolean(
|
82195
|
+
let out = `${withCasing2(name, casing2)}: boolean(${dbColumnName3({ name, casing: casing2 })})`;
|
81104
82196
|
return out;
|
81105
82197
|
}
|
81106
82198
|
if (lowered.startsWith("double precision")) {
|
81107
|
-
let out = `${withCasing2(name, casing2)}: doublePrecision(
|
82199
|
+
let out = `${withCasing2(name, casing2)}: doublePrecision(${dbColumnName3({ name, casing: casing2 })})`;
|
81108
82200
|
return out;
|
81109
82201
|
}
|
81110
82202
|
if (lowered.startsWith("real")) {
|
81111
|
-
let out = `${withCasing2(name, casing2)}: real(
|
82203
|
+
let out = `${withCasing2(name, casing2)}: real(${dbColumnName3({ name, casing: casing2 })})`;
|
81112
82204
|
return out;
|
81113
82205
|
}
|
81114
82206
|
if (lowered.startsWith("uuid")) {
|
81115
|
-
let out = `${withCasing2(name, casing2)}: uuid(
|
82207
|
+
let out = `${withCasing2(name, casing2)}: uuid(${dbColumnName3({ name, casing: casing2 })})`;
|
81116
82208
|
return out;
|
81117
82209
|
}
|
81118
82210
|
if (lowered.startsWith("numeric")) {
|
@@ -81121,7 +82213,7 @@ var init_introspect_pg = __esm({
|
|
81121
82213
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
81122
82214
|
params = { precision, scale };
|
81123
82215
|
}
|
81124
|
-
let out = params ? `${withCasing2(name, casing2)}: numeric(
|
82216
|
+
let out = params ? `${withCasing2(name, casing2)}: numeric(${dbColumnName3({ name, casing: casing2, withMode: true })}${timeConfig2(params)})` : `${withCasing2(name, casing2)}: numeric(${dbColumnName3({ name, casing: casing2 })})`;
|
81125
82217
|
return out;
|
81126
82218
|
}
|
81127
82219
|
if (lowered.startsWith("timestamp")) {
|
@@ -81135,7 +82227,7 @@ var init_introspect_pg = __esm({
|
|
81135
82227
|
withTimezone,
|
81136
82228
|
mode: "'string'"
|
81137
82229
|
});
|
81138
|
-
let out = params ? `${withCasing2(name, casing2)}: timestamp(
|
82230
|
+
let out = params ? `${withCasing2(name, casing2)}: timestamp(${dbColumnName3({ name, casing: casing2, withMode: true })}${params})` : `${withCasing2(name, casing2)}: timestamp(${dbColumnName3({ name, casing: casing2 })})`;
|
81139
82231
|
return out;
|
81140
82232
|
}
|
81141
82233
|
if (lowered.startsWith("time")) {
|
@@ -81145,44 +82237,44 @@ var init_introspect_pg = __esm({
|
|
81145
82237
|
) : null;
|
81146
82238
|
precision = precision ? precision : null;
|
81147
82239
|
const params = timeConfig2({ precision, withTimezone });
|
81148
|
-
let out = params ? `${withCasing2(name, casing2)}: time(
|
82240
|
+
let out = params ? `${withCasing2(name, casing2)}: time(${dbColumnName3({ name, casing: casing2, withMode: true })}${params})` : `${withCasing2(name, casing2)}: time(${dbColumnName3({ name, casing: casing2 })})`;
|
81149
82241
|
return out;
|
81150
82242
|
}
|
81151
82243
|
if (lowered.startsWith("interval")) {
|
81152
82244
|
const params = intervalConfig(lowered);
|
81153
|
-
let out = params ? `${withCasing2(name, casing2)}: interval(
|
82245
|
+
let out = params ? `${withCasing2(name, casing2)}: interval(${dbColumnName3({ name, casing: casing2, withMode: true })}${params})` : `${withCasing2(name, casing2)}: interval(${dbColumnName3({ name, casing: casing2 })})`;
|
81154
82246
|
return out;
|
81155
82247
|
}
|
81156
82248
|
if (lowered === "date") {
|
81157
|
-
let out = `${withCasing2(name, casing2)}: date(
|
82249
|
+
let out = `${withCasing2(name, casing2)}: date(${dbColumnName3({ name, casing: casing2 })})`;
|
81158
82250
|
return out;
|
81159
82251
|
}
|
81160
82252
|
if (lowered.startsWith("text")) {
|
81161
|
-
let out = `${withCasing2(name, casing2)}: text(
|
82253
|
+
let out = `${withCasing2(name, casing2)}: text(${dbColumnName3({ name, casing: casing2 })})`;
|
81162
82254
|
return out;
|
81163
82255
|
}
|
81164
82256
|
if (lowered.startsWith("jsonb")) {
|
81165
|
-
let out = `${withCasing2(name, casing2)}: jsonb(
|
82257
|
+
let out = `${withCasing2(name, casing2)}: jsonb(${dbColumnName3({ name, casing: casing2 })})`;
|
81166
82258
|
return out;
|
81167
82259
|
}
|
81168
82260
|
if (lowered.startsWith("json")) {
|
81169
|
-
let out = `${withCasing2(name, casing2)}: json(
|
82261
|
+
let out = `${withCasing2(name, casing2)}: json(${dbColumnName3({ name, casing: casing2 })})`;
|
81170
82262
|
return out;
|
81171
82263
|
}
|
81172
82264
|
if (lowered.startsWith("inet")) {
|
81173
|
-
let out = `${withCasing2(name, casing2)}: inet(
|
82265
|
+
let out = `${withCasing2(name, casing2)}: inet(${dbColumnName3({ name, casing: casing2 })})`;
|
81174
82266
|
return out;
|
81175
82267
|
}
|
81176
82268
|
if (lowered.startsWith("cidr")) {
|
81177
|
-
let out = `${withCasing2(name, casing2)}: cidr(
|
82269
|
+
let out = `${withCasing2(name, casing2)}: cidr(${dbColumnName3({ name, casing: casing2 })})`;
|
81178
82270
|
return out;
|
81179
82271
|
}
|
81180
82272
|
if (lowered.startsWith("macaddr8")) {
|
81181
|
-
let out = `${withCasing2(name, casing2)}: macaddr8(
|
82273
|
+
let out = `${withCasing2(name, casing2)}: macaddr8(${dbColumnName3({ name, casing: casing2 })})`;
|
81182
82274
|
return out;
|
81183
82275
|
}
|
81184
82276
|
if (lowered.startsWith("macaddr")) {
|
81185
|
-
let out = `${withCasing2(name, casing2)}: macaddr(
|
82277
|
+
let out = `${withCasing2(name, casing2)}: macaddr(${dbColumnName3({ name, casing: casing2 })})`;
|
81186
82278
|
return out;
|
81187
82279
|
}
|
81188
82280
|
if (lowered.startsWith("varchar")) {
|
@@ -81191,21 +82283,21 @@ var init_introspect_pg = __esm({
|
|
81191
82283
|
out = `${withCasing2(
|
81192
82284
|
name,
|
81193
82285
|
casing2
|
81194
|
-
)}: varchar(
|
82286
|
+
)}: varchar(${dbColumnName3({ name, casing: casing2, withMode: true })}{ length: ${lowered.substring(
|
81195
82287
|
8,
|
81196
82288
|
lowered.length - 1
|
81197
82289
|
)} })`;
|
81198
82290
|
} else {
|
81199
|
-
out = `${withCasing2(name, casing2)}: varchar(
|
82291
|
+
out = `${withCasing2(name, casing2)}: varchar(${dbColumnName3({ name, casing: casing2 })})`;
|
81200
82292
|
}
|
81201
82293
|
return out;
|
81202
82294
|
}
|
81203
82295
|
if (lowered.startsWith("point")) {
|
81204
|
-
let out = `${withCasing2(name, casing2)}: point(
|
82296
|
+
let out = `${withCasing2(name, casing2)}: point(${dbColumnName3({ name, casing: casing2 })})`;
|
81205
82297
|
return out;
|
81206
82298
|
}
|
81207
82299
|
if (lowered.startsWith("line")) {
|
81208
|
-
let out = `${withCasing2(name, casing2)}: point(
|
82300
|
+
let out = `${withCasing2(name, casing2)}: point(${dbColumnName3({ name, casing: casing2 })})`;
|
81209
82301
|
return out;
|
81210
82302
|
}
|
81211
82303
|
if (lowered.startsWith("geometry")) {
|
@@ -81214,14 +82306,14 @@ var init_introspect_pg = __esm({
|
|
81214
82306
|
if (lowered.length !== 8) {
|
81215
82307
|
const geometryOptions = lowered.slice(9, -1).split(",");
|
81216
82308
|
if (geometryOptions.length === 1 && geometryOptions[0] !== "") {
|
81217
|
-
out = `${withCasing2(name, casing2)}: geometry(
|
82309
|
+
out = `${withCasing2(name, casing2)}: geometry(${dbColumnName3({ name, casing: casing2, withMode: true })}{ type: "${geometryOptions[0]}" })`;
|
81218
82310
|
} else if (geometryOptions.length === 2) {
|
81219
|
-
out = `${withCasing2(name, casing2)}: geometry(
|
82311
|
+
out = `${withCasing2(name, casing2)}: geometry(${dbColumnName3({ name, casing: casing2, withMode: true })}{ type: "${geometryOptions[0]}", srid: ${geometryOptions[1]} })`;
|
81220
82312
|
} else {
|
81221
82313
|
isGeoUnknown = true;
|
81222
82314
|
}
|
81223
82315
|
} else {
|
81224
|
-
out = `${withCasing2(name, casing2)}: geometry(
|
82316
|
+
out = `${withCasing2(name, casing2)}: geometry(${dbColumnName3({ name, casing: casing2 })})`;
|
81225
82317
|
}
|
81226
82318
|
if (isGeoUnknown) {
|
81227
82319
|
let unknown2 = `// TODO: failed to parse geometry type because found more than 2 options inside geometry function '${type}'
|
@@ -81238,12 +82330,12 @@ var init_introspect_pg = __esm({
|
|
81238
82330
|
out = `${withCasing2(
|
81239
82331
|
name,
|
81240
82332
|
casing2
|
81241
|
-
)}: vector(
|
82333
|
+
)}: vector(${dbColumnName3({ name, casing: casing2, withMode: true })}{ dimensions: ${lowered.substring(
|
81242
82334
|
7,
|
81243
82335
|
lowered.length - 1
|
81244
82336
|
)} })`;
|
81245
82337
|
} else {
|
81246
|
-
out = `${withCasing2(name, casing2)}: vector(
|
82338
|
+
out = `${withCasing2(name, casing2)}: vector(${dbColumnName3({ name, casing: casing2 })})`;
|
81247
82339
|
}
|
81248
82340
|
return out;
|
81249
82341
|
}
|
@@ -81253,12 +82345,12 @@ var init_introspect_pg = __esm({
|
|
81253
82345
|
out = `${withCasing2(
|
81254
82346
|
name,
|
81255
82347
|
casing2
|
81256
|
-
)}: char(
|
82348
|
+
)}: char(${dbColumnName3({ name, casing: casing2, withMode: true })}{ length: ${lowered.substring(
|
81257
82349
|
5,
|
81258
82350
|
lowered.length - 1
|
81259
82351
|
)} })`;
|
81260
82352
|
} else {
|
81261
|
-
out = `${withCasing2(name, casing2)}: char(
|
82353
|
+
out = `${withCasing2(name, casing2)}: char(${dbColumnName3({ name, casing: casing2 })})`;
|
81262
82354
|
}
|
81263
82355
|
return out;
|
81264
82356
|
}
|
@@ -81501,6 +82593,7 @@ var init_introspect = __esm({
|
|
81501
82593
|
sequencesResolver,
|
81502
82594
|
tablesResolver,
|
81503
82595
|
columnsResolver,
|
82596
|
+
viewsResolver,
|
81504
82597
|
dryPg,
|
81505
82598
|
schema5
|
81506
82599
|
);
|
@@ -85222,7 +86315,7 @@ init_utils2();
|
|
85222
86315
|
var version2 = async () => {
|
85223
86316
|
const { npmVersion } = await ormCoreVersions();
|
85224
86317
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
85225
|
-
const envVersion = "0.25.0-
|
86318
|
+
const envVersion = "0.25.0-a5a41e0";
|
85226
86319
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
85227
86320
|
const versions = `drizzle-kit: ${kitVersion}
|
85228
86321
|
${ormVersion}`;
|