drizzle-kit 0.18.0 → 0.18.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.d.ts +1 -1
- package/index.js +251 -103
- package/package.json +3 -3
- package/utils.js +117 -50
package/index.js
CHANGED
|
@@ -5914,7 +5914,7 @@ var require_hanji = __commonJS({
|
|
|
5914
5914
|
}
|
|
5915
5915
|
};
|
|
5916
5916
|
exports.TaskTerminal = TaskTerminal;
|
|
5917
|
-
function
|
|
5917
|
+
function render6(view) {
|
|
5918
5918
|
const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
|
|
5919
5919
|
if (view instanceof Prompt3) {
|
|
5920
5920
|
const terminal = new Terminal(view, stdin, stdout, closable);
|
|
@@ -5926,7 +5926,7 @@ var require_hanji = __commonJS({
|
|
|
5926
5926
|
closable.close();
|
|
5927
5927
|
return;
|
|
5928
5928
|
}
|
|
5929
|
-
exports.render =
|
|
5929
|
+
exports.render = render6;
|
|
5930
5930
|
function renderWithTask3(view, task) {
|
|
5931
5931
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5932
5932
|
const terminal = new TaskTerminal(view, process.stdout);
|
|
@@ -21381,10 +21381,11 @@ var init_mysqlSerializer = __esm({
|
|
|
21381
21381
|
}
|
|
21382
21382
|
});
|
|
21383
21383
|
const fks = foreignKeys.map((fk4) => {
|
|
21384
|
+
var _a, _b;
|
|
21384
21385
|
const name = fk4.getName();
|
|
21385
21386
|
const tableFrom = tableName;
|
|
21386
|
-
const onDelete = fk4.onDelete;
|
|
21387
|
-
const onUpdate = fk4.onUpdate;
|
|
21387
|
+
const onDelete = (_a = fk4.onDelete) != null ? _a : "no action";
|
|
21388
|
+
const onUpdate = (_b = fk4.onUpdate) != null ? _b : "no action";
|
|
21388
21389
|
const reference = fk4.reference();
|
|
21389
21390
|
const referenceFT = reference.foreignTable;
|
|
21390
21391
|
const tableTo = (0, import_drizzle_orm.getTableName)(referenceFT);
|
|
@@ -21973,7 +21974,7 @@ var init_pgSerializer = __esm({
|
|
|
21973
21974
|
const columnDimensions = columnResponse.array_dimensions;
|
|
21974
21975
|
let columnType = columnResponse.data_type;
|
|
21975
21976
|
const primaryKey = tableConstraints.rows.filter(
|
|
21976
|
-
(mapRow) => mapRow.constraint_type === "PRIMARY KEY"
|
|
21977
|
+
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
|
|
21977
21978
|
);
|
|
21978
21979
|
const cprimaryKey = tableConstraints.rows.filter(
|
|
21979
21980
|
(mapRow) => mapRow.constraint_type === "PRIMARY KEY"
|
|
@@ -22011,7 +22012,7 @@ var init_pgSerializer = __esm({
|
|
|
22011
22012
|
columnToReturn[columnName] = {
|
|
22012
22013
|
name: columnName,
|
|
22013
22014
|
type: columnTypeMapped,
|
|
22014
|
-
primaryKey: primaryKey.length === 1 && cprimaryKey.length <
|
|
22015
|
+
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
|
22015
22016
|
notNull: columnResponse.is_nullable === "NO"
|
|
22016
22017
|
};
|
|
22017
22018
|
if (!isSerial && typeof defaultValue !== "undefined") {
|
|
@@ -24191,7 +24192,7 @@ var init_migrate = __esm({
|
|
|
24191
24192
|
let sql = sqlStatements.join(sqlDelimiter);
|
|
24192
24193
|
if (type === "introspect") {
|
|
24193
24194
|
sql = `-- Current sql file was generated after introspecting the database
|
|
24194
|
-
-- If you want to run this migration please uncomment this code before executing
|
|
24195
|
+
-- If you want to run this migration please uncomment this code before executing migrations
|
|
24195
24196
|
/*
|
|
24196
24197
|
${sql}
|
|
24197
24198
|
*/`;
|
|
@@ -24232,7 +24233,7 @@ ${sql}
|
|
|
24232
24233
|
});
|
|
24233
24234
|
|
|
24234
24235
|
// src/sqlgenerator.ts
|
|
24235
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor,
|
|
24236
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, 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;
|
|
24236
24237
|
var init_sqlgenerator = __esm({
|
|
24237
24238
|
"src/sqlgenerator.ts"() {
|
|
24238
24239
|
init_migrate();
|
|
@@ -24434,9 +24435,28 @@ var init_sqlgenerator = __esm({
|
|
|
24434
24435
|
return `ALTER TYPE "${name}" ADD VALUE '${value}';`;
|
|
24435
24436
|
}
|
|
24436
24437
|
};
|
|
24437
|
-
|
|
24438
|
-
can(statement) {
|
|
24439
|
-
return statement.type === "drop_table";
|
|
24438
|
+
PgDropTableConvertor = class extends Convertor {
|
|
24439
|
+
can(statement, dialect6) {
|
|
24440
|
+
return statement.type === "drop_table" && dialect6 === "pg";
|
|
24441
|
+
}
|
|
24442
|
+
convert(statement) {
|
|
24443
|
+
const { tableName, schema: schema4 } = statement;
|
|
24444
|
+
const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
24445
|
+
return `DROP TABLE ${tableNameWithSchema};`;
|
|
24446
|
+
}
|
|
24447
|
+
};
|
|
24448
|
+
MySQLDropTableConvertor = class extends Convertor {
|
|
24449
|
+
can(statement, dialect6) {
|
|
24450
|
+
return statement.type === "drop_table" && dialect6 === "mysql";
|
|
24451
|
+
}
|
|
24452
|
+
convert(statement) {
|
|
24453
|
+
const { tableName } = statement;
|
|
24454
|
+
return `DROP TABLE \`${tableName}\`;`;
|
|
24455
|
+
}
|
|
24456
|
+
};
|
|
24457
|
+
SQLiteDropTableConvertor = class extends Convertor {
|
|
24458
|
+
can(statement, dialect6) {
|
|
24459
|
+
return statement.type === "drop_table" && dialect6 === "sqlite";
|
|
24440
24460
|
}
|
|
24441
24461
|
convert(statement) {
|
|
24442
24462
|
const { tableName } = statement;
|
|
@@ -24479,8 +24499,9 @@ var init_sqlgenerator = __esm({
|
|
|
24479
24499
|
return statement.type === "alter_table_rename_column" && dialect6 === "pg";
|
|
24480
24500
|
}
|
|
24481
24501
|
convert(statement) {
|
|
24482
|
-
const { tableName, oldColumnName, newColumnName } = statement;
|
|
24483
|
-
|
|
24502
|
+
const { tableName, oldColumnName, newColumnName, schema: schema4 } = statement;
|
|
24503
|
+
const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
24504
|
+
return `ALTER TABLE ${tableNameWithSchema} RENAME COLUMN "${oldColumnName}" TO "${newColumnName}";`;
|
|
24484
24505
|
}
|
|
24485
24506
|
};
|
|
24486
24507
|
MySqlAlterTableRenameColumnConvertor = class extends Convertor {
|
|
@@ -24506,8 +24527,9 @@ var init_sqlgenerator = __esm({
|
|
|
24506
24527
|
return statement.type === "alter_table_drop_column" && dialect6 === "pg";
|
|
24507
24528
|
}
|
|
24508
24529
|
convert(statement) {
|
|
24509
|
-
const { tableName, columnName } = statement;
|
|
24510
|
-
|
|
24530
|
+
const { tableName, columnName, schema: schema4 } = statement;
|
|
24531
|
+
const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
24532
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP COLUMN IF EXISTS "${columnName}";`;
|
|
24511
24533
|
}
|
|
24512
24534
|
};
|
|
24513
24535
|
MySqlAlterTableDropColumnConvertor = class extends Convertor {
|
|
@@ -24533,12 +24555,13 @@ var init_sqlgenerator = __esm({
|
|
|
24533
24555
|
return statement.type === "alter_table_add_column" && dialect6 === "pg";
|
|
24534
24556
|
}
|
|
24535
24557
|
convert(statement) {
|
|
24536
|
-
const { tableName, column: column6 } = statement;
|
|
24558
|
+
const { tableName, column: column6, schema: schema4 } = statement;
|
|
24537
24559
|
const { name, type, notNull } = column6;
|
|
24560
|
+
const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
24538
24561
|
const defaultStatement = `${column6.default !== void 0 ? ` DEFAULT ${column6.default}` : ""}`;
|
|
24539
24562
|
const fixedType = isPgNativeType(column6.type) ? column6.type : `"${column6.type}"`;
|
|
24540
24563
|
const notNullStatement = `${notNull ? " NOT NULL" : ""}`;
|
|
24541
|
-
return `ALTER TABLE
|
|
24564
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD COLUMN "${name}" ${fixedType}${defaultStatement}${notNullStatement};`;
|
|
24542
24565
|
}
|
|
24543
24566
|
};
|
|
24544
24567
|
MySqlAlterTableAddColumnConvertor = class extends Convertor {
|
|
@@ -24576,8 +24599,9 @@ var init_sqlgenerator = __esm({
|
|
|
24576
24599
|
return statement.type === "alter_table_alter_column_set_type" && dialect6 === "pg";
|
|
24577
24600
|
}
|
|
24578
24601
|
convert(statement) {
|
|
24579
|
-
const { tableName, columnName, newDataType } = statement;
|
|
24580
|
-
|
|
24602
|
+
const { tableName, columnName, newDataType, schema: schema4 } = statement;
|
|
24603
|
+
const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
24604
|
+
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DATA TYPE ${newDataType};`;
|
|
24581
24605
|
}
|
|
24582
24606
|
};
|
|
24583
24607
|
SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
|
|
@@ -24600,8 +24624,9 @@ var init_sqlgenerator = __esm({
|
|
|
24600
24624
|
return statement.type === "alter_table_alter_column_set_default" && dialect6 === "pg";
|
|
24601
24625
|
}
|
|
24602
24626
|
convert(statement) {
|
|
24603
|
-
const { tableName, columnName } = statement;
|
|
24604
|
-
|
|
24627
|
+
const { tableName, columnName, schema: schema4 } = statement;
|
|
24628
|
+
const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
24629
|
+
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DEFAULT ${statement.newDefaultValue};`;
|
|
24605
24630
|
}
|
|
24606
24631
|
};
|
|
24607
24632
|
SqliteAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
|
|
@@ -24624,8 +24649,9 @@ var init_sqlgenerator = __esm({
|
|
|
24624
24649
|
return statement.type === "alter_table_alter_column_drop_default" && dialect6 === "pg";
|
|
24625
24650
|
}
|
|
24626
24651
|
convert(statement) {
|
|
24627
|
-
const { tableName, columnName } = statement;
|
|
24628
|
-
|
|
24652
|
+
const { tableName, columnName, schema: schema4 } = statement;
|
|
24653
|
+
const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
24654
|
+
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" DROP DEFAULT;`;
|
|
24629
24655
|
}
|
|
24630
24656
|
};
|
|
24631
24657
|
MySqlAlterTableAddPk = class extends Convertor {
|
|
@@ -24736,7 +24762,8 @@ var init_sqlgenerator = __esm({
|
|
|
24736
24762
|
}
|
|
24737
24763
|
convert(statement) {
|
|
24738
24764
|
const { name, columns } = PgSquasher.unsquashPK(statement.data);
|
|
24739
|
-
|
|
24765
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
24766
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.constraintName}" PRIMARY KEY("${columns.join('","')}");`;
|
|
24740
24767
|
}
|
|
24741
24768
|
};
|
|
24742
24769
|
PgAlterTableDeleteCompositePrimaryKeyConvertor = class extends Convertor {
|
|
@@ -24745,7 +24772,8 @@ var init_sqlgenerator = __esm({
|
|
|
24745
24772
|
}
|
|
24746
24773
|
convert(statement) {
|
|
24747
24774
|
const { name, columns } = PgSquasher.unsquashPK(statement.data);
|
|
24748
|
-
|
|
24775
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
24776
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${statement.constraintName}";`;
|
|
24749
24777
|
}
|
|
24750
24778
|
};
|
|
24751
24779
|
PgAlterTableAlterCompositePrimaryKeyConvertor = class extends Convertor {
|
|
@@ -24757,8 +24785,9 @@ var init_sqlgenerator = __esm({
|
|
|
24757
24785
|
const { name: newName, columns: newColumns } = PgSquasher.unsquashPK(
|
|
24758
24786
|
statement.new
|
|
24759
24787
|
);
|
|
24760
|
-
|
|
24761
|
-
|
|
24788
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
24789
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT ${statement.oldConstraintName};
|
|
24790
|
+
${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newConstraintName} PRIMARY KEY(${newColumns.join(",")});`;
|
|
24762
24791
|
}
|
|
24763
24792
|
};
|
|
24764
24793
|
MySqlAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
|
|
@@ -24876,7 +24905,9 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
24876
24905
|
}
|
|
24877
24906
|
convert(statement) {
|
|
24878
24907
|
const { tableName, columnName } = statement;
|
|
24879
|
-
|
|
24908
|
+
console.log(statement);
|
|
24909
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
24910
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD PRIMARY KEY ("${columnName}");`;
|
|
24880
24911
|
}
|
|
24881
24912
|
};
|
|
24882
24913
|
PgAlterTableAlterColumnDropPrimaryKeyConvertor = class extends Convertor {
|
|
@@ -24909,7 +24940,8 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
24909
24940
|
}
|
|
24910
24941
|
convert(statement) {
|
|
24911
24942
|
const { tableName, columnName } = statement;
|
|
24912
|
-
|
|
24943
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
24944
|
+
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET NOT NULL;`;
|
|
24913
24945
|
}
|
|
24914
24946
|
};
|
|
24915
24947
|
SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
|
|
@@ -24933,7 +24965,8 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
24933
24965
|
}
|
|
24934
24966
|
convert(statement) {
|
|
24935
24967
|
const { tableName, columnName } = statement;
|
|
24936
|
-
|
|
24968
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
24969
|
+
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" DROP NOT NULL;`;
|
|
24937
24970
|
}
|
|
24938
24971
|
};
|
|
24939
24972
|
SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
|
@@ -24969,7 +25002,9 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
24969
25002
|
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
|
24970
25003
|
const fromColumnsString = columnsFrom.map((it) => `"${it}"`).join(",");
|
|
24971
25004
|
const toColumnsString = columnsTo.map((it) => `"${it}"`).join(",");
|
|
24972
|
-
const
|
|
25005
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${tableFrom}"` : `"${tableFrom}"`;
|
|
25006
|
+
const tableToNameWithSchema = statement.schema ? `"${statement.schema}"."${tableTo}"` : `"${tableTo}"`;
|
|
25007
|
+
const alterStatement = `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${name}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement}`;
|
|
24973
25008
|
let sql = "DO $$ BEGIN\n";
|
|
24974
25009
|
sql += " " + alterStatement + ";\n";
|
|
24975
25010
|
sql += "EXCEPTION\n";
|
|
@@ -25020,13 +25055,15 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
25020
25055
|
convert(statement) {
|
|
25021
25056
|
const newFk = PgSquasher.unsquashFK(statement.data);
|
|
25022
25057
|
const oldFk = PgSquasher.unsquashFK(statement.oldFkey);
|
|
25023
|
-
|
|
25058
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${oldFk.tableFrom}"` : `"${oldFk.tableFrom}"`;
|
|
25059
|
+
let sql = `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${oldFk.name}";
|
|
25024
25060
|
`;
|
|
25025
25061
|
const onDeleteStatement = newFk.onDelete ? ` ON DELETE ${newFk.onDelete}` : "";
|
|
25026
25062
|
const onUpdateStatement = newFk.onUpdate ? ` ON UPDATE ${newFk.onUpdate}` : "";
|
|
25027
25063
|
const fromColumnsString = newFk.columnsFrom.map((it) => `"${it}"`).join(",");
|
|
25028
25064
|
const toColumnsString = newFk.columnsTo.map((it) => `"${it}"`).join(",");
|
|
25029
|
-
const
|
|
25065
|
+
const tableFromNameWithSchema = statement.schema ? `"${statement.schema}"."${newFk.tableFrom}"` : `"${newFk.tableFrom}"`;
|
|
25066
|
+
const alterStatement = `ALTER TABLE ${tableFromNameWithSchema} ADD CONSTRAINT "${newFk.name}" FOREIGN KEY (${fromColumnsString}) REFERENCES "${newFk.tableTo}"(${toColumnsString})${onDeleteStatement}${onUpdateStatement}`;
|
|
25030
25067
|
sql += "DO $$ BEGIN\n";
|
|
25031
25068
|
sql += " " + alterStatement + ";\n";
|
|
25032
25069
|
sql += "EXCEPTION\n";
|
|
@@ -25056,7 +25093,8 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
25056
25093
|
convert(statement) {
|
|
25057
25094
|
const tableFrom = statement.tableName;
|
|
25058
25095
|
const { name } = PgSquasher.unsquashFK(statement.data);
|
|
25059
|
-
|
|
25096
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${tableFrom}"` : `"${tableFrom}"`;
|
|
25097
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${name}";
|
|
25060
25098
|
`;
|
|
25061
25099
|
}
|
|
25062
25100
|
};
|
|
@@ -25093,7 +25131,8 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
25093
25131
|
const { name, columns, isUnique } = PgSquasher.unsquashIdx(statement.data);
|
|
25094
25132
|
const indexPart = isUnique ? "UNIQUE INDEX" : "INDEX";
|
|
25095
25133
|
const value = columns.map((it) => `"${it}"`).join(",");
|
|
25096
|
-
|
|
25134
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
25135
|
+
return `CREATE ${indexPart} IF NOT EXISTS "${name}" ON ${tableNameWithSchema} (${value});`;
|
|
25097
25136
|
}
|
|
25098
25137
|
};
|
|
25099
25138
|
CreateMySqlIndexConvertor = class extends Convertor {
|
|
@@ -25177,8 +25216,9 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
25177
25216
|
return statement.type === "alter_table_set_new_schema" && dialect6 === "pg";
|
|
25178
25217
|
}
|
|
25179
25218
|
convert(statement) {
|
|
25180
|
-
const { tableName, to } = statement;
|
|
25181
|
-
|
|
25219
|
+
const { tableName, to, from } = statement;
|
|
25220
|
+
const tableNameWithSchema = from ? `"${from}"."${tableName}"` : `"${tableName}"`;
|
|
25221
|
+
return `ALTER TABLE ${tableNameWithSchema} SET SCHEMA "${to}";
|
|
25182
25222
|
`;
|
|
25183
25223
|
}
|
|
25184
25224
|
};
|
|
@@ -25187,8 +25227,9 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
25187
25227
|
return statement.type === "alter_table_remove_from_schema" && dialect6 === "pg";
|
|
25188
25228
|
}
|
|
25189
25229
|
convert(statement) {
|
|
25190
|
-
const { tableName } = statement;
|
|
25191
|
-
|
|
25230
|
+
const { tableName, schema: schema4 } = statement;
|
|
25231
|
+
const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
|
25232
|
+
return `ALTER TABLE ${tableNameWithSchema} SET SCHEMA public;
|
|
25192
25233
|
`;
|
|
25193
25234
|
}
|
|
25194
25235
|
};
|
|
@@ -25272,7 +25313,9 @@ ${BREAKPOINT}ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.new
|
|
|
25272
25313
|
convertors.push(new MySqlCreateTableConvertor());
|
|
25273
25314
|
convertors.push(new SQLiteCreateTableConvertor());
|
|
25274
25315
|
convertors.push(new CreateTypeEnumConvertor());
|
|
25275
|
-
convertors.push(new
|
|
25316
|
+
convertors.push(new PgDropTableConvertor());
|
|
25317
|
+
convertors.push(new MySQLDropTableConvertor());
|
|
25318
|
+
convertors.push(new SQLiteDropTableConvertor());
|
|
25276
25319
|
convertors.push(new PgRenameTableConvertor());
|
|
25277
25320
|
convertors.push(new MySqlRenameTableConvertor());
|
|
25278
25321
|
convertors.push(new SqliteRenameTableConvertor());
|
|
@@ -25660,6 +25703,7 @@ var init_jsonStatements = __esm({
|
|
|
25660
25703
|
tableName,
|
|
25661
25704
|
columnName,
|
|
25662
25705
|
newDefaultValue: column6.default.new,
|
|
25706
|
+
oldDefaultValue: column6.default.old,
|
|
25663
25707
|
schema: schema4,
|
|
25664
25708
|
columnOnUpdate,
|
|
25665
25709
|
columnNotNull,
|
|
@@ -25733,6 +25777,7 @@ var init_jsonStatements = __esm({
|
|
|
25733
25777
|
setPkStatements.push({
|
|
25734
25778
|
type: "alter_table_alter_column_set_pk",
|
|
25735
25779
|
tableName,
|
|
25780
|
+
schema: schema4,
|
|
25736
25781
|
columnName
|
|
25737
25782
|
});
|
|
25738
25783
|
}
|
|
@@ -25799,15 +25844,21 @@ var init_jsonStatements = __esm({
|
|
|
25799
25844
|
});
|
|
25800
25845
|
};
|
|
25801
25846
|
prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
|
|
25802
|
-
|
|
25803
|
-
|
|
25804
|
-
|
|
25805
|
-
|
|
25806
|
-
|
|
25807
|
-
|
|
25808
|
-
|
|
25809
|
-
|
|
25810
|
-
|
|
25847
|
+
const keys = Object.keys(foreignKeys);
|
|
25848
|
+
const stmts = [];
|
|
25849
|
+
if (keys.length > 0) {
|
|
25850
|
+
stmts.push(
|
|
25851
|
+
...prepareDropReferencesJson(tableName, schema4, {
|
|
25852
|
+
[keys[0]]: foreignKeys[keys[0]].__old
|
|
25853
|
+
})
|
|
25854
|
+
);
|
|
25855
|
+
stmts.push(
|
|
25856
|
+
...prepareCreateReferencesJson(tableName, schema4, {
|
|
25857
|
+
[keys[0]]: foreignKeys[keys[0]].__new
|
|
25858
|
+
})
|
|
25859
|
+
);
|
|
25860
|
+
}
|
|
25861
|
+
return stmts;
|
|
25811
25862
|
};
|
|
25812
25863
|
prepareDropIndexesJson = (tableName, schema4, indexes) => {
|
|
25813
25864
|
return Object.values(indexes).map((indexData) => {
|
|
@@ -25847,33 +25898,36 @@ var init_jsonStatements = __esm({
|
|
|
25847
25898
|
};
|
|
25848
25899
|
});
|
|
25849
25900
|
};
|
|
25850
|
-
prepareAddCompositePrimaryKeyPg = (tableName, pks, json2) => {
|
|
25901
|
+
prepareAddCompositePrimaryKeyPg = (tableName, schema4, pks, json2) => {
|
|
25851
25902
|
return Object.values(pks).map((it) => {
|
|
25852
25903
|
return {
|
|
25853
25904
|
type: "create_composite_pk",
|
|
25854
25905
|
tableName,
|
|
25855
25906
|
data: it,
|
|
25907
|
+
schema: schema4,
|
|
25856
25908
|
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${PgSquasher.unsquashPK(it).columns.join("_")}`].name
|
|
25857
25909
|
};
|
|
25858
25910
|
});
|
|
25859
25911
|
};
|
|
25860
|
-
prepareDeleteCompositePrimaryKeyPg = (tableName, pks, json1) => {
|
|
25912
|
+
prepareDeleteCompositePrimaryKeyPg = (tableName, schema4, pks, json1) => {
|
|
25861
25913
|
return Object.values(pks).map((it) => {
|
|
25862
25914
|
return {
|
|
25863
25915
|
type: "delete_composite_pk",
|
|
25864
25916
|
tableName,
|
|
25865
25917
|
data: it,
|
|
25918
|
+
schema: schema4,
|
|
25866
25919
|
constraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${PgSquasher.unsquashPK(it).columns.join("_")}`].name
|
|
25867
25920
|
};
|
|
25868
25921
|
});
|
|
25869
25922
|
};
|
|
25870
|
-
prepareAlterCompositePrimaryKeyPg = (tableName, pks, json1, json2) => {
|
|
25923
|
+
prepareAlterCompositePrimaryKeyPg = (tableName, schema4, pks, json1, json2) => {
|
|
25871
25924
|
return Object.values(pks).map((it) => {
|
|
25872
25925
|
return {
|
|
25873
25926
|
type: "alter_composite_pk",
|
|
25874
25927
|
tableName,
|
|
25875
25928
|
old: it.__old,
|
|
25876
25929
|
new: it.__new,
|
|
25930
|
+
schema: schema4,
|
|
25877
25931
|
oldConstraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${PgSquasher.unsquashPK(it.__old).columns.join("_")}`].name,
|
|
25878
25932
|
newConstraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${PgSquasher.unsquashPK(it.__new).columns.join("_")}`].name
|
|
25879
25933
|
};
|
|
@@ -26158,6 +26212,7 @@ var init_snapshotsDiffer = __esm({
|
|
|
26158
26212
|
const jsonRemoveTableFromSchemas = [];
|
|
26159
26213
|
const jsonSetNewTableSchemas = [];
|
|
26160
26214
|
allAlteredResolved.forEach((it) => {
|
|
26215
|
+
const schemaUnwrapped = valueFromSelfOrPatchedNew(it.schema);
|
|
26161
26216
|
let addedCompositePKs;
|
|
26162
26217
|
let deletedCompositePKs;
|
|
26163
26218
|
let alteredCompositePKs;
|
|
@@ -26177,16 +26232,19 @@ var init_snapshotsDiffer = __esm({
|
|
|
26177
26232
|
} else if (dialect6 === "pg") {
|
|
26178
26233
|
addedCompositePKs = prepareAddCompositePrimaryKeyPg(
|
|
26179
26234
|
it.name,
|
|
26235
|
+
schemaUnwrapped,
|
|
26180
26236
|
it.addedCompositePKs,
|
|
26181
26237
|
curFull
|
|
26182
26238
|
);
|
|
26183
26239
|
deletedCompositePKs = prepareDeleteCompositePrimaryKeyPg(
|
|
26184
26240
|
it.name,
|
|
26241
|
+
schemaUnwrapped,
|
|
26185
26242
|
it.deletedCompositePKs,
|
|
26186
26243
|
prevFull
|
|
26187
26244
|
);
|
|
26188
26245
|
alteredCompositePKs = prepareAlterCompositePrimaryKeyPg(
|
|
26189
26246
|
it.name,
|
|
26247
|
+
schemaUnwrapped,
|
|
26190
26248
|
it.alteredCompositePKs,
|
|
26191
26249
|
prevFull,
|
|
26192
26250
|
curFull
|
|
@@ -26295,8 +26353,12 @@ var init_snapshotsDiffer = __esm({
|
|
|
26295
26353
|
},
|
|
26296
26354
|
{}
|
|
26297
26355
|
);
|
|
26298
|
-
jsonCreateIndexesForAllAlteredTables.push(
|
|
26299
|
-
|
|
26356
|
+
jsonCreateIndexesForAllAlteredTables.push(
|
|
26357
|
+
...prepareCreateIndexesJson(it.name, schema4, createdIndexes || {})
|
|
26358
|
+
);
|
|
26359
|
+
jsonDropIndexesForAllAlteredTables.push(
|
|
26360
|
+
...prepareDropIndexesJson(it.name, schema4, droppedIndexes || {})
|
|
26361
|
+
);
|
|
26300
26362
|
});
|
|
26301
26363
|
const jsonCreateReferencesForCreatedTables = created.map((it) => {
|
|
26302
26364
|
return prepareCreateReferencesJson(it.name, it.schema, it.foreignKeys);
|
|
@@ -26317,7 +26379,12 @@ var init_snapshotsDiffer = __esm({
|
|
|
26317
26379
|
return [...forAdded, ...forAltered, ...alteredFKs];
|
|
26318
26380
|
}).flat();
|
|
26319
26381
|
const jsonCreateReferences = jsonCreateReferencesForCreatedTables;
|
|
26320
|
-
const
|
|
26382
|
+
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
|
26383
|
+
(t) => t.type === "create_reference"
|
|
26384
|
+
);
|
|
26385
|
+
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
|
26386
|
+
(t) => t.type === "delete_reference"
|
|
26387
|
+
);
|
|
26321
26388
|
const createEnums = (_b = (_a = typedResult.addedEnums) == null ? void 0 : _a.map((it) => {
|
|
26322
26389
|
return prepareCreateEnumJson(it.name, it.values);
|
|
26323
26390
|
})) != null ? _b : [];
|
|
@@ -26365,15 +26432,16 @@ var init_snapshotsDiffer = __esm({
|
|
|
26365
26432
|
jsonStatements.push(...jsonRenameTables);
|
|
26366
26433
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
|
26367
26434
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
|
26435
|
+
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
|
26368
26436
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
|
26369
26437
|
jsonStatements.push(...jsonTableAlternations.alterColumns);
|
|
26370
26438
|
jsonStatements.push(...jsonTableAlternations.createColumns);
|
|
26371
|
-
jsonStatements.push(...
|
|
26439
|
+
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
|
26440
|
+
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
|
26441
|
+
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
|
26372
26442
|
jsonStatements.push(...jsonTableAlternations.dropColumns);
|
|
26373
26443
|
if (dialect6 !== "sqlite")
|
|
26374
26444
|
jsonStatements.push(...jsonCreateReferences);
|
|
26375
|
-
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
|
26376
|
-
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
|
26377
26445
|
jsonStatements.push(...jsonAddedCompositePKs);
|
|
26378
26446
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
|
26379
26447
|
jsonStatements.push(...jsonSetTableSchemas);
|
|
@@ -44143,7 +44211,10 @@ import { sql } from "drizzle-orm"
|
|
|
44143
44211
|
return defaultValue;
|
|
44144
44212
|
};
|
|
44145
44213
|
column4 = (type, name, defaultValue, autoincrement, onUpdate) => {
|
|
44146
|
-
|
|
44214
|
+
let lowered = type;
|
|
44215
|
+
if (!type.startsWith("enum(")) {
|
|
44216
|
+
lowered = type.toLowerCase();
|
|
44217
|
+
}
|
|
44147
44218
|
if (lowered === "serial") {
|
|
44148
44219
|
return `${name.camelCase()}: serial("${name}")`;
|
|
44149
44220
|
}
|
|
@@ -44226,7 +44297,7 @@ import { sql } from "drizzle-orm"
|
|
|
44226
44297
|
}
|
|
44227
44298
|
if (lowered === "date") {
|
|
44228
44299
|
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
|
44229
|
-
${name}: date("${name}", { mode: 'string' })`;
|
|
44300
|
+
${name.camelCase()}: date("${name}", { mode: 'string' })`;
|
|
44230
44301
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
44231
44302
|
out += defaultValue;
|
|
44232
44303
|
return out;
|
|
@@ -44343,7 +44414,13 @@ import { sql } from "drizzle-orm"
|
|
|
44343
44414
|
}, {});
|
|
44344
44415
|
columns.forEach((it) => {
|
|
44345
44416
|
statement += " ";
|
|
44346
|
-
statement += column4(
|
|
44417
|
+
statement += column4(
|
|
44418
|
+
it.type,
|
|
44419
|
+
it.name,
|
|
44420
|
+
it.default,
|
|
44421
|
+
it.autoincrement,
|
|
44422
|
+
it.onUpdate
|
|
44423
|
+
);
|
|
44347
44424
|
statement += it.primaryKey ? ".primaryKey()" : "";
|
|
44348
44425
|
statement += it.notNull ? ".notNull()" : "";
|
|
44349
44426
|
const fks2 = fkByColumnName[it.name];
|
|
@@ -45458,10 +45535,10 @@ __export(mysqlIntrospect_exports, {
|
|
|
45458
45535
|
mysqlIntrospect: () => mysqlIntrospect,
|
|
45459
45536
|
mysqlPushIntrospect: () => mysqlPushIntrospect
|
|
45460
45537
|
});
|
|
45461
|
-
var
|
|
45538
|
+
var import_hanji5, import_promise, connectToMySQL, mysqlIntrospect, mysqlPushIntrospect;
|
|
45462
45539
|
var init_mysqlIntrospect = __esm({
|
|
45463
45540
|
"src/cli/commands/mysqlIntrospect.ts"() {
|
|
45464
|
-
|
|
45541
|
+
import_hanji5 = __toESM(require_hanji());
|
|
45465
45542
|
init_views();
|
|
45466
45543
|
import_promise = __toESM(require_promise2());
|
|
45467
45544
|
init_mysqlSerializer();
|
|
@@ -45491,7 +45568,7 @@ var init_mysqlIntrospect = __esm({
|
|
|
45491
45568
|
mysqlIntrospect = async (config) => {
|
|
45492
45569
|
const { client, databaseName } = await connectToMySQL(config);
|
|
45493
45570
|
const progress = new IntrospectProgress();
|
|
45494
|
-
const res = await (0,
|
|
45571
|
+
const res = await (0, import_hanji5.renderWithTask)(
|
|
45495
45572
|
progress,
|
|
45496
45573
|
fromDatabase(
|
|
45497
45574
|
client,
|
|
@@ -50273,7 +50350,7 @@ var init_introspect = __esm({
|
|
|
50273
50350
|
return out;
|
|
50274
50351
|
}
|
|
50275
50352
|
if (lowered === "date") {
|
|
50276
|
-
let out = `${name}: date("${name}")`;
|
|
50353
|
+
let out = `${name.camelCase()}: date("${name}")`;
|
|
50277
50354
|
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
|
|
50278
50355
|
out += defaultValue;
|
|
50279
50356
|
return out;
|
|
@@ -50461,10 +50538,10 @@ __export(pgIntrospect_exports, {
|
|
|
50461
50538
|
PgConfig2: () => PgConfig2,
|
|
50462
50539
|
pgIntrospect: () => pgIntrospect
|
|
50463
50540
|
});
|
|
50464
|
-
var
|
|
50541
|
+
var import_hanji6, import_pg, PgConfig1, PgConfig2, Conf, pgIntrospect;
|
|
50465
50542
|
var init_pgIntrospect = __esm({
|
|
50466
50543
|
"src/cli/commands/pgIntrospect.ts"() {
|
|
50467
|
-
|
|
50544
|
+
import_hanji6 = __toESM(require_hanji());
|
|
50468
50545
|
init_lib();
|
|
50469
50546
|
init_views();
|
|
50470
50547
|
import_pg = __toESM(require_lib4());
|
|
@@ -50477,16 +50554,18 @@ var init_pgIntrospect = __esm({
|
|
|
50477
50554
|
user: stringType().default("postgres"),
|
|
50478
50555
|
password: stringType().optional(),
|
|
50479
50556
|
database: stringType(),
|
|
50480
|
-
ssl: coerce.boolean().optional()
|
|
50557
|
+
ssl: coerce.boolean().optional(),
|
|
50558
|
+
out: stringType().optional().default("./drizzle")
|
|
50481
50559
|
}).strict();
|
|
50482
50560
|
PgConfig2 = objectType({
|
|
50483
|
-
connectionString: stringType()
|
|
50561
|
+
connectionString: stringType(),
|
|
50562
|
+
out: stringType().optional().default("./drizzle")
|
|
50484
50563
|
}).strict();
|
|
50485
50564
|
Conf = unionType([PgConfig1, PgConfig2]);
|
|
50486
50565
|
pgIntrospect = async (config) => {
|
|
50487
50566
|
const pool = new import_pg.Pool(config);
|
|
50488
50567
|
const progress = new IntrospectProgress();
|
|
50489
|
-
const res = await (0,
|
|
50568
|
+
const res = await (0, import_hanji6.renderWithTask)(
|
|
50490
50569
|
progress,
|
|
50491
50570
|
fromDatabase2(pool, (stage, count, status) => {
|
|
50492
50571
|
progress.update(stage, count, status);
|
|
@@ -50565,7 +50644,7 @@ var checkHandler = (out, dialect6) => {
|
|
|
50565
50644
|
};
|
|
50566
50645
|
|
|
50567
50646
|
// src/cli/index.ts
|
|
50568
|
-
var
|
|
50647
|
+
var import_hanji7 = __toESM(require_hanji());
|
|
50569
50648
|
var import_path7 = __toESM(require("path"));
|
|
50570
50649
|
|
|
50571
50650
|
// src/cli/utils.ts
|
|
@@ -50613,7 +50692,7 @@ init_source();
|
|
|
50613
50692
|
// package.json
|
|
50614
50693
|
var package_default = {
|
|
50615
50694
|
name: "drizzle-kit",
|
|
50616
|
-
version: "0.18.
|
|
50695
|
+
version: "0.18.1",
|
|
50617
50696
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
50618
50697
|
author: "Drizzle Team",
|
|
50619
50698
|
license: "MIT",
|
|
@@ -50624,11 +50703,11 @@ var package_default = {
|
|
|
50624
50703
|
"migrate:old": "drizzle-kit generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
50625
50704
|
push: "node -r esbuild-register ./src/cli/index.ts push:mysql",
|
|
50626
50705
|
"migrate:old:mysql": "drizzle-kit generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
50627
|
-
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg
|
|
50706
|
+
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg",
|
|
50628
50707
|
"start:sqlite": "node -r esbuild-register ./src/cli/index.ts generate:sqlite --out ./dev/migrations-sqlite --schema ./dev/migrations-sqlite/schema.ts",
|
|
50629
50708
|
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql",
|
|
50630
50709
|
"check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
|
|
50631
|
-
"introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql",
|
|
50710
|
+
"introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql --config drizzle.config2.ts",
|
|
50632
50711
|
"introspect:pg": "node -r esbuild-register ./src/cli/index.ts introspect:pg --out ./dev/introspect-pg --connectionString=postgresql://postgres@localhost:5432/introspect",
|
|
50633
50712
|
drop: "node -r esbuild-register ./src/cli/index.ts drop --out ./dev/migrations-pg",
|
|
50634
50713
|
"up:pg": "node -r esbuild-register ./src/cli/index.ts up:pg --out ./dev/migrations-pg",
|
|
@@ -50792,10 +50871,11 @@ var import_path6 = require("path");
|
|
|
50792
50871
|
init_source();
|
|
50793
50872
|
var import_fs10 = require("fs");
|
|
50794
50873
|
init_views();
|
|
50874
|
+
var import_hanji4 = __toESM(require_hanji());
|
|
50795
50875
|
var prepareGenerateConfig = (options) => {
|
|
50796
50876
|
var _a;
|
|
50797
50877
|
const { schema: schema4, out, config, breakpoints, custom } = options;
|
|
50798
|
-
if (!(schema4
|
|
50878
|
+
if (!(schema4 && out)) {
|
|
50799
50879
|
const drizzleConfig = drizzleConfigFromFile(config);
|
|
50800
50880
|
if (!drizzleConfig.out) {
|
|
50801
50881
|
console.log("You must specify 'out' param in config file");
|
|
@@ -50812,6 +50892,11 @@ var prepareGenerateConfig = (options) => {
|
|
|
50812
50892
|
console.error(`'schema' param must be set`);
|
|
50813
50893
|
process.exit(1);
|
|
50814
50894
|
}
|
|
50895
|
+
const fileNames = prepareFilenames(schema4);
|
|
50896
|
+
if (fileNames.length === 0) {
|
|
50897
|
+
(0, import_hanji4.render)(`[${source_default.blue("i")}] No schema file in ${schema4} was found`);
|
|
50898
|
+
process.exit(0);
|
|
50899
|
+
}
|
|
50815
50900
|
if (!out) {
|
|
50816
50901
|
console.error(`'out' param must be set`);
|
|
50817
50902
|
process.exit(1);
|
|
@@ -50838,6 +50923,10 @@ var configCommonSchema = objectType({
|
|
|
50838
50923
|
breakpoints: booleanType().optional(),
|
|
50839
50924
|
tablesFilter: unionType([stringType(), stringType().array()]).optional()
|
|
50840
50925
|
});
|
|
50926
|
+
var configIntrospectSchema = objectType({
|
|
50927
|
+
out: stringType().optional().default("./drizzle"),
|
|
50928
|
+
breakpoints: booleanType().optional()
|
|
50929
|
+
});
|
|
50841
50930
|
var mysqlConnectionSchema = unionType([
|
|
50842
50931
|
objectType({
|
|
50843
50932
|
host: stringType(),
|
|
@@ -50855,6 +50944,10 @@ var mySqlCliConfigSchema = intersectionType(
|
|
|
50855
50944
|
configCommonSchema,
|
|
50856
50945
|
mysqlConnectionSchema
|
|
50857
50946
|
);
|
|
50947
|
+
var mySqlIntrospectConfigSchema = intersectionType(
|
|
50948
|
+
configIntrospectSchema,
|
|
50949
|
+
mysqlConnectionSchema
|
|
50950
|
+
);
|
|
50858
50951
|
var drizzleConfigFromFile = (configPath) => {
|
|
50859
50952
|
var _a;
|
|
50860
50953
|
const defaultTsConfigExists = (0, import_fs10.existsSync)((0, import_path6.join)((0, import_path6.resolve)("drizzle.config.ts")));
|
|
@@ -50888,9 +50981,53 @@ var drizzleConfigFromFile = (configPath) => {
|
|
|
50888
50981
|
}
|
|
50889
50982
|
return res.data;
|
|
50890
50983
|
};
|
|
50984
|
+
var readDrizzleConfig = (configPath) => {
|
|
50985
|
+
var _a;
|
|
50986
|
+
const defaultTsConfigExists = (0, import_fs10.existsSync)((0, import_path6.join)((0, import_path6.resolve)("drizzle.config.ts")));
|
|
50987
|
+
const defaultJsConfigExists = (0, import_fs10.existsSync)((0, import_path6.join)((0, import_path6.resolve)("drizzle.config.js")));
|
|
50988
|
+
const defaultJsonConfigExists = (0, import_fs10.existsSync)(
|
|
50989
|
+
(0, import_path6.join)((0, import_path6.resolve)("drizzle.config.json"))
|
|
50990
|
+
);
|
|
50991
|
+
const defaultConfigPath = defaultTsConfigExists ? "drizzle.config.ts" : defaultJsConfigExists ? "drizzle.config.js" : "drizzle.config.json";
|
|
50992
|
+
if (!configPath) {
|
|
50993
|
+
console.log(
|
|
50994
|
+
source_default.gray(
|
|
50995
|
+
`No config path provided, using default '${defaultConfigPath}'`
|
|
50996
|
+
)
|
|
50997
|
+
);
|
|
50998
|
+
}
|
|
50999
|
+
const path3 = (0, import_path6.join)((0, import_path6.resolve)(configPath != null ? configPath : defaultConfigPath));
|
|
51000
|
+
if (!(0, import_fs10.existsSync)(path3)) {
|
|
51001
|
+
console.log(source_default.red(`${path3} file does not exist`));
|
|
51002
|
+
process.exit(1);
|
|
51003
|
+
}
|
|
51004
|
+
console.log(source_default.grey(`Reading config file '${path3}'`));
|
|
51005
|
+
const { unregister } = safeRegister();
|
|
51006
|
+
const required = require(path3);
|
|
51007
|
+
const content = (_a = required.default) != null ? _a : required;
|
|
51008
|
+
unregister();
|
|
51009
|
+
return content;
|
|
51010
|
+
};
|
|
50891
51011
|
|
|
50892
51012
|
// src/cli/commands/pushUtils.ts
|
|
50893
51013
|
init_source();
|
|
51014
|
+
var filterStatements = (statements) => {
|
|
51015
|
+
return statements.filter((statement) => {
|
|
51016
|
+
if (statement.type === "alter_table_alter_column_set_type") {
|
|
51017
|
+
if (statement.oldDataType.startsWith("tinyint") && statement.newDataType.startsWith("boolean")) {
|
|
51018
|
+
return false;
|
|
51019
|
+
}
|
|
51020
|
+
} else if (statement.type === "alter_table_alter_column_set_default") {
|
|
51021
|
+
if (statement.newDefaultValue === false && statement.oldDefaultValue === 0 && statement.newDataType === "boolean") {
|
|
51022
|
+
return false;
|
|
51023
|
+
}
|
|
51024
|
+
if (statement.newDefaultValue === true && statement.oldDefaultValue === 1 && statement.newDataType === "boolean") {
|
|
51025
|
+
return false;
|
|
51026
|
+
}
|
|
51027
|
+
}
|
|
51028
|
+
return true;
|
|
51029
|
+
});
|
|
51030
|
+
};
|
|
50894
51031
|
var logSuggestionsAndReturn = async ({
|
|
50895
51032
|
connection,
|
|
50896
51033
|
statements
|
|
@@ -50955,9 +51092,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
50955
51092
|
statement.columnName
|
|
50956
51093
|
)} column type from ${source_default.underline(
|
|
50957
51094
|
statement.type
|
|
50958
|
-
)} to ${source_default.underline(
|
|
50959
|
-
statement.newDataType
|
|
50960
|
-
)} with ${count} items`
|
|
51095
|
+
)} to ${source_default.underline(statement.newDataType)} with ${count} items`
|
|
50961
51096
|
);
|
|
50962
51097
|
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
|
50963
51098
|
tablesToTruncate.push(statement.tableName);
|
|
@@ -51056,7 +51191,7 @@ drizzle-orm: v${npmVersion}` : "";
|
|
|
51056
51191
|
};
|
|
51057
51192
|
var optionsSchema = objectType({
|
|
51058
51193
|
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
51059
|
-
out: stringType().optional(),
|
|
51194
|
+
out: stringType().optional().default("./drizzle"),
|
|
51060
51195
|
config: stringType().optional(),
|
|
51061
51196
|
breakpoints: booleanType().optional().default(false),
|
|
51062
51197
|
custom: booleanType().optional().default(false)
|
|
@@ -51085,12 +51220,12 @@ var generateMysqlCommand = new Command("generate:mysql").option("--schema <schem
|
|
|
51085
51220
|
const { prepareAndMigrateMySql: prepareAndMigrateMySql2 } = (init_migrate(), __toCommonJS(migrate_exports));
|
|
51086
51221
|
await prepareAndMigrateMySql2(result);
|
|
51087
51222
|
});
|
|
51088
|
-
var Select = class extends
|
|
51223
|
+
var Select = class extends import_hanji7.Prompt {
|
|
51089
51224
|
constructor(items) {
|
|
51090
51225
|
super();
|
|
51091
51226
|
this.on("attach", (terminal) => terminal.toggleCursor("hide"));
|
|
51092
51227
|
this.on("detach", () => clearInterval(this.timeout));
|
|
51093
|
-
this.data = new
|
|
51228
|
+
this.data = new import_hanji7.SelectState(
|
|
51094
51229
|
items.map((it) => ({ label: it, value: `${it}-value` }))
|
|
51095
51230
|
);
|
|
51096
51231
|
this.data.bind(this);
|
|
@@ -51123,7 +51258,9 @@ var dbPushMysqlCommand = new Command("push:mysql").option(
|
|
|
51123
51258
|
const drizzleConfig = drizzleConfigFromFile(options.config);
|
|
51124
51259
|
const fileNames = prepareFilenames(drizzleConfig.schema);
|
|
51125
51260
|
if (fileNames.length === 0) {
|
|
51126
|
-
(0,
|
|
51261
|
+
(0, import_hanji7.render)(
|
|
51262
|
+
`[${source_default.blue("i")}] No schema file in ${drizzleConfig.schema} was found`
|
|
51263
|
+
);
|
|
51127
51264
|
process.exit(0);
|
|
51128
51265
|
}
|
|
51129
51266
|
const connection = await connectToMySQL2(drizzleConfig);
|
|
@@ -51138,8 +51275,9 @@ var dbPushMysqlCommand = new Command("push:mysql").option(
|
|
|
51138
51275
|
try {
|
|
51139
51276
|
if (typeof statements === "undefined") {
|
|
51140
51277
|
} else if (statements.sqlStatements.length === 0) {
|
|
51141
|
-
(0,
|
|
51278
|
+
(0, import_hanji7.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
51142
51279
|
} else {
|
|
51280
|
+
const filteredStatements = filterStatements(statements.statements);
|
|
51143
51281
|
const {
|
|
51144
51282
|
shouldAskForApprove,
|
|
51145
51283
|
statementsToExecute,
|
|
@@ -51149,7 +51287,7 @@ var dbPushMysqlCommand = new Command("push:mysql").option(
|
|
|
51149
51287
|
schemasToRemove
|
|
51150
51288
|
} = await logSuggestionsAndReturn({
|
|
51151
51289
|
connection: connection.client,
|
|
51152
|
-
statements:
|
|
51290
|
+
statements: filteredStatements
|
|
51153
51291
|
});
|
|
51154
51292
|
if (shouldAskForApprove) {
|
|
51155
51293
|
console.log("\n");
|
|
@@ -51159,14 +51297,14 @@ var dbPushMysqlCommand = new Command("push:mysql").option(
|
|
|
51159
51297
|
)
|
|
51160
51298
|
);
|
|
51161
51299
|
console.log(source_default.white("Do you still want to push changes?"));
|
|
51162
|
-
const { status, data } = await (0,
|
|
51300
|
+
const { status, data } = await (0, import_hanji7.render)(
|
|
51163
51301
|
new Select([
|
|
51164
51302
|
"No, abort",
|
|
51165
51303
|
`Yes, I want to${tablesToRemove.length > 0 ? ` remove ${tablesToRemove.length} ${tablesToRemove.length > 1 ? "tables" : "table"},` : " "}${columnsToRemove.length > 0 ? ` remove ${columnsToRemove.length} ${columnsToRemove.length > 1 ? "columns" : "column"},` : " "}${tablesToTruncate.length > 0 ? ` truncate ${tablesToTruncate.length} ${tablesToTruncate.length > 1 ? "tables" : "table"}` : ""}`.replace(/(^,)|(,$)/g, "").replace(/ +(?= )/g, "")
|
|
51166
51304
|
])
|
|
51167
51305
|
);
|
|
51168
51306
|
if ((data == null ? void 0 : data.index) === 0) {
|
|
51169
|
-
(0,
|
|
51307
|
+
(0, import_hanji7.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
51170
51308
|
process.exit(0);
|
|
51171
51309
|
}
|
|
51172
51310
|
}
|
|
@@ -51176,7 +51314,11 @@ var dbPushMysqlCommand = new Command("push:mysql").option(
|
|
|
51176
51314
|
for (const statement of statements.sqlStatements) {
|
|
51177
51315
|
await connection.client.query(statement);
|
|
51178
51316
|
}
|
|
51179
|
-
|
|
51317
|
+
if (filteredStatements.length > 0) {
|
|
51318
|
+
(0, import_hanji7.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
51319
|
+
} else {
|
|
51320
|
+
(0, import_hanji7.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
51321
|
+
}
|
|
51180
51322
|
}
|
|
51181
51323
|
} catch (e) {
|
|
51182
51324
|
console.log(e);
|
|
@@ -51236,7 +51378,7 @@ var upMysqlCommand = new Command("up:mysql").option("--out <out>", `Output folde
|
|
|
51236
51378
|
upgradeFolders("mysql", out);
|
|
51237
51379
|
upMysqlHandler(out);
|
|
51238
51380
|
});
|
|
51239
|
-
var upSqliteCommand = new Command("up:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.
|
|
51381
|
+
var upSqliteCommand = new Command("up:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.ts]`).action((options) => {
|
|
51240
51382
|
printVersions();
|
|
51241
51383
|
assertOrmCoreVersion();
|
|
51242
51384
|
const params = checkSchema.parse(options);
|
|
@@ -51249,18 +51391,21 @@ var pt1 = objectType({
|
|
|
51249
51391
|
out: stringType(),
|
|
51250
51392
|
breakpoints: booleanType().optional().default(false)
|
|
51251
51393
|
});
|
|
51252
|
-
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) => {
|
|
51394
|
+
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").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
|
|
51253
51395
|
printVersions();
|
|
51254
51396
|
assertPackages("drizzle-orm");
|
|
51255
51397
|
assertOrmCoreVersion();
|
|
51256
51398
|
const { pgIntrospect: pgIntrospect2, PgConfig2: PgConfig22, PgConfig1: PgConfig12 } = (init_pgIntrospect(), __toCommonJS(pgIntrospect_exports));
|
|
51399
|
+
const drizzleConfig = readDrizzleConfig(options.config);
|
|
51257
51400
|
const pgIntrospectConfig = unionType([
|
|
51258
51401
|
pt1.extend(PgConfig22.shape),
|
|
51259
51402
|
pt1.extend(PgConfig12.shape)
|
|
51260
51403
|
]);
|
|
51261
|
-
const res = pgIntrospectConfig.safeParse(
|
|
51404
|
+
const res = pgIntrospectConfig.safeParse(drizzleConfig);
|
|
51262
51405
|
if (!res.success) {
|
|
51263
|
-
|
|
51406
|
+
for (const issue of res.error.issues) {
|
|
51407
|
+
console.log(issue.message);
|
|
51408
|
+
}
|
|
51264
51409
|
return;
|
|
51265
51410
|
}
|
|
51266
51411
|
const { snapshots, journal } = prepareOutFolder2(res.data.out, "pg");
|
|
@@ -51286,38 +51431,41 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
|
|
|
51286
51431
|
"introspect"
|
|
51287
51432
|
);
|
|
51288
51433
|
} else {
|
|
51289
|
-
(0,
|
|
51434
|
+
(0, import_hanji7.render)(
|
|
51290
51435
|
`[${source_default.blue(
|
|
51291
51436
|
"i"
|
|
51292
51437
|
)}] No SQL generated, you already have migrations in project`
|
|
51293
51438
|
);
|
|
51294
51439
|
}
|
|
51295
|
-
(0,
|
|
51440
|
+
(0, import_hanji7.render)(
|
|
51296
51441
|
`[${source_default.green(
|
|
51297
51442
|
"\u2713"
|
|
51298
51443
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|
|
51299
51444
|
schemaFile
|
|
51300
51445
|
)} \u{1F680}`
|
|
51301
51446
|
);
|
|
51302
|
-
process.exit(
|
|
51447
|
+
process.exit(0);
|
|
51303
51448
|
});
|
|
51304
51449
|
var introspectMySqlCommand = new Command("introspect:mysql").option(
|
|
51305
51450
|
"--config <config>",
|
|
51306
51451
|
"Path to a config.json file, drizzle.config.json by default"
|
|
51307
|
-
).action(async (options) => {
|
|
51452
|
+
).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) => {
|
|
51308
51453
|
var _a;
|
|
51309
51454
|
printVersions();
|
|
51310
51455
|
assertPackages("drizzle-orm");
|
|
51311
51456
|
assertOrmCoreVersion();
|
|
51312
51457
|
const { mysqlIntrospect: mysqlIntrospect2 } = (init_mysqlIntrospect(), __toCommonJS(mysqlIntrospect_exports));
|
|
51313
|
-
const drizzleConfig =
|
|
51314
|
-
|
|
51315
|
-
|
|
51458
|
+
const drizzleConfig = readDrizzleConfig(options.config);
|
|
51459
|
+
const res = mySqlIntrospectConfigSchema.safeParse(drizzleConfig);
|
|
51460
|
+
if (!res.success) {
|
|
51461
|
+
for (const issue of res.error.issues) {
|
|
51462
|
+
console.log(issue.message);
|
|
51463
|
+
}
|
|
51316
51464
|
process.exit(1);
|
|
51317
51465
|
}
|
|
51318
|
-
const out =
|
|
51466
|
+
const out = res.data.out;
|
|
51319
51467
|
const { snapshots, journal } = prepareOutFolder2(out, "mysql");
|
|
51320
|
-
const { schema: schema4, ts } = await mysqlIntrospect2(
|
|
51468
|
+
const { schema: schema4, ts } = await mysqlIntrospect2(res.data);
|
|
51321
51469
|
const schemaFile = import_path7.default.join(out, "schema.ts");
|
|
51322
51470
|
(0, import_fs11.writeFileSync)(schemaFile, ts);
|
|
51323
51471
|
console.log();
|
|
@@ -51335,17 +51483,17 @@ var introspectMySqlCommand = new Command("introspect:mysql").option(
|
|
|
51335
51483
|
journal,
|
|
51336
51484
|
_meta,
|
|
51337
51485
|
out,
|
|
51338
|
-
(_a =
|
|
51486
|
+
(_a = res.data.breakpoints) != null ? _a : false,
|
|
51339
51487
|
"introspect"
|
|
51340
51488
|
);
|
|
51341
51489
|
} else {
|
|
51342
|
-
(0,
|
|
51490
|
+
(0, import_hanji7.render)(
|
|
51343
51491
|
`[${source_default.blue(
|
|
51344
51492
|
"i"
|
|
51345
51493
|
)}] No SQL generated, you already have migrations in project`
|
|
51346
51494
|
);
|
|
51347
51495
|
}
|
|
51348
|
-
(0,
|
|
51496
|
+
(0, import_hanji7.render)(
|
|
51349
51497
|
`[${source_default.green(
|
|
51350
51498
|
"\u2713"
|
|
51351
51499
|
)}] You schema file is ready \u279C ${source_default.bold.underline.blue(
|