drizzle-kit 0.16.9-593d066 → 0.16.9-60b8a7b
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 +354 -104
- package/package.json +8 -5
- package/utils.js +13180 -0
package/index.js
CHANGED
|
@@ -6284,7 +6284,8 @@ var init_mysqlSchema = __esm({
|
|
|
6284
6284
|
primaryKey: booleanType(),
|
|
6285
6285
|
notNull: booleanType(),
|
|
6286
6286
|
autoincrement: booleanType().optional(),
|
|
6287
|
-
default: anyType().optional()
|
|
6287
|
+
default: anyType().optional(),
|
|
6288
|
+
onUpdate: anyType().optional()
|
|
6288
6289
|
}).strict();
|
|
6289
6290
|
tableV3 = objectType({
|
|
6290
6291
|
name: stringType(),
|
|
@@ -13150,6 +13151,32 @@ var init_jsonDiffer = __esm({
|
|
|
13150
13151
|
return { ...others, notNull: { type: "deleted", value: it.notNull__deleted } };
|
|
13151
13152
|
}
|
|
13152
13153
|
return it;
|
|
13154
|
+
}).map((it) => {
|
|
13155
|
+
if ("onUpdate" in it) {
|
|
13156
|
+
return { ...it, onUpdate: { type: "changed", old: it.onUpdate.__old, new: it.onUpdate.__new } };
|
|
13157
|
+
}
|
|
13158
|
+
if ("onUpdate__added" in it) {
|
|
13159
|
+
const { onUpdate__added, ...others } = it;
|
|
13160
|
+
return { ...others, onUpdate: { type: "added", value: it.onUpdate__added } };
|
|
13161
|
+
}
|
|
13162
|
+
if ("onUpdate__deleted" in it) {
|
|
13163
|
+
const { onUpdate__deleted, ...others } = it;
|
|
13164
|
+
return { ...others, onUpdate: { type: "deleted", value: it.onUpdate__deleted } };
|
|
13165
|
+
}
|
|
13166
|
+
return it;
|
|
13167
|
+
}).map((it) => {
|
|
13168
|
+
if ("autoincrement" in it) {
|
|
13169
|
+
return { ...it, autoincrement: { type: "changed", old: it.autoincrement.__old, new: it.autoincrement.__new } };
|
|
13170
|
+
}
|
|
13171
|
+
if ("autoincrement__added" in it) {
|
|
13172
|
+
const { autoincrement__added, ...others } = it;
|
|
13173
|
+
return { ...others, autoincrement: { type: "added", value: it.autoincrement__added } };
|
|
13174
|
+
}
|
|
13175
|
+
if ("autoincrement__deleted" in it) {
|
|
13176
|
+
const { autoincrement__deleted, ...others } = it;
|
|
13177
|
+
return { ...others, autoincrement: { type: "deleted", value: it.autoincrement__deleted } };
|
|
13178
|
+
}
|
|
13179
|
+
return it;
|
|
13153
13180
|
});
|
|
13154
13181
|
return result[0];
|
|
13155
13182
|
};
|
|
@@ -13157,7 +13184,7 @@ var init_jsonDiffer = __esm({
|
|
|
13157
13184
|
});
|
|
13158
13185
|
|
|
13159
13186
|
// src/sqlgenerator.ts
|
|
13160
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, DropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, convertors, fromJson;
|
|
13187
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, DropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, MySqlAlterTableAlterColumnSetDefaultConvertor, MySqlAlterTableAlterColumnDropDefaultConvertor, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, MySqlDropIndexConvertor, convertors, fromJson;
|
|
13161
13188
|
var init_sqlgenerator = __esm({
|
|
13162
13189
|
"src/sqlgenerator.ts"() {
|
|
13163
13190
|
init_mysqlSchema();
|
|
@@ -13239,8 +13266,9 @@ var init_sqlgenerator = __esm({
|
|
|
13239
13266
|
const primaryKeyStatement = column6.primaryKey ? "PRIMARY KEY" : "";
|
|
13240
13267
|
const notNullStatement = column6.notNull ? "NOT NULL" : "";
|
|
13241
13268
|
const defaultStatement = column6.default !== void 0 ? `DEFAULT ${column6.default}` : "";
|
|
13269
|
+
const onUpdateStatement = column6.onUpdate ? `ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
13242
13270
|
const autoincrementStatement = column6.autoincrement ? "AUTO_INCREMENT" : "";
|
|
13243
|
-
statement += " " + `\`${column6.name}\` ${column6.type} ${autoincrementStatement} ${primaryKeyStatement} ${defaultStatement} ${
|
|
13271
|
+
statement += " " + `\`${column6.name}\` ${column6.type} ${autoincrementStatement} ${primaryKeyStatement} ${notNullStatement} ${defaultStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
|
|
13244
13272
|
statement += (i === columns.length - 1 ? "" : ",") + "\n";
|
|
13245
13273
|
}
|
|
13246
13274
|
statement += `);`;
|
|
@@ -13524,6 +13552,82 @@ var init_sqlgenerator = __esm({
|
|
|
13524
13552
|
return `ALTER TABLE ${tableName} ALTER COLUMN "${columnName}" DROP DEFAULT;`;
|
|
13525
13553
|
}
|
|
13526
13554
|
};
|
|
13555
|
+
MySqlAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
|
|
13556
|
+
can(statement, dialect6) {
|
|
13557
|
+
return statement.type === "alter_table_alter_column_set_default" && dialect6 === "mysql";
|
|
13558
|
+
}
|
|
13559
|
+
convert(statement) {
|
|
13560
|
+
const { tableName, columnName } = statement;
|
|
13561
|
+
return `ALTER TABLE ${tableName} ALTER COLUMN \`${columnName}\` SET DEFAULT ${statement.newDefaultValue};`;
|
|
13562
|
+
}
|
|
13563
|
+
};
|
|
13564
|
+
MySqlAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
|
|
13565
|
+
can(statement, dialect6) {
|
|
13566
|
+
return statement.type === "alter_table_alter_column_drop_default" && dialect6 === "mysql";
|
|
13567
|
+
}
|
|
13568
|
+
convert(statement) {
|
|
13569
|
+
const { tableName, columnName } = statement;
|
|
13570
|
+
return `ALTER TABLE ${tableName} ALTER COLUMN \`${columnName}\` DROP DEFAULT;`;
|
|
13571
|
+
}
|
|
13572
|
+
};
|
|
13573
|
+
MySqlModifyColumn = class extends Convertor {
|
|
13574
|
+
can(statement, dialect6) {
|
|
13575
|
+
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_on_update" || statement.type === "alter_table_alter_column_set_on_update" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_autoincrement") && dialect6 === "mysql";
|
|
13576
|
+
}
|
|
13577
|
+
convert(statement) {
|
|
13578
|
+
const { tableName, columnName } = statement;
|
|
13579
|
+
let columnType = ``;
|
|
13580
|
+
let columnDefault = "";
|
|
13581
|
+
let columnNotNull = "";
|
|
13582
|
+
let columnOnUpdate = "";
|
|
13583
|
+
let columnAutoincrement = "";
|
|
13584
|
+
if (statement.type === "alter_table_alter_column_drop_notnull") {
|
|
13585
|
+
columnType = ` ${statement.newDataType}`;
|
|
13586
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
13587
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
13588
|
+
columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
13589
|
+
columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
|
|
13590
|
+
} else if (statement.type === "alter_table_alter_column_set_notnull") {
|
|
13591
|
+
columnNotNull = ` NOT NULL`;
|
|
13592
|
+
columnType = ` ${statement.newDataType}`;
|
|
13593
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
13594
|
+
columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
13595
|
+
columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
|
|
13596
|
+
} else if (statement.type === "alter_table_alter_column_drop_on_update") {
|
|
13597
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
13598
|
+
columnType = ` ${statement.newDataType}`;
|
|
13599
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
13600
|
+
columnOnUpdate = "";
|
|
13601
|
+
columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
|
|
13602
|
+
} else if (statement.type === "alter_table_alter_column_set_on_update") {
|
|
13603
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
13604
|
+
columnOnUpdate = ` ON UPDATE CURRENT_TIMESTAMP`;
|
|
13605
|
+
columnType = ` ${statement.newDataType}`;
|
|
13606
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
13607
|
+
columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
|
|
13608
|
+
} else if (statement.type === "alter_table_alter_column_set_autoincrement") {
|
|
13609
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
13610
|
+
columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
13611
|
+
columnType = ` ${statement.newDataType}`;
|
|
13612
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
13613
|
+
columnAutoincrement = "AUTO_INCREMENT";
|
|
13614
|
+
} else if (statement.type === "alter_table_alter_column_drop_autoincrement") {
|
|
13615
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
13616
|
+
columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
13617
|
+
columnType = ` ${statement.newDataType}`;
|
|
13618
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
13619
|
+
columnAutoincrement = "";
|
|
13620
|
+
} else {
|
|
13621
|
+
columnType = ` ${statement.newDataType}`;
|
|
13622
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
13623
|
+
columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
13624
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
13625
|
+
columnAutoincrement = statement.columnAutoIncrement ? "AUTO_INCREMENT" : "";
|
|
13626
|
+
}
|
|
13627
|
+
columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
|
|
13628
|
+
return `ALTER TABLE ${tableName} MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnNotNull}${columnDefault}${columnOnUpdate};`;
|
|
13629
|
+
}
|
|
13630
|
+
};
|
|
13527
13631
|
SqliteAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
|
|
13528
13632
|
can(statement, dialect6) {
|
|
13529
13633
|
return statement.type === "alter_table_alter_column_drop_default" && dialect6 === "sqlite";
|
|
@@ -13975,6 +14079,16 @@ var init_sqlgenerator = __esm({
|
|
|
13975
14079
|
`;
|
|
13976
14080
|
}
|
|
13977
14081
|
};
|
|
14082
|
+
MySqlDropIndexConvertor = class extends Convertor {
|
|
14083
|
+
can(statement, dialect6) {
|
|
14084
|
+
return statement.type === "drop_index" && dialect6 === "mysql";
|
|
14085
|
+
}
|
|
14086
|
+
convert(statement) {
|
|
14087
|
+
const tableName = typeof statement.schema === "undefined" ? `\`${statement.tableName}\`` : `\`${statement.schema}\`.\`${statement.tableName}\``;
|
|
14088
|
+
const { name } = MySqlSquasher.unsquashIdx(statement.data);
|
|
14089
|
+
return `DROP INDEX ${name} ON ${tableName};`;
|
|
14090
|
+
}
|
|
14091
|
+
};
|
|
13978
14092
|
convertors = [];
|
|
13979
14093
|
convertors.push(new PgCreateTableConvertor());
|
|
13980
14094
|
convertors.push(new MySqlCreateTableConvertor());
|
|
@@ -13999,11 +14113,16 @@ var init_sqlgenerator = __esm({
|
|
|
13999
14113
|
convertors.push(new CreateSqliteIndexConvertor());
|
|
14000
14114
|
convertors.push(new PgDropIndexConvertor());
|
|
14001
14115
|
convertors.push(new SqliteDropIndexConvertor());
|
|
14116
|
+
convertors.push(new MySqlDropIndexConvertor());
|
|
14002
14117
|
convertors.push(new AlterTypeAddValueConvertor());
|
|
14003
14118
|
convertors.push(new PgAlterTableAlterColumnSetNotNullConvertor());
|
|
14004
14119
|
convertors.push(new PgAlterTableAlterColumnDropNotNullConvertor());
|
|
14005
14120
|
convertors.push(new PgAlterTableAlterColumnSetDefaultConvertor());
|
|
14006
14121
|
convertors.push(new PgAlterTableAlterColumnDropDefaultConvertor());
|
|
14122
|
+
convertors.push(new MySqlModifyColumn());
|
|
14123
|
+
convertors.push(new MySqlAlterTableDropColumnConvertor());
|
|
14124
|
+
convertors.push(new MySqlAlterTableAlterColumnSetDefaultConvertor());
|
|
14125
|
+
convertors.push(new MySqlAlterTableAlterColumnDropDefaultConvertor());
|
|
14007
14126
|
convertors.push(new PgCreateForeignKeyConvertor());
|
|
14008
14127
|
convertors.push(new MySqlCreateForeignKeyConvertor());
|
|
14009
14128
|
convertors.push(new PgAlterForeignKeyConvertor());
|
|
@@ -14168,10 +14287,10 @@ var init_jsonStatements = __esm({
|
|
|
14168
14287
|
};
|
|
14169
14288
|
});
|
|
14170
14289
|
};
|
|
14171
|
-
prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, dialect6) => {
|
|
14290
|
+
prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, json2, dialect6) => {
|
|
14172
14291
|
const addColumns = [];
|
|
14173
14292
|
const dropColumns = _prepareDropColumns(tableName, schema4, deleted);
|
|
14174
|
-
const alterColumns = _prepareAlterColumns(tableName, schema4, altered);
|
|
14293
|
+
const alterColumns = _prepareAlterColumns(tableName, schema4, altered, json2);
|
|
14175
14294
|
if (dialect6 === "sqlite") {
|
|
14176
14295
|
let jsonCreateFKStatements = Object.values(addedFk);
|
|
14177
14296
|
const sqliteAddColumns = _prepareSQLiteAddColumns(
|
|
@@ -14221,11 +14340,16 @@ var init_jsonStatements = __esm({
|
|
|
14221
14340
|
};
|
|
14222
14341
|
});
|
|
14223
14342
|
};
|
|
14224
|
-
_prepareAlterColumns = (tableName, schema4, columns) => {
|
|
14225
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
14343
|
+
_prepareAlterColumns = (tableName, schema4, columns, json2) => {
|
|
14344
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
14226
14345
|
let statements = [];
|
|
14227
14346
|
for (const column6 of columns) {
|
|
14228
14347
|
const columnName = typeof column6.name !== "string" ? column6.name.new : column6.name;
|
|
14348
|
+
const columnType = json2.tables[tableName].columns[columnName].type;
|
|
14349
|
+
const columnDefault = json2.tables[tableName].columns[columnName].default;
|
|
14350
|
+
const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
|
|
14351
|
+
const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
|
|
14352
|
+
const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
|
|
14229
14353
|
if (typeof column6.name !== "string") {
|
|
14230
14354
|
statements.push({
|
|
14231
14355
|
type: "alter_table_rename_column",
|
|
@@ -14241,7 +14365,11 @@ var init_jsonStatements = __esm({
|
|
|
14241
14365
|
tableName,
|
|
14242
14366
|
columnName,
|
|
14243
14367
|
newDataType: column6.type.new,
|
|
14244
|
-
schema: schema4
|
|
14368
|
+
schema: schema4,
|
|
14369
|
+
columnDefault,
|
|
14370
|
+
columnOnUpdate,
|
|
14371
|
+
columnNotNull,
|
|
14372
|
+
columnAutoIncrement
|
|
14245
14373
|
});
|
|
14246
14374
|
}
|
|
14247
14375
|
if (((_b = column6.default) == null ? void 0 : _b.type) === "added") {
|
|
@@ -14275,7 +14403,12 @@ var init_jsonStatements = __esm({
|
|
|
14275
14403
|
type: "alter_table_alter_column_set_notnull",
|
|
14276
14404
|
tableName,
|
|
14277
14405
|
columnName,
|
|
14278
|
-
schema: schema4
|
|
14406
|
+
schema: schema4,
|
|
14407
|
+
newDataType: columnType,
|
|
14408
|
+
columnDefault,
|
|
14409
|
+
columnOnUpdate,
|
|
14410
|
+
columnNotNull,
|
|
14411
|
+
columnAutoIncrement
|
|
14279
14412
|
});
|
|
14280
14413
|
}
|
|
14281
14414
|
if (((_f = column6.notNull) == null ? void 0 : _f.type) === "changed") {
|
|
@@ -14284,7 +14417,12 @@ var init_jsonStatements = __esm({
|
|
|
14284
14417
|
type,
|
|
14285
14418
|
tableName,
|
|
14286
14419
|
columnName,
|
|
14287
|
-
schema: schema4
|
|
14420
|
+
schema: schema4,
|
|
14421
|
+
newDataType: columnType,
|
|
14422
|
+
columnDefault,
|
|
14423
|
+
columnOnUpdate,
|
|
14424
|
+
columnNotNull,
|
|
14425
|
+
columnAutoIncrement
|
|
14288
14426
|
});
|
|
14289
14427
|
}
|
|
14290
14428
|
if (((_g = column6.notNull) == null ? void 0 : _g.type) === "deleted") {
|
|
@@ -14292,7 +14430,78 @@ var init_jsonStatements = __esm({
|
|
|
14292
14430
|
type: "alter_table_alter_column_drop_notnull",
|
|
14293
14431
|
tableName,
|
|
14294
14432
|
columnName,
|
|
14295
|
-
schema: schema4
|
|
14433
|
+
schema: schema4,
|
|
14434
|
+
newDataType: columnType,
|
|
14435
|
+
columnDefault,
|
|
14436
|
+
columnOnUpdate,
|
|
14437
|
+
columnNotNull,
|
|
14438
|
+
columnAutoIncrement
|
|
14439
|
+
});
|
|
14440
|
+
}
|
|
14441
|
+
if (((_h = column6.autoincrement) == null ? void 0 : _h.type) === "added") {
|
|
14442
|
+
statements.push({
|
|
14443
|
+
type: "alter_table_alter_column_set_autoincrement",
|
|
14444
|
+
tableName,
|
|
14445
|
+
columnName,
|
|
14446
|
+
schema: schema4,
|
|
14447
|
+
newDataType: columnType,
|
|
14448
|
+
columnDefault,
|
|
14449
|
+
columnOnUpdate,
|
|
14450
|
+
columnNotNull,
|
|
14451
|
+
columnAutoIncrement
|
|
14452
|
+
});
|
|
14453
|
+
}
|
|
14454
|
+
if (((_i = column6.autoincrement) == null ? void 0 : _i.type) === "changed") {
|
|
14455
|
+
const type = column6.autoincrement.new ? "alter_table_alter_column_set_notnull" : "alter_table_alter_column_drop_notnull";
|
|
14456
|
+
statements.push({
|
|
14457
|
+
type,
|
|
14458
|
+
tableName,
|
|
14459
|
+
columnName,
|
|
14460
|
+
schema: schema4,
|
|
14461
|
+
newDataType: columnType,
|
|
14462
|
+
columnDefault,
|
|
14463
|
+
columnOnUpdate,
|
|
14464
|
+
columnNotNull,
|
|
14465
|
+
columnAutoIncrement
|
|
14466
|
+
});
|
|
14467
|
+
}
|
|
14468
|
+
if (((_j = column6.autoincrement) == null ? void 0 : _j.type) === "deleted") {
|
|
14469
|
+
statements.push({
|
|
14470
|
+
type: "alter_table_alter_column_drop_autoincrement",
|
|
14471
|
+
tableName,
|
|
14472
|
+
columnName,
|
|
14473
|
+
schema: schema4,
|
|
14474
|
+
newDataType: columnType,
|
|
14475
|
+
columnDefault,
|
|
14476
|
+
columnOnUpdate,
|
|
14477
|
+
columnNotNull,
|
|
14478
|
+
columnAutoIncrement
|
|
14479
|
+
});
|
|
14480
|
+
}
|
|
14481
|
+
if (((_k = column6.onUpdate) == null ? void 0 : _k.type) === "added") {
|
|
14482
|
+
statements.push({
|
|
14483
|
+
type: "alter_table_alter_column_set_on_update",
|
|
14484
|
+
tableName,
|
|
14485
|
+
columnName,
|
|
14486
|
+
schema: schema4,
|
|
14487
|
+
newDataType: columnType,
|
|
14488
|
+
columnDefault,
|
|
14489
|
+
columnOnUpdate,
|
|
14490
|
+
columnNotNull,
|
|
14491
|
+
columnAutoIncrement
|
|
14492
|
+
});
|
|
14493
|
+
}
|
|
14494
|
+
if (((_l = column6.onUpdate) == null ? void 0 : _l.type) === "deleted") {
|
|
14495
|
+
statements.push({
|
|
14496
|
+
type: "alter_table_alter_column_drop_on_update",
|
|
14497
|
+
tableName,
|
|
14498
|
+
columnName,
|
|
14499
|
+
schema: schema4,
|
|
14500
|
+
newDataType: columnType,
|
|
14501
|
+
columnDefault,
|
|
14502
|
+
columnOnUpdate,
|
|
14503
|
+
columnNotNull,
|
|
14504
|
+
columnAutoIncrement
|
|
14296
14505
|
});
|
|
14297
14506
|
}
|
|
14298
14507
|
}
|
|
@@ -14463,13 +14672,16 @@ var init_snapshotsDiffer = __esm({
|
|
|
14463
14672
|
unique: booleanType().optional(),
|
|
14464
14673
|
default: anyType().optional(),
|
|
14465
14674
|
notNull: booleanType().optional(),
|
|
14466
|
-
autoincrement: booleanType().optional()
|
|
14675
|
+
autoincrement: booleanType().optional(),
|
|
14676
|
+
onUpdate: booleanType().optional()
|
|
14467
14677
|
}).strict();
|
|
14468
14678
|
alteredColumnSchema = objectType({
|
|
14469
14679
|
name: makeSelfOrChanged(stringType()),
|
|
14470
14680
|
type: makeChanged(stringType()).optional(),
|
|
14471
14681
|
default: makePatched(anyType()).optional(),
|
|
14472
|
-
notNull: makePatched(booleanType()).optional()
|
|
14682
|
+
notNull: makePatched(booleanType()).optional(),
|
|
14683
|
+
onUpdate: makePatched(booleanType()).optional(),
|
|
14684
|
+
autoincrement: makePatched(booleanType()).optional()
|
|
14473
14685
|
}).strict();
|
|
14474
14686
|
enumSchema2 = objectType({
|
|
14475
14687
|
name: stringType(),
|
|
@@ -14677,6 +14889,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
14677
14889
|
it.added,
|
|
14678
14890
|
it.altered,
|
|
14679
14891
|
it.addedForeignKeys,
|
|
14892
|
+
json2,
|
|
14680
14893
|
dialect6
|
|
14681
14894
|
);
|
|
14682
14895
|
}).flat().reduce(
|
|
@@ -14771,8 +14984,14 @@ var init_snapshotsDiffer = __esm({
|
|
|
14771
14984
|
jsonStatements.push(...jsonRemoveTableFromSchemas);
|
|
14772
14985
|
jsonStatements.push(...dropSchemas);
|
|
14773
14986
|
const sqlStatements = fromJson(jsonStatements, dialect6);
|
|
14987
|
+
const uniqueSqlStatements = [];
|
|
14988
|
+
sqlStatements.forEach((ss) => {
|
|
14989
|
+
if (!uniqueSqlStatements.includes(ss)) {
|
|
14990
|
+
uniqueSqlStatements.push(ss);
|
|
14991
|
+
}
|
|
14992
|
+
});
|
|
14774
14993
|
const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
|
|
14775
|
-
return { statements: jsonStatements, sqlStatements, _meta };
|
|
14994
|
+
return { statements: jsonStatements, sqlStatements: uniqueSqlStatements, _meta };
|
|
14776
14995
|
};
|
|
14777
14996
|
}
|
|
14778
14997
|
});
|
|
@@ -16508,7 +16727,7 @@ var init_upFolders = __esm({
|
|
|
16508
16727
|
idx: it.idx,
|
|
16509
16728
|
when: +it.date,
|
|
16510
16729
|
tag,
|
|
16511
|
-
breakpoints:
|
|
16730
|
+
breakpoints: false
|
|
16512
16731
|
});
|
|
16513
16732
|
const patchedJSON = fullfill(prev, it.json, it.sql, dialect6);
|
|
16514
16733
|
(0, import_fs.writeFileSync)(
|
|
@@ -22339,7 +22558,7 @@ function clearDefaults(defaultValue, collate) {
|
|
|
22339
22558
|
return `(${resultDefault})`;
|
|
22340
22559
|
}
|
|
22341
22560
|
}
|
|
22342
|
-
var import_mysql_core2, import_table, import_utils7, import_sql, import_common, dialect3, indexName, generateMySqlSnapshot, fromDatabase;
|
|
22561
|
+
var import_mysql_core2, import_table, import_utils7, import_sql, import_common, import_date, dialect3, indexName, generateMySqlSnapshot, fromDatabase;
|
|
22343
22562
|
var init_mysqlSerializer = __esm({
|
|
22344
22563
|
"src/serializer/mysqlSerializer.ts"() {
|
|
22345
22564
|
import_mysql_core2 = require("drizzle-orm/mysql-core");
|
|
@@ -22347,6 +22566,7 @@ var init_mysqlSerializer = __esm({
|
|
|
22347
22566
|
import_utils7 = require("drizzle-orm/mysql-core/utils");
|
|
22348
22567
|
import_sql = require("drizzle-orm/sql");
|
|
22349
22568
|
import_common = require("drizzle-orm/mysql-core/columns/common");
|
|
22569
|
+
import_date = require("drizzle-orm/mysql-core/columns/date.common");
|
|
22350
22570
|
dialect3 = new import_mysql_core2.MySqlDialect();
|
|
22351
22571
|
indexName = (tableName, columns) => {
|
|
22352
22572
|
return `${tableName}_${columns.join("_")}_index`;
|
|
@@ -22367,12 +22587,14 @@ var init_mysqlSerializer = __esm({
|
|
|
22367
22587
|
columns.forEach((column6) => {
|
|
22368
22588
|
const notNull = column6.notNull;
|
|
22369
22589
|
const primaryKey = column6.primary;
|
|
22590
|
+
const sqlTypeLowered = column6.getSQLType().toLowerCase();
|
|
22370
22591
|
const columnToSet = {
|
|
22371
22592
|
name: column6.name,
|
|
22372
22593
|
type: column6.getSQLType(),
|
|
22373
22594
|
primaryKey,
|
|
22374
22595
|
notNull,
|
|
22375
|
-
autoincrement: column6 instanceof import_common.MySqlColumnWithAutoIncrement ? column6.autoIncrement : false
|
|
22596
|
+
autoincrement: column6 instanceof import_common.MySqlColumnWithAutoIncrement ? column6.autoIncrement : false,
|
|
22597
|
+
onUpdate: column6 instanceof import_date.MySqlDateBaseColumn ? column6.hasOnUpdateNow : void 0
|
|
22376
22598
|
};
|
|
22377
22599
|
if (column6.default !== void 0) {
|
|
22378
22600
|
if (column6.default instanceof import_sql.SQL) {
|
|
@@ -22383,7 +22605,17 @@ var init_mysqlSerializer = __esm({
|
|
|
22383
22605
|
throw new Error();
|
|
22384
22606
|
}).join();
|
|
22385
22607
|
} else {
|
|
22386
|
-
|
|
22608
|
+
if (typeof column6.default === "string") {
|
|
22609
|
+
columnToSet.default = `"${column6.default}"`;
|
|
22610
|
+
} else {
|
|
22611
|
+
if (sqlTypeLowered === "json") {
|
|
22612
|
+
columnToSet.default = `'${JSON.stringify(column6.default)}'`;
|
|
22613
|
+
} else if (column6.default instanceof Date) {
|
|
22614
|
+
columnToSet.default = `'${column6.default.toISOString()}'`;
|
|
22615
|
+
} else {
|
|
22616
|
+
columnToSet.default = column6.default;
|
|
22617
|
+
}
|
|
22618
|
+
}
|
|
22387
22619
|
}
|
|
22388
22620
|
if (["blob", "text", "json"].includes(column6.getSQLType())) {
|
|
22389
22621
|
columnToSet.default = `(${columnToSet.default})`;
|
|
@@ -22457,10 +22689,10 @@ var init_mysqlSerializer = __esm({
|
|
|
22457
22689
|
}
|
|
22458
22690
|
};
|
|
22459
22691
|
};
|
|
22460
|
-
fromDatabase = async (db,
|
|
22692
|
+
fromDatabase = async (db, inputSchema, progressCallback) => {
|
|
22461
22693
|
const result = {};
|
|
22462
22694
|
const columns = await db.execute(`select * from information_schema.columns
|
|
22463
|
-
where table_schema = '${
|
|
22695
|
+
where table_schema = '${inputSchema}' and table_name != '__drizzle_migrations'
|
|
22464
22696
|
order by table_name, ordinal_position;`);
|
|
22465
22697
|
const response = columns[0];
|
|
22466
22698
|
const schemas = [];
|
|
@@ -22471,9 +22703,9 @@ var init_mysqlSerializer = __esm({
|
|
|
22471
22703
|
for (const column6 of response) {
|
|
22472
22704
|
columnsCount += 1;
|
|
22473
22705
|
progressCallback("columns", columnsCount, "fetching");
|
|
22474
|
-
const
|
|
22706
|
+
const schema4 = column6["TABLE_SCHEMA"];
|
|
22475
22707
|
const tableName = column6["TABLE_NAME"];
|
|
22476
|
-
tablesCount.add(`${
|
|
22708
|
+
tablesCount.add(`${schema4}.${tableName}`);
|
|
22477
22709
|
progressCallback("columns", tablesCount.size, "fetching");
|
|
22478
22710
|
const columnName = column6["COLUMN_NAME"];
|
|
22479
22711
|
const isNullable = column6["IS_NULLABLE"] === "YES";
|
|
@@ -22484,7 +22716,9 @@ var init_mysqlSerializer = __esm({
|
|
|
22484
22716
|
const isDefaultAnExpression = column6["EXTRA"] === "DEFAULT_GENERATED";
|
|
22485
22717
|
const columnDefault = column6["COLUMN_DEFAULT"];
|
|
22486
22718
|
const collation = column6["CHARACTER_SET_NAME"];
|
|
22487
|
-
|
|
22719
|
+
if (schema4 !== inputSchema) {
|
|
22720
|
+
schemas.push(schema4);
|
|
22721
|
+
}
|
|
22488
22722
|
const table4 = result[tableName];
|
|
22489
22723
|
const newColumn = {
|
|
22490
22724
|
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `"${columnDefault}"`,
|
|
@@ -22497,7 +22731,7 @@ var init_mysqlSerializer = __esm({
|
|
|
22497
22731
|
if (!table4) {
|
|
22498
22732
|
result[tableName] = {
|
|
22499
22733
|
name: tableName,
|
|
22500
|
-
schema:
|
|
22734
|
+
schema: schema4 !== inputSchema ? schema4 : void 0,
|
|
22501
22735
|
columns: {
|
|
22502
22736
|
[columnName]: newColumn
|
|
22503
22737
|
},
|
|
@@ -22510,56 +22744,62 @@ var init_mysqlSerializer = __esm({
|
|
|
22510
22744
|
}
|
|
22511
22745
|
progressCallback("columns", columnsCount, "done");
|
|
22512
22746
|
progressCallback("tables", tablesCount.size, "done");
|
|
22513
|
-
|
|
22514
|
-
|
|
22747
|
+
try {
|
|
22748
|
+
const fks = await db.execute(
|
|
22749
|
+
`SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,information_schema.referential_constraints.UPDATE_RULE, information_schema.referential_constraints.DELETE_RULE
|
|
22515
22750
|
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
|
22516
22751
|
LEFT JOIN information_schema.referential_constraints on information_schema.referential_constraints.constraint_name = information_schema.KEY_COLUMN_USAGE.CONSTRAINT_NAME
|
|
22517
22752
|
WHERE INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA = ? AND INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME != 'PRIMARY' and INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME is not null;
|
|
22518
22753
|
`,
|
|
22519
|
-
|
|
22520
|
-
|
|
22521
|
-
|
|
22522
|
-
|
|
22523
|
-
|
|
22524
|
-
|
|
22525
|
-
|
|
22526
|
-
|
|
22527
|
-
|
|
22528
|
-
|
|
22529
|
-
|
|
22530
|
-
|
|
22531
|
-
|
|
22532
|
-
|
|
22533
|
-
|
|
22534
|
-
|
|
22535
|
-
|
|
22536
|
-
|
|
22537
|
-
|
|
22538
|
-
|
|
22539
|
-
|
|
22540
|
-
|
|
22541
|
-
|
|
22542
|
-
|
|
22543
|
-
|
|
22544
|
-
|
|
22545
|
-
|
|
22546
|
-
|
|
22547
|
-
|
|
22548
|
-
|
|
22549
|
-
|
|
22754
|
+
[inputSchema]
|
|
22755
|
+
);
|
|
22756
|
+
const fkRows = fks[0];
|
|
22757
|
+
for (const fkRow of fkRows) {
|
|
22758
|
+
foreignKeysCount += 1;
|
|
22759
|
+
progressCallback("fks", foreignKeysCount, "fetching");
|
|
22760
|
+
const tableSchema = fkRow["TABLE_SCHEMA"];
|
|
22761
|
+
const tableName = fkRow["TABLE_NAME"];
|
|
22762
|
+
const constraintName = fkRow["CONSTRAINT_NAME"];
|
|
22763
|
+
const columnName = fkRow["COLUMN_NAME"];
|
|
22764
|
+
const refTableSchema = fkRow["REFERENCED_TABLE_SCHEMA"];
|
|
22765
|
+
const refTableName = fkRow["REFERENCED_TABLE_NAME"];
|
|
22766
|
+
const refColumnName = fkRow["REFERENCED_COLUMN_NAME"];
|
|
22767
|
+
const updateRule = fkRow["UPDATE_RULE"];
|
|
22768
|
+
const deleteRule = fkRow["DELETE_RULE"];
|
|
22769
|
+
const tableInResult = result[tableName];
|
|
22770
|
+
if (typeof tableInResult === "undefined")
|
|
22771
|
+
continue;
|
|
22772
|
+
if (typeof tableInResult.foreignKeys[constraintName] !== "undefined") {
|
|
22773
|
+
tableInResult.foreignKeys[constraintName].columnsFrom.push(columnName);
|
|
22774
|
+
tableInResult.foreignKeys[constraintName].columnsTo.push(
|
|
22775
|
+
refColumnName
|
|
22776
|
+
);
|
|
22777
|
+
} else {
|
|
22778
|
+
tableInResult.foreignKeys[constraintName] = {
|
|
22779
|
+
name: constraintName,
|
|
22780
|
+
tableFrom: tableName,
|
|
22781
|
+
tableTo: refTableName,
|
|
22782
|
+
columnsFrom: [columnName],
|
|
22783
|
+
columnsTo: [refColumnName],
|
|
22784
|
+
onDelete: deleteRule == null ? void 0 : deleteRule.toLowerCase(),
|
|
22785
|
+
onUpdate: updateRule == null ? void 0 : updateRule.toLowerCase()
|
|
22786
|
+
};
|
|
22787
|
+
}
|
|
22788
|
+
tableInResult.foreignKeys[constraintName].columnsFrom = [
|
|
22789
|
+
...new Set(tableInResult.foreignKeys[constraintName].columnsFrom)
|
|
22790
|
+
];
|
|
22791
|
+
tableInResult.foreignKeys[constraintName].columnsTo = [
|
|
22792
|
+
...new Set(tableInResult.foreignKeys[constraintName].columnsTo)
|
|
22793
|
+
];
|
|
22550
22794
|
}
|
|
22551
|
-
|
|
22552
|
-
|
|
22553
|
-
];
|
|
22554
|
-
tableInResult.foreignKeys[constraintName].columnsTo = [
|
|
22555
|
-
...new Set(tableInResult.foreignKeys[constraintName].columnsTo)
|
|
22556
|
-
];
|
|
22795
|
+
} catch (e) {
|
|
22796
|
+
console.log(`Can't proccess foreign keys`);
|
|
22557
22797
|
}
|
|
22558
22798
|
progressCallback("fks", foreignKeysCount, "done");
|
|
22559
22799
|
const idxs = await db.execute(
|
|
22560
22800
|
`select * from INFORMATION_SCHEMA.STATISTICS
|
|
22561
22801
|
WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = ? and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`,
|
|
22562
|
-
[
|
|
22802
|
+
[inputSchema]
|
|
22563
22803
|
);
|
|
22564
22804
|
const idxRows = idxs[0];
|
|
22565
22805
|
for (const idxRow of idxRows) {
|
|
@@ -23327,7 +23567,8 @@ var init_migrate = __esm({
|
|
|
23327
23567
|
snapshots.length,
|
|
23328
23568
|
journal,
|
|
23329
23569
|
_meta,
|
|
23330
|
-
outFolder
|
|
23570
|
+
outFolder,
|
|
23571
|
+
config.breakpoints
|
|
23331
23572
|
);
|
|
23332
23573
|
} catch (e) {
|
|
23333
23574
|
console.error(e);
|
|
@@ -23355,7 +23596,8 @@ var init_migrate = __esm({
|
|
|
23355
23596
|
snapshots.length,
|
|
23356
23597
|
journal,
|
|
23357
23598
|
_meta,
|
|
23358
|
-
outFolder
|
|
23599
|
+
outFolder,
|
|
23600
|
+
config.breakpoints
|
|
23359
23601
|
);
|
|
23360
23602
|
} catch (e) {
|
|
23361
23603
|
console.error(e);
|
|
@@ -23383,7 +23625,8 @@ var init_migrate = __esm({
|
|
|
23383
23625
|
snapshots.length,
|
|
23384
23626
|
journal,
|
|
23385
23627
|
_meta,
|
|
23386
|
-
outFolder
|
|
23628
|
+
outFolder,
|
|
23629
|
+
config.breakpoints
|
|
23387
23630
|
);
|
|
23388
23631
|
} catch (e) {
|
|
23389
23632
|
console.error(e);
|
|
@@ -23569,7 +23812,7 @@ var init_migrate = __esm({
|
|
|
23569
23812
|
result.deleted.push(...leftMissing);
|
|
23570
23813
|
return result;
|
|
23571
23814
|
};
|
|
23572
|
-
writeResult = (cur, sqlStatements, idx, journal, _meta, outFolder) => {
|
|
23815
|
+
writeResult = (cur, sqlStatements, idx, journal, _meta, outFolder, breakpoints) => {
|
|
23573
23816
|
console.log(schema(cur));
|
|
23574
23817
|
if (sqlStatements.length === 0) {
|
|
23575
23818
|
console.log("No schema changes, nothing to migrate \u{1F634}");
|
|
@@ -23584,25 +23827,13 @@ var init_migrate = __esm({
|
|
|
23584
23827
|
(0, import_path4.join)(metaFolderPath, `${prefix}_snapshot.json`),
|
|
23585
23828
|
JSON.stringify(toSave, null, 2)
|
|
23586
23829
|
);
|
|
23587
|
-
const sqlDelimiter = "\n";
|
|
23588
|
-
const sqlBreakopoints = sqlStatements.reduce(
|
|
23589
|
-
(acc, cur2) => {
|
|
23590
|
-
const breakpoint = acc.offset + sqlDelimiter.length + cur2.length;
|
|
23591
|
-
acc.res.push(breakpoint);
|
|
23592
|
-
acc.offset = breakpoint;
|
|
23593
|
-
return acc;
|
|
23594
|
-
},
|
|
23595
|
-
{
|
|
23596
|
-
offset: 0,
|
|
23597
|
-
res: []
|
|
23598
|
-
}
|
|
23599
|
-
);
|
|
23830
|
+
const sqlDelimiter = breakpoints ? "--> statement-breakpoint\n" : "\n";
|
|
23600
23831
|
const sql = sqlStatements.join(sqlDelimiter);
|
|
23601
23832
|
journal.entries.push({
|
|
23602
23833
|
idx,
|
|
23603
23834
|
when: +new Date(),
|
|
23604
23835
|
tag,
|
|
23605
|
-
breakpoints
|
|
23836
|
+
breakpoints
|
|
23606
23837
|
});
|
|
23607
23838
|
import_fs5.default.writeFileSync(metaJournal, JSON.stringify(journal, null, 2));
|
|
23608
23839
|
import_fs5.default.writeFileSync(`${outFolder}/${tag}.sql`, sql);
|
|
@@ -44848,13 +45079,13 @@ var init_mysql_introspect = __esm({
|
|
|
44848
45079
|
},
|
|
44849
45080
|
{ mysql: [] }
|
|
44850
45081
|
);
|
|
44851
|
-
const schemaStatements = Object.entries(schemas).
|
|
45082
|
+
const schemaStatements = Object.entries(schemas).map((it) => {
|
|
44852
45083
|
return `export const ${it[1]} = mysqlSchema("${it[0]}");
|
|
44853
45084
|
`;
|
|
44854
45085
|
}).join();
|
|
44855
45086
|
const tableStatements = Object.values(schema4.tables).map((table4) => {
|
|
44856
45087
|
const schema5 = schemas[table4.schema];
|
|
44857
|
-
const func = schema5
|
|
45088
|
+
const func = schema5 ? schema5 : "mysqlTable";
|
|
44858
45089
|
let statement = "";
|
|
44859
45090
|
if (imports.mysql.includes(table4.name.camelCase())) {
|
|
44860
45091
|
statement = `// Table name is in conflict with ${table4.name.camelCase()} import.
|
|
@@ -45184,16 +45415,21 @@ var init_mysqlIntrospect = __esm({
|
|
|
45184
45415
|
if (typeof config.connectionString !== "undefined") {
|
|
45185
45416
|
const connection = config.connectionString;
|
|
45186
45417
|
client = await (0, import_promise.createConnection)(connection);
|
|
45187
|
-
|
|
45418
|
+
const connectionUrl = new URL(connection);
|
|
45419
|
+
const pathname = connectionUrl.pathname;
|
|
45420
|
+
databaseName = pathname.split("/")[pathname.split("/").length - 1];
|
|
45188
45421
|
} else {
|
|
45189
45422
|
client = await (0, import_promise.createConnection)(config);
|
|
45190
45423
|
databaseName = config.database;
|
|
45191
45424
|
}
|
|
45192
45425
|
await client.connect();
|
|
45193
45426
|
const progress = new IntrospectProgress();
|
|
45194
|
-
const res = await (0, import_hanji4.renderWithTask)(
|
|
45195
|
-
progress
|
|
45196
|
-
|
|
45427
|
+
const res = await (0, import_hanji4.renderWithTask)(
|
|
45428
|
+
progress,
|
|
45429
|
+
fromDatabase(client, databaseName, (stage, count, status) => {
|
|
45430
|
+
progress.update(stage, count, status);
|
|
45431
|
+
})
|
|
45432
|
+
);
|
|
45197
45433
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
45198
45434
|
const ts = schemaToTypeScript2(schema4);
|
|
45199
45435
|
return { schema: schema4, ts };
|
|
@@ -45318,15 +45554,16 @@ var package_default = {
|
|
|
45318
45554
|
name: "drizzle-kit",
|
|
45319
45555
|
version: "0.16.9",
|
|
45320
45556
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
45321
|
-
author: "
|
|
45557
|
+
author: "Drizzle Team",
|
|
45322
45558
|
license: "MIT",
|
|
45323
45559
|
bin: {
|
|
45324
45560
|
"drizzle-kit": "./index.js"
|
|
45325
45561
|
},
|
|
45326
45562
|
scripts: {
|
|
45327
45563
|
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate --out ./dev/migrations --dialect pg --schema ./dev/data",
|
|
45564
|
+
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/migrations --schema ./dev/migrations/schema.ts",
|
|
45328
45565
|
"check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
|
|
45329
|
-
"introspect:mysql":
|
|
45566
|
+
"introspect:mysql": 'node -r esbuild-register ./src/cli/index.ts introspect:mysql --out ./dev/migrations --connectionString mysql://eteb3igve6392dte6e47:pscale_pw_GyFkQr8pIWTuPTU9iJ7ajE7HfBxLQZ7kwJJ67PlOhbr@eu-central.connect.psdb.cloud/test?ssl={\\"rejectUnauthorized\\":true}',
|
|
45330
45567
|
"up:pg": "node -r esbuild-register ./src/cli/index.ts up --out ./dev/equedi --dialect pg",
|
|
45331
45568
|
"check:equedi": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/equedi --dialect pg",
|
|
45332
45569
|
run: "node -r esbuild-register index.ts",
|
|
@@ -45338,7 +45575,9 @@ var package_default = {
|
|
|
45338
45575
|
sim: "node -r esbuild-register ./dev/simulate.ts",
|
|
45339
45576
|
"sim:sqlite": "node -r esbuild-register ./dev/sqlite/index.ts",
|
|
45340
45577
|
test: "ava test",
|
|
45341
|
-
build: "
|
|
45578
|
+
build: "pnpm build:cli && pnpm build:utils",
|
|
45579
|
+
"build:cli": "esbuild ./src/cli/index.ts --bundle --platform=node --target=node10.4 --outfile=./dist/index.js --external:esbuild --external:drizzle-orm-pg --external:drizzle-orm-sqlite --external:drizzle-orm-mysql --external:drizzle-orm --external:pg-native",
|
|
45580
|
+
"build:utils": "esbuild ./src/utils.ts --bundle --platform=node --target=node10.4 --outfile=./dist/utils.js",
|
|
45342
45581
|
pack: "build && package",
|
|
45343
45582
|
tsc: "tsc -p tsconfig.build.json",
|
|
45344
45583
|
pub: "cp package.json readme.md dist/ && cd dist && npm publish"
|
|
@@ -45373,7 +45612,7 @@ var package_default = {
|
|
|
45373
45612
|
ava: "^5.1.0",
|
|
45374
45613
|
dockerode: "^3.3.4",
|
|
45375
45614
|
"drizzle-kit": "^0.16.8",
|
|
45376
|
-
"drizzle-orm": "0.
|
|
45615
|
+
"drizzle-orm": "0.21.0-2e66963",
|
|
45377
45616
|
esbuild: "^0.15.7",
|
|
45378
45617
|
"esbuild-register": "^3.3.3",
|
|
45379
45618
|
eslint: "^8.29.0",
|
|
@@ -45702,18 +45941,21 @@ drizzle-orm: v${npmVersion}` : "";
|
|
|
45702
45941
|
};
|
|
45703
45942
|
var configSchema = objectType({
|
|
45704
45943
|
schema: stringType(),
|
|
45705
|
-
out: stringType().default("drizzle")
|
|
45944
|
+
out: stringType().default("drizzle"),
|
|
45945
|
+
breakpoints: booleanType()
|
|
45706
45946
|
}).strict();
|
|
45707
45947
|
var optionsSchema = objectType({
|
|
45708
45948
|
schema: stringType().optional(),
|
|
45709
45949
|
out: stringType().optional(),
|
|
45710
|
-
config: stringType().optional()
|
|
45950
|
+
config: stringType().optional(),
|
|
45951
|
+
breakpoints: booleanType().optional().default(false)
|
|
45711
45952
|
}).strict();
|
|
45712
|
-
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(
|
|
45953
|
+
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(
|
|
45713
45954
|
"--config <config>",
|
|
45714
45955
|
"Path to a config.json file, drizzle.config.json by default"
|
|
45715
45956
|
).action(async (options) => {
|
|
45716
45957
|
printVersions();
|
|
45958
|
+
assertOrmCoreVersion();
|
|
45717
45959
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
45718
45960
|
const result = prepareGenerateConfig(oprtionsParsed);
|
|
45719
45961
|
if (result instanceof Error) {
|
|
@@ -45724,11 +45966,12 @@ var generatePgCommand = new Command("generate:pg").option("--schema <schema>", "
|
|
|
45724
45966
|
const { prepareAndMigratePg: prepareAndMigratePg2 } = (init_migrate(), __toCommonJS(migrate_exports));
|
|
45725
45967
|
await prepareAndMigratePg2(result);
|
|
45726
45968
|
});
|
|
45727
|
-
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(
|
|
45969
|
+
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(
|
|
45728
45970
|
"--config <config>",
|
|
45729
45971
|
"Path to a config.json file, drizzle.config.json by default"
|
|
45730
45972
|
).action(async (options) => {
|
|
45731
45973
|
printVersions();
|
|
45974
|
+
assertOrmCoreVersion();
|
|
45732
45975
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
45733
45976
|
const result = prepareGenerateConfig(oprtionsParsed);
|
|
45734
45977
|
if (result instanceof Error) {
|
|
@@ -45739,11 +45982,12 @@ var generateMysqlCommand = new Command("generate:mysql").option("--schema <schem
|
|
|
45739
45982
|
const { prepareAndMigrateMySql: prepareAndMigrateMySql2 } = (init_migrate(), __toCommonJS(migrate_exports));
|
|
45740
45983
|
await prepareAndMigrateMySql2(result);
|
|
45741
45984
|
});
|
|
45742
|
-
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(
|
|
45985
|
+
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(
|
|
45743
45986
|
"--config <config>",
|
|
45744
45987
|
"Path to a config.json file, drizzle.config.json by default"
|
|
45745
45988
|
).action(async (options) => {
|
|
45746
45989
|
printVersions();
|
|
45990
|
+
assertOrmCoreVersion();
|
|
45747
45991
|
const oprtionsParsed = optionsSchema.parse(options);
|
|
45748
45992
|
const result = prepareGenerateConfig(oprtionsParsed);
|
|
45749
45993
|
if (result instanceof Error) {
|
|
@@ -45755,7 +45999,7 @@ var generateSqliteCommand = new Command("generate:sqlite").option("--schema <sch
|
|
|
45755
45999
|
await prepareAndMigrateSqlite2(result);
|
|
45756
46000
|
});
|
|
45757
46001
|
var prepareGenerateConfig = (options) => {
|
|
45758
|
-
const { schema: schema4, out, config } = options;
|
|
46002
|
+
const { schema: schema4, out, config, breakpoints } = options;
|
|
45759
46003
|
if (!(schema4 || out)) {
|
|
45760
46004
|
const path4 = config != null ? config : "drizzle.config.json";
|
|
45761
46005
|
const drizzleConfig = JSON.parse(
|
|
@@ -45766,7 +46010,7 @@ var prepareGenerateConfig = (options) => {
|
|
|
45766
46010
|
if (!schema4) {
|
|
45767
46011
|
return new Error(`'schema' param must be set`);
|
|
45768
46012
|
}
|
|
45769
|
-
return configSchema.parse({ schema: schema4, out });
|
|
46013
|
+
return configSchema.parse({ schema: schema4, out, breakpoints });
|
|
45770
46014
|
};
|
|
45771
46015
|
var checkSchema = objectType({
|
|
45772
46016
|
out: stringType().optional(),
|
|
@@ -45774,6 +46018,7 @@ var checkSchema = objectType({
|
|
|
45774
46018
|
}).strict();
|
|
45775
46019
|
var checkPgCommand = new Command("check:pg").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
|
|
45776
46020
|
printVersions();
|
|
46021
|
+
assertOrmCoreVersion();
|
|
45777
46022
|
const params = checkSchema.parse(options);
|
|
45778
46023
|
const out = assertEitherConfigOrOut(params.config, params.out);
|
|
45779
46024
|
if (!out) {
|
|
@@ -45785,6 +46030,7 @@ var checkPgCommand = new Command("check:pg").option("--out <out>", `Output folde
|
|
|
45785
46030
|
});
|
|
45786
46031
|
var checkSqliteCommand = new Command("check:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
|
|
45787
46032
|
printVersions();
|
|
46033
|
+
assertOrmCoreVersion();
|
|
45788
46034
|
const params = checkSchema.parse(options);
|
|
45789
46035
|
const out = assertEitherConfigOrOut(params.config, params.out);
|
|
45790
46036
|
if (!out) {
|
|
@@ -45796,6 +46042,7 @@ var checkSqliteCommand = new Command("check:sqlite").option("--out <out>", `Outp
|
|
|
45796
46042
|
});
|
|
45797
46043
|
var upPgCommand = new Command("up:pg").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
|
|
45798
46044
|
printVersions();
|
|
46045
|
+
assertOrmCoreVersion();
|
|
45799
46046
|
const params = checkSchema.parse(options);
|
|
45800
46047
|
const out = assertEitherConfigOrOut(params.config, params.out);
|
|
45801
46048
|
if (!out) {
|
|
@@ -45813,6 +46060,7 @@ var upPgCommand = new Command("up:pg").option("--out <out>", `Output folder`).op
|
|
|
45813
46060
|
});
|
|
45814
46061
|
var upMysqlCommand = new Command("up:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
|
|
45815
46062
|
printVersions();
|
|
46063
|
+
assertOrmCoreVersion();
|
|
45816
46064
|
const params = checkSchema.parse(options);
|
|
45817
46065
|
const out = assertEitherConfigOrOut(params.config, params.out);
|
|
45818
46066
|
if (!out) {
|
|
@@ -45834,6 +46082,7 @@ var upMysqlCommand = new Command("up:mysql").option("--out <out>", `Output folde
|
|
|
45834
46082
|
});
|
|
45835
46083
|
var upSqliteCommand = new Command("up:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
|
|
45836
46084
|
printVersions();
|
|
46085
|
+
assertOrmCoreVersion();
|
|
45837
46086
|
const params = checkSchema.parse(options);
|
|
45838
46087
|
const out = assertEitherConfigOrOut(params.config, params.out);
|
|
45839
46088
|
if (!out) {
|
|
@@ -45843,9 +46092,10 @@ var upSqliteCommand = new Command("up:sqlite").option("--out <out>", `Output fol
|
|
|
45843
46092
|
upSqliteHandler(out);
|
|
45844
46093
|
});
|
|
45845
46094
|
var pt1 = objectType({
|
|
45846
|
-
out: stringType()
|
|
46095
|
+
out: stringType(),
|
|
46096
|
+
breakpoints: booleanType().optional().default(false)
|
|
45847
46097
|
});
|
|
45848
|
-
var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Migrations folder`).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").action(async (options) => {
|
|
46098
|
+
var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).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").action(async (options) => {
|
|
45849
46099
|
printVersions();
|
|
45850
46100
|
assertPackages("drizzle-orm");
|
|
45851
46101
|
assertOrmCoreVersion();
|
|
@@ -45870,7 +46120,7 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
|
|
|
45870
46120
|
squashPgScheme(schema4),
|
|
45871
46121
|
"pg"
|
|
45872
46122
|
);
|
|
45873
|
-
writeResult(schema4, sqlStatements, 0, journal, _meta, res.data.out);
|
|
46123
|
+
writeResult(schema4, sqlStatements, 0, journal, _meta, res.data.out, res.data.breakpoints);
|
|
45874
46124
|
} else {
|
|
45875
46125
|
(0, import_hanji5.render)(
|
|
45876
46126
|
`[${source_default.blue(
|
|
@@ -45887,7 +46137,7 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
|
|
|
45887
46137
|
);
|
|
45888
46138
|
process.exit(1);
|
|
45889
46139
|
});
|
|
45890
|
-
var introspectMySqlCommand = new Command("introspect:mysql").option("--out <out>", `Migrations folder`).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) => {
|
|
46140
|
+
var introspectMySqlCommand = new Command("introspect:mysql").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) => {
|
|
45891
46141
|
printVersions();
|
|
45892
46142
|
assertPackages("drizzle-orm");
|
|
45893
46143
|
assertOrmCoreVersion();
|
|
@@ -45912,7 +46162,7 @@ var introspectMySqlCommand = new Command("introspect:mysql").option("--out <out>
|
|
|
45912
46162
|
squashMysqlScheme(schema4),
|
|
45913
46163
|
"mysql"
|
|
45914
46164
|
);
|
|
45915
|
-
writeResult(schema4, sqlStatements, 0, journal, _meta, res.data.out);
|
|
46165
|
+
writeResult(schema4, sqlStatements, 0, journal, _meta, res.data.out, res.data.breakpoints);
|
|
45916
46166
|
} else {
|
|
45917
46167
|
(0, import_hanji5.render)(
|
|
45918
46168
|
`[${source_default.blue(
|