drizzle-kit 0.17.0-6323eb6 → 0.17.0-7c10593
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 +149 -60
- package/package.json +4 -3
- package/readme.md +88 -14
- package/utils.js +43 -3
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6016,7 +6015,6 @@ var require_hanji = __commonJS({
|
|
|
6016
6015
|
var import_hanji, err, info, error, schema, isRenamePromptItem, ResolveColumnSelect, ResolveTableSelect, ResolveSchemasSelect, Spinner, IntrospectProgress, DropMigrationView, trimmedRange;
|
|
6017
6016
|
var init_views = __esm({
|
|
6018
6017
|
"src/cli/views.ts"() {
|
|
6019
|
-
"use strict";
|
|
6020
6018
|
init_source();
|
|
6021
6019
|
import_hanji = __toESM(require_hanji());
|
|
6022
6020
|
err = (msg) => {
|
|
@@ -6338,17 +6336,15 @@ Is ${source_default.bold.blue(
|
|
|
6338
6336
|
var originUUID, snapshotVersion;
|
|
6339
6337
|
var init_global = __esm({
|
|
6340
6338
|
"src/global.ts"() {
|
|
6341
|
-
"use strict";
|
|
6342
6339
|
originUUID = "00000000-0000-0000-0000-000000000000";
|
|
6343
6340
|
snapshotVersion = "5";
|
|
6344
6341
|
}
|
|
6345
6342
|
});
|
|
6346
6343
|
|
|
6347
6344
|
// src/serializer/mysqlSchema.ts
|
|
6348
|
-
var index, fk, column, tableV3, compositePK, table, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternal, schemaV3, schemaV4, schema2, tableSquashed, schemaSquashed, MySqlSquasher, squashMysqlScheme, mysqlSchema, mysqlSchemaV4, mysqlSchemaV3, backwardCompatibleMysqlSchema, dryMySql;
|
|
6345
|
+
var index, fk, column, tableV3, compositePK, tableV4, table, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternal, schemaV3, schemaV4, schema2, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlSchemeV4, squashMysqlScheme, mysqlSchema, mysqlSchemaV4, mysqlSchemaV3, backwardCompatibleMysqlSchema, dryMySql;
|
|
6349
6346
|
var init_mysqlSchema = __esm({
|
|
6350
6347
|
"src/serializer/mysqlSchema.ts"() {
|
|
6351
|
-
"use strict";
|
|
6352
6348
|
init_global();
|
|
6353
6349
|
init_utils();
|
|
6354
6350
|
init_lib();
|
|
@@ -6388,6 +6384,13 @@ var init_mysqlSchema = __esm({
|
|
|
6388
6384
|
name: stringType(),
|
|
6389
6385
|
columns: stringType().array()
|
|
6390
6386
|
}).strict();
|
|
6387
|
+
tableV4 = objectType({
|
|
6388
|
+
name: stringType(),
|
|
6389
|
+
schema: stringType().optional(),
|
|
6390
|
+
columns: recordType(stringType(), column),
|
|
6391
|
+
indexes: recordType(stringType(), index),
|
|
6392
|
+
foreignKeys: recordType(stringType(), fk)
|
|
6393
|
+
}).strict();
|
|
6391
6394
|
table = objectType({
|
|
6392
6395
|
name: stringType(),
|
|
6393
6396
|
schema: stringType().optional(),
|
|
@@ -6409,7 +6412,7 @@ var init_mysqlSchema = __esm({
|
|
|
6409
6412
|
schemaInternalV4 = objectType({
|
|
6410
6413
|
version: literalType("4"),
|
|
6411
6414
|
dialect,
|
|
6412
|
-
tables: recordType(stringType(),
|
|
6415
|
+
tables: recordType(stringType(), tableV4),
|
|
6413
6416
|
schemas: recordType(stringType(), stringType())
|
|
6414
6417
|
}).strict();
|
|
6415
6418
|
schemaInternal = objectType({
|
|
@@ -6426,6 +6429,13 @@ var init_mysqlSchema = __esm({
|
|
|
6426
6429
|
schemaV3 = schemaInternalV3.merge(schemaHash);
|
|
6427
6430
|
schemaV4 = schemaInternalV4.merge(schemaHash);
|
|
6428
6431
|
schema2 = schemaInternal.merge(schemaHash);
|
|
6432
|
+
tableSquashedV4 = objectType({
|
|
6433
|
+
name: stringType(),
|
|
6434
|
+
schema: stringType().optional(),
|
|
6435
|
+
columns: recordType(stringType(), column),
|
|
6436
|
+
indexes: recordType(stringType(), stringType()),
|
|
6437
|
+
foreignKeys: recordType(stringType(), stringType())
|
|
6438
|
+
}).strict();
|
|
6429
6439
|
tableSquashed = objectType({
|
|
6430
6440
|
name: stringType(),
|
|
6431
6441
|
schema: stringType().optional(),
|
|
@@ -6440,6 +6450,12 @@ var init_mysqlSchema = __esm({
|
|
|
6440
6450
|
tables: recordType(stringType(), tableSquashed),
|
|
6441
6451
|
schemas: recordType(stringType(), stringType())
|
|
6442
6452
|
}).strict();
|
|
6453
|
+
schemaSquashedV4 = objectType({
|
|
6454
|
+
version: literalType("4"),
|
|
6455
|
+
dialect,
|
|
6456
|
+
tables: recordType(stringType(), tableSquashedV4),
|
|
6457
|
+
schemas: recordType(stringType(), stringType())
|
|
6458
|
+
}).strict();
|
|
6443
6459
|
MySqlSquasher = {
|
|
6444
6460
|
squashIdx: (idx) => {
|
|
6445
6461
|
var _a, _b, _c;
|
|
@@ -6491,6 +6507,34 @@ var init_mysqlSchema = __esm({
|
|
|
6491
6507
|
return result;
|
|
6492
6508
|
}
|
|
6493
6509
|
};
|
|
6510
|
+
squashMysqlSchemeV4 = (json) => {
|
|
6511
|
+
const mappedTables = Object.fromEntries(
|
|
6512
|
+
Object.entries(json.tables).map((it) => {
|
|
6513
|
+
const squashedIndexes = mapValues(it[1].indexes, (index4) => {
|
|
6514
|
+
return MySqlSquasher.squashIdx(index4);
|
|
6515
|
+
});
|
|
6516
|
+
const squashedFKs = mapValues(it[1].foreignKeys, (fk4) => {
|
|
6517
|
+
return MySqlSquasher.squashFK(fk4);
|
|
6518
|
+
});
|
|
6519
|
+
return [
|
|
6520
|
+
it[0],
|
|
6521
|
+
{
|
|
6522
|
+
name: it[1].name,
|
|
6523
|
+
schema: it[1].schema,
|
|
6524
|
+
columns: it[1].columns,
|
|
6525
|
+
indexes: squashedIndexes,
|
|
6526
|
+
foreignKeys: squashedFKs
|
|
6527
|
+
}
|
|
6528
|
+
];
|
|
6529
|
+
})
|
|
6530
|
+
);
|
|
6531
|
+
return {
|
|
6532
|
+
version: "4",
|
|
6533
|
+
dialect: json.dialect,
|
|
6534
|
+
tables: mappedTables,
|
|
6535
|
+
schemas: json.schemas
|
|
6536
|
+
};
|
|
6537
|
+
};
|
|
6494
6538
|
squashMysqlScheme = (json) => {
|
|
6495
6539
|
const mappedTables = Object.fromEntries(
|
|
6496
6540
|
Object.entries(json.tables).map((it) => {
|
|
@@ -6544,10 +6588,9 @@ var init_mysqlSchema = __esm({
|
|
|
6544
6588
|
});
|
|
6545
6589
|
|
|
6546
6590
|
// src/serializer/pgSchema.ts
|
|
6547
|
-
var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, compositePK2, table2, schemaHash2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternal, tableSquashed2, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
|
6591
|
+
var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, compositePK2, tableV42, table2, schemaHash2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgSchemeV4, squashPgScheme, dryPg;
|
|
6548
6592
|
var init_pgSchema = __esm({
|
|
6549
6593
|
"src/serializer/pgSchema.ts"() {
|
|
6550
|
-
"use strict";
|
|
6551
6594
|
init_global();
|
|
6552
6595
|
init_utils();
|
|
6553
6596
|
init_lib();
|
|
@@ -6639,6 +6682,13 @@ var init_pgSchema = __esm({
|
|
|
6639
6682
|
name: stringType(),
|
|
6640
6683
|
columns: stringType().array()
|
|
6641
6684
|
}).strict();
|
|
6685
|
+
tableV42 = objectType({
|
|
6686
|
+
name: stringType(),
|
|
6687
|
+
schema: stringType(),
|
|
6688
|
+
columns: recordType(stringType(), column2),
|
|
6689
|
+
indexes: recordType(stringType(), index2),
|
|
6690
|
+
foreignKeys: recordType(stringType(), fk2)
|
|
6691
|
+
}).strict();
|
|
6642
6692
|
table2 = objectType({
|
|
6643
6693
|
name: stringType(),
|
|
6644
6694
|
schema: stringType(),
|
|
@@ -6660,7 +6710,7 @@ var init_pgSchema = __esm({
|
|
|
6660
6710
|
pgSchemaInternalV4 = objectType({
|
|
6661
6711
|
version: literalType("4"),
|
|
6662
6712
|
dialect: literalType("pg"),
|
|
6663
|
-
tables: recordType(stringType(),
|
|
6713
|
+
tables: recordType(stringType(), tableV42),
|
|
6664
6714
|
enums: recordType(stringType(), enumSchema),
|
|
6665
6715
|
schemas: recordType(stringType(), stringType())
|
|
6666
6716
|
}).strict();
|
|
@@ -6684,6 +6734,20 @@ var init_pgSchema = __esm({
|
|
|
6684
6734
|
foreignKeys: recordType(stringType(), stringType()),
|
|
6685
6735
|
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
6686
6736
|
}).strict();
|
|
6737
|
+
tableSquashedV42 = objectType({
|
|
6738
|
+
name: stringType(),
|
|
6739
|
+
schema: stringType(),
|
|
6740
|
+
columns: recordType(stringType(), column2),
|
|
6741
|
+
indexes: recordType(stringType(), stringType()),
|
|
6742
|
+
foreignKeys: recordType(stringType(), stringType())
|
|
6743
|
+
}).strict();
|
|
6744
|
+
pgSchemaSquashedV4 = objectType({
|
|
6745
|
+
version: literalType("4"),
|
|
6746
|
+
dialect: enumType(["pg"]),
|
|
6747
|
+
tables: recordType(stringType(), tableSquashedV42),
|
|
6748
|
+
enums: recordType(stringType(), enumSchema),
|
|
6749
|
+
schemas: recordType(stringType(), stringType())
|
|
6750
|
+
}).strict();
|
|
6687
6751
|
pgSchemaSquashed = objectType({
|
|
6688
6752
|
version: literalType("5"),
|
|
6689
6753
|
dialect: enumType(["pg"]),
|
|
@@ -6747,6 +6811,35 @@ var init_pgSchema = __esm({
|
|
|
6747
6811
|
return result;
|
|
6748
6812
|
}
|
|
6749
6813
|
};
|
|
6814
|
+
squashPgSchemeV4 = (json) => {
|
|
6815
|
+
const mappedTables = Object.fromEntries(
|
|
6816
|
+
Object.entries(json.tables).map((it) => {
|
|
6817
|
+
const squashedIndexes = mapValues(it[1].indexes, (index4) => {
|
|
6818
|
+
return PgSquasher.squashIdx(index4);
|
|
6819
|
+
});
|
|
6820
|
+
const squashedFKs = mapValues(it[1].foreignKeys, (fk4) => {
|
|
6821
|
+
return PgSquasher.squashFK(fk4);
|
|
6822
|
+
});
|
|
6823
|
+
return [
|
|
6824
|
+
it[0],
|
|
6825
|
+
{
|
|
6826
|
+
name: it[1].name,
|
|
6827
|
+
schema: it[1].schema,
|
|
6828
|
+
columns: it[1].columns,
|
|
6829
|
+
indexes: squashedIndexes,
|
|
6830
|
+
foreignKeys: squashedFKs
|
|
6831
|
+
}
|
|
6832
|
+
];
|
|
6833
|
+
})
|
|
6834
|
+
);
|
|
6835
|
+
return {
|
|
6836
|
+
version: "4",
|
|
6837
|
+
dialect: json.dialect,
|
|
6838
|
+
tables: mappedTables,
|
|
6839
|
+
enums: json.enums,
|
|
6840
|
+
schemas: json.schemas
|
|
6841
|
+
};
|
|
6842
|
+
};
|
|
6750
6843
|
squashPgScheme = (json) => {
|
|
6751
6844
|
const mappedTables = Object.fromEntries(
|
|
6752
6845
|
Object.entries(json.tables).map((it) => {
|
|
@@ -6801,7 +6894,6 @@ var init_pgSchema = __esm({
|
|
|
6801
6894
|
var index3, fk3, compositePK3, column3, tableV33, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV3, sqliteSchemaV4, sqliteSchema, backwardCompatibleSqliteSchema;
|
|
6802
6895
|
var init_sqliteSchema = __esm({
|
|
6803
6896
|
"src/serializer/sqliteSchema.ts"() {
|
|
6804
|
-
"use strict";
|
|
6805
6897
|
init_global();
|
|
6806
6898
|
init_utils();
|
|
6807
6899
|
init_lib();
|
|
@@ -13169,7 +13261,6 @@ function applyJsonDiff(json1, json2) {
|
|
|
13169
13261
|
var import_json_diff, findAlternationsInTable, alternationsInColumn;
|
|
13170
13262
|
var init_jsonDiffer = __esm({
|
|
13171
13263
|
"src/jsonDiffer.js"() {
|
|
13172
|
-
"use strict";
|
|
13173
13264
|
import_json_diff = __toESM(require_lib());
|
|
13174
13265
|
"use-strict";
|
|
13175
13266
|
findAlternationsInTable = (table4, tableSchema) => {
|
|
@@ -13314,7 +13405,6 @@ var init_jsonDiffer = __esm({
|
|
|
13314
13405
|
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, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, 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;
|
|
13315
13406
|
var init_sqlgenerator = __esm({
|
|
13316
13407
|
"src/sqlgenerator.ts"() {
|
|
13317
|
-
"use strict";
|
|
13318
13408
|
init_mysqlSchema();
|
|
13319
13409
|
init_pgSchema();
|
|
13320
13410
|
init_sqliteSchema();
|
|
@@ -14414,7 +14504,6 @@ drop type __venum;
|
|
|
14414
14504
|
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, prepareAlterTableColumnsJson, _prepareDropColumns, _prepareAddColumns, _prepareSQLiteAddColumns, _prepareAlterColumns, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
|
14415
14505
|
var init_jsonStatements = __esm({
|
|
14416
14506
|
"src/jsonStatements.ts"() {
|
|
14417
|
-
"use strict";
|
|
14418
14507
|
init_mysqlSchema();
|
|
14419
14508
|
init_pgSchema();
|
|
14420
14509
|
init_sqliteSchema();
|
|
@@ -14896,7 +14985,6 @@ var init_jsonStatements = __esm({
|
|
|
14896
14985
|
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, valueFromSelfOrPatchedNew, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, applySnapshotsDiff;
|
|
14897
14986
|
var init_snapshotsDiffer = __esm({
|
|
14898
14987
|
"src/snapshotsDiffer.ts"() {
|
|
14899
|
-
"use strict";
|
|
14900
14988
|
init_sqlgenerator();
|
|
14901
14989
|
init_lib();
|
|
14902
14990
|
init_jsonDiffer();
|
|
@@ -15352,7 +15440,6 @@ var init_snapshotsDiffer = __esm({
|
|
|
15352
15440
|
var prepareMigrationMetadata, adjectives, heroes;
|
|
15353
15441
|
var init_words = __esm({
|
|
15354
15442
|
"src/utils/words.ts"() {
|
|
15355
|
-
"use strict";
|
|
15356
15443
|
prepareMigrationMetadata = (idx) => {
|
|
15357
15444
|
const prefix = idx.toFixed(0).padStart(4, "0");
|
|
15358
15445
|
const suffix = `${adjectives.random()}_${heroes.random()}`;
|
|
@@ -16674,7 +16761,6 @@ var init_words = __esm({
|
|
|
16674
16761
|
var import_crypto, import_fs, upPgHandlerV4toV5, upPgHandler, upPgHandlerV4, updateUpToV4, update1to2, update2to3, update3to4;
|
|
16675
16762
|
var init_pgUp = __esm({
|
|
16676
16763
|
"src/cli/commands/pgUp.ts"() {
|
|
16677
|
-
"use strict";
|
|
16678
16764
|
init_source();
|
|
16679
16765
|
import_crypto = require("crypto");
|
|
16680
16766
|
import_fs = require("fs");
|
|
@@ -16712,7 +16798,7 @@ var init_pgUp = __esm({
|
|
|
16712
16798
|
}
|
|
16713
16799
|
mappedColumns[ckey] = { ...column6, default: newDefault, type: newType };
|
|
16714
16800
|
}
|
|
16715
|
-
mappedTables[key] = { ...table4, columns: mappedColumns };
|
|
16801
|
+
mappedTables[key] = { ...table4, columns: mappedColumns, compositePrimaryKeys: {} };
|
|
16716
16802
|
}
|
|
16717
16803
|
return {
|
|
16718
16804
|
version: "5",
|
|
@@ -16914,7 +17000,6 @@ var init_pgUp = __esm({
|
|
|
16914
17000
|
var import_fs2, upMysqlHandler, upMySqlHandlerV4toV5, upMysqlHandlerV4, updateToLatestV4, updateV3toV4;
|
|
16915
17001
|
var init_mysqlUp = __esm({
|
|
16916
17002
|
"src/cli/commands/mysqlUp.ts"() {
|
|
16917
|
-
"use strict";
|
|
16918
17003
|
init_source();
|
|
16919
17004
|
import_fs2 = __toESM(require("fs"));
|
|
16920
17005
|
init_mysqlSchema();
|
|
@@ -16972,7 +17057,7 @@ var init_mysqlUp = __esm({
|
|
|
16972
17057
|
autoincrement: newAutoIncrement
|
|
16973
17058
|
};
|
|
16974
17059
|
}
|
|
16975
|
-
mappedTables[key] = { ...table4, columns: mappedColumns };
|
|
17060
|
+
mappedTables[key] = { ...table4, columns: mappedColumns, compositePrimaryKeys: {} };
|
|
16976
17061
|
}
|
|
16977
17062
|
return {
|
|
16978
17063
|
version: "5",
|
|
@@ -17025,7 +17110,6 @@ var init_mysqlUp = __esm({
|
|
|
17025
17110
|
var import_fs3, import_path, schemasResolverWithSQL, resolveSchemas, resolveTablesWithSQL, resolveTables, resolveColumnsWithSQL, resolveColumns, fullfill, fullfillpg, fullfillmysql, fullfillsqlite, upgradeFolders;
|
|
17026
17111
|
var init_upFolders = __esm({
|
|
17027
17112
|
"src/cli/commands/upFolders.ts"() {
|
|
17028
|
-
"use strict";
|
|
17029
17113
|
import_fs3 = require("fs");
|
|
17030
17114
|
import_path = require("path");
|
|
17031
17115
|
init_jsonDiffer();
|
|
@@ -17229,8 +17313,8 @@ var init_upFolders = __esm({
|
|
|
17229
17313
|
return upPgHandlerV4toV5(b);
|
|
17230
17314
|
}
|
|
17231
17315
|
const a = pgSchemaV4.parse(prev);
|
|
17232
|
-
const json1 =
|
|
17233
|
-
const json2 =
|
|
17316
|
+
const json1 = squashPgSchemeV4(a);
|
|
17317
|
+
const json2 = squashPgSchemeV4(b);
|
|
17234
17318
|
const diffResult = applyJsonDiff(json1, json2);
|
|
17235
17319
|
const parseResult = diffResultScheme.safeParse(diffResult);
|
|
17236
17320
|
if (!parseResult.success) {
|
|
@@ -17301,8 +17385,8 @@ var init_upFolders = __esm({
|
|
|
17301
17385
|
return upMySqlHandlerV4toV5(b);
|
|
17302
17386
|
}
|
|
17303
17387
|
const a = mysqlSchemaV4.parse(prev);
|
|
17304
|
-
const json1 =
|
|
17305
|
-
const json2 =
|
|
17388
|
+
const json1 = squashMysqlSchemeV4(a);
|
|
17389
|
+
const json2 = squashMysqlSchemeV4(b);
|
|
17306
17390
|
const diffResult = applyJsonDiff(json1, json2);
|
|
17307
17391
|
const parseResult = diffResultScheme.safeParse(diffResult);
|
|
17308
17392
|
if (!parseResult.success) {
|
|
@@ -17469,6 +17553,7 @@ var init_upFolders = __esm({
|
|
|
17469
17553
|
date.setUTCHours(Number(it.substring(8, 10)));
|
|
17470
17554
|
date.setUTCMinutes(Number(it.substring(10, 12)));
|
|
17471
17555
|
date.setUTCSeconds(Number(it.substring(12, 14)));
|
|
17556
|
+
date.setUTCMilliseconds(0);
|
|
17472
17557
|
const path2 = (0, import_path.join)(out, it);
|
|
17473
17558
|
const pathJson = (0, import_path.join)(out, it, "snapshot.json");
|
|
17474
17559
|
const pathSQL = (0, import_path.join)(out, it, "migration.sql");
|
|
@@ -17523,7 +17608,6 @@ var init_upFolders = __esm({
|
|
|
17523
17608
|
var import_fs4, import_path2, assertV1OutFolder, dryJournal, snapshotsPriorV4, prepareOutFolder2, mapValues, validatorForDialect, validateWithReport, prepareMigrationFolder, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
|
|
17524
17609
|
var init_utils = __esm({
|
|
17525
17610
|
"src/utils.ts"() {
|
|
17526
|
-
"use strict";
|
|
17527
17611
|
import_fs4 = require("fs");
|
|
17528
17612
|
init_views();
|
|
17529
17613
|
init_mysqlSchema();
|
|
@@ -25618,7 +25702,6 @@ __export(mysqlImports_exports, {
|
|
|
25618
25702
|
var import_mysql_core, prepareFromMySqlImports;
|
|
25619
25703
|
var init_mysqlImports = __esm({
|
|
25620
25704
|
"src/serializer/mysqlImports.ts"() {
|
|
25621
|
-
"use strict";
|
|
25622
25705
|
import_mysql_core = require("drizzle-orm/mysql-core");
|
|
25623
25706
|
prepareFromMySqlImports = (imports) => {
|
|
25624
25707
|
const tables = [];
|
|
@@ -25670,7 +25753,6 @@ function clearDefaults(defaultValue, collate) {
|
|
|
25670
25753
|
var import_mysql_core2, import_table, import_utils9, import_sql, import_common, import_date, dialect3, indexName, generateMySqlSnapshot, fromDatabase;
|
|
25671
25754
|
var init_mysqlSerializer = __esm({
|
|
25672
25755
|
"src/serializer/mysqlSerializer.ts"() {
|
|
25673
|
-
"use strict";
|
|
25674
25756
|
import_mysql_core2 = require("drizzle-orm/mysql-core");
|
|
25675
25757
|
import_table = require("drizzle-orm/table");
|
|
25676
25758
|
import_utils9 = require("drizzle-orm/mysql-core/utils");
|
|
@@ -25841,7 +25923,7 @@ var init_mysqlSerializer = __esm({
|
|
|
25841
25923
|
const dataType = column6["DATA_TYPE"];
|
|
25842
25924
|
const columnType = column6["COLUMN_TYPE"];
|
|
25843
25925
|
const isPrimary = column6["COLUMN_KEY"] === "PRI";
|
|
25844
|
-
const isAutoincrement = column6["EXTRA"] === "auto_increment"
|
|
25926
|
+
const isAutoincrement = column6["EXTRA"] === "auto_increment";
|
|
25845
25927
|
const isDefaultAnExpression = column6["EXTRA"] === "DEFAULT_GENERATED";
|
|
25846
25928
|
const columnDefault = column6["COLUMN_DEFAULT"];
|
|
25847
25929
|
const collation = column6["CHARACTER_SET_NAME"];
|
|
@@ -26015,7 +26097,6 @@ __export(pgImports_exports, {
|
|
|
26015
26097
|
var import_pg_core, prepareFromPgImports;
|
|
26016
26098
|
var init_pgImports = __esm({
|
|
26017
26099
|
"src/serializer/pgImports.ts"() {
|
|
26018
|
-
"use strict";
|
|
26019
26100
|
import_pg_core = require("drizzle-orm/pg-core");
|
|
26020
26101
|
prepareFromPgImports = (imports) => {
|
|
26021
26102
|
const tables = [];
|
|
@@ -26054,7 +26135,6 @@ __export(pgSerializer_exports, {
|
|
|
26054
26135
|
var import_pg_core2, import_utils10, import_sql2, import_table2, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
|
|
26055
26136
|
var init_pgSerializer = __esm({
|
|
26056
26137
|
"src/serializer/pgSerializer.ts"() {
|
|
26057
|
-
"use strict";
|
|
26058
26138
|
import_pg_core2 = require("drizzle-orm/pg-core");
|
|
26059
26139
|
import_utils10 = require("drizzle-orm/pg-core/utils");
|
|
26060
26140
|
import_sql2 = require("drizzle-orm/sql");
|
|
@@ -26534,7 +26614,6 @@ __export(sqliteImports_exports, {
|
|
|
26534
26614
|
var import_sqlite_core, prepareFromSqliteImports;
|
|
26535
26615
|
var init_sqliteImports = __esm({
|
|
26536
26616
|
"src/serializer/sqliteImports.ts"() {
|
|
26537
|
-
"use strict";
|
|
26538
26617
|
import_sqlite_core = require("drizzle-orm/sqlite-core");
|
|
26539
26618
|
prepareFromSqliteImports = (imports) => {
|
|
26540
26619
|
const tables = [];
|
|
@@ -26561,7 +26640,6 @@ __export(sqliteSerializer_exports, {
|
|
|
26561
26640
|
var import_table3, import_sql3, import_sqlite_core2, import_utils11, dialect5, generateSqliteSnapshot;
|
|
26562
26641
|
var init_sqliteSerializer = __esm({
|
|
26563
26642
|
"src/serializer/sqliteSerializer.ts"() {
|
|
26564
|
-
"use strict";
|
|
26565
26643
|
import_table3 = require("drizzle-orm/table");
|
|
26566
26644
|
import_sql3 = require("drizzle-orm/sql");
|
|
26567
26645
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
|
@@ -26570,12 +26648,19 @@ var init_sqliteSerializer = __esm({
|
|
|
26570
26648
|
generateSqliteSnapshot = (tables, enums) => {
|
|
26571
26649
|
const result = {};
|
|
26572
26650
|
for (const table4 of tables) {
|
|
26573
|
-
const tableName = (0, import_table3.getTableName)(table4);
|
|
26574
26651
|
const columnsObject = {};
|
|
26575
26652
|
const indexesObject = {};
|
|
26576
26653
|
const foreignKeysObject = {};
|
|
26577
26654
|
const primaryKeysObject = {};
|
|
26578
|
-
|
|
26655
|
+
const {
|
|
26656
|
+
name: tableName,
|
|
26657
|
+
columns,
|
|
26658
|
+
indexes,
|
|
26659
|
+
foreignKeys: tableForeignKeys,
|
|
26660
|
+
schema: schema4,
|
|
26661
|
+
primaryKeys
|
|
26662
|
+
} = (0, import_utils11.getTableConfig)(table4);
|
|
26663
|
+
columns.forEach((column6) => {
|
|
26579
26664
|
const notNull = column6.notNull;
|
|
26580
26665
|
const primaryKey = column6.primary;
|
|
26581
26666
|
const columnToSet = {
|
|
@@ -26583,7 +26668,7 @@ var init_sqliteSerializer = __esm({
|
|
|
26583
26668
|
type: column6.getSQLType(),
|
|
26584
26669
|
primaryKey,
|
|
26585
26670
|
notNull,
|
|
26586
|
-
autoincrement: column6.autoIncrement
|
|
26671
|
+
autoincrement: column6 instanceof import_sqlite_core2.SQLiteBaseInteger ? column6.autoIncrement : void 0
|
|
26587
26672
|
};
|
|
26588
26673
|
if (column6.default !== void 0) {
|
|
26589
26674
|
if (column6.default instanceof import_sql3.SQL) {
|
|
@@ -26602,7 +26687,7 @@ var init_sqliteSerializer = __esm({
|
|
|
26602
26687
|
}
|
|
26603
26688
|
columnsObject[column6.name] = columnToSet;
|
|
26604
26689
|
});
|
|
26605
|
-
const foreignKeys =
|
|
26690
|
+
const foreignKeys = tableForeignKeys.map((fk4) => {
|
|
26606
26691
|
const name = fk4.getName();
|
|
26607
26692
|
const tableFrom = tableName;
|
|
26608
26693
|
const onDelete = fk4.onDelete;
|
|
@@ -26625,11 +26710,11 @@ var init_sqliteSerializer = __esm({
|
|
|
26625
26710
|
foreignKeys.forEach((it) => {
|
|
26626
26711
|
foreignKeysObject[it.name] = it;
|
|
26627
26712
|
});
|
|
26628
|
-
|
|
26713
|
+
indexes.forEach((value) => {
|
|
26629
26714
|
var _a;
|
|
26630
|
-
const
|
|
26715
|
+
const columns2 = value.config.columns;
|
|
26631
26716
|
const name = value.config.name;
|
|
26632
|
-
let indexColumns =
|
|
26717
|
+
let indexColumns = columns2.map((it) => {
|
|
26633
26718
|
if (it instanceof import_sql3.SQL) {
|
|
26634
26719
|
return dialect5.sqlToQuery(it).sql;
|
|
26635
26720
|
} else {
|
|
@@ -26649,7 +26734,7 @@ var init_sqliteSerializer = __esm({
|
|
|
26649
26734
|
where
|
|
26650
26735
|
};
|
|
26651
26736
|
});
|
|
26652
|
-
|
|
26737
|
+
primaryKeys.forEach((it) => {
|
|
26653
26738
|
primaryKeysObject[it.getName()] = {
|
|
26654
26739
|
columns: it.columns.map((it2) => it2.name)
|
|
26655
26740
|
};
|
|
@@ -26680,7 +26765,6 @@ var init_sqliteSerializer = __esm({
|
|
|
26680
26765
|
var import_fs5, import_node, import_path3, import_glob, safeRegister, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
|
|
26681
26766
|
var init_serializer = __esm({
|
|
26682
26767
|
"src/serializer/index.ts"() {
|
|
26683
|
-
"use strict";
|
|
26684
26768
|
import_fs5 = __toESM(require("fs"));
|
|
26685
26769
|
import_node = __toESM(require_node2());
|
|
26686
26770
|
import_path3 = __toESM(require("path"));
|
|
@@ -26746,7 +26830,6 @@ var init_serializer = __esm({
|
|
|
26746
26830
|
var import_fs6, import_crypto2, prepareMySqlMigrationSnapshot, prepareSqliteMigrationSnapshot, preparePgMigrationSnapshot, preparePrevSnapshot;
|
|
26747
26831
|
var init_migrationPreparator = __esm({
|
|
26748
26832
|
"src/migrationPreparator.ts"() {
|
|
26749
|
-
"use strict";
|
|
26750
26833
|
import_fs6 = __toESM(require("fs"));
|
|
26751
26834
|
import_crypto2 = require("crypto");
|
|
26752
26835
|
init_serializer();
|
|
@@ -26816,7 +26899,6 @@ __export(migrate_exports, {
|
|
|
26816
26899
|
var import_fs7, import_path4, import_hanji2, prepareAndMigratePg, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, writeResult, prepareSnapshotFolderName, two;
|
|
26817
26900
|
var init_migrate = __esm({
|
|
26818
26901
|
"src/cli/commands/migrate.ts"() {
|
|
26819
|
-
"use strict";
|
|
26820
26902
|
import_fs7 = __toESM(require("fs"));
|
|
26821
26903
|
init_migrationPreparator();
|
|
26822
26904
|
init_snapshotsDiffer();
|
|
@@ -27099,7 +27181,7 @@ var init_migrate = __esm({
|
|
|
27099
27181
|
result.deleted.push(...leftMissing);
|
|
27100
27182
|
return result;
|
|
27101
27183
|
};
|
|
27102
|
-
writeResult = (cur, sqlStatements, journal, _meta, outFolder, breakpoints) => {
|
|
27184
|
+
writeResult = (cur, sqlStatements, journal, _meta, outFolder, breakpoints, isIntrospect = false) => {
|
|
27103
27185
|
console.log(schema(cur));
|
|
27104
27186
|
if (sqlStatements.length === 0) {
|
|
27105
27187
|
console.log("No schema changes, nothing to migrate \u{1F634}");
|
|
@@ -27117,7 +27199,14 @@ var init_migrate = __esm({
|
|
|
27117
27199
|
JSON.stringify(toSave, null, 2)
|
|
27118
27200
|
);
|
|
27119
27201
|
const sqlDelimiter = breakpoints ? "--> statement-breakpoint\n" : "\n";
|
|
27120
|
-
|
|
27202
|
+
let sql = sqlStatements.join(sqlDelimiter);
|
|
27203
|
+
if (isIntrospect) {
|
|
27204
|
+
sql = `-- Current sql file was generated after introspecting the database
|
|
27205
|
+
-- If you want to run this migration please uncomment this code before executing migraitons
|
|
27206
|
+
/*
|
|
27207
|
+
${sql}
|
|
27208
|
+
*/`;
|
|
27209
|
+
}
|
|
27121
27210
|
journal.entries.push({
|
|
27122
27211
|
idx,
|
|
27123
27212
|
version: cur.version,
|
|
@@ -27239,7 +27328,6 @@ var init_camelcase = __esm({
|
|
|
27239
27328
|
// src/@types/utils.ts
|
|
27240
27329
|
var init_utils2 = __esm({
|
|
27241
27330
|
"src/@types/utils.ts"() {
|
|
27242
|
-
"use strict";
|
|
27243
27331
|
init_camelcase();
|
|
27244
27332
|
String.prototype.trimChar = function(char) {
|
|
27245
27333
|
let start = 0;
|
|
@@ -31643,7 +31731,6 @@ var require_lib3 = __commonJS({
|
|
|
31643
31731
|
var pgImportsList, objToStatement2, timeConfig, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch, relations, schemaToTypeScript, isCyclic, isSelf, column4, dimensionsInArray, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
|
|
31644
31732
|
var init_introspect = __esm({
|
|
31645
31733
|
"src/introspect.ts"() {
|
|
31646
|
-
"use strict";
|
|
31647
31734
|
init_utils2();
|
|
31648
31735
|
init_pgSerializer();
|
|
31649
31736
|
pgImportsList = /* @__PURE__ */ new Set([
|
|
@@ -32083,7 +32170,7 @@ var init_introspect = __esm({
|
|
|
32083
32170
|
createTableIndexes = (tableName, idxs) => {
|
|
32084
32171
|
let statement = "";
|
|
32085
32172
|
idxs.forEach((it) => {
|
|
32086
|
-
let idxKey = it.name.startsWith(tableName) ? it.name.slice(tableName.length + 1) : it.name;
|
|
32173
|
+
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
|
32087
32174
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
|
32088
32175
|
idxKey = idxKey.camelCase();
|
|
32089
32176
|
const indexGeneratedName = indexName2(tableName, it.columns);
|
|
@@ -32144,7 +32231,6 @@ __export(pgIntrospect_exports, {
|
|
|
32144
32231
|
var import_hanji4, import_pg, PgConfig1, PgConfig2, Conf, pgIntrospect;
|
|
32145
32232
|
var init_pgIntrospect = __esm({
|
|
32146
32233
|
"src/cli/commands/pgIntrospect.ts"() {
|
|
32147
|
-
"use strict";
|
|
32148
32234
|
import_hanji4 = __toESM(require_hanji());
|
|
32149
32235
|
init_lib();
|
|
32150
32236
|
init_views();
|
|
@@ -48560,7 +48646,6 @@ var require_promise2 = __commonJS({
|
|
|
48560
48646
|
var mysqlImportsList, objToStatement22, timeConfig2, binaryConfig, importsPatch2, relations2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
|
|
48561
48647
|
var init_mysql_introspect = __esm({
|
|
48562
48648
|
"src/mysql-introspect.ts"() {
|
|
48563
|
-
"use strict";
|
|
48564
48649
|
init_utils2();
|
|
48565
48650
|
init_mysqlSerializer();
|
|
48566
48651
|
mysqlImportsList = /* @__PURE__ */ new Set([
|
|
@@ -48646,7 +48731,9 @@ var init_mysql_introspect = __esm({
|
|
|
48646
48731
|
(idx) => idx.isUnique ? "uniqueIndex" : "index"
|
|
48647
48732
|
);
|
|
48648
48733
|
const fkImpots = Object.values(it.foreignKeys).map((it2) => "foreignKey");
|
|
48649
|
-
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
48734
|
+
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
|
48735
|
+
(it2) => "primaryKey"
|
|
48736
|
+
);
|
|
48650
48737
|
res.mysql.push(...idxImports);
|
|
48651
48738
|
res.mysql.push(...fkImpots);
|
|
48652
48739
|
res.mysql.push(...pkImports);
|
|
@@ -48750,13 +48837,13 @@ import { sql } from "drizzle-orm/sql"
|
|
|
48750
48837
|
if (lowered.startsWith("int")) {
|
|
48751
48838
|
let out = `${name.camelCase()}: int("${name}")`;
|
|
48752
48839
|
out += autoincrement ? `.autoincrement()` : "";
|
|
48753
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
48840
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
48754
48841
|
return out;
|
|
48755
48842
|
}
|
|
48756
48843
|
if (lowered.startsWith("tinyint")) {
|
|
48757
48844
|
let out = `${name.camelCase()}: tinyint("${name}")`;
|
|
48758
48845
|
out += autoincrement ? `.autoincrement()` : "";
|
|
48759
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
48846
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
48760
48847
|
return out;
|
|
48761
48848
|
}
|
|
48762
48849
|
if (lowered.startsWith("smallint")) {
|
|
@@ -48894,7 +48981,7 @@ import { sql } from "drizzle-orm/sql"
|
|
|
48894
48981
|
params = { precision, scale };
|
|
48895
48982
|
}
|
|
48896
48983
|
let out = params ? `${name.camelCase()}: decimal("${name}", ${timeConfig2(params)})` : `${name.camelCase()}: decimal("${name}")`;
|
|
48897
|
-
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
48984
|
+
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
48898
48985
|
out += defaultValue;
|
|
48899
48986
|
return out;
|
|
48900
48987
|
}
|
|
@@ -48966,7 +49053,7 @@ import { sql } from "drizzle-orm/sql"
|
|
|
48966
49053
|
createTableIndexes2 = (tableName, idxs) => {
|
|
48967
49054
|
let statement = "";
|
|
48968
49055
|
idxs.forEach((it) => {
|
|
48969
|
-
let idxKey = it.name.startsWith(tableName) ? it.name.slice(tableName.length + 1) : it.name;
|
|
49056
|
+
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
|
48970
49057
|
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
|
48971
49058
|
idxKey = idxKey.camelCase();
|
|
48972
49059
|
const indexGeneratedName = indexName(tableName, it.columns);
|
|
@@ -49027,7 +49114,6 @@ __export(mysqlIntrospect_exports, {
|
|
|
49027
49114
|
var import_hanji5, import_promise, MySQLConfig1, MySQLConfig2, Conf2, mysqlIntrospect;
|
|
49028
49115
|
var init_mysqlIntrospect = __esm({
|
|
49029
49116
|
"src/cli/commands/mysqlIntrospect.ts"() {
|
|
49030
|
-
"use strict";
|
|
49031
49117
|
import_hanji5 = __toESM(require_hanji());
|
|
49032
49118
|
init_lib();
|
|
49033
49119
|
init_views();
|
|
@@ -49199,8 +49285,9 @@ var package_default = {
|
|
|
49199
49285
|
scripts: {
|
|
49200
49286
|
"migrate:old": "drizzle-kit generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
49201
49287
|
"migrate:old:mysql": "drizzle-kit generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
49202
|
-
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/
|
|
49203
|
-
"start:
|
|
49288
|
+
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
49289
|
+
"start:sqlite": "node -r esbuild-register ./src/cli/index.ts generate:sqlite --out ./dev/migrations-sqlite --schema ./dev/migrations-sqlite/schema.ts",
|
|
49290
|
+
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
49204
49291
|
"check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
|
|
49205
49292
|
"introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql --out ./dev/introspect-mysql --connectionString",
|
|
49206
49293
|
"introspect:pg": "node -r esbuild-register ./src/cli/index.ts introspect:pg --out ./dev/introspect-pg --connectionString=postgresql://postgres@localhost:5432/introspect",
|
|
@@ -49571,7 +49658,8 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
|
|
|
49571
49658
|
journal,
|
|
49572
49659
|
_meta,
|
|
49573
49660
|
res.data.out,
|
|
49574
|
-
res.data.breakpoints
|
|
49661
|
+
res.data.breakpoints,
|
|
49662
|
+
true
|
|
49575
49663
|
);
|
|
49576
49664
|
} else {
|
|
49577
49665
|
(0, import_hanji6.render)(
|
|
@@ -49622,7 +49710,8 @@ var introspectMySqlCommand = new Command("introspect:mysql").option("--out <out>
|
|
|
49622
49710
|
journal,
|
|
49623
49711
|
_meta,
|
|
49624
49712
|
res.data.out,
|
|
49625
|
-
res.data.breakpoints
|
|
49713
|
+
res.data.breakpoints,
|
|
49714
|
+
true
|
|
49626
49715
|
);
|
|
49627
49716
|
} else {
|
|
49628
49717
|
(0, import_hanji6.render)(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-kit",
|
|
3
|
-
"version": "0.17.0-
|
|
3
|
+
"version": "0.17.0-7c10593",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Drizzle Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"migrate:old": "drizzle-kit generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
12
12
|
"migrate:old:mysql": "drizzle-kit generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
13
|
-
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/
|
|
14
|
-
"start:
|
|
13
|
+
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
14
|
+
"start:sqlite": "node -r esbuild-register ./src/cli/index.ts generate:sqlite --out ./dev/migrations-sqlite --schema ./dev/migrations-sqlite/schema.ts",
|
|
15
|
+
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
15
16
|
"check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
|
|
16
17
|
"introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql --out ./dev/introspect-mysql --connectionString",
|
|
17
18
|
"introspect:pg": "node -r esbuild-register ./src/cli/index.ts introspect:pg --out ./dev/introspect-pg --connectionString=postgresql://postgres@localhost:5432/introspect",
|
package/readme.md
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
## Drizzle Kit
|
|
2
|
+
|
|
2
3
|
DrizzleKit - is a CLI migrator tool for DrizzleORM. It is probably one and only tool that lets you completely automatically generate SQL migrations and covers ~95% of the common cases like delitions and renames by prompting user input.\
|
|
3
|
-
https://github.com/drizzle-team/drizzle-kit-mirror - is a mirror repository for issues.
|
|
4
|
+
<https://github.com/drizzle-team/drizzle-kit-mirror> - is a mirror repository for issues.
|
|
4
5
|
|
|
5
6
|
### How it works
|
|
7
|
+
|
|
6
8
|
`drizzle-kit` will traverse `schema folder` or `schema file`, generate schema snapshot and compare it to the previous version(if there's one).\
|
|
7
9
|
Based on the difference it will generate all needed SQL migrations and if there're any `automatically unresolvable` cases like `renames` it will prompt user for input.
|
|
8
10
|
|
|
9
11
|
For schema file:
|
|
12
|
+
|
|
10
13
|
```typescript
|
|
11
14
|
// ./src/db/schema.ts
|
|
12
15
|
|
|
@@ -26,17 +29,19 @@ export const authOtp = pgTable("auth_otp", {
|
|
|
26
29
|
userId: integer("user_id").references(() => users.id),
|
|
27
30
|
});
|
|
28
31
|
```
|
|
32
|
+
|
|
29
33
|
It will generate:
|
|
34
|
+
|
|
30
35
|
```SQL
|
|
31
36
|
CREATE TABLE IF NOT EXISTS auth_otp (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
"id" SERIAL PRIMARY KEY,
|
|
38
|
+
"phone" character varying(256),
|
|
39
|
+
"user_id" INT
|
|
35
40
|
);
|
|
36
41
|
|
|
37
42
|
CREATE TABLE IF NOT EXISTS users (
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
"id" SERIAL PRIMARY KEY,
|
|
44
|
+
"full_name" character varying(256)
|
|
40
45
|
);
|
|
41
46
|
|
|
42
47
|
DO $$ BEGIN
|
|
@@ -49,26 +54,69 @@ CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);
|
|
|
49
54
|
```
|
|
50
55
|
|
|
51
56
|
### Installation & configuration
|
|
57
|
+
|
|
52
58
|
```shell
|
|
53
|
-
|
|
59
|
+
npm install -D drizzle-kit
|
|
54
60
|
```
|
|
55
61
|
|
|
56
62
|
Running with CLI options
|
|
63
|
+
|
|
57
64
|
```shell
|
|
58
|
-
|
|
65
|
+
npm exec drizzle-kit generate --out migrations-folder --dialect pg --schema src/db/schema.ts
|
|
59
66
|
```
|
|
60
67
|
|
|
61
68
|
Or put your file to `drizzle.config.json` configuration file:
|
|
69
|
+
|
|
62
70
|
```json
|
|
63
71
|
{
|
|
64
72
|
"out": "./migrations-folder",
|
|
65
73
|
"schema": "./src/db"
|
|
66
74
|
}
|
|
67
75
|
```
|
|
76
|
+
|
|
68
77
|
---
|
|
78
|
+
|
|
79
|
+
## Upgrading to 0.17.0
|
|
80
|
+
|
|
81
|
+
Before running any new migrations `drizzle-kit` will ask you to upgrade in a first place
|
|
82
|
+
|
|
83
|
+
Migration file structure < 0.17.0
|
|
84
|
+
|
|
85
|
+
```plaintext
|
|
86
|
+
📦 <project root>
|
|
87
|
+
└ 📂 migrations
|
|
88
|
+
└ 📂 20221207174503
|
|
89
|
+
├ 📜 migration.sql
|
|
90
|
+
├ 📜 snapshot.json
|
|
91
|
+
└ 📂 20230101104503
|
|
92
|
+
├ 📜 migration.sql
|
|
93
|
+
├ 📜 snapshot.json
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Migration file structure >= 0.17.0
|
|
97
|
+
|
|
98
|
+
```plaintext
|
|
99
|
+
📦 <project root>
|
|
100
|
+
└ 📂 migrations
|
|
101
|
+
└ 📂 meta
|
|
102
|
+
├ 📜 _journal.json
|
|
103
|
+
├ 📜 0000_snapshot.json
|
|
104
|
+
├ 📜 0001_snapshot.json
|
|
105
|
+
└ 📜 0000_icy_stranger.sql
|
|
106
|
+
└ 📜 0001_strange_avengers.sql
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
To easily migrate from previous folder structure to new you need to run `up` command in drizzle kit. It's a great helper to upgrade your migrations to new format on each drizzle kit major update
|
|
110
|
+
|
|
111
|
+

|
|
112
|
+
---
|
|
113
|
+
|
|
69
114
|
## List of commands
|
|
70
115
|
|
|
71
116
|
### Generate SQL migrations based on current .ts schema\
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
72
120
|
**`$ drizzle-kit generate:pg`** \
|
|
73
121
|
**`$ drizzle-kit generate:mysql`** \
|
|
74
122
|
**`$ drizzle-kit generate:sqlite`** \
|
|
@@ -76,6 +124,7 @@ Or put your file to `drizzle.config.json` configuration file:
|
|
|
76
124
|
`--config` [optional defalut=drizzle.config.json] config file path\
|
|
77
125
|
`--schema` path to typescript schema file or folder with multiple schema files\
|
|
78
126
|
`--out` [optional default=drizzle/] migrations folder
|
|
127
|
+
|
|
79
128
|
```shell
|
|
80
129
|
$ drizzle-kit generate:pg
|
|
81
130
|
## runs generate command with drizzle.config.json
|
|
@@ -91,40 +140,65 @@ $ drizzle-kit generate:pg --schema=./src/schema.ts --out=./migrations/
|
|
|
91
140
|
```
|
|
92
141
|
|
|
93
142
|
### Introspect existing database and generate typescript schema
|
|
94
|
-
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
**`$ drizzle-kit introspect:pg`** \
|
|
147
|
+
**`$ drizzle-kit introspect:mysql`**
|
|
148
|
+
|
|
95
149
|
```shell
|
|
96
150
|
drizzle-kit introspect:pg --out=migrations/ --connectionString=postgresql://user:pass@host:port/db_name
|
|
97
151
|
|
|
98
152
|
drizzle-kit introspect:pg --out=migrations/ --host=0.0.0.0 --port=5432 --user=postgres --password=pass --database=db_name --ssl
|
|
99
153
|
```
|
|
100
154
|
|
|
155
|
+

|
|
156
|
+
|
|
101
157
|
### Update stale snapshots
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
102
161
|
**`$ drizzle-kit up:pg`** \
|
|
103
162
|
**`$ drizzle-kit up:mysql`**\
|
|
104
163
|
**`$ drizzle-kit up:sqlite`**
|
|
105
164
|
|
|
106
165
|
`--out` [optional] migrations folder\
|
|
107
166
|
`--config` [optional defalut=drizzle.config.json] config file path
|
|
167
|
+
|
|
108
168
|
```shell
|
|
109
169
|
## migrations folder is taken from drizzle.config.json
|
|
110
|
-
drizzle-kit up:
|
|
170
|
+
drizzle-kit up:mysql
|
|
111
171
|
|
|
112
|
-
drizzle-kit up:
|
|
172
|
+
drizzle-kit up:mysql --out=migrations/
|
|
113
173
|
```
|
|
114
174
|
|
|
175
|
+

|
|
176
|
+
|
|
177
|
+
### Drop migration
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
**`$ drizzle-kit drop`** \
|
|
182
|
+
|
|
183
|
+
`--out` [optional] migrations folder\
|
|
184
|
+
`--config` [optional defalut=drizzle.config.json] config file path
|
|
185
|
+
|
|
186
|
+

|
|
187
|
+
|
|
115
188
|
### Migrations collisions check
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
116
192
|
**`$ drizzle-kit check:pg`**\
|
|
117
193
|
**`$ drizzle-kit check:mysql`**\
|
|
118
194
|
**`$ drizzle-kit check:sqlite`**
|
|
119
195
|
|
|
120
196
|
`--out` [optional] migration folder\
|
|
121
197
|
`--config` [optional defalut=drizzle.config.json] config file path
|
|
198
|
+
|
|
122
199
|
```shell
|
|
123
200
|
## migrations folder is taken from drizzle.config.json
|
|
124
201
|
drizzle-kit check:pg
|
|
125
202
|
|
|
126
203
|
drizzle-kit check:pg --out=migrations/
|
|
127
204
|
```
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
package/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -10358,6 +10357,13 @@ var compositePK = objectType({
|
|
|
10358
10357
|
name: stringType(),
|
|
10359
10358
|
columns: stringType().array()
|
|
10360
10359
|
}).strict();
|
|
10360
|
+
var tableV4 = objectType({
|
|
10361
|
+
name: stringType(),
|
|
10362
|
+
schema: stringType().optional(),
|
|
10363
|
+
columns: recordType(stringType(), column),
|
|
10364
|
+
indexes: recordType(stringType(), index),
|
|
10365
|
+
foreignKeys: recordType(stringType(), fk)
|
|
10366
|
+
}).strict();
|
|
10361
10367
|
var table = objectType({
|
|
10362
10368
|
name: stringType(),
|
|
10363
10369
|
schema: stringType().optional(),
|
|
@@ -10379,7 +10385,7 @@ var schemaInternalV3 = objectType({
|
|
|
10379
10385
|
var schemaInternalV4 = objectType({
|
|
10380
10386
|
version: literalType("4"),
|
|
10381
10387
|
dialect,
|
|
10382
|
-
tables: recordType(stringType(),
|
|
10388
|
+
tables: recordType(stringType(), tableV4),
|
|
10383
10389
|
schemas: recordType(stringType(), stringType())
|
|
10384
10390
|
}).strict();
|
|
10385
10391
|
var schemaInternal = objectType({
|
|
@@ -10396,6 +10402,13 @@ var schemaInternal = objectType({
|
|
|
10396
10402
|
var schemaV3 = schemaInternalV3.merge(schemaHash);
|
|
10397
10403
|
var schemaV4 = schemaInternalV4.merge(schemaHash);
|
|
10398
10404
|
var schema = schemaInternal.merge(schemaHash);
|
|
10405
|
+
var tableSquashedV4 = objectType({
|
|
10406
|
+
name: stringType(),
|
|
10407
|
+
schema: stringType().optional(),
|
|
10408
|
+
columns: recordType(stringType(), column),
|
|
10409
|
+
indexes: recordType(stringType(), stringType()),
|
|
10410
|
+
foreignKeys: recordType(stringType(), stringType())
|
|
10411
|
+
}).strict();
|
|
10399
10412
|
var tableSquashed = objectType({
|
|
10400
10413
|
name: stringType(),
|
|
10401
10414
|
schema: stringType().optional(),
|
|
@@ -10410,6 +10423,12 @@ var schemaSquashed = objectType({
|
|
|
10410
10423
|
tables: recordType(stringType(), tableSquashed),
|
|
10411
10424
|
schemas: recordType(stringType(), stringType())
|
|
10412
10425
|
}).strict();
|
|
10426
|
+
var schemaSquashedV4 = objectType({
|
|
10427
|
+
version: literalType("4"),
|
|
10428
|
+
dialect,
|
|
10429
|
+
tables: recordType(stringType(), tableSquashedV4),
|
|
10430
|
+
schemas: recordType(stringType(), stringType())
|
|
10431
|
+
}).strict();
|
|
10413
10432
|
var MySqlSquasher = {
|
|
10414
10433
|
squashIdx: (idx) => {
|
|
10415
10434
|
var _a, _b, _c;
|
|
@@ -10566,6 +10585,13 @@ var compositePK2 = objectType({
|
|
|
10566
10585
|
name: stringType(),
|
|
10567
10586
|
columns: stringType().array()
|
|
10568
10587
|
}).strict();
|
|
10588
|
+
var tableV42 = objectType({
|
|
10589
|
+
name: stringType(),
|
|
10590
|
+
schema: stringType(),
|
|
10591
|
+
columns: recordType(stringType(), column2),
|
|
10592
|
+
indexes: recordType(stringType(), index2),
|
|
10593
|
+
foreignKeys: recordType(stringType(), fk2)
|
|
10594
|
+
}).strict();
|
|
10569
10595
|
var table2 = objectType({
|
|
10570
10596
|
name: stringType(),
|
|
10571
10597
|
schema: stringType(),
|
|
@@ -10587,7 +10613,7 @@ var pgSchemaInternalV3 = objectType({
|
|
|
10587
10613
|
var pgSchemaInternalV4 = objectType({
|
|
10588
10614
|
version: literalType("4"),
|
|
10589
10615
|
dialect: literalType("pg"),
|
|
10590
|
-
tables: recordType(stringType(),
|
|
10616
|
+
tables: recordType(stringType(), tableV42),
|
|
10591
10617
|
enums: recordType(stringType(), enumSchema),
|
|
10592
10618
|
schemas: recordType(stringType(), stringType())
|
|
10593
10619
|
}).strict();
|
|
@@ -10611,6 +10637,20 @@ var tableSquashed2 = objectType({
|
|
|
10611
10637
|
foreignKeys: recordType(stringType(), stringType()),
|
|
10612
10638
|
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
10613
10639
|
}).strict();
|
|
10640
|
+
var tableSquashedV42 = objectType({
|
|
10641
|
+
name: stringType(),
|
|
10642
|
+
schema: stringType(),
|
|
10643
|
+
columns: recordType(stringType(), column2),
|
|
10644
|
+
indexes: recordType(stringType(), stringType()),
|
|
10645
|
+
foreignKeys: recordType(stringType(), stringType())
|
|
10646
|
+
}).strict();
|
|
10647
|
+
var pgSchemaSquashedV4 = objectType({
|
|
10648
|
+
version: literalType("4"),
|
|
10649
|
+
dialect: enumType(["pg"]),
|
|
10650
|
+
tables: recordType(stringType(), tableSquashedV42),
|
|
10651
|
+
enums: recordType(stringType(), enumSchema),
|
|
10652
|
+
schemas: recordType(stringType(), stringType())
|
|
10653
|
+
}).strict();
|
|
10614
10654
|
var pgSchemaSquashed = objectType({
|
|
10615
10655
|
version: literalType("5"),
|
|
10616
10656
|
dialect: enumType(["pg"]),
|