drizzle-kit 0.17.1-9fd4c75 → 0.17.1
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.js +124 -54
- package/package.json +3 -2
- package/utils.js +4 -4
package/index.js
CHANGED
|
@@ -14092,7 +14092,7 @@ ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.newConstraintNam
|
|
|
14092
14092
|
const onUpdateStatement = onUpdate ? `ON UPDATE ${onUpdate}` : "";
|
|
14093
14093
|
const fromColumnsString = columnsFrom.map((it) => `"${it}"`).join(",");
|
|
14094
14094
|
const toColumnsString = columnsTo.map((it) => `"${it}"`).join(",");
|
|
14095
|
-
const alterStatement = `ALTER TABLE
|
|
14095
|
+
const alterStatement = `ALTER TABLE ${tableFrom} ADD CONSTRAINT ${name} FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableTo}(${toColumnsString}) ${onDeleteStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
|
|
14096
14096
|
let sql = "DO $$ BEGIN\n";
|
|
14097
14097
|
sql += " " + alterStatement + ";\n";
|
|
14098
14098
|
sql += "EXCEPTION\n";
|
|
@@ -14143,13 +14143,13 @@ ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.newConstraintNam
|
|
|
14143
14143
|
convert(statement) {
|
|
14144
14144
|
const newFk = PgSquasher.unsquashFK(statement.data);
|
|
14145
14145
|
const oldFk = PgSquasher.unsquashFK(statement.oldFkey);
|
|
14146
|
-
let sql = `ALTER TABLE
|
|
14146
|
+
let sql = `ALTER TABLE ${oldFk.tableFrom} DROP CONSTRAINT ${oldFk.name};
|
|
14147
14147
|
`;
|
|
14148
14148
|
const onDeleteStatement = newFk.onDelete ? `ON DELETE ${newFk.onDelete}` : "";
|
|
14149
14149
|
const onUpdateStatement = newFk.onUpdate ? `ON UPDATE ${newFk.onDelete}` : "";
|
|
14150
14150
|
const fromColumnsString = newFk.columnsFrom.map((it) => `"${it}"`).join(",");
|
|
14151
14151
|
const toColumnsString = newFk.columnsTo.map((it) => `"${it}"`).join(",");
|
|
14152
|
-
const alterStatement = `ALTER TABLE
|
|
14152
|
+
const alterStatement = `ALTER TABLE ${newFk.tableFrom} ADD CONSTRAINT ${newFk.name} FOREIGN KEY (${fromColumnsString}) REFERENCES ${newFk.tableTo}(${toColumnsString}) ${onDeleteStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
|
|
14153
14153
|
sql += "DO $$ BEGIN\n";
|
|
14154
14154
|
sql += " " + alterStatement + ";\n";
|
|
14155
14155
|
sql += "EXCEPTION\n";
|
|
@@ -14180,7 +14180,7 @@ ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.newConstraintNam
|
|
|
14180
14180
|
convert(statement) {
|
|
14181
14181
|
const tableFrom = statement.tableName;
|
|
14182
14182
|
const { name } = PgSquasher.unsquashFK(statement.data);
|
|
14183
|
-
return `ALTER TABLE
|
|
14183
|
+
return `ALTER TABLE ${tableFrom} DROP CONSTRAINT ${name};
|
|
14184
14184
|
`;
|
|
14185
14185
|
}
|
|
14186
14186
|
};
|
|
@@ -25712,9 +25712,7 @@ var init_mysqlImports = __esm({
|
|
|
25712
25712
|
const i0values = Object.values(i0);
|
|
25713
25713
|
i0values.forEach((t) => {
|
|
25714
25714
|
if (t instanceof import_mysql_core.MySqlTable) {
|
|
25715
|
-
tables.push(
|
|
25716
|
-
t
|
|
25717
|
-
);
|
|
25715
|
+
tables.push(t);
|
|
25718
25716
|
}
|
|
25719
25717
|
if ((0, import_mysql_core.isMySqlSchema)(t)) {
|
|
25720
25718
|
schemas.push(t);
|
|
@@ -25759,6 +25757,7 @@ var init_mysqlSerializer = __esm({
|
|
|
25759
25757
|
import_sql = require("drizzle-orm/sql");
|
|
25760
25758
|
import_common = require("drizzle-orm/mysql-core/columns/common");
|
|
25761
25759
|
import_date = require("drizzle-orm/mysql-core/columns/date.common");
|
|
25760
|
+
init_serializer();
|
|
25762
25761
|
dialect3 = new import_mysql_core2.MySqlDialect();
|
|
25763
25762
|
indexName = (tableName, columns) => {
|
|
25764
25763
|
return `${tableName}_${columns.join("_")}_index`;
|
|
@@ -25792,12 +25791,7 @@ var init_mysqlSerializer = __esm({
|
|
|
25792
25791
|
};
|
|
25793
25792
|
if (column6.default !== void 0) {
|
|
25794
25793
|
if (column6.default instanceof import_sql.SQL) {
|
|
25795
|
-
columnToSet.default = column6.default
|
|
25796
|
-
if (typeof it === "string") {
|
|
25797
|
-
return `${it}`;
|
|
25798
|
-
}
|
|
25799
|
-
throw new Error();
|
|
25800
|
-
}).join();
|
|
25794
|
+
columnToSet.default = sqlToStr(column6.default);
|
|
25801
25795
|
} else {
|
|
25802
25796
|
if (typeof column6.default === "string") {
|
|
25803
25797
|
columnToSet.default = `'${column6.default}'`;
|
|
@@ -26111,9 +26105,7 @@ var init_pgImports = __esm({
|
|
|
26111
26105
|
return;
|
|
26112
26106
|
}
|
|
26113
26107
|
if (t instanceof import_pg_core.PgTable) {
|
|
26114
|
-
tables.push(
|
|
26115
|
-
t
|
|
26116
|
-
);
|
|
26108
|
+
tables.push(t);
|
|
26117
26109
|
}
|
|
26118
26110
|
if ((0, import_pg_core.isPgSchema)(t)) {
|
|
26119
26111
|
schemas.push(t);
|
|
@@ -26139,6 +26131,7 @@ var init_pgSerializer = __esm({
|
|
|
26139
26131
|
import_utils10 = require("drizzle-orm/pg-core/utils");
|
|
26140
26132
|
import_sql2 = require("drizzle-orm/sql");
|
|
26141
26133
|
import_table2 = require("drizzle-orm/table");
|
|
26134
|
+
init_serializer();
|
|
26142
26135
|
dialect4 = new import_pg_core2.PgDialect();
|
|
26143
26136
|
indexName2 = (tableName, columns) => {
|
|
26144
26137
|
return `${tableName}_${columns.join("_")}_index`;
|
|
@@ -26171,12 +26164,7 @@ var init_pgSerializer = __esm({
|
|
|
26171
26164
|
};
|
|
26172
26165
|
if (column6.default !== void 0) {
|
|
26173
26166
|
if (column6.default instanceof import_sql2.SQL) {
|
|
26174
|
-
columnToSet.default = column6.default
|
|
26175
|
-
if (typeof it === "string") {
|
|
26176
|
-
return `${it}`;
|
|
26177
|
-
}
|
|
26178
|
-
throw new Error("Only strings are allowed in .default()");
|
|
26179
|
-
}).join();
|
|
26167
|
+
columnToSet.default = sqlToStr(column6.default);
|
|
26180
26168
|
} else {
|
|
26181
26169
|
if (typeof column6.default === "string") {
|
|
26182
26170
|
columnToSet.default = `'${column6.default}'`;
|
|
@@ -26644,6 +26632,7 @@ var init_sqliteSerializer = __esm({
|
|
|
26644
26632
|
import_sql3 = require("drizzle-orm/sql");
|
|
26645
26633
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
|
26646
26634
|
import_utils11 = require("drizzle-orm/sqlite-core/utils");
|
|
26635
|
+
init_serializer();
|
|
26647
26636
|
dialect5 = new import_sqlite_core2.SQLiteSyncDialect();
|
|
26648
26637
|
generateSqliteSnapshot = (tables, enums) => {
|
|
26649
26638
|
const result = {};
|
|
@@ -26657,7 +26646,6 @@ var init_sqliteSerializer = __esm({
|
|
|
26657
26646
|
columns,
|
|
26658
26647
|
indexes,
|
|
26659
26648
|
foreignKeys: tableForeignKeys,
|
|
26660
|
-
schema: schema4,
|
|
26661
26649
|
primaryKeys
|
|
26662
26650
|
} = (0, import_utils11.getTableConfig)(table4);
|
|
26663
26651
|
columns.forEach((column6) => {
|
|
@@ -26672,12 +26660,7 @@ var init_sqliteSerializer = __esm({
|
|
|
26672
26660
|
};
|
|
26673
26661
|
if (column6.default !== void 0) {
|
|
26674
26662
|
if (column6.default instanceof import_sql3.SQL) {
|
|
26675
|
-
columnToSet.default = column6.default
|
|
26676
|
-
if (typeof it === "string") {
|
|
26677
|
-
return `${it}`;
|
|
26678
|
-
}
|
|
26679
|
-
throw new Error("Only strings are allowed in .default()");
|
|
26680
|
-
}).join();
|
|
26663
|
+
columnToSet.default = sqlToStr(column6.default);
|
|
26681
26664
|
} else {
|
|
26682
26665
|
columnToSet.default = typeof column6.default === "string" ? `'${column6.default}'` : column6.default;
|
|
26683
26666
|
}
|
|
@@ -26762,7 +26745,7 @@ var init_sqliteSerializer = __esm({
|
|
|
26762
26745
|
});
|
|
26763
26746
|
|
|
26764
26747
|
// src/serializer/index.ts
|
|
26765
|
-
var import_fs5, import_node, import_path3, import_glob, safeRegister, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
|
|
26748
|
+
var import_fs5, import_node, import_path3, import_glob, safeRegister, sqlToStr, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
|
|
26766
26749
|
var init_serializer = __esm({
|
|
26767
26750
|
"src/serializer/index.ts"() {
|
|
26768
26751
|
import_fs5 = __toESM(require("fs"));
|
|
@@ -26781,6 +26764,19 @@ var init_serializer = __esm({
|
|
|
26781
26764
|
} };
|
|
26782
26765
|
}
|
|
26783
26766
|
};
|
|
26767
|
+
sqlToStr = (sql) => {
|
|
26768
|
+
return sql.toQuery({
|
|
26769
|
+
escapeName: (name) => {
|
|
26770
|
+
throw new Error("we don't support params for `sql` default values");
|
|
26771
|
+
},
|
|
26772
|
+
escapeParam: (num, value) => {
|
|
26773
|
+
throw new Error("we don't support params for `sql` default values");
|
|
26774
|
+
},
|
|
26775
|
+
escapeString: (str) => {
|
|
26776
|
+
throw new Error("we don't support params for `sql` default values");
|
|
26777
|
+
}
|
|
26778
|
+
}).sql;
|
|
26779
|
+
};
|
|
26784
26780
|
serializeMySql = (path2) => {
|
|
26785
26781
|
const filenames = prepareFilenames(path2);
|
|
26786
26782
|
const { unregister } = safeRegister();
|
|
@@ -26845,7 +26841,13 @@ var init_migrationPreparator = __esm({
|
|
|
26845
26841
|
const idPrev = prevSnapshot.id;
|
|
26846
26842
|
const { version, dialect: dialect6, ...rest } = serialized;
|
|
26847
26843
|
const result = { version, dialect: dialect6, id, prevId: idPrev, ...rest };
|
|
26848
|
-
|
|
26844
|
+
const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
|
|
26845
|
+
const custom = {
|
|
26846
|
+
id,
|
|
26847
|
+
prevId: idPrev,
|
|
26848
|
+
...prevRest
|
|
26849
|
+
};
|
|
26850
|
+
return { prev: prevSnapshot, cur: result, custom };
|
|
26849
26851
|
};
|
|
26850
26852
|
prepareSqliteMigrationSnapshot = (snapshots, schemaPath) => {
|
|
26851
26853
|
const prevSnapshot = sqliteSchema.parse(
|
|
@@ -26862,7 +26864,13 @@ var init_migrationPreparator = __esm({
|
|
|
26862
26864
|
prevId: idPrev,
|
|
26863
26865
|
...rest
|
|
26864
26866
|
};
|
|
26865
|
-
|
|
26867
|
+
const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
|
|
26868
|
+
const custom = {
|
|
26869
|
+
id,
|
|
26870
|
+
prevId: idPrev,
|
|
26871
|
+
...prevRest
|
|
26872
|
+
};
|
|
26873
|
+
return { prev: prevSnapshot, cur: result, custom };
|
|
26866
26874
|
};
|
|
26867
26875
|
preparePgMigrationSnapshot = (snapshots, schemaPath) => {
|
|
26868
26876
|
const prevSnapshot = pgSchema.parse(preparePrevSnapshot(snapshots, dryPg));
|
|
@@ -26871,7 +26879,13 @@ var init_migrationPreparator = __esm({
|
|
|
26871
26879
|
const idPrev = prevSnapshot.id;
|
|
26872
26880
|
const { version, dialect: dialect6, ...rest } = serialized;
|
|
26873
26881
|
const result = { version, dialect: dialect6, id, prevId: idPrev, ...rest };
|
|
26874
|
-
|
|
26882
|
+
const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
|
|
26883
|
+
const custom = {
|
|
26884
|
+
id,
|
|
26885
|
+
prevId: idPrev,
|
|
26886
|
+
...prevRest
|
|
26887
|
+
};
|
|
26888
|
+
return { prev: prevSnapshot, cur: result, custom };
|
|
26875
26889
|
};
|
|
26876
26890
|
preparePrevSnapshot = (snapshots, defaultPrev) => {
|
|
26877
26891
|
let prevSnapshot;
|
|
@@ -26917,9 +26931,25 @@ var init_migrate = __esm({
|
|
|
26917
26931
|
try {
|
|
26918
26932
|
assertV1OutFolder(outFolder, "pg");
|
|
26919
26933
|
const { snapshots, journal } = prepareMigrationFolder(outFolder, "pg");
|
|
26920
|
-
const { prev, cur } = preparePgMigrationSnapshot(snapshots, schemaPath);
|
|
26934
|
+
const { prev, cur, custom } = preparePgMigrationSnapshot(snapshots, schemaPath);
|
|
26921
26935
|
const validatedPrev = pgSchema.parse(prev);
|
|
26922
26936
|
const validatedCur = pgSchema.parse(cur);
|
|
26937
|
+
if (config.custom) {
|
|
26938
|
+
writeResult(
|
|
26939
|
+
custom,
|
|
26940
|
+
[],
|
|
26941
|
+
journal,
|
|
26942
|
+
{
|
|
26943
|
+
columns: {},
|
|
26944
|
+
schemas: {},
|
|
26945
|
+
tables: {}
|
|
26946
|
+
},
|
|
26947
|
+
outFolder,
|
|
26948
|
+
config.breakpoints,
|
|
26949
|
+
"custom"
|
|
26950
|
+
);
|
|
26951
|
+
return;
|
|
26952
|
+
}
|
|
26923
26953
|
const squashedPrev = squashPgScheme(validatedPrev);
|
|
26924
26954
|
const squashedCur = squashPgScheme(validatedCur);
|
|
26925
26955
|
const { sqlStatements, _meta } = await prepareSQL(
|
|
@@ -26947,9 +26977,25 @@ var init_migrate = __esm({
|
|
|
26947
26977
|
try {
|
|
26948
26978
|
assertV1OutFolder(outFolder, "mysql");
|
|
26949
26979
|
const { snapshots, journal } = prepareMigrationFolder(outFolder, "mysql");
|
|
26950
|
-
const { prev, cur } = prepareMySqlMigrationSnapshot(snapshots, schemaPath);
|
|
26980
|
+
const { prev, cur, custom } = prepareMySqlMigrationSnapshot(snapshots, schemaPath);
|
|
26951
26981
|
const validatedPrev = mysqlSchema.parse(prev);
|
|
26952
26982
|
const validatedCur = mysqlSchema.parse(cur);
|
|
26983
|
+
if (config.custom) {
|
|
26984
|
+
writeResult(
|
|
26985
|
+
custom,
|
|
26986
|
+
[],
|
|
26987
|
+
journal,
|
|
26988
|
+
{
|
|
26989
|
+
columns: {},
|
|
26990
|
+
schemas: {},
|
|
26991
|
+
tables: {}
|
|
26992
|
+
},
|
|
26993
|
+
outFolder,
|
|
26994
|
+
config.breakpoints,
|
|
26995
|
+
"custom"
|
|
26996
|
+
);
|
|
26997
|
+
return;
|
|
26998
|
+
}
|
|
26953
26999
|
const squashedPrev = squashMysqlScheme(validatedPrev);
|
|
26954
27000
|
const squashedCur = squashMysqlScheme(validatedCur);
|
|
26955
27001
|
const { sqlStatements, _meta } = await prepareSQL(
|
|
@@ -26977,9 +27023,25 @@ var init_migrate = __esm({
|
|
|
26977
27023
|
try {
|
|
26978
27024
|
assertV1OutFolder(outFolder, "sqlite");
|
|
26979
27025
|
const { snapshots, journal } = prepareMigrationFolder(outFolder, "sqlite");
|
|
26980
|
-
const { prev, cur } = prepareSqliteMigrationSnapshot(snapshots, schemaPath);
|
|
27026
|
+
const { prev, cur, custom } = prepareSqliteMigrationSnapshot(snapshots, schemaPath);
|
|
26981
27027
|
const validatedPrev = sqliteSchema.parse(prev);
|
|
26982
27028
|
const validatedCur = sqliteSchema.parse(cur);
|
|
27029
|
+
if (config.custom) {
|
|
27030
|
+
writeResult(
|
|
27031
|
+
custom,
|
|
27032
|
+
[],
|
|
27033
|
+
journal,
|
|
27034
|
+
{
|
|
27035
|
+
columns: {},
|
|
27036
|
+
schemas: {},
|
|
27037
|
+
tables: {}
|
|
27038
|
+
},
|
|
27039
|
+
outFolder,
|
|
27040
|
+
config.breakpoints,
|
|
27041
|
+
"custom"
|
|
27042
|
+
);
|
|
27043
|
+
return;
|
|
27044
|
+
}
|
|
26983
27045
|
const squashedPrev = squashSqliteScheme(validatedPrev);
|
|
26984
27046
|
const squashedCur = squashSqliteScheme(validatedCur);
|
|
26985
27047
|
const { sqlStatements, _meta } = await prepareSQL(
|
|
@@ -27181,11 +27243,13 @@ var init_migrate = __esm({
|
|
|
27181
27243
|
result.deleted.push(...leftMissing);
|
|
27182
27244
|
return result;
|
|
27183
27245
|
};
|
|
27184
|
-
writeResult = (cur, sqlStatements, journal, _meta, outFolder, breakpoints,
|
|
27185
|
-
|
|
27186
|
-
|
|
27187
|
-
|
|
27188
|
-
|
|
27246
|
+
writeResult = (cur, sqlStatements, journal, _meta, outFolder, breakpoints, type = "none") => {
|
|
27247
|
+
if (type === "none") {
|
|
27248
|
+
console.log(schema(cur));
|
|
27249
|
+
if (sqlStatements.length === 0) {
|
|
27250
|
+
console.log("No schema changes, nothing to migrate \u{1F634}");
|
|
27251
|
+
return;
|
|
27252
|
+
}
|
|
27189
27253
|
}
|
|
27190
27254
|
const lastEntryInJournal = journal.entries[journal.entries.length - 1];
|
|
27191
27255
|
const idx = typeof lastEntryInJournal === "undefined" ? 0 : lastEntryInJournal.idx + 1;
|
|
@@ -27200,13 +27264,17 @@ var init_migrate = __esm({
|
|
|
27200
27264
|
);
|
|
27201
27265
|
const sqlDelimiter = breakpoints ? "--> statement-breakpoint\n" : "\n";
|
|
27202
27266
|
let sql = sqlStatements.join(sqlDelimiter);
|
|
27203
|
-
if (
|
|
27267
|
+
if (type === "introspect") {
|
|
27204
27268
|
sql = `-- Current sql file was generated after introspecting the database
|
|
27205
27269
|
-- If you want to run this migration please uncomment this code before executing migraitons
|
|
27206
27270
|
/*
|
|
27207
27271
|
${sql}
|
|
27208
27272
|
*/`;
|
|
27209
27273
|
}
|
|
27274
|
+
if (type === "custom") {
|
|
27275
|
+
console.log("Prepared empty file for your custom SQL migration!");
|
|
27276
|
+
sql = "-- Custom SQL migration file, put you code below! --";
|
|
27277
|
+
}
|
|
27210
27278
|
journal.entries.push({
|
|
27211
27279
|
idx,
|
|
27212
27280
|
version: cur.version,
|
|
@@ -49242,7 +49310,7 @@ var assertPackages = (...pkgs) => {
|
|
|
49242
49310
|
process.exit(1);
|
|
49243
49311
|
}
|
|
49244
49312
|
};
|
|
49245
|
-
var requiredApiVersion =
|
|
49313
|
+
var requiredApiVersion = 4;
|
|
49246
49314
|
var assertOrmCoreVersion = () => {
|
|
49247
49315
|
const { compatibilityVersion } = require("drizzle-orm/version");
|
|
49248
49316
|
if (compatibilityVersion && compatibilityVersion === requiredApiVersion)
|
|
@@ -49339,8 +49407,9 @@ var package_default = {
|
|
|
49339
49407
|
"@typescript-eslint/parser": "^5.46.1",
|
|
49340
49408
|
ava: "^5.1.0",
|
|
49341
49409
|
dockerode: "^3.3.4",
|
|
49410
|
+
dotenv: "^16.0.3",
|
|
49342
49411
|
"drizzle-kit": "^0.16.8",
|
|
49343
|
-
"drizzle-orm": "0.
|
|
49412
|
+
"drizzle-orm": "0.23.2-e17a5ba",
|
|
49344
49413
|
esbuild: "^0.15.7",
|
|
49345
49414
|
"esbuild-register": "^3.3.3",
|
|
49346
49415
|
eslint: "^8.29.0",
|
|
@@ -49467,21 +49536,22 @@ drizzle-orm: v${npmVersion}` : "";
|
|
|
49467
49536
|
var configSchema = objectType({
|
|
49468
49537
|
schema: unionType([stringType(), stringType().array()]),
|
|
49469
49538
|
out: stringType().default("drizzle"),
|
|
49470
|
-
breakpoints: booleanType()
|
|
49539
|
+
breakpoints: booleanType(),
|
|
49540
|
+
custom: booleanType()
|
|
49471
49541
|
}).strict();
|
|
49472
49542
|
var optionsSchema = objectType({
|
|
49473
49543
|
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
49474
49544
|
out: stringType().optional(),
|
|
49475
49545
|
config: stringType().optional(),
|
|
49476
|
-
breakpoints: booleanType().optional().default(false)
|
|
49546
|
+
breakpoints: booleanType().optional().default(false),
|
|
49547
|
+
custom: booleanType().optional().default(false)
|
|
49477
49548
|
}).strict();
|
|
49478
|
-
var generatePgCommand = new 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(
|
|
49549
|
+
var generatePgCommand = new 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(
|
|
49479
49550
|
"--config <config>",
|
|
49480
49551
|
"Path to a config.json file, drizzle.config.json by default"
|
|
49481
49552
|
).action(async (options) => {
|
|
49482
49553
|
printVersions();
|
|
49483
49554
|
assertOrmCoreVersion();
|
|
49484
|
-
console.log(options);
|
|
49485
49555
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
49486
49556
|
const result = prepareGenerateConfig(oprtionsParsed);
|
|
49487
49557
|
if (result instanceof Error) {
|
|
@@ -49492,7 +49562,7 @@ var generatePgCommand = new Command("generate:pg").option("--schema <schema...>"
|
|
|
49492
49562
|
const { prepareAndMigratePg: prepareAndMigratePg2 } = (init_migrate(), __toCommonJS(migrate_exports));
|
|
49493
49563
|
await prepareAndMigratePg2(result);
|
|
49494
49564
|
});
|
|
49495
|
-
var generateMysqlCommand = new Command("generate:mysql").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(
|
|
49565
|
+
var generateMysqlCommand = new Command("generate:mysql").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(
|
|
49496
49566
|
"--config <config>",
|
|
49497
49567
|
"Path to a config.json file, drizzle.config.json by default"
|
|
49498
49568
|
).action(async (options) => {
|
|
@@ -49508,7 +49578,7 @@ var generateMysqlCommand = new Command("generate:mysql").option("--schema <schem
|
|
|
49508
49578
|
const { prepareAndMigrateMySql: prepareAndMigrateMySql2 } = (init_migrate(), __toCommonJS(migrate_exports));
|
|
49509
49579
|
await prepareAndMigrateMySql2(result);
|
|
49510
49580
|
});
|
|
49511
|
-
var generateSqliteCommand = new Command("generate:sqlite").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(
|
|
49581
|
+
var generateSqliteCommand = new Command("generate:sqlite").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(
|
|
49512
49582
|
"--config <config>",
|
|
49513
49583
|
"Path to a config.json file, drizzle.config.json by default"
|
|
49514
49584
|
).action(async (options) => {
|
|
@@ -49525,7 +49595,7 @@ var generateSqliteCommand = new Command("generate:sqlite").option("--schema <sch
|
|
|
49525
49595
|
await prepareAndMigrateSqlite2(result);
|
|
49526
49596
|
});
|
|
49527
49597
|
var prepareGenerateConfig = (options) => {
|
|
49528
|
-
const { schema: schema4, out, config, breakpoints } = options;
|
|
49598
|
+
const { schema: schema4, out, config, breakpoints, custom } = options;
|
|
49529
49599
|
if (!(schema4 || out)) {
|
|
49530
49600
|
const path2 = config != null ? config : "drizzle.config.json";
|
|
49531
49601
|
const drizzleConfig = JSON.parse(
|
|
@@ -49536,7 +49606,7 @@ var prepareGenerateConfig = (options) => {
|
|
|
49536
49606
|
if (!schema4) {
|
|
49537
49607
|
return new Error(`'schema' param must be set`);
|
|
49538
49608
|
}
|
|
49539
|
-
return configSchema.parse({ schema: schema4, out, breakpoints });
|
|
49609
|
+
return configSchema.parse({ schema: schema4, out, breakpoints, custom });
|
|
49540
49610
|
};
|
|
49541
49611
|
var checkSchema = objectType({
|
|
49542
49612
|
out: stringType().optional(),
|
|
@@ -49657,7 +49727,7 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
|
|
|
49657
49727
|
_meta,
|
|
49658
49728
|
res.data.out,
|
|
49659
49729
|
res.data.breakpoints,
|
|
49660
|
-
|
|
49730
|
+
"introspect"
|
|
49661
49731
|
);
|
|
49662
49732
|
} else {
|
|
49663
49733
|
(0, import_hanji6.render)(
|
|
@@ -49709,7 +49779,7 @@ var introspectMySqlCommand = new Command("introspect:mysql").option("--out <out>
|
|
|
49709
49779
|
_meta,
|
|
49710
49780
|
res.data.out,
|
|
49711
49781
|
res.data.breakpoints,
|
|
49712
|
-
|
|
49782
|
+
"introspect"
|
|
49713
49783
|
);
|
|
49714
49784
|
} else {
|
|
49715
49785
|
(0, import_hanji6.render)(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-kit",
|
|
3
|
-
"version": "0.17.1
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Drizzle Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -66,8 +66,9 @@
|
|
|
66
66
|
"@typescript-eslint/parser": "^5.46.1",
|
|
67
67
|
"ava": "^5.1.0",
|
|
68
68
|
"dockerode": "^3.3.4",
|
|
69
|
+
"dotenv": "^16.0.3",
|
|
69
70
|
"drizzle-kit": "^0.16.8",
|
|
70
|
-
"drizzle-orm": "0.
|
|
71
|
+
"drizzle-orm": "0.23.2-e17a5ba",
|
|
71
72
|
"esbuild": "^0.15.7",
|
|
72
73
|
"esbuild-register": "^3.3.3",
|
|
73
74
|
"eslint": "^8.29.0",
|
package/utils.js
CHANGED
|
@@ -11810,7 +11810,7 @@ var PgCreateForeignKeyConvertor = class extends Convertor {
|
|
|
11810
11810
|
const onUpdateStatement = onUpdate ? `ON UPDATE ${onUpdate}` : "";
|
|
11811
11811
|
const fromColumnsString = columnsFrom.map((it) => `"${it}"`).join(",");
|
|
11812
11812
|
const toColumnsString = columnsTo.map((it) => `"${it}"`).join(",");
|
|
11813
|
-
const alterStatement = `ALTER TABLE
|
|
11813
|
+
const alterStatement = `ALTER TABLE ${tableFrom} ADD CONSTRAINT ${name} FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableTo}(${toColumnsString}) ${onDeleteStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
|
|
11814
11814
|
let sql = "DO $$ BEGIN\n";
|
|
11815
11815
|
sql += " " + alterStatement + ";\n";
|
|
11816
11816
|
sql += "EXCEPTION\n";
|
|
@@ -11861,13 +11861,13 @@ var PgAlterForeignKeyConvertor = class extends Convertor {
|
|
|
11861
11861
|
convert(statement) {
|
|
11862
11862
|
const newFk = PgSquasher.unsquashFK(statement.data);
|
|
11863
11863
|
const oldFk = PgSquasher.unsquashFK(statement.oldFkey);
|
|
11864
|
-
let sql = `ALTER TABLE
|
|
11864
|
+
let sql = `ALTER TABLE ${oldFk.tableFrom} DROP CONSTRAINT ${oldFk.name};
|
|
11865
11865
|
`;
|
|
11866
11866
|
const onDeleteStatement = newFk.onDelete ? `ON DELETE ${newFk.onDelete}` : "";
|
|
11867
11867
|
const onUpdateStatement = newFk.onUpdate ? `ON UPDATE ${newFk.onDelete}` : "";
|
|
11868
11868
|
const fromColumnsString = newFk.columnsFrom.map((it) => `"${it}"`).join(",");
|
|
11869
11869
|
const toColumnsString = newFk.columnsTo.map((it) => `"${it}"`).join(",");
|
|
11870
|
-
const alterStatement = `ALTER TABLE
|
|
11870
|
+
const alterStatement = `ALTER TABLE ${newFk.tableFrom} ADD CONSTRAINT ${newFk.name} FOREIGN KEY (${fromColumnsString}) REFERENCES ${newFk.tableTo}(${toColumnsString}) ${onDeleteStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
|
|
11871
11871
|
sql += "DO $$ BEGIN\n";
|
|
11872
11872
|
sql += " " + alterStatement + ";\n";
|
|
11873
11873
|
sql += "EXCEPTION\n";
|
|
@@ -11898,7 +11898,7 @@ var PgDeleteForeignKeyConvertor = class extends Convertor {
|
|
|
11898
11898
|
convert(statement) {
|
|
11899
11899
|
const tableFrom = statement.tableName;
|
|
11900
11900
|
const { name } = PgSquasher.unsquashFK(statement.data);
|
|
11901
|
-
return `ALTER TABLE
|
|
11901
|
+
return `ALTER TABLE ${tableFrom} DROP CONSTRAINT ${name};
|
|
11902
11902
|
`;
|
|
11903
11903
|
}
|
|
11904
11904
|
};
|