drizzle-kit 0.19.0-c1c76b7 → 0.19.0-f59ce29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +901 -314
- package/index.d.ts +35 -9
- package/package.json +3 -2
- package/readme.md +0 -153
- package/utils.js +9 -5
package/index.cjs
CHANGED
|
@@ -5620,7 +5620,7 @@ var init_mysqlSerializer = __esm({
|
|
|
5620
5620
|
// : undefined,
|
|
5621
5621
|
};
|
|
5622
5622
|
if (column7.default !== void 0) {
|
|
5623
|
-
if (column7.default
|
|
5623
|
+
if ((0, import_drizzle_orm2.is)(column7.default, import_drizzle_orm3.SQL)) {
|
|
5624
5624
|
columnToSet.default = sqlToStr(column7.default);
|
|
5625
5625
|
} else {
|
|
5626
5626
|
if (typeof column7.default === "string") {
|
|
@@ -5682,7 +5682,7 @@ var init_mysqlSerializer = __esm({
|
|
|
5682
5682
|
const columns2 = value.config.columns;
|
|
5683
5683
|
const name = value.config.name;
|
|
5684
5684
|
let indexColumns = columns2.map((it) => {
|
|
5685
|
-
if (it
|
|
5685
|
+
if ((0, import_drizzle_orm2.is)(it, import_drizzle_orm3.SQL)) {
|
|
5686
5686
|
return dialect3.sqlToQuery(it).sql;
|
|
5687
5687
|
} else {
|
|
5688
5688
|
return it.name;
|
|
@@ -6009,7 +6009,7 @@ var init_pgSerializer = __esm({
|
|
|
6009
6009
|
notNull
|
|
6010
6010
|
};
|
|
6011
6011
|
if (column7.default !== void 0) {
|
|
6012
|
-
if (column7.default
|
|
6012
|
+
if ((0, import_drizzle_orm5.is)(column7.default, import_drizzle_orm5.SQL)) {
|
|
6013
6013
|
columnToSet.default = sqlToStr(column7.default);
|
|
6014
6014
|
} else {
|
|
6015
6015
|
if (typeof column7.default === "string") {
|
|
@@ -6072,7 +6072,7 @@ var init_pgSerializer = __esm({
|
|
|
6072
6072
|
columns2.map((it) => it.name)
|
|
6073
6073
|
);
|
|
6074
6074
|
let indexColumns = columns2.map((it) => {
|
|
6075
|
-
if (it
|
|
6075
|
+
if ((0, import_drizzle_orm5.is)(it, import_drizzle_orm5.SQL)) {
|
|
6076
6076
|
return dialect4.sqlToQuery(it).sql;
|
|
6077
6077
|
} else {
|
|
6078
6078
|
return it.name;
|
|
@@ -6105,6 +6105,7 @@ var init_pgSerializer = __esm({
|
|
|
6105
6105
|
const schemasObject = Object.fromEntries(
|
|
6106
6106
|
schemas.filter((it) => it.schemaName !== "public").map((it) => [it.schemaName, it.schemaName])
|
|
6107
6107
|
);
|
|
6108
|
+
console.log(JSON.stringify(result, null, 2));
|
|
6108
6109
|
return {
|
|
6109
6110
|
version: "5",
|
|
6110
6111
|
dialect: "pg",
|
|
@@ -6127,22 +6128,23 @@ var init_pgSerializer = __esm({
|
|
|
6127
6128
|
--end;
|
|
6128
6129
|
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
|
6129
6130
|
};
|
|
6130
|
-
fromDatabase2 = async (db, progressCallback) => {
|
|
6131
|
+
fromDatabase2 = async (db, tablesFilter = (table4) => true, progressCallback) => {
|
|
6131
6132
|
const result = {};
|
|
6132
6133
|
const allTables = await db.query(
|
|
6133
6134
|
`SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema = 'public';`
|
|
6134
6135
|
);
|
|
6135
6136
|
const schemas = new Set(allTables.rows.map((it) => it.table_schema));
|
|
6136
6137
|
schemas.delete("public");
|
|
6137
|
-
if (progressCallback) {
|
|
6138
|
-
progressCallback("tables", allTables.rows.length, "done");
|
|
6139
|
-
}
|
|
6140
6138
|
let columnsCount = 0;
|
|
6141
6139
|
let indexesCount = 0;
|
|
6142
6140
|
let foreignKeysCount = 0;
|
|
6141
|
+
let tableCount = 0;
|
|
6143
6142
|
const all = allTables.rows.map((row) => {
|
|
6144
6143
|
return new Promise(async (res, rej) => {
|
|
6145
6144
|
const tableName = row.table_name;
|
|
6145
|
+
if (!tablesFilter(tableName))
|
|
6146
|
+
return res("");
|
|
6147
|
+
tableCount += 1;
|
|
6146
6148
|
const tableSchema = row.table_schema;
|
|
6147
6149
|
try {
|
|
6148
6150
|
const columnToReturn = {};
|
|
@@ -6350,6 +6352,9 @@ var init_pgSerializer = __esm({
|
|
|
6350
6352
|
res("");
|
|
6351
6353
|
});
|
|
6352
6354
|
});
|
|
6355
|
+
if (progressCallback) {
|
|
6356
|
+
progressCallback("tables", tableCount, "done");
|
|
6357
|
+
}
|
|
6353
6358
|
for await (const _ of all) {
|
|
6354
6359
|
}
|
|
6355
6360
|
if (progressCallback) {
|
|
@@ -6553,10 +6558,10 @@ var init_sqliteSerializer = __esm({
|
|
|
6553
6558
|
type: column7.getSQLType(),
|
|
6554
6559
|
primaryKey,
|
|
6555
6560
|
notNull,
|
|
6556
|
-
autoincrement: column7
|
|
6561
|
+
autoincrement: (0, import_drizzle_orm8.is)(column7, import_sqlite_core2.SQLiteBaseInteger) ? column7.autoIncrement : false
|
|
6557
6562
|
};
|
|
6558
6563
|
if (column7.default !== void 0) {
|
|
6559
|
-
if (column7.default
|
|
6564
|
+
if ((0, import_drizzle_orm8.is)(column7.default, import_drizzle_orm9.SQL)) {
|
|
6560
6565
|
columnToSet.default = sqlToStr(column7.default);
|
|
6561
6566
|
} else {
|
|
6562
6567
|
columnToSet.default = typeof column7.default === "string" ? `'${column7.default}'` : column7.default;
|
|
@@ -6591,7 +6596,7 @@ var init_sqliteSerializer = __esm({
|
|
|
6591
6596
|
const columns2 = value.config.columns;
|
|
6592
6597
|
const name = value.config.name;
|
|
6593
6598
|
let indexColumns = columns2.map((it) => {
|
|
6594
|
-
if (it
|
|
6599
|
+
if ((0, import_drizzle_orm8.is)(it, import_drizzle_orm9.SQL)) {
|
|
6595
6600
|
return dialect5.sqlToQuery(it).sql;
|
|
6596
6601
|
} else {
|
|
6597
6602
|
return it.name;
|
|
@@ -6599,7 +6604,7 @@ var init_sqliteSerializer = __esm({
|
|
|
6599
6604
|
});
|
|
6600
6605
|
let where = void 0;
|
|
6601
6606
|
if (value.config.where !== void 0) {
|
|
6602
|
-
if (value.config.where
|
|
6607
|
+
if ((0, import_drizzle_orm8.is)(value.config.where, import_drizzle_orm9.SQL)) {
|
|
6603
6608
|
where = dialect5.sqlToQuery(value.config.where).sql;
|
|
6604
6609
|
}
|
|
6605
6610
|
}
|
|
@@ -7821,7 +7826,7 @@ var init_words = __esm({
|
|
|
7821
7826
|
"mesmero",
|
|
7822
7827
|
"metal_master",
|
|
7823
7828
|
"meteorite",
|
|
7824
|
-
"
|
|
7829
|
+
"micromacro",
|
|
7825
7830
|
"microbe",
|
|
7826
7831
|
"microchip",
|
|
7827
7832
|
"micromax",
|
|
@@ -8397,7 +8402,7 @@ var init_migrate = __esm({
|
|
|
8397
8402
|
prepareSQLitePush = async (config, snapshot) => {
|
|
8398
8403
|
const schemaPath = config.schema;
|
|
8399
8404
|
try {
|
|
8400
|
-
const { prev, cur } = prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
|
|
8405
|
+
const { prev, cur } = await prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
|
|
8401
8406
|
const validatedPrev = sqliteSchema.parse(prev);
|
|
8402
8407
|
const validatedCur = sqliteSchema.parse(cur);
|
|
8403
8408
|
const squashedPrev = squashSqliteScheme(validatedPrev);
|
|
@@ -8822,7 +8827,7 @@ var init_sqlgenerator = __esm({
|
|
|
8822
8827
|
const primaryKeyStatement = column7.primaryKey ? "PRIMARY KEY" : "";
|
|
8823
8828
|
const notNullStatement = column7.notNull ? "NOT NULL" : "";
|
|
8824
8829
|
const defaultStatement = column7.default !== void 0 ? `DEFAULT ${column7.default}` : "";
|
|
8825
|
-
const type = isPgNativeType(column7.type) ? column7.type :
|
|
8830
|
+
const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
|
|
8826
8831
|
statement += " " + `"${column7.name}" ${type} ${primaryKeyStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim();
|
|
8827
8832
|
statement += (i === columns.length - 1 ? "" : ",") + "\n";
|
|
8828
8833
|
}
|
|
@@ -8986,9 +8991,9 @@ var init_sqlgenerator = __esm({
|
|
|
8986
8991
|
return statement.type === "rename_table" && dialect6 === "pg";
|
|
8987
8992
|
}
|
|
8988
8993
|
convert(statement) {
|
|
8989
|
-
const { tableNameFrom, tableNameTo, toSchema
|
|
8990
|
-
const from =
|
|
8991
|
-
const to =
|
|
8994
|
+
const { tableNameFrom, tableNameTo, toSchema, fromSchema } = statement;
|
|
8995
|
+
const from = fromSchema ? `"${fromSchema}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
|
|
8996
|
+
const to = `"${tableNameTo}"`;
|
|
8992
8997
|
return `ALTER TABLE ${from} RENAME TO ${to};`;
|
|
8993
8998
|
}
|
|
8994
8999
|
};
|
|
@@ -10916,7 +10921,11 @@ var init_snapshotsDiffer = __esm({
|
|
|
10916
10921
|
}).flat();
|
|
10917
10922
|
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
|
10918
10923
|
const schema4 = valueFromSelfOrPatchedNew(it.schema);
|
|
10919
|
-
const forAdded =
|
|
10924
|
+
const forAdded = prepareCreateReferencesJson(
|
|
10925
|
+
it.name,
|
|
10926
|
+
schema4,
|
|
10927
|
+
it.addedForeignKeys
|
|
10928
|
+
);
|
|
10920
10929
|
const forAltered = prepareDropReferencesJson(
|
|
10921
10930
|
it.name,
|
|
10922
10931
|
schema4,
|
|
@@ -28744,7 +28753,7 @@ var require_promise = __commonJS({
|
|
|
28744
28753
|
});
|
|
28745
28754
|
|
|
28746
28755
|
// src/mysql-introspect.ts
|
|
28747
|
-
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
|
|
28756
|
+
var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
|
|
28748
28757
|
var init_mysql_introspect = __esm({
|
|
28749
28758
|
"src/mysql-introspect.ts"() {
|
|
28750
28759
|
init_utils2();
|
|
@@ -28814,7 +28823,16 @@ var init_mysql_introspect = __esm({
|
|
|
28814
28823
|
"timestamp without time zone": "timestamp"
|
|
28815
28824
|
};
|
|
28816
28825
|
relations = /* @__PURE__ */ new Set();
|
|
28817
|
-
|
|
28826
|
+
withCasing = (value, casing) => {
|
|
28827
|
+
if (typeof casing === "undefined") {
|
|
28828
|
+
return value;
|
|
28829
|
+
}
|
|
28830
|
+
if (casing === "camel") {
|
|
28831
|
+
return value.camelCase();
|
|
28832
|
+
}
|
|
28833
|
+
return value;
|
|
28834
|
+
};
|
|
28835
|
+
schemaToTypeScript = (schema4, casing) => {
|
|
28818
28836
|
Object.values(schema4.tables).forEach((table4) => {
|
|
28819
28837
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
|
28820
28838
|
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
|
@@ -28823,7 +28841,7 @@ var init_mysql_introspect = __esm({
|
|
|
28823
28841
|
});
|
|
28824
28842
|
const schemas = Object.fromEntries(
|
|
28825
28843
|
Object.entries(schema4.schemas).map((it) => {
|
|
28826
|
-
return [it[0], it[1]
|
|
28844
|
+
return [it[0], withCasing(it[1], casing)];
|
|
28827
28845
|
})
|
|
28828
28846
|
);
|
|
28829
28847
|
const imports = Object.values(schema4.tables).reduce(
|
|
@@ -28865,16 +28883,20 @@ var init_mysql_introspect = __esm({
|
|
|
28865
28883
|
const schema5 = schemas[table4.schema];
|
|
28866
28884
|
const func = schema5 ? schema5 : "mysqlTable";
|
|
28867
28885
|
let statement = "";
|
|
28868
|
-
if (imports.mysql.includes(table4.name
|
|
28869
|
-
statement = `// Table name is in conflict with ${
|
|
28886
|
+
if (imports.mysql.includes(withCasing(table4.name, casing))) {
|
|
28887
|
+
statement = `// Table name is in conflict with ${withCasing(
|
|
28888
|
+
table4.name,
|
|
28889
|
+
casing
|
|
28890
|
+
)} import.
|
|
28870
28891
|
// Please change to any other name, that is not in imports list
|
|
28871
28892
|
`;
|
|
28872
28893
|
}
|
|
28873
|
-
statement += `export const ${table4.name
|
|
28894
|
+
statement += `export const ${withCasing(table4.name, casing)} = ${func}("${table4.name}", {
|
|
28874
28895
|
`;
|
|
28875
28896
|
statement += createTableColumns(
|
|
28876
28897
|
Object.values(table4.columns),
|
|
28877
|
-
Object.values(table4.foreignKeys)
|
|
28898
|
+
Object.values(table4.foreignKeys),
|
|
28899
|
+
casing
|
|
28878
28900
|
);
|
|
28879
28901
|
statement += "}";
|
|
28880
28902
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
@@ -28884,9 +28906,16 @@ var init_mysql_introspect = __esm({
|
|
|
28884
28906
|
statement += ",\n";
|
|
28885
28907
|
statement += "(table) => {\n";
|
|
28886
28908
|
statement += " return {\n";
|
|
28887
|
-
statement += createTableIndexes(
|
|
28888
|
-
|
|
28889
|
-
|
|
28909
|
+
statement += createTableIndexes(
|
|
28910
|
+
table4.name,
|
|
28911
|
+
Object.values(table4.indexes),
|
|
28912
|
+
casing
|
|
28913
|
+
);
|
|
28914
|
+
statement += createTableFKs(Object.values(filteredFKs), casing);
|
|
28915
|
+
statement += createTablePKs(
|
|
28916
|
+
Object.values(table4.compositePrimaryKeys),
|
|
28917
|
+
casing
|
|
28918
|
+
);
|
|
28890
28919
|
statement += " }\n";
|
|
28891
28920
|
statement += "}";
|
|
28892
28921
|
}
|
|
@@ -28930,46 +28959,49 @@ import { sql } from "drizzle-orm"
|
|
|
28930
28959
|
}
|
|
28931
28960
|
return defaultValue;
|
|
28932
28961
|
};
|
|
28933
|
-
column4 = (type, name, defaultValue, autoincrement, onUpdate) => {
|
|
28962
|
+
column4 = (type, name, defaultValue, autoincrement, onUpdate, casing) => {
|
|
28934
28963
|
let lowered = type;
|
|
28935
28964
|
if (!type.startsWith("enum(")) {
|
|
28936
28965
|
lowered = type.toLowerCase();
|
|
28937
28966
|
}
|
|
28938
28967
|
if (lowered === "serial") {
|
|
28939
|
-
return `${name
|
|
28968
|
+
return `${withCasing(name, casing)}: serial("${name}")`;
|
|
28940
28969
|
}
|
|
28941
28970
|
if (lowered.startsWith("int")) {
|
|
28942
|
-
let out = `${name
|
|
28971
|
+
let out = `${withCasing(name, casing)}: int("${name}")`;
|
|
28943
28972
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28944
28973
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28945
28974
|
return out;
|
|
28946
28975
|
}
|
|
28947
28976
|
if (lowered.startsWith("tinyint")) {
|
|
28948
|
-
let out = `${name
|
|
28977
|
+
let out = `${withCasing(name, casing)}: tinyint("${name}")`;
|
|
28949
28978
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28950
28979
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28951
28980
|
return out;
|
|
28952
28981
|
}
|
|
28953
28982
|
if (lowered.startsWith("smallint")) {
|
|
28954
|
-
let out = `${name
|
|
28983
|
+
let out = `${withCasing(name, casing)}: smallint("${name}")`;
|
|
28955
28984
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28956
28985
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28957
28986
|
return out;
|
|
28958
28987
|
}
|
|
28959
28988
|
if (lowered.startsWith("mediumint")) {
|
|
28960
|
-
let out = `${name
|
|
28989
|
+
let out = `${withCasing(name, casing)}: mediumint("${name}")`;
|
|
28961
28990
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28962
28991
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28963
28992
|
return out;
|
|
28964
28993
|
}
|
|
28965
28994
|
if (lowered.startsWith("bigint")) {
|
|
28966
|
-
let out = `${
|
|
28995
|
+
let out = `${withCasing(
|
|
28996
|
+
name,
|
|
28997
|
+
casing
|
|
28998
|
+
)}: bigint("${name}", { mode: "number" })`;
|
|
28967
28999
|
out += autoincrement ? `.autoincrement()` : "";
|
|
28968
29000
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28969
29001
|
return out;
|
|
28970
29002
|
}
|
|
28971
29003
|
if (lowered === "boolean") {
|
|
28972
|
-
let out = `${name
|
|
29004
|
+
let out = `${withCasing(name, casing)}: boolean("${name}")`;
|
|
28973
29005
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28974
29006
|
return out;
|
|
28975
29007
|
}
|
|
@@ -28979,17 +29011,17 @@ import { sql } from "drizzle-orm"
|
|
|
28979
29011
|
const [precision, scale] = lowered.slice(7, lowered.length - 1).split(",");
|
|
28980
29012
|
params = { precision, scale };
|
|
28981
29013
|
}
|
|
28982
|
-
let out = params ? `${name
|
|
29014
|
+
let out = params ? `${withCasing(name, casing)}: double("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: double("${name}")`;
|
|
28983
29015
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28984
29016
|
return out;
|
|
28985
29017
|
}
|
|
28986
29018
|
if (lowered === "float") {
|
|
28987
|
-
let out = `${name
|
|
29019
|
+
let out = `${withCasing(name, casing)}: float("${name}")`;
|
|
28988
29020
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28989
29021
|
return out;
|
|
28990
29022
|
}
|
|
28991
29023
|
if (lowered === "real") {
|
|
28992
|
-
let out = `${name
|
|
29024
|
+
let out = `${withCasing(name, casing)}: real("${name}")`;
|
|
28993
29025
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
28994
29026
|
return out;
|
|
28995
29027
|
}
|
|
@@ -28998,7 +29030,7 @@ import { sql } from "drizzle-orm"
|
|
|
28998
29030
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
|
28999
29031
|
fsp = fsp ? fsp : null;
|
|
29000
29032
|
const params = timeConfig({ fsp, mode: "'string'" });
|
|
29001
|
-
let out = params ? `${name
|
|
29033
|
+
let out = params ? `${withCasing(name, casing)}: timestamp("${name}", ${params})` : `${withCasing(name, casing)}: timestamp("${name}")`;
|
|
29002
29034
|
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29003
29035
|
out += defaultValue;
|
|
29004
29036
|
let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
|
|
@@ -29010,50 +29042,56 @@ import { sql } from "drizzle-orm"
|
|
|
29010
29042
|
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
|
29011
29043
|
fsp = fsp ? fsp : null;
|
|
29012
29044
|
const params = timeConfig({ fsp });
|
|
29013
|
-
let out = params ? `${name
|
|
29045
|
+
let out = params ? `${withCasing(name, casing)}: time("${name}", ${params})` : `${withCasing(name, casing)}: time("${name}")`;
|
|
29014
29046
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29015
29047
|
out += defaultValue;
|
|
29016
29048
|
return out;
|
|
29017
29049
|
}
|
|
29018
29050
|
if (lowered === "date") {
|
|
29019
29051
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
|
29020
|
-
${
|
|
29052
|
+
${withCasing(
|
|
29053
|
+
name,
|
|
29054
|
+
casing
|
|
29055
|
+
)}: date("${name}", { mode: 'string' })`;
|
|
29021
29056
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29022
29057
|
out += defaultValue;
|
|
29023
29058
|
return out;
|
|
29024
29059
|
}
|
|
29025
29060
|
if (lowered === "text") {
|
|
29026
|
-
let out = `${name
|
|
29061
|
+
let out = `${withCasing(name, casing)}: text("${name}")`;
|
|
29027
29062
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29028
29063
|
return out;
|
|
29029
29064
|
}
|
|
29030
29065
|
if (lowered === "tinytext") {
|
|
29031
|
-
let out = `${name
|
|
29066
|
+
let out = `${withCasing(name, casing)}: tinytext("${name}")`;
|
|
29032
29067
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29033
29068
|
return out;
|
|
29034
29069
|
}
|
|
29035
29070
|
if (lowered === "mediumtext") {
|
|
29036
|
-
let out = `${name
|
|
29071
|
+
let out = `${withCasing(name, casing)}: mediumtext("${name}")`;
|
|
29037
29072
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29038
29073
|
return out;
|
|
29039
29074
|
}
|
|
29040
29075
|
if (lowered === "longtext") {
|
|
29041
|
-
let out = `${name
|
|
29076
|
+
let out = `${withCasing(name, casing)}: longtext("${name}")`;
|
|
29042
29077
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29043
29078
|
return out;
|
|
29044
29079
|
}
|
|
29045
29080
|
if (lowered === "year") {
|
|
29046
|
-
let out = `${name
|
|
29081
|
+
let out = `${withCasing(name, casing)}: year("${name}")`;
|
|
29047
29082
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29048
29083
|
return out;
|
|
29049
29084
|
}
|
|
29050
29085
|
if (lowered === "json") {
|
|
29051
|
-
let out = `${name
|
|
29086
|
+
let out = `${withCasing(name, casing)}: json("${name}")`;
|
|
29052
29087
|
out += defaultValue ? `.default(${mapColumnDefaultForJson(defaultValue)})` : "";
|
|
29053
29088
|
return out;
|
|
29054
29089
|
}
|
|
29055
29090
|
if (lowered.startsWith("varchar")) {
|
|
29056
|
-
let out = `${
|
|
29091
|
+
let out = `${withCasing(
|
|
29092
|
+
name,
|
|
29093
|
+
casing
|
|
29094
|
+
)}: varchar("${name}", { length: ${lowered.substring(
|
|
29057
29095
|
"varchar".length + 1,
|
|
29058
29096
|
lowered.length - 1
|
|
29059
29097
|
)} })`;
|
|
@@ -29061,7 +29099,10 @@ import { sql } from "drizzle-orm"
|
|
|
29061
29099
|
return out;
|
|
29062
29100
|
}
|
|
29063
29101
|
if (lowered.startsWith("char")) {
|
|
29064
|
-
let out = `${
|
|
29102
|
+
let out = `${withCasing(
|
|
29103
|
+
name,
|
|
29104
|
+
casing
|
|
29105
|
+
)}: char("${name}", { length: ${lowered.substring(
|
|
29065
29106
|
"char".length + 1,
|
|
29066
29107
|
lowered.length - 1
|
|
29067
29108
|
)} })`;
|
|
@@ -29072,10 +29113,13 @@ import { sql } from "drizzle-orm"
|
|
|
29072
29113
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
|
29073
29114
|
`;
|
|
29074
29115
|
const fsp = lowered.startsWith("datetime(") ? lowered.substring("datetime".length + 1, lowered.length - 1) : void 0;
|
|
29075
|
-
out = fsp ? `${
|
|
29116
|
+
out = fsp ? `${withCasing(
|
|
29117
|
+
name,
|
|
29118
|
+
casing
|
|
29119
|
+
)}: datetime("${name}", { mode: 'string', fsp: ${lowered.substring(
|
|
29076
29120
|
"datetime".length + 1,
|
|
29077
29121
|
lowered.length - 1
|
|
29078
|
-
)} })` : `${name
|
|
29122
|
+
)} })` : `${withCasing(name, casing)}: datetime("${name}", { mode: 'string'})`;
|
|
29079
29123
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29080
29124
|
out += defaultValue;
|
|
29081
29125
|
return out;
|
|
@@ -29086,7 +29130,7 @@ import { sql } from "drizzle-orm"
|
|
|
29086
29130
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
|
29087
29131
|
params = { precision, scale };
|
|
29088
29132
|
}
|
|
29089
|
-
let out = params ? `${name
|
|
29133
|
+
let out = params ? `${withCasing(name, casing)}: decimal("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: decimal("${name}")`;
|
|
29090
29134
|
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29091
29135
|
out += defaultValue;
|
|
29092
29136
|
return out;
|
|
@@ -29096,14 +29140,14 @@ import { sql } from "drizzle-orm"
|
|
|
29096
29140
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
|
29097
29141
|
length = length ? length : null;
|
|
29098
29142
|
const params = binaryConfig({ length });
|
|
29099
|
-
let out = params ? `${name
|
|
29143
|
+
let out = params ? `${withCasing(name, casing)}: binary("${name}", ${params})` : `${withCasing(name, casing)}: binary("${name}")`;
|
|
29100
29144
|
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29101
29145
|
out += defaultValue;
|
|
29102
29146
|
return out;
|
|
29103
29147
|
}
|
|
29104
29148
|
if (lowered.startsWith("enum")) {
|
|
29105
29149
|
const values = lowered.substring("enum".length + 1, lowered.length - 1);
|
|
29106
|
-
let out = `${name
|
|
29150
|
+
let out = `${withCasing(name, casing)}: mysqlEnum("${name}", [${values}])`;
|
|
29107
29151
|
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29108
29152
|
return out;
|
|
29109
29153
|
}
|
|
@@ -29112,7 +29156,7 @@ import { sql } from "drizzle-orm"
|
|
|
29112
29156
|
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
|
29113
29157
|
length = length ? length : null;
|
|
29114
29158
|
const params = binaryConfig({ length });
|
|
29115
|
-
let out = params ? `${name
|
|
29159
|
+
let out = params ? `${withCasing(name, casing)}: varbinary("${name}", ${params})` : `${withCasing(name, casing)}: varbinary("${name}")`;
|
|
29116
29160
|
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
29117
29161
|
out += defaultValue;
|
|
29118
29162
|
return out;
|
|
@@ -29121,7 +29165,7 @@ import { sql } from "drizzle-orm"
|
|
|
29121
29165
|
return `// Warning: Can't parse ${type} from database
|
|
29122
29166
|
// ${type}Type: ${type}("${name}")`;
|
|
29123
29167
|
};
|
|
29124
|
-
createTableColumns = (columns, fks) => {
|
|
29168
|
+
createTableColumns = (columns, fks, casing) => {
|
|
29125
29169
|
let statement = "";
|
|
29126
29170
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
|
29127
29171
|
return !isSelf(it);
|
|
@@ -29139,7 +29183,8 @@ import { sql } from "drizzle-orm"
|
|
|
29139
29183
|
it.name,
|
|
29140
29184
|
it.default,
|
|
29141
29185
|
it.autoincrement,
|
|
29142
|
-
it.onUpdate
|
|
29186
|
+
it.onUpdate,
|
|
29187
|
+
casing
|
|
29143
29188
|
);
|
|
29144
29189
|
statement += it.primaryKey ? ".primaryKey()" : "";
|
|
29145
29190
|
statement += it.notNull ? ".notNull()" : "";
|
|
@@ -29152,9 +29197,15 @@ import { sql } from "drizzle-orm"
|
|
|
29152
29197
|
const typeSuffix = isCyclic(it2) ? ": AnyMySqlColumn" : "";
|
|
29153
29198
|
const paramsStr = objToStatement2(params);
|
|
29154
29199
|
if (paramsStr) {
|
|
29155
|
-
return `.references(()${typeSuffix} => ${
|
|
29156
|
-
|
|
29157
|
-
|
|
29200
|
+
return `.references(()${typeSuffix} => ${withCasing(
|
|
29201
|
+
it2.tableTo,
|
|
29202
|
+
casing
|
|
29203
|
+
)}.${withCasing(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
|
29204
|
+
}
|
|
29205
|
+
return `.references(()${typeSuffix} => ${withCasing(
|
|
29206
|
+
it2.tableTo,
|
|
29207
|
+
casing
|
|
29208
|
+
)}.${withCasing(it2.columnsTo[0], casing)})`;
|
|
29158
29209
|
}).join("");
|
|
29159
29210
|
statement += fksStatement;
|
|
29160
29211
|
}
|
|
@@ -29162,31 +29213,31 @@ import { sql } from "drizzle-orm"
|
|
|
29162
29213
|
});
|
|
29163
29214
|
return statement;
|
|
29164
29215
|
};
|
|
29165
|
-
createTableIndexes = (tableName, idxs) => {
|
|
29216
|
+
createTableIndexes = (tableName, idxs, casing) => {
|
|
29166
29217
|
let statement = "";
|
|
29167
29218
|
idxs.forEach((it) => {
|
|
29168
29219
|
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
|
29169
29220
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
|
29170
|
-
idxKey = idxKey
|
|
29221
|
+
idxKey = withCasing(idxKey, casing);
|
|
29171
29222
|
const indexGeneratedName = indexName(tableName, it.columns);
|
|
29172
29223
|
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
|
29173
29224
|
statement += ` ${idxKey}: `;
|
|
29174
29225
|
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
|
29175
29226
|
statement += `${escapedIndexName})`;
|
|
29176
|
-
statement += `.on(${it.columns.map((it2) => `table.${it2
|
|
29227
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
|
|
29177
29228
|
statement += `
|
|
29178
29229
|
`;
|
|
29179
29230
|
});
|
|
29180
29231
|
return statement;
|
|
29181
29232
|
};
|
|
29182
|
-
createTablePKs = (pks) => {
|
|
29233
|
+
createTablePKs = (pks, casing) => {
|
|
29183
29234
|
let statement = "";
|
|
29184
29235
|
pks.forEach((it) => {
|
|
29185
|
-
let idxKey = it.name
|
|
29236
|
+
let idxKey = withCasing(it.name, casing);
|
|
29186
29237
|
statement += ` ${idxKey}: `;
|
|
29187
29238
|
statement += "primaryKey(";
|
|
29188
29239
|
statement += `${it.columns.map((c) => {
|
|
29189
|
-
return `table.${c
|
|
29240
|
+
return `table.${withCasing(c, casing)}`;
|
|
29190
29241
|
}).join(", ")}`;
|
|
29191
29242
|
statement += ")";
|
|
29192
29243
|
statement += `
|
|
@@ -29194,16 +29245,16 @@ import { sql } from "drizzle-orm"
|
|
|
29194
29245
|
});
|
|
29195
29246
|
return statement;
|
|
29196
29247
|
};
|
|
29197
|
-
createTableFKs = (fks) => {
|
|
29248
|
+
createTableFKs = (fks, casing) => {
|
|
29198
29249
|
let statement = "";
|
|
29199
29250
|
fks.forEach((it) => {
|
|
29200
29251
|
const isSelf4 = it.tableTo === it.tableFrom;
|
|
29201
|
-
const tableTo = isSelf4 ? "table" : `${it.tableTo
|
|
29202
|
-
statement += ` ${it.name
|
|
29252
|
+
const tableTo = isSelf4 ? "table" : `${withCasing(it.tableTo, casing)}`;
|
|
29253
|
+
statement += ` ${withCasing(it.name, casing)}: foreignKey({
|
|
29203
29254
|
`;
|
|
29204
|
-
statement += ` columns: [${it.columnsFrom.map((i) => `table.${i
|
|
29255
|
+
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing(i, casing)}`).join(", ")}],
|
|
29205
29256
|
`;
|
|
29206
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i
|
|
29257
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing(i, casing)}`).join(", ")}]
|
|
29207
29258
|
`;
|
|
29208
29259
|
statement += ` })`;
|
|
29209
29260
|
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
|
@@ -30516,15 +30567,21 @@ var init_mysqlIntrospect = __esm({
|
|
|
30516
30567
|
connectToMySQL = async (config) => {
|
|
30517
30568
|
let client;
|
|
30518
30569
|
let databaseName;
|
|
30519
|
-
if ("
|
|
30520
|
-
const connection = config.connectionString;
|
|
30570
|
+
if (config.dbCredentials.type === "url") {
|
|
30571
|
+
const connection = config.dbCredentials.connectionString;
|
|
30521
30572
|
client = await (0, import_promise.createConnection)(connection);
|
|
30522
30573
|
const connectionUrl = new URL(connection);
|
|
30523
30574
|
const pathname = connectionUrl.pathname;
|
|
30524
30575
|
databaseName = pathname.split("/")[pathname.split("/").length - 1];
|
|
30525
|
-
|
|
30526
|
-
|
|
30527
|
-
|
|
30576
|
+
if (!databaseName || databaseName === "") {
|
|
30577
|
+
throw Error(
|
|
30578
|
+
"You should specify a database name in connection string (mysql://USER:PASSWORD@HOST:PORT/DATABASE)"
|
|
30579
|
+
);
|
|
30580
|
+
}
|
|
30581
|
+
} else if (config.dbCredentials.type === "params") {
|
|
30582
|
+
const { type, ...creds } = config.dbCredentials;
|
|
30583
|
+
client = await (0, import_promise.createConnection)(creds);
|
|
30584
|
+
databaseName = creds.database;
|
|
30528
30585
|
} else {
|
|
30529
30586
|
throw Error(
|
|
30530
30587
|
"Either `connectionString` or `host, port, etc.` params be provided in config file"
|
|
@@ -30533,22 +30590,35 @@ var init_mysqlIntrospect = __esm({
|
|
|
30533
30590
|
await client.connect();
|
|
30534
30591
|
return { client, databaseName };
|
|
30535
30592
|
};
|
|
30536
|
-
mysqlIntrospect = async (config) => {
|
|
30593
|
+
mysqlIntrospect = async (config, filters) => {
|
|
30537
30594
|
const { client, databaseName } = await connectToMySQL(config);
|
|
30595
|
+
const matchers = filters.map((it) => {
|
|
30596
|
+
return new Minimatch(it);
|
|
30597
|
+
});
|
|
30598
|
+
const filter2 = (tableName) => {
|
|
30599
|
+
if (matchers.length === 0)
|
|
30600
|
+
return true;
|
|
30601
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
30602
|
+
const matcher = matchers[i];
|
|
30603
|
+
if (matcher.match(tableName))
|
|
30604
|
+
return true;
|
|
30605
|
+
}
|
|
30606
|
+
return false;
|
|
30607
|
+
};
|
|
30538
30608
|
const progress = new IntrospectProgress();
|
|
30539
30609
|
const res = await (0, import_hanji5.renderWithTask)(
|
|
30540
30610
|
progress,
|
|
30541
30611
|
fromDatabase(
|
|
30542
30612
|
client,
|
|
30543
30613
|
databaseName,
|
|
30544
|
-
|
|
30614
|
+
filter2,
|
|
30545
30615
|
(stage, count, status) => {
|
|
30546
30616
|
progress.update(stage, count, status);
|
|
30547
30617
|
}
|
|
30548
30618
|
)
|
|
30549
30619
|
);
|
|
30550
30620
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
30551
|
-
const ts = schemaToTypeScript(schema4);
|
|
30621
|
+
const ts = schemaToTypeScript(schema4, config.introspect.casing);
|
|
30552
30622
|
return { schema: schema4, ts };
|
|
30553
30623
|
};
|
|
30554
30624
|
mysqlPushIntrospect = async (connection, filters) => {
|
|
@@ -30574,7 +30644,7 @@ var init_mysqlIntrospect = __esm({
|
|
|
30574
30644
|
});
|
|
30575
30645
|
|
|
30576
30646
|
// src/sqlite-introspect.ts
|
|
30577
|
-
var sqliteImportsList, indexName3, objToStatement22, relations2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
|
|
30647
|
+
var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
|
|
30578
30648
|
var init_sqlite_introspect = __esm({
|
|
30579
30649
|
"src/sqlite-introspect.ts"() {
|
|
30580
30650
|
init_utils2();
|
|
@@ -30600,7 +30670,16 @@ var init_sqlite_introspect = __esm({
|
|
|
30600
30670
|
return statement;
|
|
30601
30671
|
};
|
|
30602
30672
|
relations2 = /* @__PURE__ */ new Set();
|
|
30603
|
-
|
|
30673
|
+
withCasing2 = (value, casing) => {
|
|
30674
|
+
if (typeof casing === "undefined") {
|
|
30675
|
+
return value;
|
|
30676
|
+
}
|
|
30677
|
+
if (casing === "camel") {
|
|
30678
|
+
return value.camelCase();
|
|
30679
|
+
}
|
|
30680
|
+
return value;
|
|
30681
|
+
};
|
|
30682
|
+
schemaToTypeScript2 = (schema4, casing) => {
|
|
30604
30683
|
Object.values(schema4.tables).forEach((table4) => {
|
|
30605
30684
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
|
30606
30685
|
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
|
@@ -30632,16 +30711,20 @@ var init_sqlite_introspect = __esm({
|
|
|
30632
30711
|
const tableStatements = Object.values(schema4.tables).map((table4) => {
|
|
30633
30712
|
const func = "sqliteTable";
|
|
30634
30713
|
let statement = "";
|
|
30635
|
-
if (imports.sqlite.includes(table4.name
|
|
30636
|
-
statement = `// Table name is in conflict with ${
|
|
30714
|
+
if (imports.sqlite.includes(withCasing2(table4.name, casing))) {
|
|
30715
|
+
statement = `// Table name is in conflict with ${withCasing2(
|
|
30716
|
+
table4.name,
|
|
30717
|
+
casing
|
|
30718
|
+
)} import.
|
|
30637
30719
|
// Please change to any other name, that is not in imports list
|
|
30638
30720
|
`;
|
|
30639
30721
|
}
|
|
30640
|
-
statement += `export const ${table4.name
|
|
30722
|
+
statement += `export const ${withCasing2(table4.name, casing)} = ${func}("${table4.name}", {
|
|
30641
30723
|
`;
|
|
30642
30724
|
statement += createTableColumns2(
|
|
30643
30725
|
Object.values(table4.columns),
|
|
30644
|
-
Object.values(table4.foreignKeys)
|
|
30726
|
+
Object.values(table4.foreignKeys),
|
|
30727
|
+
casing
|
|
30645
30728
|
);
|
|
30646
30729
|
statement += "}";
|
|
30647
30730
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
@@ -30651,9 +30734,16 @@ var init_sqlite_introspect = __esm({
|
|
|
30651
30734
|
statement += ",\n";
|
|
30652
30735
|
statement += "(table) => {\n";
|
|
30653
30736
|
statement += " return {\n";
|
|
30654
|
-
statement += createTableIndexes2(
|
|
30655
|
-
|
|
30656
|
-
|
|
30737
|
+
statement += createTableIndexes2(
|
|
30738
|
+
table4.name,
|
|
30739
|
+
Object.values(table4.indexes),
|
|
30740
|
+
casing
|
|
30741
|
+
);
|
|
30742
|
+
statement += createTableFKs2(Object.values(filteredFKs), casing);
|
|
30743
|
+
statement += createTablePKs2(
|
|
30744
|
+
Object.values(table4.compositePrimaryKeys),
|
|
30745
|
+
casing
|
|
30746
|
+
);
|
|
30657
30747
|
statement += " }\n";
|
|
30658
30748
|
statement += "}";
|
|
30659
30749
|
}
|
|
@@ -30689,37 +30779,37 @@ import { sql } from "drizzle-orm"
|
|
|
30689
30779
|
}
|
|
30690
30780
|
return defaultValue;
|
|
30691
30781
|
};
|
|
30692
|
-
column5 = (type, name, defaultValue, autoincrement,
|
|
30782
|
+
column5 = (type, name, defaultValue, autoincrement, casing) => {
|
|
30693
30783
|
let lowered = type;
|
|
30694
30784
|
if (lowered.startsWith("integer")) {
|
|
30695
|
-
let out = `${name
|
|
30785
|
+
let out = `${withCasing2(name, casing)}: integer("${name}")`;
|
|
30696
30786
|
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
30697
30787
|
return out;
|
|
30698
30788
|
}
|
|
30699
30789
|
if (lowered === "real") {
|
|
30700
|
-
let out = `${name
|
|
30790
|
+
let out = `${withCasing2(name, casing)}: real("${name}")`;
|
|
30701
30791
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
30702
30792
|
return out;
|
|
30703
30793
|
}
|
|
30704
30794
|
if (lowered === "text") {
|
|
30705
|
-
let out = `${name
|
|
30795
|
+
let out = `${withCasing2(name, casing)}: text("${name}")`;
|
|
30706
30796
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
30707
30797
|
return out;
|
|
30708
30798
|
}
|
|
30709
30799
|
if (lowered === "blob") {
|
|
30710
|
-
let out = `${name
|
|
30800
|
+
let out = `${withCasing2(name, casing)}: blob("${name}")`;
|
|
30711
30801
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
30712
30802
|
return out;
|
|
30713
30803
|
}
|
|
30714
30804
|
if (lowered === "numeric") {
|
|
30715
|
-
let out = `${name
|
|
30805
|
+
let out = `${withCasing2(name, casing)}: numeric("${name}")`;
|
|
30716
30806
|
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
|
|
30717
30807
|
return out;
|
|
30718
30808
|
}
|
|
30719
30809
|
return `// Warning: Can't parse ${type} from database
|
|
30720
30810
|
// ${type}Type: ${type}("${name}")`;
|
|
30721
30811
|
};
|
|
30722
|
-
createTableColumns2 = (columns, fks) => {
|
|
30812
|
+
createTableColumns2 = (columns, fks, casing) => {
|
|
30723
30813
|
let statement = "";
|
|
30724
30814
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
|
30725
30815
|
return !isSelf2(it);
|
|
@@ -30732,7 +30822,7 @@ import { sql } from "drizzle-orm"
|
|
|
30732
30822
|
}, {});
|
|
30733
30823
|
columns.forEach((it) => {
|
|
30734
30824
|
statement += " ";
|
|
30735
|
-
statement += column5(it.type, it.name, it.default, it.autoincrement);
|
|
30825
|
+
statement += column5(it.type, it.name, it.default, it.autoincrement, casing);
|
|
30736
30826
|
statement += it.primaryKey ? `.primaryKey(${it.autoincrement ? "{ autoIncrement: true }" : ""})` : "";
|
|
30737
30827
|
statement += it.notNull ? ".notNull()" : "";
|
|
30738
30828
|
const fks2 = fkByColumnName[it.name];
|
|
@@ -30744,9 +30834,15 @@ import { sql } from "drizzle-orm"
|
|
|
30744
30834
|
const typeSuffix = isCyclic2(it2) ? ": AnySQLiteColumn" : "";
|
|
30745
30835
|
const paramsStr = objToStatement22(params);
|
|
30746
30836
|
if (paramsStr) {
|
|
30747
|
-
return `.references(()${typeSuffix} => ${
|
|
30748
|
-
|
|
30749
|
-
|
|
30837
|
+
return `.references(()${typeSuffix} => ${withCasing2(
|
|
30838
|
+
it2.tableTo,
|
|
30839
|
+
casing
|
|
30840
|
+
)}.${withCasing2(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
|
30841
|
+
}
|
|
30842
|
+
return `.references(()${typeSuffix} => ${withCasing2(
|
|
30843
|
+
it2.tableTo,
|
|
30844
|
+
casing
|
|
30845
|
+
)}.${withCasing2(it2.columnsTo[0], casing)})`;
|
|
30750
30846
|
}).join("");
|
|
30751
30847
|
statement += fksStatement;
|
|
30752
30848
|
}
|
|
@@ -30754,30 +30850,30 @@ import { sql } from "drizzle-orm"
|
|
|
30754
30850
|
});
|
|
30755
30851
|
return statement;
|
|
30756
30852
|
};
|
|
30757
|
-
createTableIndexes2 = (tableName, idxs) => {
|
|
30853
|
+
createTableIndexes2 = (tableName, idxs, casing) => {
|
|
30758
30854
|
let statement = "";
|
|
30759
30855
|
idxs.forEach((it) => {
|
|
30760
30856
|
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
|
30761
30857
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
|
30762
|
-
idxKey = idxKey
|
|
30858
|
+
idxKey = withCasing2(idxKey, casing);
|
|
30763
30859
|
const indexGeneratedName = indexName3(tableName, it.columns);
|
|
30764
30860
|
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
|
30765
30861
|
statement += ` ${idxKey}: `;
|
|
30766
30862
|
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
|
30767
30863
|
statement += `${escapedIndexName})`;
|
|
30768
|
-
statement += `.on(${it.columns.map((it2) => `table.${it2
|
|
30864
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
|
|
30769
30865
|
statement += `
|
|
30770
30866
|
`;
|
|
30771
30867
|
});
|
|
30772
30868
|
return statement;
|
|
30773
30869
|
};
|
|
30774
|
-
createTablePKs2 = (pks) => {
|
|
30870
|
+
createTablePKs2 = (pks, casing) => {
|
|
30775
30871
|
let statement = "";
|
|
30776
30872
|
pks.forEach((it, i) => {
|
|
30777
30873
|
statement += ` pk${i}: `;
|
|
30778
30874
|
statement += "primaryKey(";
|
|
30779
30875
|
statement += `${it.columns.map((c) => {
|
|
30780
|
-
return `table.${c
|
|
30876
|
+
return `table.${withCasing2(c, casing)}`;
|
|
30781
30877
|
}).join(", ")}`;
|
|
30782
30878
|
statement += ")";
|
|
30783
30879
|
statement += `
|
|
@@ -30785,16 +30881,16 @@ import { sql } from "drizzle-orm"
|
|
|
30785
30881
|
});
|
|
30786
30882
|
return statement;
|
|
30787
30883
|
};
|
|
30788
|
-
createTableFKs2 = (fks) => {
|
|
30884
|
+
createTableFKs2 = (fks, casing) => {
|
|
30789
30885
|
let statement = "";
|
|
30790
30886
|
fks.forEach((it) => {
|
|
30791
30887
|
const isSelf4 = it.tableTo === it.tableFrom;
|
|
30792
|
-
const tableTo = isSelf4 ? "table" : `${it.tableTo
|
|
30793
|
-
statement += ` ${it.name
|
|
30888
|
+
const tableTo = isSelf4 ? "table" : `${withCasing2(it.tableTo, casing)}`;
|
|
30889
|
+
statement += ` ${withCasing2(it.name, casing)}: foreignKey(() => ({
|
|
30794
30890
|
`;
|
|
30795
|
-
statement += ` columns: [${it.columnsFrom.map((i) => `table.${i
|
|
30891
|
+
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing2(i, casing)}`).join(", ")}],
|
|
30796
30892
|
`;
|
|
30797
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i
|
|
30893
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing2(i, casing)}`).join(", ")}]
|
|
30798
30894
|
`;
|
|
30799
30895
|
statement += ` }))`;
|
|
30800
30896
|
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
|
@@ -39411,21 +39507,34 @@ var init_sqliteIntrospect = __esm({
|
|
|
39411
39507
|
}
|
|
39412
39508
|
return {};
|
|
39413
39509
|
};
|
|
39414
|
-
sqliteIntrospect = async (config) => {
|
|
39510
|
+
sqliteIntrospect = async (config, filters) => {
|
|
39415
39511
|
const { client } = await connectToSQLite(config);
|
|
39512
|
+
const matchers = filters.map((it) => {
|
|
39513
|
+
return new Minimatch(it);
|
|
39514
|
+
});
|
|
39515
|
+
const filter2 = (tableName) => {
|
|
39516
|
+
if (matchers.length === 0)
|
|
39517
|
+
return true;
|
|
39518
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
39519
|
+
const matcher = matchers[i];
|
|
39520
|
+
if (matcher.match(tableName))
|
|
39521
|
+
return true;
|
|
39522
|
+
}
|
|
39523
|
+
return false;
|
|
39524
|
+
};
|
|
39416
39525
|
const progress = new IntrospectProgress();
|
|
39417
39526
|
const res = await (0, import_hanji6.renderWithTask)(
|
|
39418
39527
|
progress,
|
|
39419
39528
|
fromDatabase3(
|
|
39420
39529
|
client,
|
|
39421
|
-
|
|
39530
|
+
filter2,
|
|
39422
39531
|
(stage, count, status) => {
|
|
39423
39532
|
progress.update(stage, count, status);
|
|
39424
39533
|
}
|
|
39425
39534
|
)
|
|
39426
39535
|
);
|
|
39427
39536
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
39428
|
-
const ts = schemaToTypeScript2(schema4);
|
|
39537
|
+
const ts = schemaToTypeScript2(schema4, config.introspect.casing);
|
|
39429
39538
|
return { schema: schema4, ts };
|
|
39430
39539
|
};
|
|
39431
39540
|
sqlitePushIntrospect = async (client, filters) => {
|
|
@@ -41088,50 +41197,47 @@ var require_type_overrides = __commonJS({
|
|
|
41088
41197
|
}
|
|
41089
41198
|
});
|
|
41090
41199
|
|
|
41091
|
-
// node_modules/.pnpm/pg-connection-string@2.
|
|
41200
|
+
// node_modules/.pnpm/pg-connection-string@2.6.0/node_modules/pg-connection-string/index.js
|
|
41092
41201
|
var require_pg_connection_string = __commonJS({
|
|
41093
|
-
"node_modules/.pnpm/pg-connection-string@2.
|
|
41202
|
+
"node_modules/.pnpm/pg-connection-string@2.6.0/node_modules/pg-connection-string/index.js"(exports, module2) {
|
|
41094
41203
|
"use strict";
|
|
41095
|
-
var url = require("url");
|
|
41096
|
-
var fs6 = require("fs");
|
|
41097
41204
|
function parse(str) {
|
|
41098
41205
|
if (str.charAt(0) === "/") {
|
|
41099
|
-
|
|
41100
|
-
return { host:
|
|
41206
|
+
const config2 = str.split(" ");
|
|
41207
|
+
return { host: config2[0], database: config2[1] };
|
|
41101
41208
|
}
|
|
41102
|
-
|
|
41103
|
-
|
|
41104
|
-
|
|
41105
|
-
)
|
|
41106
|
-
|
|
41107
|
-
|
|
41108
|
-
|
|
41109
|
-
|
|
41110
|
-
|
|
41209
|
+
const config = {};
|
|
41210
|
+
let result;
|
|
41211
|
+
let dummyHost = false;
|
|
41212
|
+
if (/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {
|
|
41213
|
+
str = encodeURI(str).replace(/\%25(\d\d)/g, "%$1");
|
|
41214
|
+
}
|
|
41215
|
+
try {
|
|
41216
|
+
result = new URL(str, "postgres://base");
|
|
41217
|
+
} catch (e) {
|
|
41218
|
+
result = new URL(str.replace("@/", "@___DUMMY___/"), "postgres://base");
|
|
41219
|
+
dummyHost = true;
|
|
41111
41220
|
}
|
|
41112
|
-
|
|
41113
|
-
|
|
41114
|
-
|
|
41221
|
+
for (const entry of result.searchParams.entries()) {
|
|
41222
|
+
config[entry[0]] = entry[1];
|
|
41223
|
+
}
|
|
41224
|
+
config.user = config.user || decodeURIComponent(result.username);
|
|
41225
|
+
config.password = config.password || decodeURIComponent(result.password);
|
|
41115
41226
|
config.port = result.port;
|
|
41116
41227
|
if (result.protocol == "socket:") {
|
|
41117
41228
|
config.host = decodeURI(result.pathname);
|
|
41118
|
-
config.database = result.
|
|
41119
|
-
config.client_encoding = result.
|
|
41229
|
+
config.database = result.searchParams.get("db");
|
|
41230
|
+
config.client_encoding = result.searchParams.get("encoding");
|
|
41120
41231
|
return config;
|
|
41121
41232
|
}
|
|
41233
|
+
const hostname = dummyHost ? "" : result.hostname;
|
|
41122
41234
|
if (!config.host) {
|
|
41123
|
-
config.host =
|
|
41124
|
-
}
|
|
41125
|
-
|
|
41126
|
-
if (!config.host && pathname && /^%2f/i.test(pathname)) {
|
|
41127
|
-
var pathnameSplit = pathname.split("/");
|
|
41128
|
-
config.host = decodeURIComponent(pathnameSplit[0]);
|
|
41129
|
-
pathname = pathnameSplit.splice(1).join("/");
|
|
41130
|
-
}
|
|
41131
|
-
if (pathname && pathname.charAt(0) === "/") {
|
|
41132
|
-
pathname = pathname.slice(1) || null;
|
|
41235
|
+
config.host = decodeURIComponent(hostname);
|
|
41236
|
+
} else if (hostname) {
|
|
41237
|
+
result.pathname = hostname + result.pathname;
|
|
41133
41238
|
}
|
|
41134
|
-
|
|
41239
|
+
const pathname = result.pathname.slice(1) || null;
|
|
41240
|
+
config.database = pathname ? decodeURI(pathname) : null;
|
|
41135
41241
|
if (config.ssl === "true" || config.ssl === "1") {
|
|
41136
41242
|
config.ssl = true;
|
|
41137
41243
|
}
|
|
@@ -41141,6 +41247,7 @@ var require_pg_connection_string = __commonJS({
|
|
|
41141
41247
|
if (config.sslcert || config.sslkey || config.sslrootcert || config.sslmode) {
|
|
41142
41248
|
config.ssl = {};
|
|
41143
41249
|
}
|
|
41250
|
+
const fs6 = config.sslcert || config.sslkey || config.sslrootcert ? require("fs") : null;
|
|
41144
41251
|
if (config.sslcert) {
|
|
41145
41252
|
config.ssl.cert = fs6.readFileSync(config.sslcert).toString();
|
|
41146
41253
|
}
|
|
@@ -43990,7 +44097,7 @@ var require_lib5 = __commonJS({
|
|
|
43990
44097
|
});
|
|
43991
44098
|
|
|
43992
44099
|
// src/introspect.ts
|
|
43993
|
-
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
|
|
44100
|
+
var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
|
|
43994
44101
|
var init_introspect = __esm({
|
|
43995
44102
|
"src/introspect.ts"() {
|
|
43996
44103
|
init_utils2();
|
|
@@ -44102,7 +44209,16 @@ var init_introspect = __esm({
|
|
|
44102
44209
|
"time with time zone": "time"
|
|
44103
44210
|
};
|
|
44104
44211
|
relations3 = /* @__PURE__ */ new Set();
|
|
44105
|
-
|
|
44212
|
+
withCasing3 = (value, casing) => {
|
|
44213
|
+
if (typeof casing === "undefined") {
|
|
44214
|
+
return value;
|
|
44215
|
+
}
|
|
44216
|
+
if (casing.casing === "camel") {
|
|
44217
|
+
return value.camelCase();
|
|
44218
|
+
}
|
|
44219
|
+
return value;
|
|
44220
|
+
};
|
|
44221
|
+
schemaToTypeScript3 = (schema4, casing) => {
|
|
44106
44222
|
Object.values(schema4.tables).forEach((table4) => {
|
|
44107
44223
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
|
44108
44224
|
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
|
@@ -44111,7 +44227,7 @@ var init_introspect = __esm({
|
|
|
44111
44227
|
});
|
|
44112
44228
|
const schemas = Object.fromEntries(
|
|
44113
44229
|
Object.entries(schema4.schemas).map((it) => {
|
|
44114
|
-
return [it[0], it[1]
|
|
44230
|
+
return [it[0], withCasing3(it[1], casing)];
|
|
44115
44231
|
})
|
|
44116
44232
|
);
|
|
44117
44233
|
const enumTypes = new Set(Object.values(schema4.enums).map((it) => it.name));
|
|
@@ -44145,7 +44261,7 @@ var init_introspect = __esm({
|
|
|
44145
44261
|
);
|
|
44146
44262
|
const enumStatements = Object.values(schema4.enums).map((it) => {
|
|
44147
44263
|
const values = Object.values(it.values).map((it2) => `'${it2}'`).join(", ");
|
|
44148
|
-
return `export const ${it.name
|
|
44264
|
+
return `export const ${withCasing3(it.name, casing)} = pgEnum("${it.name}", [${values}])
|
|
44149
44265
|
`;
|
|
44150
44266
|
}).join("").concat("\n");
|
|
44151
44267
|
const schemaStatements = Object.entries(schemas).map((it) => {
|
|
@@ -44155,12 +44271,16 @@ var init_introspect = __esm({
|
|
|
44155
44271
|
const tableStatements = Object.values(schema4.tables).map((table4) => {
|
|
44156
44272
|
const schema5 = schemas[table4.schema];
|
|
44157
44273
|
const func = schema5 ? schema5 : "pgTable";
|
|
44158
|
-
let statement = `export const ${
|
|
44274
|
+
let statement = `export const ${withCasing3(
|
|
44275
|
+
table4.name,
|
|
44276
|
+
casing
|
|
44277
|
+
)} = ${func}("${table4.name}", {
|
|
44159
44278
|
`;
|
|
44160
44279
|
statement += createTableColumns3(
|
|
44161
44280
|
Object.values(table4.columns),
|
|
44162
44281
|
Object.values(table4.foreignKeys),
|
|
44163
|
-
enumTypes
|
|
44282
|
+
enumTypes,
|
|
44283
|
+
casing
|
|
44164
44284
|
);
|
|
44165
44285
|
statement += "}";
|
|
44166
44286
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
@@ -44170,9 +44290,16 @@ var init_introspect = __esm({
|
|
|
44170
44290
|
statement += ",\n";
|
|
44171
44291
|
statement += "(table) => {\n";
|
|
44172
44292
|
statement += " return {\n";
|
|
44173
|
-
statement += createTableIndexes3(
|
|
44174
|
-
|
|
44175
|
-
|
|
44293
|
+
statement += createTableIndexes3(
|
|
44294
|
+
table4.name,
|
|
44295
|
+
Object.values(table4.indexes),
|
|
44296
|
+
casing
|
|
44297
|
+
);
|
|
44298
|
+
statement += createTableFKs3(Object.values(filteredFKs), casing);
|
|
44299
|
+
statement += createTablePKs3(
|
|
44300
|
+
Object.values(table4.compositePrimaryKeys),
|
|
44301
|
+
casing
|
|
44302
|
+
);
|
|
44176
44303
|
statement += " }\n";
|
|
44177
44304
|
statement += "}";
|
|
44178
44305
|
}
|
|
@@ -44207,51 +44334,54 @@ var init_introspect = __esm({
|
|
|
44207
44334
|
isSelf3 = (fk4) => {
|
|
44208
44335
|
return fk4.tableFrom === fk4.tableTo;
|
|
44209
44336
|
};
|
|
44210
|
-
column6 = (type, name, enumTypes, defaultValue) => {
|
|
44337
|
+
column6 = (type, name, enumTypes, defaultValue, casing) => {
|
|
44211
44338
|
const lowered = type.toLowerCase();
|
|
44212
44339
|
if (lowered.startsWith("serial")) {
|
|
44213
|
-
return `${name
|
|
44340
|
+
return `${withCasing3(name, casing)}: serial("${name}")`;
|
|
44214
44341
|
}
|
|
44215
44342
|
if (lowered.startsWith("smallserial")) {
|
|
44216
|
-
return `${name
|
|
44343
|
+
return `${withCasing3(name, casing)}: smallserial("${name}")`;
|
|
44217
44344
|
}
|
|
44218
44345
|
if (lowered.startsWith("bigserial")) {
|
|
44219
|
-
return `${
|
|
44346
|
+
return `${withCasing3(
|
|
44347
|
+
name,
|
|
44348
|
+
casing
|
|
44349
|
+
)}: bigserial("${name}", { mode: "bigint" })`;
|
|
44220
44350
|
}
|
|
44221
44351
|
if (lowered.startsWith("integer")) {
|
|
44222
|
-
let out = `${name
|
|
44352
|
+
let out = `${withCasing3(name, casing)}: integer("${name}")`;
|
|
44223
44353
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44224
44354
|
return out;
|
|
44225
44355
|
}
|
|
44226
44356
|
if (lowered.startsWith("smallint")) {
|
|
44227
|
-
let out = `${name
|
|
44357
|
+
let out = `${withCasing3(name, casing)}: smallint("${name}")`;
|
|
44228
44358
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44229
44359
|
return out;
|
|
44230
44360
|
}
|
|
44231
44361
|
if (lowered.startsWith("bigint")) {
|
|
44232
44362
|
let out = `// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
|
44233
44363
|
`;
|
|
44234
|
-
out += `${name
|
|
44364
|
+
out += `${withCasing3(name, casing)}: bigint("${name}", { mode: "number" })`;
|
|
44235
44365
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44236
44366
|
return out;
|
|
44237
44367
|
}
|
|
44238
44368
|
if (lowered.startsWith("boolean")) {
|
|
44239
|
-
let out = `${name
|
|
44369
|
+
let out = `${withCasing3(name, casing)}: boolean("${name}")`;
|
|
44240
44370
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44241
44371
|
return out;
|
|
44242
44372
|
}
|
|
44243
44373
|
if (lowered.startsWith("double precision")) {
|
|
44244
|
-
let out = `${name
|
|
44374
|
+
let out = `${withCasing3(name, casing)}: doublePrecision("${name}")`;
|
|
44245
44375
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44246
44376
|
return out;
|
|
44247
44377
|
}
|
|
44248
44378
|
if (lowered.startsWith("real")) {
|
|
44249
|
-
let out = `${name
|
|
44379
|
+
let out = `${withCasing3(name, casing)}: real("${name}")`;
|
|
44250
44380
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44251
44381
|
return out;
|
|
44252
44382
|
}
|
|
44253
44383
|
if (lowered.startsWith("uuid")) {
|
|
44254
|
-
let out = `${name
|
|
44384
|
+
let out = `${withCasing3(name, casing)}: uuid("${name}")`;
|
|
44255
44385
|
out += defaultValue === "gen_random_uuid()" ? ".defaultRandom()" : defaultValue ? `.default(sql\`${defaultValue}\`)` : "";
|
|
44256
44386
|
return out;
|
|
44257
44387
|
}
|
|
@@ -44261,7 +44391,7 @@ var init_introspect = __esm({
|
|
|
44261
44391
|
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
|
44262
44392
|
params = { precision, scale };
|
|
44263
44393
|
}
|
|
44264
|
-
let out = params ? `${name
|
|
44394
|
+
let out = params ? `${withCasing3(name, casing)}: numeric("${name}", ${timeConfig2(params)})` : `${withCasing3(name, casing)}: numeric("${name}")`;
|
|
44265
44395
|
defaultValue = defaultValue ? defaultValue.startsWith(`'`) && defaultValue.endsWith(`'`) ? defaultValue.substring(1, defaultValue.length - 1) : defaultValue : void 0;
|
|
44266
44396
|
out += defaultValue ? `.default('${defaultValue}')` : "";
|
|
44267
44397
|
return out;
|
|
@@ -44277,7 +44407,7 @@ var init_introspect = __esm({
|
|
|
44277
44407
|
withTimezone,
|
|
44278
44408
|
mode: "'string'"
|
|
44279
44409
|
});
|
|
44280
|
-
let out = params ? `${name
|
|
44410
|
+
let out = params ? `${withCasing3(name, casing)}: timestamp("${name}", ${params})` : `${withCasing3(name, casing)}: timestamp("${name}")`;
|
|
44281
44411
|
defaultValue = defaultValue === "now()" || defaultValue === "CURRENT_TIMESTAMP" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
|
|
44282
44412
|
out += defaultValue;
|
|
44283
44413
|
return out;
|
|
@@ -44289,59 +44419,59 @@ var init_introspect = __esm({
|
|
|
44289
44419
|
) : null;
|
|
44290
44420
|
precision = precision ? precision : null;
|
|
44291
44421
|
const params = timeConfig2({ precision, withTimezone });
|
|
44292
|
-
let out = params ? `${name
|
|
44422
|
+
let out = params ? `${withCasing3(name, casing)}: time("${name}", ${params})` : `${withCasing3(name, casing)}: time("${name}")`;
|
|
44293
44423
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
|
|
44294
44424
|
out += defaultValue;
|
|
44295
44425
|
return out;
|
|
44296
44426
|
}
|
|
44297
44427
|
if (lowered.startsWith("interval")) {
|
|
44298
44428
|
const params = intervalConfig(lowered);
|
|
44299
|
-
let out = params ? `${name
|
|
44429
|
+
let out = params ? `${withCasing3(name, casing)}: interval("${name}", ${params})` : `${withCasing3(name, casing)}: interval("${name}")`;
|
|
44300
44430
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44301
44431
|
return out;
|
|
44302
44432
|
}
|
|
44303
44433
|
if (lowered === "date") {
|
|
44304
|
-
let out = `${name
|
|
44434
|
+
let out = `${withCasing3(name, casing)}: date("${name}")`;
|
|
44305
44435
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
|
|
44306
44436
|
out += defaultValue;
|
|
44307
44437
|
return out;
|
|
44308
44438
|
}
|
|
44309
44439
|
if (lowered.startsWith("text")) {
|
|
44310
|
-
let out = `${name
|
|
44440
|
+
let out = `${withCasing3(name, casing)}: text("${name}")`;
|
|
44311
44441
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44312
44442
|
return out;
|
|
44313
44443
|
}
|
|
44314
44444
|
if (lowered === "json") {
|
|
44315
|
-
let out = `${name
|
|
44445
|
+
let out = `${withCasing3(name, casing)}: json("${name}")`;
|
|
44316
44446
|
defaultValue = (defaultValue == null ? void 0 : defaultValue.endsWith("::json")) ? defaultValue.substring(1, defaultValue.length - 7) : defaultValue;
|
|
44317
44447
|
const def = defaultValue ? defaultValue : null;
|
|
44318
44448
|
out += defaultValue ? `.default(${def})` : "";
|
|
44319
44449
|
return out;
|
|
44320
44450
|
}
|
|
44321
44451
|
if (lowered === "jsonb") {
|
|
44322
|
-
let out = `${name
|
|
44452
|
+
let out = `${withCasing3(name, casing)}: jsonb("${name}")`;
|
|
44323
44453
|
defaultValue = (defaultValue == null ? void 0 : defaultValue.endsWith("::jsonb")) ? defaultValue.substring(1, defaultValue.length - 8) : defaultValue;
|
|
44324
44454
|
const def = defaultValue ? defaultValue : null;
|
|
44325
44455
|
out += defaultValue ? `.default(${def})` : "";
|
|
44326
44456
|
return out;
|
|
44327
44457
|
}
|
|
44328
44458
|
if (lowered.startsWith("inet")) {
|
|
44329
|
-
let out = `${name
|
|
44459
|
+
let out = `${withCasing3(name, casing)}: inet("${name}")`;
|
|
44330
44460
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44331
44461
|
return out;
|
|
44332
44462
|
}
|
|
44333
44463
|
if (lowered.startsWith("cidr")) {
|
|
44334
|
-
let out = `${name
|
|
44464
|
+
let out = `${withCasing3(name, casing)}: cidr("${name}")`;
|
|
44335
44465
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44336
44466
|
return out;
|
|
44337
44467
|
}
|
|
44338
44468
|
if (lowered.startsWith("macaddr")) {
|
|
44339
|
-
let out = `${name
|
|
44469
|
+
let out = `${withCasing3(name, casing)}: macaddr("${name}")`;
|
|
44340
44470
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44341
44471
|
return out;
|
|
44342
44472
|
}
|
|
44343
44473
|
if (lowered.startsWith("macaddr8")) {
|
|
44344
|
-
let out = `${name
|
|
44474
|
+
let out = `${withCasing3(name, casing)}: macaddr8("${name}")`;
|
|
44345
44475
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44346
44476
|
return out;
|
|
44347
44477
|
}
|
|
@@ -44349,12 +44479,15 @@ var init_introspect = __esm({
|
|
|
44349
44479
|
const split = lowered.split(" ");
|
|
44350
44480
|
let out;
|
|
44351
44481
|
if (lowered.length !== 7) {
|
|
44352
|
-
out = `${
|
|
44482
|
+
out = `${withCasing3(
|
|
44483
|
+
name,
|
|
44484
|
+
casing
|
|
44485
|
+
)}: varchar("${name}", { length: ${lowered.substring(
|
|
44353
44486
|
8,
|
|
44354
44487
|
lowered.length - 1
|
|
44355
44488
|
)} })`;
|
|
44356
44489
|
} else {
|
|
44357
|
-
out = `${name
|
|
44490
|
+
out = `${withCasing3(name, casing)}: varchar("${name}")`;
|
|
44358
44491
|
}
|
|
44359
44492
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44360
44493
|
return out;
|
|
@@ -44362,24 +44495,30 @@ var init_introspect = __esm({
|
|
|
44362
44495
|
if (lowered.startsWith("char")) {
|
|
44363
44496
|
let out;
|
|
44364
44497
|
if (lowered.length !== 4) {
|
|
44365
|
-
out = `${
|
|
44498
|
+
out = `${withCasing3(
|
|
44499
|
+
name,
|
|
44500
|
+
casing
|
|
44501
|
+
)}: char("${name}", { length: ${lowered.substring(
|
|
44366
44502
|
5,
|
|
44367
44503
|
lowered.length - 1
|
|
44368
44504
|
)} })`;
|
|
44369
44505
|
} else {
|
|
44370
|
-
out = `${name
|
|
44506
|
+
out = `${withCasing3(name, casing)}: char("${name}")`;
|
|
44371
44507
|
}
|
|
44372
44508
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44373
44509
|
return out;
|
|
44374
44510
|
}
|
|
44375
44511
|
if (enumTypes.has(type)) {
|
|
44376
|
-
let out = `${name
|
|
44512
|
+
let out = `${withCasing3(name, casing)}: ${withCasing3(
|
|
44513
|
+
type,
|
|
44514
|
+
casing
|
|
44515
|
+
)}("${name}")`;
|
|
44377
44516
|
out += defaultValue ? `.default(${defaultValue})` : "";
|
|
44378
44517
|
return out;
|
|
44379
44518
|
}
|
|
44380
44519
|
let unknown = `// TODO: failed to parse database type '${type}'
|
|
44381
44520
|
`;
|
|
44382
|
-
unknown += ` ${name
|
|
44521
|
+
unknown += ` ${withCasing3(name, casing)}: unknown("${name}")`;
|
|
44383
44522
|
return unknown;
|
|
44384
44523
|
};
|
|
44385
44524
|
dimensionsInArray = (str) => {
|
|
@@ -44391,7 +44530,7 @@ var init_introspect = __esm({
|
|
|
44391
44530
|
}
|
|
44392
44531
|
return res;
|
|
44393
44532
|
};
|
|
44394
|
-
createTableColumns3 = (columns, fks, enumTypes) => {
|
|
44533
|
+
createTableColumns3 = (columns, fks, enumTypes, casing) => {
|
|
44395
44534
|
let statement = "";
|
|
44396
44535
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
|
44397
44536
|
return !isSelf3(it);
|
|
@@ -44403,7 +44542,7 @@ var init_introspect = __esm({
|
|
|
44403
44542
|
return res;
|
|
44404
44543
|
}, {});
|
|
44405
44544
|
columns.forEach((it) => {
|
|
44406
|
-
const columnStatement = column6(it.type, it.name, enumTypes, it.default);
|
|
44545
|
+
const columnStatement = column6(it.type, it.name, enumTypes, it.default, casing);
|
|
44407
44546
|
statement += " ";
|
|
44408
44547
|
statement += columnStatement;
|
|
44409
44548
|
statement += dimensionsInArray(it.type);
|
|
@@ -44418,9 +44557,15 @@ var init_introspect = __esm({
|
|
|
44418
44557
|
const typeSuffix = isCyclic3(it2) ? ": AnyPgColumn" : "";
|
|
44419
44558
|
const paramsStr = objToStatement23(params);
|
|
44420
44559
|
if (paramsStr) {
|
|
44421
|
-
return `.references(()${typeSuffix} => ${
|
|
44422
|
-
|
|
44423
|
-
|
|
44560
|
+
return `.references(()${typeSuffix} => ${withCasing3(
|
|
44561
|
+
it2.tableTo,
|
|
44562
|
+
casing
|
|
44563
|
+
)}.${withCasing3(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
|
44564
|
+
}
|
|
44565
|
+
return `.references(()${typeSuffix} => ${withCasing3(
|
|
44566
|
+
it2.tableTo,
|
|
44567
|
+
casing
|
|
44568
|
+
)}.${withCasing3(it2.columnsTo[0], casing)})`;
|
|
44424
44569
|
}).join("");
|
|
44425
44570
|
statement += fksStatement;
|
|
44426
44571
|
}
|
|
@@ -44428,31 +44573,31 @@ var init_introspect = __esm({
|
|
|
44428
44573
|
});
|
|
44429
44574
|
return statement;
|
|
44430
44575
|
};
|
|
44431
|
-
createTableIndexes3 = (tableName, idxs) => {
|
|
44576
|
+
createTableIndexes3 = (tableName, idxs, casing) => {
|
|
44432
44577
|
let statement = "";
|
|
44433
44578
|
idxs.forEach((it) => {
|
|
44434
44579
|
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
|
44435
44580
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
|
44436
|
-
idxKey = idxKey
|
|
44581
|
+
idxKey = withCasing3(idxKey, casing);
|
|
44437
44582
|
const indexGeneratedName = indexName2(tableName, it.columns);
|
|
44438
44583
|
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
|
44439
44584
|
statement += ` ${idxKey}: `;
|
|
44440
44585
|
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
|
44441
44586
|
statement += `${escapedIndexName})`;
|
|
44442
|
-
statement += `.on(${it.columns.map((it2) => `table.${it2
|
|
44587
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
|
|
44443
44588
|
statement += `
|
|
44444
44589
|
`;
|
|
44445
44590
|
});
|
|
44446
44591
|
return statement;
|
|
44447
44592
|
};
|
|
44448
|
-
createTablePKs3 = (pks) => {
|
|
44593
|
+
createTablePKs3 = (pks, casing) => {
|
|
44449
44594
|
let statement = "";
|
|
44450
44595
|
pks.forEach((it) => {
|
|
44451
|
-
let idxKey = it.name
|
|
44596
|
+
let idxKey = withCasing3(it.name, casing);
|
|
44452
44597
|
statement += ` ${idxKey}: `;
|
|
44453
44598
|
statement += "primaryKey(";
|
|
44454
44599
|
statement += `${it.columns.map((c) => {
|
|
44455
|
-
return `table.${c
|
|
44600
|
+
return `table.${withCasing3(c, casing)}`;
|
|
44456
44601
|
}).join(", ")}`;
|
|
44457
44602
|
statement += ")";
|
|
44458
44603
|
statement += `
|
|
@@ -44460,16 +44605,16 @@ var init_introspect = __esm({
|
|
|
44460
44605
|
});
|
|
44461
44606
|
return statement;
|
|
44462
44607
|
};
|
|
44463
|
-
createTableFKs3 = (fks) => {
|
|
44608
|
+
createTableFKs3 = (fks, casing) => {
|
|
44464
44609
|
let statement = "";
|
|
44465
44610
|
fks.forEach((it) => {
|
|
44466
44611
|
const isSelf4 = it.tableTo === it.tableFrom;
|
|
44467
|
-
const tableTo = isSelf4 ? "table" : `${it.tableTo
|
|
44468
|
-
statement += ` ${it.name
|
|
44612
|
+
const tableTo = isSelf4 ? "table" : `${withCasing3(it.tableTo, casing)}`;
|
|
44613
|
+
statement += ` ${withCasing3(it.name, casing)}: foreignKey({
|
|
44469
44614
|
`;
|
|
44470
|
-
statement += ` columns: [${it.columnsFrom.map((i) => `table.${i
|
|
44615
|
+
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing3(i, casing)}`).join(", ")}],
|
|
44471
44616
|
`;
|
|
44472
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i
|
|
44617
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing3(i, casing)}`).join(", ")}]
|
|
44473
44618
|
`;
|
|
44474
44619
|
statement += ` })`;
|
|
44475
44620
|
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
|
@@ -44485,45 +44630,42 @@ var init_introspect = __esm({
|
|
|
44485
44630
|
// src/cli/commands/pgIntrospect.ts
|
|
44486
44631
|
var pgIntrospect_exports = {};
|
|
44487
44632
|
__export(pgIntrospect_exports, {
|
|
44488
|
-
PgConfig1: () => PgConfig1,
|
|
44489
|
-
PgConfig2: () => PgConfig2,
|
|
44490
44633
|
pgIntrospect: () => pgIntrospect
|
|
44491
44634
|
});
|
|
44492
|
-
var import_hanji7, import_pg,
|
|
44635
|
+
var import_hanji7, import_pg, pgIntrospect;
|
|
44493
44636
|
var init_pgIntrospect = __esm({
|
|
44494
44637
|
"src/cli/commands/pgIntrospect.ts"() {
|
|
44495
44638
|
import_hanji7 = __toESM(require_hanji());
|
|
44496
|
-
init_lib();
|
|
44497
44639
|
init_views();
|
|
44498
44640
|
import_pg = __toESM(require_lib5());
|
|
44499
44641
|
init_pgSerializer();
|
|
44500
44642
|
init_introspect();
|
|
44501
44643
|
init_global();
|
|
44502
|
-
|
|
44503
|
-
|
|
44504
|
-
|
|
44505
|
-
|
|
44506
|
-
|
|
44507
|
-
|
|
44508
|
-
|
|
44509
|
-
|
|
44510
|
-
|
|
44511
|
-
|
|
44512
|
-
|
|
44513
|
-
|
|
44514
|
-
|
|
44515
|
-
|
|
44516
|
-
|
|
44517
|
-
|
|
44644
|
+
init_mjs();
|
|
44645
|
+
pgIntrospect = async (config, filters) => {
|
|
44646
|
+
const pool = new import_pg.Pool(config.dbCredentials);
|
|
44647
|
+
const matchers = filters.map((it) => {
|
|
44648
|
+
return new Minimatch(it);
|
|
44649
|
+
});
|
|
44650
|
+
const filter2 = (tableName) => {
|
|
44651
|
+
if (matchers.length === 0)
|
|
44652
|
+
return true;
|
|
44653
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
44654
|
+
const matcher = matchers[i];
|
|
44655
|
+
if (matcher.match(tableName))
|
|
44656
|
+
return true;
|
|
44657
|
+
}
|
|
44658
|
+
return false;
|
|
44659
|
+
};
|
|
44518
44660
|
const progress = new IntrospectProgress();
|
|
44519
44661
|
const res = await (0, import_hanji7.renderWithTask)(
|
|
44520
44662
|
progress,
|
|
44521
|
-
fromDatabase2(pool, (stage, count, status) => {
|
|
44663
|
+
fromDatabase2(pool, filter2, (stage, count, status) => {
|
|
44522
44664
|
progress.update(stage, count, status);
|
|
44523
44665
|
})
|
|
44524
44666
|
);
|
|
44525
44667
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
44526
|
-
const ts = schemaToTypeScript3(schema4);
|
|
44668
|
+
const ts = schemaToTypeScript3(schema4, { casing: config.introspect.casing });
|
|
44527
44669
|
return { schema: schema4, ts };
|
|
44528
44670
|
};
|
|
44529
44671
|
}
|
|
@@ -44596,7 +44738,7 @@ var assertPackages = async (...pkgs) => {
|
|
|
44596
44738
|
process.exit(1);
|
|
44597
44739
|
}
|
|
44598
44740
|
};
|
|
44599
|
-
var requiredApiVersion =
|
|
44741
|
+
var requiredApiVersion = 5;
|
|
44600
44742
|
var assertOrmCoreVersion = async () => {
|
|
44601
44743
|
try {
|
|
44602
44744
|
const { compatibilityVersion } = await import("drizzle-orm/version");
|
|
@@ -44667,6 +44809,7 @@ var package_default = {
|
|
|
44667
44809
|
"sim:sqlite": "node -r esbuild-register ./dev/sqlite/index.ts",
|
|
44668
44810
|
test: "ava test --timeout=60s",
|
|
44669
44811
|
build: "rm -rf ./dist && tsx build.ts && tsc -p tsconfig.cli-types.json",
|
|
44812
|
+
"build:dev": "rm -rf ./dist && tsx build.dev.ts && tsc -p tsconfig.cli-types.json && chmod +x ./dist/index.cjs",
|
|
44670
44813
|
pack: "build && package",
|
|
44671
44814
|
tsc: "tsc -p tsconfig.build.json",
|
|
44672
44815
|
pub: "cp package.json readme.md dist/ && cd dist && npm publish"
|
|
@@ -44707,7 +44850,7 @@ var package_default = {
|
|
|
44707
44850
|
"better-sqlite3": "^8.4.0",
|
|
44708
44851
|
dockerode: "^3.3.4",
|
|
44709
44852
|
dotenv: "^16.0.3",
|
|
44710
|
-
"drizzle-orm": "0.
|
|
44853
|
+
"drizzle-orm": "0.27.0-56b9edc",
|
|
44711
44854
|
esbuild: "^0.17.19",
|
|
44712
44855
|
"esbuild-register": "^3.4.2",
|
|
44713
44856
|
eslint: "^8.29.0",
|
|
@@ -44791,6 +44934,10 @@ var dropMigration = async (out) => {
|
|
|
44791
44934
|
const journal = JSON.parse(
|
|
44792
44935
|
(0, import_fs9.readFileSync)(metaFilePath, "utf-8")
|
|
44793
44936
|
);
|
|
44937
|
+
if (journal.entries.length === 0) {
|
|
44938
|
+
console.log(`[${source_default.blue("i")}] no migration entries found in ${metaFilePath}`);
|
|
44939
|
+
return;
|
|
44940
|
+
}
|
|
44794
44941
|
const result = await (0, import_hanji3.render)(new DropMigrationView(journal.entries));
|
|
44795
44942
|
if (result.status === "aborted")
|
|
44796
44943
|
return;
|
|
@@ -44862,12 +45009,38 @@ var assertOutFolder = async (it) => {
|
|
|
44862
45009
|
var configCommonSchema = objectType({
|
|
44863
45010
|
schema: unionType([stringType(), stringType().array()]),
|
|
44864
45011
|
out: stringType().optional(),
|
|
44865
|
-
breakpoints: booleanType().
|
|
45012
|
+
breakpoints: booleanType().default(true),
|
|
44866
45013
|
tablesFilter: unionType([stringType(), stringType().array()]).optional()
|
|
44867
45014
|
});
|
|
45015
|
+
var introspectCasing = objectType({
|
|
45016
|
+
casing: unionType([literalType("camel"), literalType("preserve")]).default("camel")
|
|
45017
|
+
}).default({ casing: "camel" });
|
|
44868
45018
|
var configIntrospectSchema = objectType({
|
|
45019
|
+
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
44869
45020
|
out: stringType().optional().default("./drizzle"),
|
|
44870
|
-
breakpoints: booleanType().
|
|
45021
|
+
breakpoints: booleanType().default(true),
|
|
45022
|
+
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
|
45023
|
+
introspect: introspectCasing
|
|
45024
|
+
});
|
|
45025
|
+
var configIntrospectCliSchema = objectType({
|
|
45026
|
+
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
45027
|
+
out: stringType().optional().default("./drizzle"),
|
|
45028
|
+
breakpoints: booleanType().default(true),
|
|
45029
|
+
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
|
45030
|
+
introspectCasing: unionType([literalType("camel"), literalType("preserve")]).default(
|
|
45031
|
+
"camel"
|
|
45032
|
+
)
|
|
45033
|
+
});
|
|
45034
|
+
var configGenerateSchema = objectType({
|
|
45035
|
+
schema: unionType([stringType(), stringType().array()]),
|
|
45036
|
+
out: stringType().optional().default("./drizzle"),
|
|
45037
|
+
breakpoints: booleanType().default(true)
|
|
45038
|
+
});
|
|
45039
|
+
var configPushSchema = objectType({
|
|
45040
|
+
schema: unionType([stringType(), stringType().array()]),
|
|
45041
|
+
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
|
45042
|
+
verbose: booleanType().default(false),
|
|
45043
|
+
strict: booleanType().default(false)
|
|
44871
45044
|
});
|
|
44872
45045
|
var mysqlConnectionSchema = unionType([
|
|
44873
45046
|
objectType({
|
|
@@ -44897,7 +45070,6 @@ var drizzleConfigFromFile = async (configPath) => {
|
|
|
44897
45070
|
const defaultJsonConfigExists = (0, import_fs10.existsSync)(
|
|
44898
45071
|
(0, import_path6.join)((0, import_path6.resolve)("drizzle.config.json"))
|
|
44899
45072
|
);
|
|
44900
|
-
console.log(configPath);
|
|
44901
45073
|
const defaultConfigPath = defaultTsConfigExists ? "drizzle.config.ts" : defaultJsConfigExists ? "drizzle.config.js" : "drizzle.config.json";
|
|
44902
45074
|
if (!configPath) {
|
|
44903
45075
|
console.log(
|
|
@@ -44972,6 +45144,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
44972
45144
|
}) => {
|
|
44973
45145
|
let shouldAskForApprove = false;
|
|
44974
45146
|
const statementsToExecute = [];
|
|
45147
|
+
const infoToPrint = [];
|
|
44975
45148
|
const tablesToRemove = [];
|
|
44976
45149
|
const columnsToRemove = [];
|
|
44977
45150
|
const schemasToRemove = [];
|
|
@@ -44983,7 +45156,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
44983
45156
|
);
|
|
44984
45157
|
const count = Number(res[0][0].count);
|
|
44985
45158
|
if (count > 0) {
|
|
44986
|
-
|
|
45159
|
+
infoToPrint.push(
|
|
44987
45160
|
`\xB7 You're about to delete ${source_default.underline(
|
|
44988
45161
|
statement.tableName
|
|
44989
45162
|
)} table with ${count} items`
|
|
@@ -44997,7 +45170,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
44997
45170
|
);
|
|
44998
45171
|
const count = Number(res[0][0].count);
|
|
44999
45172
|
if (count > 0) {
|
|
45000
|
-
|
|
45173
|
+
infoToPrint.push(
|
|
45001
45174
|
`\xB7 You're about to delete ${source_default.underline(
|
|
45002
45175
|
statement.columnName
|
|
45003
45176
|
)} column in ${statement.tableName} table with ${count} items`
|
|
@@ -45011,7 +45184,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45011
45184
|
);
|
|
45012
45185
|
const count = Number(res[0][0].count);
|
|
45013
45186
|
if (count > 0) {
|
|
45014
|
-
|
|
45187
|
+
infoToPrint.push(
|
|
45015
45188
|
`\xB7 You're about to delete ${source_default.underline(
|
|
45016
45189
|
statement.name
|
|
45017
45190
|
)} schema with ${count} tables`
|
|
@@ -45025,7 +45198,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45025
45198
|
);
|
|
45026
45199
|
const count = Number(res[0][0].count);
|
|
45027
45200
|
if (count > 0) {
|
|
45028
|
-
|
|
45201
|
+
infoToPrint.push(
|
|
45029
45202
|
`\xB7 You're about to change ${source_default.underline(
|
|
45030
45203
|
statement.columnName
|
|
45031
45204
|
)} column type from ${source_default.underline(
|
|
@@ -45043,7 +45216,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45043
45216
|
);
|
|
45044
45217
|
const count = Number(res[0][0].count);
|
|
45045
45218
|
if (count > 0) {
|
|
45046
|
-
|
|
45219
|
+
infoToPrint.push(
|
|
45047
45220
|
`\xB7 You're about to remove default value from ${source_default.underline(
|
|
45048
45221
|
statement.columnName
|
|
45049
45222
|
)} not-null column with ${count} items`
|
|
@@ -45061,7 +45234,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45061
45234
|
);
|
|
45062
45235
|
const count = Number(res[0][0].count);
|
|
45063
45236
|
if (count > 0) {
|
|
45064
|
-
|
|
45237
|
+
infoToPrint.push(
|
|
45065
45238
|
`\xB7 You're about to set not-null constraint to ${source_default.underline(
|
|
45066
45239
|
statement.columnName
|
|
45067
45240
|
)} column without default, which contains ${count} items`
|
|
@@ -45077,7 +45250,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45077
45250
|
);
|
|
45078
45251
|
const count = Number(res[0][0].count);
|
|
45079
45252
|
if (count > 0) {
|
|
45080
|
-
|
|
45253
|
+
infoToPrint.push(
|
|
45081
45254
|
`\xB7 You're about to change ${source_default.underline(
|
|
45082
45255
|
statement.tableName
|
|
45083
45256
|
)} primary key. This statements may fail and you table may left without primary key`
|
|
@@ -45092,7 +45265,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45092
45265
|
);
|
|
45093
45266
|
const count = Number(res[0][0].count);
|
|
45094
45267
|
if (count > 0) {
|
|
45095
|
-
|
|
45268
|
+
infoToPrint.push(
|
|
45096
45269
|
`\xB7 You're about to add not-null ${source_default.underline(
|
|
45097
45270
|
statement.column.name
|
|
45098
45271
|
)} column without default value, which contains ${count} items`
|
|
@@ -45107,6 +45280,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
45107
45280
|
return {
|
|
45108
45281
|
statementsToExecute,
|
|
45109
45282
|
shouldAskForApprove,
|
|
45283
|
+
infoToPrint,
|
|
45110
45284
|
columnsToRemove: [...new Set(columnsToRemove)],
|
|
45111
45285
|
schemasToRemove: [...new Set(schemasToRemove)],
|
|
45112
45286
|
tablesToTruncate: [...new Set(tablesToTruncate)],
|
|
@@ -45292,11 +45466,32 @@ var logSuggestionsAndReturn2 = async ({
|
|
|
45292
45466
|
}
|
|
45293
45467
|
}
|
|
45294
45468
|
} else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk") {
|
|
45295
|
-
if (typeof
|
|
45296
|
-
|
|
45297
|
-
statement.tableName
|
|
45298
|
-
json2
|
|
45469
|
+
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
|
45470
|
+
const res = await connection.query(
|
|
45471
|
+
`select count(*) as count from \`${statement.tableName}\``
|
|
45299
45472
|
);
|
|
45473
|
+
const count = Number(res[0].count);
|
|
45474
|
+
if (count > 0) {
|
|
45475
|
+
infoToPrint.push(
|
|
45476
|
+
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
|
45477
|
+
statement.columnName
|
|
45478
|
+
)} column without default value, which contains ${count} items`
|
|
45479
|
+
);
|
|
45480
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
|
45481
|
+
statement.tableName,
|
|
45482
|
+
json2,
|
|
45483
|
+
true
|
|
45484
|
+
);
|
|
45485
|
+
tablesToTruncate.push(statement.tableName);
|
|
45486
|
+
shouldAskForApprove = true;
|
|
45487
|
+
}
|
|
45488
|
+
} else {
|
|
45489
|
+
if (typeof tablesContext[statement.tableName] === "undefined") {
|
|
45490
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
|
45491
|
+
statement.tableName,
|
|
45492
|
+
json2
|
|
45493
|
+
);
|
|
45494
|
+
}
|
|
45300
45495
|
}
|
|
45301
45496
|
const tablesReferncingCurrent = [];
|
|
45302
45497
|
for (const table4 of Object.values(json1.tables)) {
|
|
@@ -45374,14 +45569,8 @@ var sqliteConnectionSchema = unionType([
|
|
|
45374
45569
|
})
|
|
45375
45570
|
})
|
|
45376
45571
|
]);
|
|
45377
|
-
var configIntrospectSchema2 = objectType({
|
|
45378
|
-
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
45379
|
-
out: stringType().optional().default("./drizzle"),
|
|
45380
|
-
breakpoints: booleanType().optional(),
|
|
45381
|
-
tablesFilter: unionType([stringType(), stringType().array()]).optional()
|
|
45382
|
-
});
|
|
45383
45572
|
var sqliteCliConfigSchema = intersectionType(
|
|
45384
|
-
|
|
45573
|
+
configIntrospectSchema,
|
|
45385
45574
|
sqliteConnectionSchema
|
|
45386
45575
|
);
|
|
45387
45576
|
|
|
@@ -45392,27 +45581,42 @@ var withStyle = {
|
|
|
45392
45581
|
warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`
|
|
45393
45582
|
};
|
|
45394
45583
|
var outputs = {
|
|
45395
|
-
|
|
45396
|
-
|
|
45397
|
-
|
|
45398
|
-
|
|
45584
|
+
common: {
|
|
45585
|
+
ambiguousParams: (command) => withStyle.error(
|
|
45586
|
+
`You can't use both --config and other cli options for ${command} command`
|
|
45587
|
+
),
|
|
45588
|
+
schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`)
|
|
45589
|
+
},
|
|
45590
|
+
postgres: {
|
|
45591
|
+
connection: {
|
|
45592
|
+
driver: () => withStyle.error(
|
|
45593
|
+
`Only "pg" is available options for "--driver"`
|
|
45594
|
+
),
|
|
45595
|
+
required: () => withStyle.error(
|
|
45596
|
+
`Either "connectionString" or "host", "database" are required for database connection`
|
|
45399
45597
|
)
|
|
45400
|
-
}
|
|
45598
|
+
}
|
|
45599
|
+
},
|
|
45600
|
+
mysql: {
|
|
45401
45601
|
connection: {
|
|
45402
45602
|
driver: () => withStyle.error(
|
|
45403
|
-
`
|
|
45603
|
+
`Only "mysql2" is available options for "--driver"`
|
|
45404
45604
|
),
|
|
45605
|
+
required: () => withStyle.error(
|
|
45606
|
+
`Either "connectionString" or "host", "database" are required for database connection`
|
|
45607
|
+
)
|
|
45608
|
+
}
|
|
45609
|
+
},
|
|
45610
|
+
sqlite: {
|
|
45611
|
+
connection: {
|
|
45612
|
+
driver: () => withStyle.error(`Either "turso", "libsql", "better-sqlite" are available options for "--driver"`),
|
|
45405
45613
|
url: (driver) => withStyle.error(`"--url" is a required option for driver "${driver}"`),
|
|
45406
45614
|
authToken: (driver) => withStyle.error(
|
|
45407
45615
|
`"--auth-token" is a required option for driver "${driver}"`
|
|
45408
45616
|
)
|
|
45409
45617
|
},
|
|
45410
45618
|
introspect: {},
|
|
45411
|
-
push: {
|
|
45412
|
-
schema: () => withStyle.error(
|
|
45413
|
-
`"--schema" is a required field for sqlite:push command`
|
|
45414
|
-
)
|
|
45415
|
-
}
|
|
45619
|
+
push: {}
|
|
45416
45620
|
}
|
|
45417
45621
|
};
|
|
45418
45622
|
|
|
@@ -45445,7 +45649,7 @@ var checkCollisions = (options, command, inputWhitelist = []) => {
|
|
|
45445
45649
|
}
|
|
45446
45650
|
return {
|
|
45447
45651
|
success: false,
|
|
45448
|
-
message: outputs.
|
|
45652
|
+
message: outputs.common.ambiguousParams(command),
|
|
45449
45653
|
action: "error"
|
|
45450
45654
|
};
|
|
45451
45655
|
};
|
|
@@ -45467,15 +45671,9 @@ var sqliteConnectionCli = unionType([
|
|
|
45467
45671
|
})
|
|
45468
45672
|
]);
|
|
45469
45673
|
var sqliteCliIntrospectParams = intersectionType(
|
|
45470
|
-
|
|
45674
|
+
configIntrospectCliSchema,
|
|
45471
45675
|
sqliteConnectionCli
|
|
45472
45676
|
);
|
|
45473
|
-
var configPushSchema = objectType({
|
|
45474
|
-
schema: unionType([stringType(), stringType().array()]),
|
|
45475
|
-
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
|
45476
|
-
verbose: booleanType().default(false),
|
|
45477
|
-
strict: booleanType().default(false)
|
|
45478
|
-
});
|
|
45479
45677
|
var sqliteCliPushParams = intersectionType(
|
|
45480
45678
|
configPushSchema,
|
|
45481
45679
|
sqliteConnectionCli
|
|
@@ -45525,14 +45723,14 @@ var printConfigConnectionIssues = (options) => {
|
|
|
45525
45723
|
console.log(outputs.sqlite.connection.driver());
|
|
45526
45724
|
}
|
|
45527
45725
|
};
|
|
45528
|
-
var validateIntrospect = (options) => {
|
|
45726
|
+
var validateIntrospect = async (options) => {
|
|
45529
45727
|
const collisionRes = checkCollisions(options, "introspect:sqlite");
|
|
45530
45728
|
if (!collisionRes.success) {
|
|
45531
45729
|
console.log(collisionRes.message);
|
|
45532
45730
|
process.exit(1);
|
|
45533
45731
|
}
|
|
45534
45732
|
if (collisionRes.action === "config") {
|
|
45535
|
-
const drizzleConfig = readDrizzleConfig(options.config);
|
|
45733
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
|
45536
45734
|
const configRes = sqliteCliConfigSchema.safeParse(drizzleConfig);
|
|
45537
45735
|
if (!configRes.success) {
|
|
45538
45736
|
printConfigConnectionIssues(drizzleConfig);
|
|
@@ -45546,15 +45744,27 @@ var validateIntrospect = (options) => {
|
|
|
45546
45744
|
process.exit(1);
|
|
45547
45745
|
}
|
|
45548
45746
|
if (cliRes.data.driver === "turso") {
|
|
45549
|
-
const { authToken, url: url2, ...rest2 } = cliRes.data;
|
|
45550
|
-
return {
|
|
45747
|
+
const { authToken, url: url2, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
|
|
45748
|
+
return {
|
|
45749
|
+
...rest2,
|
|
45750
|
+
dbCredentials: { url: url2, authToken },
|
|
45751
|
+
introspect: { casing: introspectCasing3 }
|
|
45752
|
+
};
|
|
45551
45753
|
}
|
|
45552
45754
|
if (cliRes.data.driver === "libsql") {
|
|
45553
|
-
const { url: url2, ...rest2 } = cliRes.data;
|
|
45554
|
-
return {
|
|
45755
|
+
const { url: url2, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
|
|
45756
|
+
return {
|
|
45757
|
+
...rest2,
|
|
45758
|
+
dbCredentials: { url: url2 },
|
|
45759
|
+
introspect: { casing: introspectCasing3 }
|
|
45760
|
+
};
|
|
45555
45761
|
}
|
|
45556
|
-
const { url, ...rest } = cliRes.data;
|
|
45557
|
-
return {
|
|
45762
|
+
const { url, introspectCasing: introspectCasing2, ...rest } = cliRes.data;
|
|
45763
|
+
return {
|
|
45764
|
+
...rest,
|
|
45765
|
+
dbCredentials: { url },
|
|
45766
|
+
introspect: { casing: introspectCasing2 }
|
|
45767
|
+
};
|
|
45558
45768
|
};
|
|
45559
45769
|
var validatePush = async (options) => {
|
|
45560
45770
|
const collisionRes = checkCollisions(options, "push:sqlite");
|
|
@@ -45575,7 +45785,7 @@ var validatePush = async (options) => {
|
|
|
45575
45785
|
const cliRes = sqliteCliPushParams.safeParse(options);
|
|
45576
45786
|
if (!cliRes.success) {
|
|
45577
45787
|
if (typeof options.schema === "undefined") {
|
|
45578
|
-
console.log(outputs.
|
|
45788
|
+
console.log(outputs.common.schema("push:sqlite"));
|
|
45579
45789
|
}
|
|
45580
45790
|
printCliConnectionIssues(options);
|
|
45581
45791
|
process.exit(1);
|
|
@@ -45588,6 +45798,269 @@ var validatePush = async (options) => {
|
|
|
45588
45798
|
return { ...rest, dbCredentials: { url } };
|
|
45589
45799
|
};
|
|
45590
45800
|
|
|
45801
|
+
// src/cli/validations/pg.ts
|
|
45802
|
+
init_lib();
|
|
45803
|
+
var pgConnectionCli = unionType([
|
|
45804
|
+
objectType({
|
|
45805
|
+
driver: literalType("pg"),
|
|
45806
|
+
host: stringType(),
|
|
45807
|
+
port: coerce.number().optional(),
|
|
45808
|
+
user: stringType().default("postgres"),
|
|
45809
|
+
password: stringType().optional(),
|
|
45810
|
+
database: stringType(),
|
|
45811
|
+
ssl: coerce.boolean().optional(),
|
|
45812
|
+
type: literalType("params").default("params")
|
|
45813
|
+
}),
|
|
45814
|
+
objectType({
|
|
45815
|
+
driver: literalType("pg"),
|
|
45816
|
+
connectionString: stringType(),
|
|
45817
|
+
type: literalType("url").default("url")
|
|
45818
|
+
})
|
|
45819
|
+
]);
|
|
45820
|
+
var pgConnectionConfig = unionType([
|
|
45821
|
+
objectType({
|
|
45822
|
+
driver: literalType("pg"),
|
|
45823
|
+
dbCredentials: objectType({
|
|
45824
|
+
host: stringType(),
|
|
45825
|
+
port: coerce.number().optional(),
|
|
45826
|
+
user: stringType().default("postgres"),
|
|
45827
|
+
password: stringType().optional(),
|
|
45828
|
+
database: stringType(),
|
|
45829
|
+
ssl: coerce.boolean().optional()
|
|
45830
|
+
})
|
|
45831
|
+
}),
|
|
45832
|
+
objectType({
|
|
45833
|
+
driver: literalType("pg"),
|
|
45834
|
+
dbCredentials: objectType({
|
|
45835
|
+
connectionString: stringType()
|
|
45836
|
+
})
|
|
45837
|
+
})
|
|
45838
|
+
]);
|
|
45839
|
+
var pgConfigIntrospectSchema = intersectionType(
|
|
45840
|
+
configIntrospectSchema,
|
|
45841
|
+
pgConnectionConfig
|
|
45842
|
+
);
|
|
45843
|
+
var pgCliIntrospectParams = intersectionType(
|
|
45844
|
+
configIntrospectCliSchema,
|
|
45845
|
+
pgConnectionCli
|
|
45846
|
+
);
|
|
45847
|
+
var printCliConnectionIssues2 = (options) => {
|
|
45848
|
+
if (options.driver === "pg") {
|
|
45849
|
+
if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
|
|
45850
|
+
console.log(outputs.postgres.connection.required());
|
|
45851
|
+
}
|
|
45852
|
+
} else {
|
|
45853
|
+
console.log(outputs.postgres.connection.driver());
|
|
45854
|
+
}
|
|
45855
|
+
};
|
|
45856
|
+
var printConfigConnectionIssues2 = (options) => {
|
|
45857
|
+
if (options.driver === "pg") {
|
|
45858
|
+
if (typeof options.dbCredentials.connectionString === "undefined" && (typeof options.dbCredentials.host === "undefined" || typeof options.dbCredentials.database === "undefined")) {
|
|
45859
|
+
console.log(outputs.postgres.connection.required());
|
|
45860
|
+
}
|
|
45861
|
+
} else {
|
|
45862
|
+
console.log(outputs.postgres.connection.driver());
|
|
45863
|
+
}
|
|
45864
|
+
};
|
|
45865
|
+
var validatePgIntrospect = async (options) => {
|
|
45866
|
+
const collisionRes = checkCollisions(options, "introspect:pg");
|
|
45867
|
+
if (!collisionRes.success) {
|
|
45868
|
+
console.log(collisionRes.message);
|
|
45869
|
+
process.exit(1);
|
|
45870
|
+
}
|
|
45871
|
+
if (collisionRes.action === "config") {
|
|
45872
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
|
45873
|
+
const configRes = pgConfigIntrospectSchema.safeParse(drizzleConfig);
|
|
45874
|
+
if (!configRes.success) {
|
|
45875
|
+
printConfigConnectionIssues2(drizzleConfig);
|
|
45876
|
+
process.exit(1);
|
|
45877
|
+
}
|
|
45878
|
+
return configRes.data;
|
|
45879
|
+
}
|
|
45880
|
+
const cliRes = pgCliIntrospectParams.safeParse(options);
|
|
45881
|
+
if (!cliRes.success) {
|
|
45882
|
+
printCliConnectionIssues2(options);
|
|
45883
|
+
process.exit(1);
|
|
45884
|
+
}
|
|
45885
|
+
if (cliRes.data.type === "url") {
|
|
45886
|
+
const { connectionString, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
|
|
45887
|
+
return {
|
|
45888
|
+
...rest2,
|
|
45889
|
+
dbCredentials: { connectionString },
|
|
45890
|
+
introspect: { casing: introspectCasing3 }
|
|
45891
|
+
};
|
|
45892
|
+
}
|
|
45893
|
+
const {
|
|
45894
|
+
host,
|
|
45895
|
+
password,
|
|
45896
|
+
port,
|
|
45897
|
+
database,
|
|
45898
|
+
ssl,
|
|
45899
|
+
user,
|
|
45900
|
+
introspectCasing: introspectCasing2,
|
|
45901
|
+
...rest
|
|
45902
|
+
} = cliRes.data;
|
|
45903
|
+
return {
|
|
45904
|
+
...rest,
|
|
45905
|
+
dbCredentials: { host, password, port, database, ssl, user },
|
|
45906
|
+
introspect: { casing: introspectCasing2 }
|
|
45907
|
+
};
|
|
45908
|
+
};
|
|
45909
|
+
|
|
45910
|
+
// src/cli/validations/mysql.ts
|
|
45911
|
+
init_lib();
|
|
45912
|
+
var mysqlConnectionCli = unionType([
|
|
45913
|
+
objectType({
|
|
45914
|
+
driver: literalType("mysql2"),
|
|
45915
|
+
host: stringType(),
|
|
45916
|
+
port: coerce.number().optional(),
|
|
45917
|
+
user: stringType().default("mysql"),
|
|
45918
|
+
password: stringType().optional(),
|
|
45919
|
+
database: stringType(),
|
|
45920
|
+
type: literalType("params").default("params")
|
|
45921
|
+
}),
|
|
45922
|
+
objectType({
|
|
45923
|
+
driver: literalType("mysql2"),
|
|
45924
|
+
connectionString: stringType(),
|
|
45925
|
+
type: literalType("url").default("url")
|
|
45926
|
+
})
|
|
45927
|
+
]);
|
|
45928
|
+
var mysqlConnectionConfig = unionType([
|
|
45929
|
+
objectType({
|
|
45930
|
+
driver: literalType("mysql2"),
|
|
45931
|
+
dbCredentials: objectType({
|
|
45932
|
+
host: stringType(),
|
|
45933
|
+
port: coerce.number().optional(),
|
|
45934
|
+
user: stringType().default("mysql"),
|
|
45935
|
+
password: stringType().optional(),
|
|
45936
|
+
database: stringType(),
|
|
45937
|
+
type: literalType("params").default("params")
|
|
45938
|
+
})
|
|
45939
|
+
}),
|
|
45940
|
+
objectType({
|
|
45941
|
+
driver: literalType("mysql2"),
|
|
45942
|
+
dbCredentials: objectType({
|
|
45943
|
+
connectionString: stringType(),
|
|
45944
|
+
type: literalType("url").default("url")
|
|
45945
|
+
})
|
|
45946
|
+
})
|
|
45947
|
+
]);
|
|
45948
|
+
var mysqlConfigIntrospectSchema = intersectionType(
|
|
45949
|
+
configIntrospectSchema,
|
|
45950
|
+
mysqlConnectionConfig
|
|
45951
|
+
);
|
|
45952
|
+
var mysqlCliIntrospectParams = intersectionType(
|
|
45953
|
+
configIntrospectCliSchema,
|
|
45954
|
+
mysqlConnectionCli
|
|
45955
|
+
);
|
|
45956
|
+
var mysqlCliPushParams = intersectionType(
|
|
45957
|
+
configPushSchema,
|
|
45958
|
+
mysqlConnectionCli
|
|
45959
|
+
);
|
|
45960
|
+
var mysqlConfigPushParams = intersectionType(
|
|
45961
|
+
configPushSchema,
|
|
45962
|
+
mysqlConnectionConfig
|
|
45963
|
+
);
|
|
45964
|
+
var printCliConnectionIssues3 = (options) => {
|
|
45965
|
+
if (options.driver === "mysql2") {
|
|
45966
|
+
if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
|
|
45967
|
+
console.log(outputs.mysql.connection.required());
|
|
45968
|
+
}
|
|
45969
|
+
} else {
|
|
45970
|
+
console.log(outputs.mysql.connection.driver());
|
|
45971
|
+
}
|
|
45972
|
+
};
|
|
45973
|
+
var printConfigConnectionIssues3 = (options) => {
|
|
45974
|
+
if (options.driver === "mysql2") {
|
|
45975
|
+
if (typeof options.dbCredentials.connectionString === "undefined" && (typeof options.dbCredentials.host === "undefined" || typeof options.dbCredentials.database === "undefined")) {
|
|
45976
|
+
console.log(outputs.mysql.connection.required());
|
|
45977
|
+
}
|
|
45978
|
+
} else {
|
|
45979
|
+
console.log(outputs.mysql.connection.driver());
|
|
45980
|
+
}
|
|
45981
|
+
};
|
|
45982
|
+
var validateMySqlIntrospect = async (options) => {
|
|
45983
|
+
const collisionRes = checkCollisions(options, "introspect:mysql");
|
|
45984
|
+
if (!collisionRes.success) {
|
|
45985
|
+
console.log(collisionRes.message);
|
|
45986
|
+
process.exit(1);
|
|
45987
|
+
}
|
|
45988
|
+
if (collisionRes.action === "config") {
|
|
45989
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
|
45990
|
+
const configRes = mysqlConfigIntrospectSchema.safeParse(drizzleConfig);
|
|
45991
|
+
if (!configRes.success) {
|
|
45992
|
+
printConfigConnectionIssues3(drizzleConfig);
|
|
45993
|
+
process.exit(1);
|
|
45994
|
+
}
|
|
45995
|
+
return configRes.data;
|
|
45996
|
+
}
|
|
45997
|
+
const cliRes = mysqlCliIntrospectParams.safeParse(options);
|
|
45998
|
+
if (!cliRes.success) {
|
|
45999
|
+
printCliConnectionIssues3(options);
|
|
46000
|
+
process.exit(1);
|
|
46001
|
+
}
|
|
46002
|
+
if (cliRes.data.type === "url") {
|
|
46003
|
+
const { connectionString, introspectCasing: introspectCasing3, type: type2, ...rest2 } = cliRes.data;
|
|
46004
|
+
return {
|
|
46005
|
+
...rest2,
|
|
46006
|
+
dbCredentials: { connectionString, type: type2 },
|
|
46007
|
+
introspect: { casing: introspectCasing3 }
|
|
46008
|
+
};
|
|
46009
|
+
}
|
|
46010
|
+
const {
|
|
46011
|
+
host,
|
|
46012
|
+
password,
|
|
46013
|
+
port,
|
|
46014
|
+
database,
|
|
46015
|
+
user,
|
|
46016
|
+
type,
|
|
46017
|
+
introspectCasing: introspectCasing2,
|
|
46018
|
+
...rest
|
|
46019
|
+
} = cliRes.data;
|
|
46020
|
+
return {
|
|
46021
|
+
...rest,
|
|
46022
|
+
dbCredentials: { host, password, port, database, user, type },
|
|
46023
|
+
introspect: { casing: introspectCasing2 }
|
|
46024
|
+
};
|
|
46025
|
+
};
|
|
46026
|
+
var validateMySqlPush = async (options) => {
|
|
46027
|
+
const collisionRes = checkCollisions(options, "push:mysql");
|
|
46028
|
+
if (!collisionRes.success) {
|
|
46029
|
+
console.log(collisionRes.message);
|
|
46030
|
+
console.log();
|
|
46031
|
+
process.exit(1);
|
|
46032
|
+
}
|
|
46033
|
+
if (collisionRes.action === "config") {
|
|
46034
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
|
46035
|
+
const configRes = mysqlConfigPushParams.safeParse(drizzleConfig);
|
|
46036
|
+
if (!configRes.success) {
|
|
46037
|
+
printConfigConnectionIssues3(drizzleConfig);
|
|
46038
|
+
process.exit(1);
|
|
46039
|
+
}
|
|
46040
|
+
return configRes.data;
|
|
46041
|
+
}
|
|
46042
|
+
const cliRes = mysqlCliPushParams.safeParse(options);
|
|
46043
|
+
if (!cliRes.success) {
|
|
46044
|
+
if (typeof options.schema === "undefined") {
|
|
46045
|
+
console.log(outputs.common.schema("push:mysql"));
|
|
46046
|
+
}
|
|
46047
|
+
printCliConnectionIssues3(options);
|
|
46048
|
+
process.exit(1);
|
|
46049
|
+
}
|
|
46050
|
+
if (cliRes.data.type === "url") {
|
|
46051
|
+
const { connectionString, type: type2, ...rest2 } = cliRes.data;
|
|
46052
|
+
return {
|
|
46053
|
+
...rest2,
|
|
46054
|
+
dbCredentials: { connectionString, type: type2 }
|
|
46055
|
+
};
|
|
46056
|
+
}
|
|
46057
|
+
const { host, password, port, database, user, type, ...rest } = cliRes.data;
|
|
46058
|
+
return {
|
|
46059
|
+
...rest,
|
|
46060
|
+
dbCredentials: { host, password, port, database, user, type }
|
|
46061
|
+
};
|
|
46062
|
+
};
|
|
46063
|
+
|
|
45591
46064
|
// src/cli/index.ts
|
|
45592
46065
|
var printVersions = async () => {
|
|
45593
46066
|
const v = await versions();
|
|
@@ -45605,7 +46078,7 @@ var optionsSchema = objectType({
|
|
|
45605
46078
|
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
45606
46079
|
out: stringType().optional().default("./drizzle"),
|
|
45607
46080
|
config: stringType().optional(),
|
|
45608
|
-
breakpoints: booleanType().optional().default(
|
|
46081
|
+
breakpoints: booleanType().optional().default(true),
|
|
45609
46082
|
custom: booleanType().optional().default(false)
|
|
45610
46083
|
}).strict();
|
|
45611
46084
|
var generatePgCommand = new import_commander.Command("generate:pg").option("--schema <schema...>", "Path to a schema file or folder").option("--out <out>", `Output folder, 'drizzle' by default`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--custom", "Prepare empty migration file for custom SQL").option(
|
|
@@ -45614,6 +46087,15 @@ var generatePgCommand = new import_commander.Command("generate:pg").option("--sc
|
|
|
45614
46087
|
).action(async (options) => {
|
|
45615
46088
|
await printVersions();
|
|
45616
46089
|
await assertOrmCoreVersion();
|
|
46090
|
+
const collisionRes = checkCollisions(
|
|
46091
|
+
options,
|
|
46092
|
+
"generate:pg",
|
|
46093
|
+
["custom"]
|
|
46094
|
+
);
|
|
46095
|
+
if (!collisionRes.success) {
|
|
46096
|
+
console.log(collisionRes.message);
|
|
46097
|
+
process.exit(1);
|
|
46098
|
+
}
|
|
45617
46099
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
45618
46100
|
const result = await prepareGenerateConfig(oprtionsParsed);
|
|
45619
46101
|
await assertPackages("drizzle-orm");
|
|
@@ -45626,6 +46108,15 @@ var generateMysqlCommand = new import_commander.Command("generate:mysql").option
|
|
|
45626
46108
|
).action(async (options) => {
|
|
45627
46109
|
await printVersions();
|
|
45628
46110
|
await assertOrmCoreVersion();
|
|
46111
|
+
const collisionRes = checkCollisions(
|
|
46112
|
+
options,
|
|
46113
|
+
"generate:mysql",
|
|
46114
|
+
["custom"]
|
|
46115
|
+
);
|
|
46116
|
+
if (!collisionRes.success) {
|
|
46117
|
+
console.log(collisionRes.message);
|
|
46118
|
+
process.exit(1);
|
|
46119
|
+
}
|
|
45629
46120
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
45630
46121
|
const result = await prepareGenerateConfig(oprtionsParsed);
|
|
45631
46122
|
await assertPackages("drizzle-orm");
|
|
@@ -45664,12 +46155,14 @@ var Select = class extends import_hanji8.Prompt {
|
|
|
45664
46155
|
var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
45665
46156
|
"--config <config>",
|
|
45666
46157
|
"Path to a config.json file, drizzle.config.json by default"
|
|
45667
|
-
).action(async (options) => {
|
|
46158
|
+
).option("--schema <schema...>", "Path to a schema file or folder").option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "MySQL connection string").option("--driver <driver>", "MySQL database path").option("--connectionString <connectionString>", "MySQL connection string").option("--host <host>", "MySQL host").option("--port <port>", "MySQL port").option("--user <user>", "MySQL user").option("--password <password>", "MySQL password").option("--database <database>", "MySQL database name").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
|
|
45668
46159
|
await printVersions();
|
|
45669
46160
|
await assertPackages("drizzle-orm");
|
|
45670
46161
|
await assertOrmCoreVersion();
|
|
45671
46162
|
const { mysqlPushIntrospect: mysqlPushIntrospect2, connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_mysqlIntrospect(), mysqlIntrospect_exports));
|
|
45672
|
-
const drizzleConfig = await
|
|
46163
|
+
const drizzleConfig = await validateMySqlPush(
|
|
46164
|
+
options
|
|
46165
|
+
);
|
|
45673
46166
|
const fileNames = prepareFilenames(drizzleConfig.schema);
|
|
45674
46167
|
if (fileNames.length === 0) {
|
|
45675
46168
|
(0, import_hanji8.render)(
|
|
@@ -45698,13 +46191,38 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
45698
46191
|
columnsToRemove,
|
|
45699
46192
|
tablesToRemove,
|
|
45700
46193
|
tablesToTruncate,
|
|
46194
|
+
infoToPrint,
|
|
45701
46195
|
schemasToRemove
|
|
45702
46196
|
} = await logSuggestionsAndReturn({
|
|
45703
46197
|
connection: connection.client,
|
|
45704
46198
|
statements: filteredStatements
|
|
45705
46199
|
});
|
|
46200
|
+
if (drizzleConfig.verbose) {
|
|
46201
|
+
console.log();
|
|
46202
|
+
console.log(
|
|
46203
|
+
withStyle.warning("You are about to execute current statements:")
|
|
46204
|
+
);
|
|
46205
|
+
console.log();
|
|
46206
|
+
console.log(
|
|
46207
|
+
[...statementsToExecute, ...statements.sqlStatements].map((s) => source_default.blue(s)).join("\n")
|
|
46208
|
+
);
|
|
46209
|
+
console.log();
|
|
46210
|
+
}
|
|
46211
|
+
if (drizzleConfig.strict) {
|
|
46212
|
+
if (!shouldAskForApprove) {
|
|
46213
|
+
const { status, data } = await (0, import_hanji8.render)(
|
|
46214
|
+
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
46215
|
+
);
|
|
46216
|
+
if ((data == null ? void 0 : data.index) === 0) {
|
|
46217
|
+
(0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
46218
|
+
process.exit(0);
|
|
46219
|
+
}
|
|
46220
|
+
}
|
|
46221
|
+
}
|
|
45706
46222
|
if (shouldAskForApprove) {
|
|
45707
|
-
console.log("
|
|
46223
|
+
console.log(withStyle.warning("Found data-loss statements:"));
|
|
46224
|
+
console.log(infoToPrint.join("\n"));
|
|
46225
|
+
console.log();
|
|
45708
46226
|
console.log(
|
|
45709
46227
|
source_default.red.bold(
|
|
45710
46228
|
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
|
@@ -45840,6 +46358,15 @@ var generateSqliteCommand = new import_commander.Command("generate:sqlite").opti
|
|
|
45840
46358
|
).action(async (options) => {
|
|
45841
46359
|
await printVersions();
|
|
45842
46360
|
await assertOrmCoreVersion();
|
|
46361
|
+
const collisionRes = checkCollisions(
|
|
46362
|
+
options,
|
|
46363
|
+
"generate:sqlite",
|
|
46364
|
+
["custom"]
|
|
46365
|
+
);
|
|
46366
|
+
if (!collisionRes.success) {
|
|
46367
|
+
console.log(collisionRes.message);
|
|
46368
|
+
process.exit(1);
|
|
46369
|
+
}
|
|
45843
46370
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
45844
46371
|
const result = await prepareGenerateConfig(oprtionsParsed);
|
|
45845
46372
|
await assertPackages("drizzle-orm");
|
|
@@ -45853,6 +46380,14 @@ var checkSchema = objectType({
|
|
|
45853
46380
|
var checkPgCommand = new import_commander.Command("check:pg").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
45854
46381
|
await printVersions();
|
|
45855
46382
|
await assertOrmCoreVersion();
|
|
46383
|
+
const collisionRes = checkCollisions(
|
|
46384
|
+
options,
|
|
46385
|
+
"check:pg"
|
|
46386
|
+
);
|
|
46387
|
+
if (!collisionRes.success) {
|
|
46388
|
+
console.log(collisionRes.message);
|
|
46389
|
+
process.exit(1);
|
|
46390
|
+
}
|
|
45856
46391
|
const params = checkSchema.parse(options);
|
|
45857
46392
|
const out = await assertOutFolder(params);
|
|
45858
46393
|
checkHandler(out, "pg");
|
|
@@ -45861,14 +46396,46 @@ var checkPgCommand = new import_commander.Command("check:pg").option("--out <out
|
|
|
45861
46396
|
var checkSqliteCommand = new import_commander.Command("check:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
45862
46397
|
await printVersions();
|
|
45863
46398
|
await assertOrmCoreVersion();
|
|
46399
|
+
const collisionRes = checkCollisions(
|
|
46400
|
+
options,
|
|
46401
|
+
"check:sqlite"
|
|
46402
|
+
);
|
|
46403
|
+
if (!collisionRes.success) {
|
|
46404
|
+
console.log(collisionRes.message);
|
|
46405
|
+
process.exit(1);
|
|
46406
|
+
}
|
|
45864
46407
|
const params = checkSchema.parse(options);
|
|
45865
46408
|
const out = await assertOutFolder(params);
|
|
45866
46409
|
checkHandler(out, "sqlite");
|
|
45867
46410
|
console.log("Everything's fine \u{1F436}\u{1F525}");
|
|
45868
46411
|
});
|
|
46412
|
+
var checkMySqlCommand = new import_commander.Command("check:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
46413
|
+
await printVersions();
|
|
46414
|
+
await assertOrmCoreVersion();
|
|
46415
|
+
const collisionRes = checkCollisions(
|
|
46416
|
+
options,
|
|
46417
|
+
"check:mysql"
|
|
46418
|
+
);
|
|
46419
|
+
if (!collisionRes.success) {
|
|
46420
|
+
console.log(collisionRes.message);
|
|
46421
|
+
process.exit(1);
|
|
46422
|
+
}
|
|
46423
|
+
const params = checkSchema.parse(options);
|
|
46424
|
+
const out = await assertOutFolder(params);
|
|
46425
|
+
checkHandler(out, "mysql");
|
|
46426
|
+
console.log("Everything's fine \u{1F436}\u{1F525}");
|
|
46427
|
+
});
|
|
45869
46428
|
var upPgCommand = new import_commander.Command("up:pg").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
45870
46429
|
await printVersions();
|
|
45871
46430
|
await assertOrmCoreVersion();
|
|
46431
|
+
const collisionRes = checkCollisions(
|
|
46432
|
+
options,
|
|
46433
|
+
"up:pg"
|
|
46434
|
+
);
|
|
46435
|
+
if (!collisionRes.success) {
|
|
46436
|
+
console.log(collisionRes.message);
|
|
46437
|
+
process.exit(1);
|
|
46438
|
+
}
|
|
45872
46439
|
const params = checkSchema.parse(options);
|
|
45873
46440
|
const out = await assertOutFolder(params);
|
|
45874
46441
|
await assertPackages("drizzle-orm");
|
|
@@ -45879,6 +46446,14 @@ var upPgCommand = new import_commander.Command("up:pg").option("--out <out>", `O
|
|
|
45879
46446
|
var upMysqlCommand = new import_commander.Command("up:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
45880
46447
|
await printVersions();
|
|
45881
46448
|
await assertOrmCoreVersion();
|
|
46449
|
+
const collisionRes = checkCollisions(
|
|
46450
|
+
options,
|
|
46451
|
+
"up:mysql"
|
|
46452
|
+
);
|
|
46453
|
+
if (!collisionRes.success) {
|
|
46454
|
+
console.log(collisionRes.message);
|
|
46455
|
+
process.exit(1);
|
|
46456
|
+
}
|
|
45882
46457
|
const params = checkSchema.parse(options);
|
|
45883
46458
|
const out = await assertOutFolder(params);
|
|
45884
46459
|
await assertPackages("drizzle-orm");
|
|
@@ -45889,36 +46464,36 @@ var upMysqlCommand = new import_commander.Command("up:mysql").option("--out <out
|
|
|
45889
46464
|
var upSqliteCommand = new import_commander.Command("up:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
|
|
45890
46465
|
await printVersions();
|
|
45891
46466
|
await assertOrmCoreVersion();
|
|
46467
|
+
const collisionRes = checkCollisions(
|
|
46468
|
+
options,
|
|
46469
|
+
"up:sqlite"
|
|
46470
|
+
);
|
|
46471
|
+
if (!collisionRes.success) {
|
|
46472
|
+
console.log(collisionRes.message);
|
|
46473
|
+
process.exit(1);
|
|
46474
|
+
}
|
|
45892
46475
|
const params = checkSchema.parse(options);
|
|
45893
46476
|
const out = await assertOutFolder(params);
|
|
45894
46477
|
upSqliteHandlerV4(out);
|
|
45895
46478
|
upgradeFolders("sqlite", out);
|
|
45896
46479
|
upSqliteHandler(out);
|
|
45897
46480
|
});
|
|
45898
|
-
var
|
|
45899
|
-
|
|
45900
|
-
|
|
45901
|
-
|
|
45902
|
-
var introspectPgCommand = new import_commander.Command("introspect:pg").option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--introspect-casing <introspectCasing>", "Column object keys naming strategy").option("--connectionString <connectionString>", "Postgres connection string").option("--host <host>", "Postgres host").option("--port <port>", "Postgres port").option("--user <user>", "Postgres user").option("--password <password>", "Postgres password").option("--database <database>", "Postgres database name").option("--ssl <ssl>", "Postgres ssl").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
|
|
46481
|
+
var introspectPgCommand = new import_commander.Command("introspect:pg").option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option(
|
|
46482
|
+
"--introspect-casing <introspectCasing>",
|
|
46483
|
+
"Column object keys naming strategy"
|
|
46484
|
+
).option("--driver <driver>", "Postgres connection string").option("--connectionString <connectionString>", "Postgres connection string").option("--host <host>", "Postgres host").option("--port <port>", "Postgres port").option("--user <user>", "Postgres user").option("--password <password>", "Postgres password").option("--database <database>", "Postgres database name").option("--ssl <ssl>", "Postgres ssl").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
|
|
45903
46485
|
await printVersions();
|
|
45904
46486
|
await assertPackages("drizzle-orm");
|
|
45905
46487
|
await assertOrmCoreVersion();
|
|
45906
|
-
const { pgIntrospect: pgIntrospect2
|
|
45907
|
-
const
|
|
45908
|
-
|
|
45909
|
-
|
|
45910
|
-
|
|
45911
|
-
|
|
45912
|
-
const
|
|
45913
|
-
|
|
45914
|
-
|
|
45915
|
-
console.log(issue.message);
|
|
45916
|
-
}
|
|
45917
|
-
return;
|
|
45918
|
-
}
|
|
45919
|
-
const { snapshots, journal } = prepareOutFolder2(res.data.out, "pg");
|
|
45920
|
-
const { schema: schema4, ts } = await pgIntrospect2(res.data);
|
|
45921
|
-
const schemaFile = import_path7.default.join(res.data.out, "schema.ts");
|
|
46488
|
+
const { pgIntrospect: pgIntrospect2 } = await Promise.resolve().then(() => (init_pgIntrospect(), pgIntrospect_exports));
|
|
46489
|
+
const validatedConfig = await validatePgIntrospect(
|
|
46490
|
+
options
|
|
46491
|
+
);
|
|
46492
|
+
const { snapshots, journal } = prepareOutFolder2(validatedConfig.out, "pg");
|
|
46493
|
+
const filterConfig = validatedConfig.tablesFilter;
|
|
46494
|
+
const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
|
|
46495
|
+
const { schema: schema4, ts } = await pgIntrospect2(validatedConfig, tablesFilter);
|
|
46496
|
+
const schemaFile = import_path7.default.join(validatedConfig.out, "schema.ts");
|
|
45922
46497
|
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
|
45923
46498
|
console.log();
|
|
45924
46499
|
if (snapshots.length === 0) {
|
|
@@ -45934,8 +46509,8 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
|
|
|
45934
46509
|
sqlStatements,
|
|
45935
46510
|
journal,
|
|
45936
46511
|
_meta,
|
|
45937
|
-
|
|
45938
|
-
|
|
46512
|
+
validatedConfig.out,
|
|
46513
|
+
validatedConfig.breakpoints,
|
|
45939
46514
|
"introspect"
|
|
45940
46515
|
);
|
|
45941
46516
|
} else {
|
|
@@ -45957,22 +46532,20 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
|
|
|
45957
46532
|
var introspectMySqlCommand = new import_commander.Command("introspect:mysql").option(
|
|
45958
46533
|
"--config <config>",
|
|
45959
46534
|
"Path to a config.json file, drizzle.config.json by default"
|
|
46535
|
+
).option(
|
|
46536
|
+
"--introspect-casing <introspectCasing>",
|
|
46537
|
+
"Column object keys naming strategy"
|
|
45960
46538
|
).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--connectionString <connectionString>", "MySQL connection string").option("--host <host>", "MySQL host").option("--port <port>", "MySQL port").option("--user <user>", "MySQL user").option("--password <password>", "MySQL password").option("--database <database>", "MySQL database name").action(async (options) => {
|
|
45961
46539
|
await printVersions();
|
|
45962
46540
|
await assertPackages("drizzle-orm");
|
|
45963
46541
|
await assertOrmCoreVersion();
|
|
45964
46542
|
const { mysqlIntrospect: mysqlIntrospect2 } = await Promise.resolve().then(() => (init_mysqlIntrospect(), mysqlIntrospect_exports));
|
|
45965
|
-
const
|
|
45966
|
-
const
|
|
45967
|
-
if (!res.success) {
|
|
45968
|
-
for (const issue of res.error.issues) {
|
|
45969
|
-
console.log(issue.message);
|
|
45970
|
-
}
|
|
45971
|
-
process.exit(1);
|
|
45972
|
-
}
|
|
45973
|
-
const out = res.data.out;
|
|
46543
|
+
const res = await validateMySqlIntrospect(options);
|
|
46544
|
+
const out = res.out;
|
|
45974
46545
|
const { snapshots, journal } = prepareOutFolder2(out, "mysql");
|
|
45975
|
-
const
|
|
46546
|
+
const filterConfig = res.tablesFilter;
|
|
46547
|
+
const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
|
|
46548
|
+
const { schema: schema4, ts } = await mysqlIntrospect2(res, tablesFilter);
|
|
45976
46549
|
const schemaFile = import_path7.default.join(out, "schema.ts");
|
|
45977
46550
|
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
|
45978
46551
|
console.log();
|
|
@@ -45990,7 +46563,7 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
|
|
|
45990
46563
|
journal,
|
|
45991
46564
|
_meta,
|
|
45992
46565
|
out,
|
|
45993
|
-
res.
|
|
46566
|
+
res.breakpoints ?? false,
|
|
45994
46567
|
"introspect"
|
|
45995
46568
|
);
|
|
45996
46569
|
} else {
|
|
@@ -46012,15 +46585,20 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
|
|
|
46012
46585
|
var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").option(
|
|
46013
46586
|
"--config <config>",
|
|
46014
46587
|
"Path to a config.json file, drizzle.config.json by default"
|
|
46588
|
+
).option(
|
|
46589
|
+
"--introspect-casing <introspectCasing>",
|
|
46590
|
+
"Column object keys naming strategy"
|
|
46015
46591
|
).option("--schema <schema>", `Migrations folder`).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database url").option("--auth-token <authToken>", "SQLite database path").action(async (options) => {
|
|
46016
46592
|
printVersions();
|
|
46017
46593
|
assertPackages("drizzle-orm");
|
|
46018
46594
|
assertOrmCoreVersion();
|
|
46019
46595
|
const { sqliteIntrospect: sqliteIntrospect2 } = await Promise.resolve().then(() => (init_sqliteIntrospect(), sqliteIntrospect_exports));
|
|
46020
|
-
const res = validateIntrospect(options);
|
|
46596
|
+
const res = await validateIntrospect(options);
|
|
46021
46597
|
const out = res.out;
|
|
46022
46598
|
const { snapshots, journal } = prepareOutFolder2(out, "sqlite");
|
|
46023
|
-
const
|
|
46599
|
+
const filterConfig = res.tablesFilter;
|
|
46600
|
+
const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
|
|
46601
|
+
const { schema: schema4, ts } = await sqliteIntrospect2(res, tablesFilter);
|
|
46024
46602
|
const schemaFile = import_path7.default.join(out, "schema.ts");
|
|
46025
46603
|
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
|
46026
46604
|
console.log();
|
|
@@ -46060,10 +46638,18 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
|
|
|
46060
46638
|
var dropCommand = new import_commander.Command("drop").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
|
|
46061
46639
|
await printVersions();
|
|
46062
46640
|
await assertOrmCoreVersion();
|
|
46641
|
+
const collisionRes = checkCollisions(
|
|
46642
|
+
options,
|
|
46643
|
+
"drop"
|
|
46644
|
+
);
|
|
46645
|
+
if (!collisionRes.success) {
|
|
46646
|
+
console.log(collisionRes.message);
|
|
46647
|
+
process.exit(1);
|
|
46648
|
+
}
|
|
46063
46649
|
const params = checkSchema.parse(options);
|
|
46064
46650
|
const out = await assertOutFolder(params);
|
|
46065
46651
|
assertV1OutFolder(out, "{dialect}");
|
|
46066
|
-
dropMigration(out);
|
|
46652
|
+
await dropMigration(out);
|
|
46067
46653
|
});
|
|
46068
46654
|
var main = async () => {
|
|
46069
46655
|
const version2 = await versions();
|
|
@@ -46082,6 +46668,7 @@ var main = async () => {
|
|
|
46082
46668
|
import_commander.program.addCommand(dbPushMysqlCommand);
|
|
46083
46669
|
import_commander.program.addCommand(introspectSQLiteCommand);
|
|
46084
46670
|
import_commander.program.addCommand(dbPushSqliteCommand);
|
|
46671
|
+
import_commander.program.addCommand(checkMySqlCommand);
|
|
46085
46672
|
import_commander.program.parse();
|
|
46086
46673
|
};
|
|
46087
46674
|
main();
|