drizzle-kit 0.20.1 → 0.20.2-8e648e0
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/bin.cjs +2040 -1978
- package/cli/commands/mysqlIntrospect.d.ts +114 -0
- package/cli/commands/mysqlPushUtils.d.ts +17 -0
- package/cli/commands/sqlitePushUtils.d.ts +21 -0
- package/drivers/index.d.ts +14 -0
- package/mysql-introspect.d.ts +4 -0
- package/package.json +1 -1
- package/serializer/mysqlImports.d.ts +5 -0
- package/serializer/mysqlSerializer.d.ts +2 -2
- package/serializer/sqliteImports.d.ts +4 -0
- package/utils.d.ts +22 -0
- package/utils.js +826 -74
package/bin.cjs
CHANGED
@@ -11406,14 +11406,30 @@ var init_utils = __esm({
|
|
11406
11406
|
// src/serializer/mysqlImports.ts
|
11407
11407
|
var mysqlImports_exports = {};
|
11408
11408
|
__export(mysqlImports_exports, {
|
11409
|
+
prepareFromExports: () => prepareFromExports,
|
11409
11410
|
prepareFromMySqlImports: () => prepareFromMySqlImports
|
11410
11411
|
});
|
11411
|
-
var import_mysql_core, import_drizzle_orm, prepareFromMySqlImports;
|
11412
|
+
var import_mysql_core, import_drizzle_orm, prepareFromExports, prepareFromMySqlImports;
|
11412
11413
|
var init_mysqlImports = __esm({
|
11413
11414
|
"src/serializer/mysqlImports.ts"() {
|
11414
11415
|
import_mysql_core = require("drizzle-orm/mysql-core");
|
11415
11416
|
import_drizzle_orm = require("drizzle-orm");
|
11416
11417
|
init_utils();
|
11418
|
+
prepareFromExports = (exports) => {
|
11419
|
+
const tables = [];
|
11420
|
+
const enums = [];
|
11421
|
+
const schemas = [];
|
11422
|
+
const i0values = Object.values(exports);
|
11423
|
+
i0values.forEach((t) => {
|
11424
|
+
if ((0, import_drizzle_orm.is)(t, import_mysql_core.MySqlTable)) {
|
11425
|
+
tables.push(t);
|
11426
|
+
}
|
11427
|
+
if ((0, import_drizzle_orm.is)(t, import_mysql_core.MySqlSchema)) {
|
11428
|
+
schemas.push(t);
|
11429
|
+
}
|
11430
|
+
});
|
11431
|
+
return { tables, enums, schemas };
|
11432
|
+
};
|
11417
11433
|
prepareFromMySqlImports = async (imports) => {
|
11418
11434
|
const tables = [];
|
11419
11435
|
const enums = [];
|
@@ -11422,15 +11438,10 @@ var init_mysqlImports = __esm({
|
|
11422
11438
|
for (let i = 0; i < imports.length; i++) {
|
11423
11439
|
const it = imports[i];
|
11424
11440
|
const i0 = require(`${it}`);
|
11425
|
-
const
|
11426
|
-
|
11427
|
-
|
11428
|
-
|
11429
|
-
}
|
11430
|
-
if ((0, import_drizzle_orm.is)(t, import_mysql_core.MySqlSchema)) {
|
11431
|
-
schemas.push(t);
|
11432
|
-
}
|
11433
|
-
});
|
11441
|
+
const prepared = prepareFromExports(i0);
|
11442
|
+
tables.push(...prepared.tables);
|
11443
|
+
enums.push(...prepared.enums);
|
11444
|
+
schemas.push(...prepared.schemas);
|
11434
11445
|
}
|
11435
11446
|
unregister();
|
11436
11447
|
return { tables, enums, schemas };
|
@@ -11774,21 +11785,20 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
11774
11785
|
fromDatabase = async (db, inputSchema, tablesFilter = (table4) => true, progressCallback) => {
|
11775
11786
|
const result = {};
|
11776
11787
|
const internals = { tables: {} };
|
11777
|
-
const columns = await db.
|
11788
|
+
const columns = await db.query(`select * from information_schema.columns
|
11778
11789
|
where table_schema = '${inputSchema}' and table_name != '__drizzle_migrations'
|
11779
11790
|
order by table_name, ordinal_position;`);
|
11780
|
-
const response = columns
|
11791
|
+
const response = columns;
|
11781
11792
|
const schemas = [];
|
11782
11793
|
let columnsCount = 0;
|
11783
11794
|
let tablesCount = /* @__PURE__ */ new Set();
|
11784
11795
|
let indexesCount = 0;
|
11785
11796
|
let foreignKeysCount = 0;
|
11786
|
-
const idxs = await db.
|
11797
|
+
const idxs = await db.query(
|
11787
11798
|
`select * from INFORMATION_SCHEMA.STATISTICS
|
11788
|
-
WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA =
|
11789
|
-
[inputSchema]
|
11799
|
+
WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = '${inputSchema}' and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`
|
11790
11800
|
);
|
11791
|
-
const idxRows = idxs
|
11801
|
+
const idxRows = idxs;
|
11792
11802
|
for (const column7 of response) {
|
11793
11803
|
if (!tablesFilter(column7["TABLE_NAME"]))
|
11794
11804
|
continue;
|
@@ -11881,19 +11891,18 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
11881
11891
|
result[tableName].columns[columnName] = newColumn;
|
11882
11892
|
}
|
11883
11893
|
}
|
11884
|
-
const tablePks = await db.
|
11894
|
+
const tablePks = await db.query(
|
11885
11895
|
`SELECT table_name, column_name, ordinal_position
|
11886
11896
|
FROM information_schema.table_constraints t
|
11887
11897
|
LEFT JOIN information_schema.key_column_usage k
|
11888
11898
|
USING(constraint_name,table_schema,table_name)
|
11889
11899
|
WHERE t.constraint_type='PRIMARY KEY'
|
11890
11900
|
and table_name != '__drizzle_migrations'
|
11891
|
-
AND t.table_schema =
|
11892
|
-
ORDER BY ordinal_position
|
11893
|
-
[inputSchema]
|
11901
|
+
AND t.table_schema = '${inputSchema}'
|
11902
|
+
ORDER BY ordinal_position`
|
11894
11903
|
);
|
11895
11904
|
const tableToPk = {};
|
11896
|
-
const tableToPkRows = tablePks
|
11905
|
+
const tableToPkRows = tablePks;
|
11897
11906
|
for (const tableToPkRow of tableToPkRows) {
|
11898
11907
|
const tableName = tableToPkRow["TABLE_NAME"];
|
11899
11908
|
const columnName = tableToPkRow["COLUMN_NAME"];
|
@@ -11920,15 +11929,14 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
11920
11929
|
progressCallback("tables", tablesCount.size, "done");
|
11921
11930
|
}
|
11922
11931
|
try {
|
11923
|
-
const fks = await db.
|
11932
|
+
const fks = await db.query(
|
11924
11933
|
`SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,information_schema.referential_constraints.UPDATE_RULE, information_schema.referential_constraints.DELETE_RULE
|
11925
11934
|
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
11926
11935
|
LEFT JOIN information_schema.referential_constraints on information_schema.referential_constraints.constraint_name = information_schema.KEY_COLUMN_USAGE.CONSTRAINT_NAME
|
11927
|
-
WHERE INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA =
|
11928
|
-
|
11929
|
-
[inputSchema]
|
11936
|
+
WHERE INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA = '${inputSchema}' AND INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME != 'PRIMARY' and INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME is not null;
|
11937
|
+
`
|
11930
11938
|
);
|
11931
|
-
const fkRows = fks
|
11939
|
+
const fkRows = fks;
|
11932
11940
|
for (const fkRow of fkRows) {
|
11933
11941
|
foreignKeysCount += 1;
|
11934
11942
|
if (progressCallback) {
|
@@ -12036,16 +12044,16 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
12036
12044
|
// src/serializer/pgImports.ts
|
12037
12045
|
var pgImports_exports = {};
|
12038
12046
|
__export(pgImports_exports, {
|
12039
|
-
prepareFromExports: () =>
|
12047
|
+
prepareFromExports: () => prepareFromExports2,
|
12040
12048
|
prepareFromPgImports: () => prepareFromPgImports
|
12041
12049
|
});
|
12042
|
-
var import_pg_core, import_drizzle_orm4,
|
12050
|
+
var import_pg_core, import_drizzle_orm4, prepareFromExports2, prepareFromPgImports;
|
12043
12051
|
var init_pgImports = __esm({
|
12044
12052
|
"src/serializer/pgImports.ts"() {
|
12045
12053
|
import_pg_core = require("drizzle-orm/pg-core");
|
12046
12054
|
import_drizzle_orm4 = require("drizzle-orm");
|
12047
12055
|
init_utils();
|
12048
|
-
|
12056
|
+
prepareFromExports2 = (exports) => {
|
12049
12057
|
const tables = [];
|
12050
12058
|
const enums = [];
|
12051
12059
|
const schemas = [];
|
@@ -12072,10 +12080,10 @@ var init_pgImports = __esm({
|
|
12072
12080
|
for (let i = 0; i < imports.length; i++) {
|
12073
12081
|
const it = imports[i];
|
12074
12082
|
const i0 = require(`${it}`);
|
12075
|
-
const prepared =
|
12076
|
-
tables
|
12077
|
-
enums
|
12078
|
-
schemas
|
12083
|
+
const prepared = prepareFromExports2(i0);
|
12084
|
+
tables.push(...prepared.tables);
|
12085
|
+
enums.push(...prepared.enums);
|
12086
|
+
schemas.push(...prepared.schemas);
|
12079
12087
|
}
|
12080
12088
|
unregister();
|
12081
12089
|
return { tables, enums, schemas };
|
@@ -12809,14 +12817,26 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12809
12817
|
// src/serializer/sqliteImports.ts
|
12810
12818
|
var sqliteImports_exports = {};
|
12811
12819
|
__export(sqliteImports_exports, {
|
12820
|
+
prepareFromExports: () => prepareFromExports3,
|
12812
12821
|
prepareFromSqliteImports: () => prepareFromSqliteImports
|
12813
12822
|
});
|
12814
|
-
var import_sqlite_core, import_drizzle_orm6, prepareFromSqliteImports;
|
12823
|
+
var import_sqlite_core, import_drizzle_orm6, prepareFromExports3, prepareFromSqliteImports;
|
12815
12824
|
var init_sqliteImports = __esm({
|
12816
12825
|
"src/serializer/sqliteImports.ts"() {
|
12817
12826
|
import_sqlite_core = require("drizzle-orm/sqlite-core");
|
12818
12827
|
import_drizzle_orm6 = require("drizzle-orm");
|
12819
12828
|
init_utils();
|
12829
|
+
prepareFromExports3 = (exports) => {
|
12830
|
+
const tables = [];
|
12831
|
+
const enums = [];
|
12832
|
+
const i0values = Object.values(exports);
|
12833
|
+
i0values.forEach((t) => {
|
12834
|
+
if ((0, import_drizzle_orm6.is)(t, import_sqlite_core.SQLiteTable)) {
|
12835
|
+
tables.push(t);
|
12836
|
+
}
|
12837
|
+
});
|
12838
|
+
return { tables, enums };
|
12839
|
+
};
|
12820
12840
|
prepareFromSqliteImports = async (imports) => {
|
12821
12841
|
const tables = [];
|
12822
12842
|
const enums = [];
|
@@ -12824,12 +12844,9 @@ var init_sqliteImports = __esm({
|
|
12824
12844
|
for (let i = 0; i < imports.length; i++) {
|
12825
12845
|
const it = imports[i];
|
12826
12846
|
const i0 = require(`${it}`);
|
12827
|
-
const
|
12828
|
-
|
12829
|
-
|
12830
|
-
tables.push(t);
|
12831
|
-
}
|
12832
|
-
});
|
12847
|
+
const prepared = prepareFromExports3(i0);
|
12848
|
+
tables.push(...prepared.tables);
|
12849
|
+
enums.push(...prepared.enums);
|
12833
12850
|
}
|
12834
12851
|
unregister();
|
12835
12852
|
return { tables, enums };
|
@@ -25294,11 +25311,14 @@ var drivers_exports = {};
|
|
25294
25311
|
__export(drivers_exports, {
|
25295
25312
|
BetterSqlite: () => BetterSqlite,
|
25296
25313
|
DrizzleDbClient: () => DrizzleDbClient,
|
25314
|
+
DrizzleORMMySQLClient: () => DrizzleORMMySQLClient,
|
25297
25315
|
DrizzleORMPgClient: () => DrizzleORMPgClient,
|
25316
|
+
DrizzleORMSQLiteClient: () => DrizzleORMSQLiteClient,
|
25317
|
+
MySQL2Client: () => MySQL2Client,
|
25298
25318
|
PgPostgres: () => PgPostgres,
|
25299
25319
|
TursoSqlite: () => TursoSqlite
|
25300
25320
|
});
|
25301
|
-
var import_drizzle_orm8, DrizzleDbClient, DrizzleORMPgClient, BetterSqlite, TursoSqlite, PgPostgres;
|
25321
|
+
var import_drizzle_orm8, DrizzleDbClient, DrizzleORMPgClient, DrizzleORMMySQLClient, DrizzleORMSQLiteClient, BetterSqlite, MySQL2Client, TursoSqlite, PgPostgres;
|
25302
25322
|
var init_drivers = __esm({
|
25303
25323
|
"src/drivers/index.ts"() {
|
25304
25324
|
import_drizzle_orm8 = require("drizzle-orm");
|
@@ -25317,6 +25337,24 @@ var init_drivers = __esm({
|
|
25317
25337
|
return res.rows;
|
25318
25338
|
}
|
25319
25339
|
};
|
25340
|
+
DrizzleORMMySQLClient = class extends DrizzleDbClient {
|
25341
|
+
async query(query, values) {
|
25342
|
+
const res = await this.db.execute(import_drizzle_orm8.sql.raw(query));
|
25343
|
+
return res[0];
|
25344
|
+
}
|
25345
|
+
async run(query) {
|
25346
|
+
await this.db.execute(import_drizzle_orm8.sql.raw(query));
|
25347
|
+
}
|
25348
|
+
};
|
25349
|
+
DrizzleORMSQLiteClient = class extends DrizzleDbClient {
|
25350
|
+
async query(query, values) {
|
25351
|
+
const res = this.db.all(import_drizzle_orm8.sql.raw(query));
|
25352
|
+
return res;
|
25353
|
+
}
|
25354
|
+
async run(query) {
|
25355
|
+
this.db.run(import_drizzle_orm8.sql.raw(query));
|
25356
|
+
}
|
25357
|
+
};
|
25320
25358
|
BetterSqlite = class extends DrizzleDbClient {
|
25321
25359
|
async run(query) {
|
25322
25360
|
this.db.prepare(query).run();
|
@@ -25325,6 +25363,15 @@ var init_drivers = __esm({
|
|
25325
25363
|
return this.db.prepare(query).all();
|
25326
25364
|
}
|
25327
25365
|
};
|
25366
|
+
MySQL2Client = class extends DrizzleDbClient {
|
25367
|
+
async run(query) {
|
25368
|
+
await this.db.execute(query);
|
25369
|
+
}
|
25370
|
+
async query(query) {
|
25371
|
+
const res = await this.db.execute(query);
|
25372
|
+
return res[0];
|
25373
|
+
}
|
25374
|
+
};
|
25328
25375
|
TursoSqlite = class extends DrizzleDbClient {
|
25329
25376
|
async run(query) {
|
25330
25377
|
await this.db.execute(query);
|
@@ -58440,716 +58487,1555 @@ var init_studioUtils = __esm({
|
|
58440
58487
|
}
|
58441
58488
|
});
|
58442
58489
|
|
58443
|
-
// src/
|
58444
|
-
var
|
58445
|
-
var
|
58446
|
-
"src/
|
58447
|
-
import_fs8 = require("fs");
|
58448
|
-
init_views();
|
58449
|
-
init_mysqlSchema();
|
58450
|
-
init_pgSchema();
|
58451
|
-
init_sqliteSchema();
|
58490
|
+
// src/cli/commands/sqlitePushUtils.ts
|
58491
|
+
var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
|
58492
|
+
var init_sqlitePushUtils = __esm({
|
58493
|
+
"src/cli/commands/sqlitePushUtils.ts"() {
|
58452
58494
|
init_source();
|
58453
|
-
|
58454
|
-
|
58455
|
-
|
58456
|
-
|
58457
|
-
|
58458
|
-
|
58459
|
-
|
58460
|
-
|
58461
|
-
|
58462
|
-
|
58463
|
-
|
58464
|
-
|
58465
|
-
init_studioUtils();
|
58466
|
-
init_pgConnect();
|
58467
|
-
assertV1OutFolder = (out, dialect6) => {
|
58468
|
-
if (!(0, import_fs8.existsSync)(out))
|
58469
|
-
return;
|
58470
|
-
const oldMigrationFolders = (0, import_fs8.readdirSync)(out).filter(
|
58471
|
-
(it) => it.length === 14 && /^\d+$/.test(it)
|
58495
|
+
init_sqliteSchema();
|
58496
|
+
init_sqlgenerator();
|
58497
|
+
_moveDataStatements = (tableName, json, dataLoss = false) => {
|
58498
|
+
const statements = [];
|
58499
|
+
statements.push(
|
58500
|
+
new SqliteRenameTableConvertor().convert({
|
58501
|
+
type: "rename_table",
|
58502
|
+
tableNameFrom: tableName,
|
58503
|
+
tableNameTo: `__old_push_${tableName}`,
|
58504
|
+
fromSchema: "",
|
58505
|
+
toSchema: ""
|
58506
|
+
})
|
58472
58507
|
);
|
58473
|
-
|
58474
|
-
|
58475
|
-
|
58476
|
-
|
58477
|
-
|
58508
|
+
const tableColumns = Object.values(json.tables[tableName].columns);
|
58509
|
+
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
58510
|
+
const compositePKs = Object.values(
|
58511
|
+
json.tables[tableName].compositePrimaryKeys
|
58512
|
+
).map((it) => SQLiteSquasher.unsquashPK(it));
|
58513
|
+
statements.push(
|
58514
|
+
new SQLiteCreateTableConvertor().convert({
|
58515
|
+
type: "sqlite_create_table",
|
58516
|
+
tableName,
|
58517
|
+
columns: tableColumns,
|
58518
|
+
referenceData,
|
58519
|
+
compositePKs
|
58520
|
+
})
|
58521
|
+
);
|
58522
|
+
if (!dataLoss) {
|
58523
|
+
statements.push(
|
58524
|
+
`INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
|
58478
58525
|
);
|
58479
|
-
process.exit(1);
|
58480
58526
|
}
|
58481
|
-
|
58482
|
-
|
58483
|
-
|
58484
|
-
|
58485
|
-
|
58486
|
-
|
58487
|
-
};
|
58488
|
-
};
|
58489
|
-
snapshotsPriorV4 = (out) => {
|
58490
|
-
const oldMigrationFolders = (0, import_fs8.readdirSync)(out).filter(
|
58491
|
-
(it) => it.length === 14 && /^\d+$/.test(it)
|
58527
|
+
statements.push(
|
58528
|
+
new SQLiteDropTableConvertor().convert({
|
58529
|
+
type: "drop_table",
|
58530
|
+
tableName: `__old_push_${tableName}`,
|
58531
|
+
schema: ""
|
58532
|
+
})
|
58492
58533
|
);
|
58493
|
-
|
58494
|
-
|
58495
|
-
|
58496
|
-
|
58497
|
-
|
58498
|
-
|
58499
|
-
|
58500
|
-
|
58501
|
-
|
58502
|
-
const journalPath = (0, import_path5.join)(meta, "_journal.json");
|
58503
|
-
if (!(0, import_fs8.existsSync)((0, import_path5.join)(out, "meta"))) {
|
58504
|
-
(0, import_fs8.mkdirSync)(meta, { recursive: true });
|
58505
|
-
(0, import_fs8.writeFileSync)(journalPath, JSON.stringify(dryJournal(dialect6)));
|
58534
|
+
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
58535
|
+
statements.push(
|
58536
|
+
new CreateSqliteIndexConvertor().convert({
|
58537
|
+
type: "create_index",
|
58538
|
+
tableName,
|
58539
|
+
schema: "",
|
58540
|
+
data: idx
|
58541
|
+
})
|
58542
|
+
);
|
58506
58543
|
}
|
58507
|
-
|
58508
|
-
const snapshots = (0, import_fs8.readdirSync)(meta).filter((it) => !it.startsWith("_")).map((it) => (0, import_path5.join)(meta, it));
|
58509
|
-
snapshots.sort();
|
58510
|
-
return { meta, snapshots, journal };
|
58544
|
+
return statements;
|
58511
58545
|
};
|
58512
|
-
|
58513
|
-
const
|
58514
|
-
|
58515
|
-
|
58516
|
-
|
58517
|
-
|
58546
|
+
getOldTableName = (tableName, meta) => {
|
58547
|
+
for (const key of Object.keys(meta.tables)) {
|
58548
|
+
const value = meta.tables[key];
|
58549
|
+
if (`"${tableName}"` === value) {
|
58550
|
+
return key.substring(1, key.length - 1);
|
58551
|
+
}
|
58552
|
+
}
|
58553
|
+
return tableName;
|
58518
58554
|
};
|
58519
|
-
|
58520
|
-
|
58521
|
-
|
58522
|
-
|
58523
|
-
|
58524
|
-
|
58525
|
-
case "mysql":
|
58526
|
-
return { validator: backwardCompatibleMysqlSchema, version: 5 };
|
58555
|
+
getNewTableName = (tableName, meta) => {
|
58556
|
+
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
58557
|
+
return meta.tables[`"${tableName}"`].substring(
|
58558
|
+
1,
|
58559
|
+
meta.tables[`"${tableName}"`].length - 1
|
58560
|
+
);
|
58527
58561
|
}
|
58562
|
+
return tableName;
|
58528
58563
|
};
|
58529
|
-
|
58530
|
-
|
58531
|
-
|
58532
|
-
|
58533
|
-
|
58534
|
-
|
58535
|
-
|
58536
|
-
|
58537
|
-
|
58538
|
-
|
58539
|
-
|
58564
|
+
logSuggestionsAndReturn = async ({
|
58565
|
+
connection,
|
58566
|
+
statements,
|
58567
|
+
json1,
|
58568
|
+
json2,
|
58569
|
+
meta
|
58570
|
+
}) => {
|
58571
|
+
let shouldAskForApprove = false;
|
58572
|
+
const statementsToExecute = [];
|
58573
|
+
const infoToPrint = [];
|
58574
|
+
const tablesToRemove = [];
|
58575
|
+
const columnsToRemove = [];
|
58576
|
+
const schemasToRemove = [];
|
58577
|
+
const tablesToTruncate = [];
|
58578
|
+
const tablesContext = {};
|
58579
|
+
for (const statement of statements) {
|
58580
|
+
if (statement.type === "drop_table") {
|
58581
|
+
const res = await connection.query(
|
58582
|
+
`select count(*) as count from \`${statement.tableName}\``
|
58583
|
+
);
|
58584
|
+
const count = Number(res[0].count);
|
58585
|
+
if (count > 0) {
|
58586
|
+
infoToPrint.push(
|
58587
|
+
`\xB7 You're about to delete ${source_default.underline(
|
58588
|
+
statement.tableName
|
58589
|
+
)} table with ${count} items`
|
58540
58590
|
);
|
58541
|
-
|
58591
|
+
tablesToRemove.push(statement.tableName);
|
58592
|
+
shouldAskForApprove = true;
|
58542
58593
|
}
|
58543
|
-
const
|
58544
|
-
|
58545
|
-
|
58546
|
-
|
58594
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
58595
|
+
statementsToExecute.push(stmnt);
|
58596
|
+
} else if (statement.type === "alter_table_drop_column") {
|
58597
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
58598
|
+
const columnIsPartOfPk = Object.values(
|
58599
|
+
json1.tables[newTableName].compositePrimaryKeys
|
58600
|
+
).find(
|
58601
|
+
(c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName)
|
58602
|
+
);
|
58603
|
+
const columnIsPartOfIndex = Object.values(
|
58604
|
+
json1.tables[newTableName].indexes
|
58605
|
+
).find(
|
58606
|
+
(c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName)
|
58607
|
+
);
|
58608
|
+
const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
|
58609
|
+
const columnIsPartOfFk = Object.values(
|
58610
|
+
json1.tables[newTableName].foreignKeys
|
58611
|
+
).find(
|
58612
|
+
(t) => SQLiteSquasher.unsquashFK(t).columnsFrom.includes(statement.columnName)
|
58613
|
+
);
|
58614
|
+
const res = await connection.query(
|
58615
|
+
`select count(*) as count from \`${newTableName}\``
|
58616
|
+
);
|
58617
|
+
const count = Number(res[0].count);
|
58618
|
+
if (count > 0) {
|
58619
|
+
infoToPrint.push(
|
58620
|
+
`\xB7 You're about to delete ${source_default.underline(
|
58621
|
+
statement.columnName
|
58622
|
+
)} column in ${newTableName} table with ${count} items`
|
58623
|
+
);
|
58624
|
+
columnsToRemove.push(`${newTableName}_${statement.columnName}`);
|
58625
|
+
shouldAskForApprove = true;
|
58547
58626
|
}
|
58548
|
-
|
58549
|
-
|
58550
|
-
|
58551
|
-
|
58627
|
+
if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
|
58628
|
+
tablesContext[newTableName] = [
|
58629
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
58630
|
+
];
|
58631
|
+
const tablesReferncingCurrent = [];
|
58632
|
+
for (const table4 of Object.values(json1.tables)) {
|
58633
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
58634
|
+
(t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName
|
58635
|
+
).map((t) => SQLiteSquasher.unsquashFK(t).tableFrom);
|
58636
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
58637
|
+
}
|
58638
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
58639
|
+
for (const table4 of uniqueTableRefs) {
|
58640
|
+
if (typeof tablesContext[table4] === "undefined") {
|
58641
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
58642
|
+
}
|
58643
|
+
}
|
58644
|
+
} else {
|
58645
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
58646
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
58647
|
+
statementsToExecute.push(stmnt);
|
58648
|
+
}
|
58649
|
+
}
|
58650
|
+
} else if (statement.type === "sqlite_alter_table_add_column") {
|
58651
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
58652
|
+
if (statement.column.notNull && !statement.column.default) {
|
58653
|
+
const res = await connection.query(
|
58654
|
+
`select count(*) as count from \`${newTableName}\``
|
58655
|
+
);
|
58656
|
+
const count = Number(res[0].count);
|
58657
|
+
if (count > 0) {
|
58658
|
+
infoToPrint.push(
|
58659
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
58660
|
+
statement.column.name
|
58661
|
+
)} column without default value, which contains ${count} items`
|
58662
|
+
);
|
58663
|
+
tablesToTruncate.push(newTableName);
|
58664
|
+
statementsToExecute.push(`delete from ${newTableName};`);
|
58665
|
+
shouldAskForApprove = true;
|
58666
|
+
}
|
58667
|
+
}
|
58668
|
+
if (statement.column.primaryKey) {
|
58669
|
+
tablesContext[newTableName] = [
|
58670
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
58671
|
+
];
|
58672
|
+
const tablesReferncingCurrent = [];
|
58673
|
+
for (const table4 of Object.values(json1.tables)) {
|
58674
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
58675
|
+
(t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName
|
58676
|
+
).map((t) => SQLiteSquasher.unsquashFK(t).tableFrom);
|
58677
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
58678
|
+
}
|
58679
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
58680
|
+
for (const table4 of uniqueTableRefs) {
|
58681
|
+
if (typeof tablesContext[table4] === "undefined") {
|
58682
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
58683
|
+
}
|
58684
|
+
}
|
58685
|
+
} else {
|
58686
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
58687
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
58688
|
+
statementsToExecute.push(stmnt);
|
58689
|
+
}
|
58690
|
+
}
|
58691
|
+
} else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk") {
|
58692
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
58693
|
+
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
58694
|
+
const res = await connection.query(
|
58695
|
+
`select count(*) as count from \`${newTableName}\``
|
58696
|
+
);
|
58697
|
+
const count = Number(res[0].count);
|
58698
|
+
if (count > 0) {
|
58699
|
+
infoToPrint.push(
|
58700
|
+
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
58701
|
+
statement.columnName
|
58702
|
+
)} column without default value, which contains ${count} items`
|
58703
|
+
);
|
58704
|
+
tablesToTruncate.push(newTableName);
|
58705
|
+
shouldAskForApprove = true;
|
58706
|
+
}
|
58707
|
+
tablesContext[newTableName] = _moveDataStatements(
|
58708
|
+
statement.tableName,
|
58709
|
+
json2,
|
58710
|
+
true
|
58711
|
+
);
|
58712
|
+
} else {
|
58713
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
58714
|
+
tablesContext[newTableName] = _moveDataStatements(
|
58715
|
+
statement.tableName,
|
58716
|
+
json2
|
58717
|
+
);
|
58718
|
+
}
|
58719
|
+
}
|
58720
|
+
const tablesReferncingCurrent = [];
|
58721
|
+
for (const table4 of Object.values(json1.tables)) {
|
58722
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName).map((t) => {
|
58723
|
+
return getNewTableName(
|
58724
|
+
SQLiteSquasher.unsquashFK(t).tableFrom,
|
58725
|
+
meta
|
58726
|
+
);
|
58727
|
+
});
|
58728
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
58729
|
+
}
|
58730
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
58731
|
+
for (const table4 of uniqueTableRefs) {
|
58732
|
+
if (typeof tablesContext[table4] === "undefined") {
|
58733
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
58734
|
+
}
|
58735
|
+
}
|
58736
|
+
} else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
|
58737
|
+
const fk4 = SQLiteSquasher.unsquashFK(statement.data);
|
58738
|
+
if (typeof tablesContext[statement.tableName] === "undefined") {
|
58739
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
58740
|
+
statement.tableName,
|
58741
|
+
json2
|
58742
|
+
);
|
58743
|
+
}
|
58744
|
+
} else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
|
58745
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
58746
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
58747
|
+
tablesContext[newTableName] = _moveDataStatements(
|
58748
|
+
statement.tableName,
|
58749
|
+
json2
|
58750
|
+
);
|
58751
|
+
}
|
58752
|
+
} else {
|
58753
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
58754
|
+
if (typeof stmnt !== "undefined") {
|
58755
|
+
statementsToExecute.push(stmnt);
|
58552
58756
|
}
|
58553
|
-
const idEntry = accum.idsMap[snapshot["prevId"]] ?? {
|
58554
|
-
parent: it,
|
58555
|
-
snapshots: []
|
58556
|
-
};
|
58557
|
-
idEntry.snapshots.push(it);
|
58558
|
-
accum.idsMap[snapshot["prevId"]] = idEntry;
|
58559
|
-
return accum;
|
58560
|
-
},
|
58561
|
-
{
|
58562
|
-
malformed: [],
|
58563
|
-
nonLatest: [],
|
58564
|
-
idToNameMap: {},
|
58565
|
-
idsMap: {},
|
58566
|
-
rawMap: {}
|
58567
58757
|
}
|
58568
|
-
);
|
58569
|
-
return result;
|
58570
|
-
};
|
58571
|
-
prepareMigrationFolder = (outFolder = "drizzle", dialect6) => {
|
58572
|
-
const { snapshots, journal } = prepareOutFolder2(outFolder, dialect6);
|
58573
|
-
const report = validateWithReport(snapshots, dialect6);
|
58574
|
-
if (report.nonLatest.length > 0) {
|
58575
|
-
console.log(
|
58576
|
-
report.nonLatest.map((it) => {
|
58577
|
-
return `${it}/snapshot.json is not of the latest version`;
|
58578
|
-
}).concat(`Run ${source_default.green.bold(`drizzle-kit up:${dialect6}`)}`).join("\n")
|
58579
|
-
);
|
58580
|
-
process.exit(0);
|
58581
|
-
}
|
58582
|
-
if (report.malformed.length) {
|
58583
|
-
const message2 = report.malformed.map((it) => {
|
58584
|
-
return `${it} data is malformed`;
|
58585
|
-
}).join("\n");
|
58586
|
-
console.log(message2);
|
58587
|
-
}
|
58588
|
-
const collisionEntries = Object.entries(report.idsMap).filter(
|
58589
|
-
(it) => it[1].snapshots.length > 1
|
58590
|
-
);
|
58591
|
-
const message = collisionEntries.map((it) => {
|
58592
|
-
const data = it[1];
|
58593
|
-
return `[${data.snapshots.join(
|
58594
|
-
", "
|
58595
|
-
)}] are pointing to a parent snapshot: ${data.parent}/snapshot.json which is a collision.`;
|
58596
|
-
}).join("\n").trim();
|
58597
|
-
if (message) {
|
58598
|
-
console.log(source_default.red.bold("Error:"), message);
|
58599
58758
|
}
|
58600
|
-
const
|
58601
|
-
|
58602
|
-
process.exit(0);
|
58759
|
+
for (const context of Object.values(tablesContext)) {
|
58760
|
+
statementsToExecute.push(...context);
|
58603
58761
|
}
|
58604
|
-
return {
|
58605
|
-
|
58606
|
-
|
58607
|
-
|
58608
|
-
|
58609
|
-
|
58610
|
-
|
58762
|
+
return {
|
58763
|
+
statementsToExecute,
|
58764
|
+
shouldAskForApprove,
|
58765
|
+
infoToPrint,
|
58766
|
+
columnsToRemove: [...new Set(columnsToRemove)],
|
58767
|
+
schemasToRemove: [...new Set(schemasToRemove)],
|
58768
|
+
tablesToTruncate: [...new Set(tablesToTruncate)],
|
58769
|
+
tablesToRemove: [...new Set(tablesToRemove)]
|
58611
58770
|
};
|
58612
|
-
schemas.forEach((it) => {
|
58613
|
-
const from = schemaRenameKey(it.from);
|
58614
|
-
const to = schemaRenameKey(it.to);
|
58615
|
-
_meta.schemas[from] = to;
|
58616
|
-
});
|
58617
|
-
tables.forEach((it) => {
|
58618
|
-
const from = tableRenameKey(it.from);
|
58619
|
-
const to = tableRenameKey(it.to);
|
58620
|
-
_meta.tables[from] = to;
|
58621
|
-
});
|
58622
|
-
columns.forEach((it) => {
|
58623
|
-
const from = columnRenameKey(it.from.table, it.from.schema, it.from.column);
|
58624
|
-
const to = columnRenameKey(it.to.table, it.to.schema, it.to.column);
|
58625
|
-
_meta.columns[from] = to;
|
58626
|
-
});
|
58627
|
-
return _meta;
|
58628
|
-
};
|
58629
|
-
schemaRenameKey = (it) => {
|
58630
|
-
return it;
|
58631
|
-
};
|
58632
|
-
tableRenameKey = (it) => {
|
58633
|
-
const out = it.schema ? `"${it.schema}"."${it.name}"` : `"${it.name}"`;
|
58634
|
-
return out;
|
58635
|
-
};
|
58636
|
-
columnRenameKey = (table4, schema4, column7) => {
|
58637
|
-
const out = schema4 ? `"${schema4}"."${table4}"."${column7}"` : `"${table4}"."${column7}"`;
|
58638
|
-
return out;
|
58639
58771
|
};
|
58640
58772
|
}
|
58641
58773
|
});
|
58642
58774
|
|
58643
|
-
// src/
|
58644
|
-
var
|
58645
|
-
var
|
58646
|
-
"src/
|
58647
|
-
|
58648
|
-
|
58649
|
-
|
58650
|
-
|
58651
|
-
|
58652
|
-
|
58653
|
-
|
58654
|
-
|
58655
|
-
|
58656
|
-
|
58657
|
-
|
58658
|
-
|
58659
|
-
|
58660
|
-
|
58661
|
-
|
58662
|
-
|
58663
|
-
|
58664
|
-
|
58665
|
-
|
58666
|
-
|
58667
|
-
|
58668
|
-
|
58775
|
+
// src/mysql-introspect.ts
|
58776
|
+
var mysqlImportsList, objToStatement23, timeConfig2, binaryConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, mapColumnDefault2, mapColumnDefaultForJson, column6, createTableColumns3, createTableIndexes3, createTableUniques3, createTablePKs3, createTableFKs3;
|
58777
|
+
var init_mysql_introspect = __esm({
|
58778
|
+
"src/mysql-introspect.ts"() {
|
58779
|
+
init_utils2();
|
58780
|
+
init_mysqlSerializer();
|
58781
|
+
mysqlImportsList = /* @__PURE__ */ new Set([
|
58782
|
+
"mysqlTable",
|
58783
|
+
"mysqlEnum",
|
58784
|
+
"bigint",
|
58785
|
+
"binary",
|
58786
|
+
"boolean",
|
58787
|
+
"char",
|
58788
|
+
"date",
|
58789
|
+
"datetime",
|
58790
|
+
"decimal",
|
58791
|
+
"double",
|
58792
|
+
"float",
|
58793
|
+
"int",
|
58794
|
+
"json",
|
58795
|
+
"mediumint",
|
58796
|
+
"real",
|
58797
|
+
"serial",
|
58798
|
+
"smallint",
|
58799
|
+
"text",
|
58800
|
+
"tinytext",
|
58801
|
+
"mediumtext",
|
58802
|
+
"longtext",
|
58803
|
+
"time",
|
58804
|
+
"timestamp",
|
58805
|
+
"tinyint",
|
58806
|
+
"varbinary",
|
58807
|
+
"varchar",
|
58808
|
+
"year",
|
58809
|
+
"enum"
|
58669
58810
|
]);
|
58670
|
-
|
58671
|
-
|
58672
|
-
|
58673
|
-
|
58674
|
-
|
58675
|
-
|
58676
|
-
|
58677
|
-
|
58678
|
-
|
58679
|
-
|
58680
|
-
|
58681
|
-
|
58682
|
-
|
58683
|
-
|
58684
|
-
|
58685
|
-
|
58686
|
-
|
58687
|
-
|
58688
|
-
|
58689
|
-
|
58690
|
-
|
58691
|
-
|
58692
|
-
|
58693
|
-
|
58694
|
-
|
58695
|
-
|
58696
|
-
|
58697
|
-
|
58698
|
-
|
58699
|
-
|
58700
|
-
|
58811
|
+
objToStatement23 = (json) => {
|
58812
|
+
json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
|
58813
|
+
const keys = Object.keys(json);
|
58814
|
+
if (keys.length === 0)
|
58815
|
+
return;
|
58816
|
+
let statement = "{ ";
|
58817
|
+
statement += keys.map((it) => `${it}: "${json[it]}"`).join(", ");
|
58818
|
+
statement += " }";
|
58819
|
+
return statement;
|
58820
|
+
};
|
58821
|
+
timeConfig2 = (json) => {
|
58822
|
+
json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
|
58823
|
+
const keys = Object.keys(json);
|
58824
|
+
if (keys.length === 0)
|
58825
|
+
return;
|
58826
|
+
let statement = "{ ";
|
58827
|
+
statement += keys.map((it) => `${it}: ${json[it]}`).join(", ");
|
58828
|
+
statement += " }";
|
58829
|
+
return statement;
|
58830
|
+
};
|
58831
|
+
binaryConfig = (json) => {
|
58832
|
+
json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
|
58833
|
+
const keys = Object.keys(json);
|
58834
|
+
if (keys.length === 0)
|
58835
|
+
return;
|
58836
|
+
let statement = "{ ";
|
58837
|
+
statement += keys.map((it) => `${it}: ${json[it]}`).join(", ");
|
58838
|
+
statement += " }";
|
58839
|
+
return statement;
|
58840
|
+
};
|
58841
|
+
importsPatch2 = {
|
58842
|
+
"double precision": "doublePrecision",
|
58843
|
+
"timestamp without time zone": "timestamp"
|
58844
|
+
};
|
58845
|
+
relations3 = /* @__PURE__ */ new Set();
|
58846
|
+
withCasing3 = (value, casing) => {
|
58847
|
+
if (typeof casing === "undefined") {
|
58848
|
+
return value;
|
58701
58849
|
}
|
58702
|
-
if (
|
58703
|
-
return
|
58704
|
-
success: true,
|
58705
|
-
action: "config"
|
58706
|
-
};
|
58850
|
+
if (casing === "camel") {
|
58851
|
+
return value.camelCase();
|
58707
58852
|
}
|
58708
|
-
return
|
58709
|
-
success: false,
|
58710
|
-
message: outputs.common.ambiguousParams(command),
|
58711
|
-
action: "error"
|
58712
|
-
};
|
58853
|
+
return value;
|
58713
58854
|
};
|
58714
|
-
|
58715
|
-
|
58716
|
-
|
58717
|
-
|
58718
|
-
|
58719
|
-
|
58720
|
-
|
58721
|
-
|
58722
|
-
|
58723
|
-
|
58724
|
-
|
58725
|
-
|
58726
|
-
|
58727
|
-
|
58728
|
-
|
58729
|
-
|
58730
|
-
|
58731
|
-
|
58732
|
-
|
58733
|
-
|
58734
|
-
|
58735
|
-
|
58736
|
-
|
58737
|
-
|
58738
|
-
|
58739
|
-
|
58740
|
-
|
58741
|
-
|
58742
|
-
|
58743
|
-
|
58744
|
-
|
58745
|
-
|
58746
|
-
|
58747
|
-
|
58748
|
-
|
58749
|
-
|
58750
|
-
|
58751
|
-
|
58752
|
-
|
58753
|
-
|
58754
|
-
|
58755
|
-
|
58756
|
-
|
58757
|
-
|
58758
|
-
|
58759
|
-
|
58760
|
-
}
|
58761
|
-
|
58762
|
-
|
58763
|
-
|
58855
|
+
schemaToTypeScript3 = (schema4, casing) => {
|
58856
|
+
Object.values(schema4.tables).forEach((table4) => {
|
58857
|
+
Object.values(table4.foreignKeys).forEach((fk4) => {
|
58858
|
+
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
58859
|
+
relations3.add(relation);
|
58860
|
+
});
|
58861
|
+
});
|
58862
|
+
const schemas = Object.fromEntries(
|
58863
|
+
Object.entries(schema4.schemas).map((it) => {
|
58864
|
+
return [it[0], withCasing3(it[1], casing)];
|
58865
|
+
})
|
58866
|
+
);
|
58867
|
+
const imports = Object.values(schema4.tables).reduce(
|
58868
|
+
(res, it) => {
|
58869
|
+
const idxImports = Object.values(it.indexes).map(
|
58870
|
+
(idx) => idx.isUnique ? "uniqueIndex" : "index"
|
58871
|
+
);
|
58872
|
+
const fkImpots = Object.values(it.foreignKeys).map((it2) => "foreignKey");
|
58873
|
+
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
58874
|
+
(it2) => "primaryKey"
|
58875
|
+
);
|
58876
|
+
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
58877
|
+
(it2) => "unique"
|
58878
|
+
);
|
58879
|
+
res.mysql.push(...idxImports);
|
58880
|
+
res.mysql.push(...fkImpots);
|
58881
|
+
res.mysql.push(...pkImports);
|
58882
|
+
res.mysql.push(...uniqueImports);
|
58883
|
+
const columnImports = Object.values(it.columns).map((col) => {
|
58884
|
+
let patched = importsPatch2[col.type] ?? col.type;
|
58885
|
+
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
58886
|
+
patched = patched.startsWith("char(") ? "char" : patched;
|
58887
|
+
patched = patched.startsWith("binary(") ? "binary" : patched;
|
58888
|
+
patched = patched.startsWith("decimal(") ? "decimal" : patched;
|
58889
|
+
patched = patched.startsWith("smallint(") ? "smallint" : patched;
|
58890
|
+
patched = patched.startsWith("enum(") ? "mysqlEnum" : patched;
|
58891
|
+
patched = patched.startsWith("datetime(") ? "datetime" : patched;
|
58892
|
+
patched = patched.startsWith("varbinary(") ? "varbinary" : patched;
|
58893
|
+
patched = patched.startsWith("int(") ? "int" : patched;
|
58894
|
+
return patched;
|
58895
|
+
}).filter((type) => {
|
58896
|
+
return mysqlImportsList.has(type);
|
58897
|
+
});
|
58898
|
+
res.mysql.push(...columnImports);
|
58899
|
+
return res;
|
58900
|
+
},
|
58901
|
+
{ mysql: [] }
|
58902
|
+
);
|
58903
|
+
const schemaStatements = Object.entries(schemas).map((it) => {
|
58904
|
+
return `export const ${it[1]} = mysqlSchema("${it[0]}");
|
58905
|
+
`;
|
58906
|
+
}).join();
|
58907
|
+
const tableStatements = Object.values(schema4.tables).map((table4) => {
|
58908
|
+
const tableSchema = schemas[table4.schema];
|
58909
|
+
const func = tableSchema ? tableSchema : "mysqlTable";
|
58910
|
+
let statement = "";
|
58911
|
+
if (imports.mysql.includes(withCasing3(table4.name, casing))) {
|
58912
|
+
statement = `// Table name is in conflict with ${withCasing3(
|
58913
|
+
table4.name,
|
58914
|
+
casing
|
58915
|
+
)} import.
|
58916
|
+
// Please change to any other name, that is not in imports list
|
58917
|
+
`;
|
58764
58918
|
}
|
58765
|
-
|
58766
|
-
|
58767
|
-
|
58919
|
+
statement += `export const ${withCasing3(table4.name, casing)} = ${func}("${table4.name}", {
|
58920
|
+
`;
|
58921
|
+
statement += createTableColumns3(
|
58922
|
+
Object.values(table4.columns),
|
58923
|
+
Object.values(table4.foreignKeys),
|
58924
|
+
casing,
|
58925
|
+
table4.name,
|
58926
|
+
schema4
|
58927
|
+
);
|
58928
|
+
statement += "}";
|
58929
|
+
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
58930
|
+
return it.columnsFrom.length > 1 || isSelf3(it);
|
58931
|
+
});
|
58932
|
+
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
58933
|
+
statement += ",\n";
|
58934
|
+
statement += "(table) => {\n";
|
58935
|
+
statement += " return {\n";
|
58936
|
+
statement += createTableIndexes3(
|
58937
|
+
table4.name,
|
58938
|
+
Object.values(table4.indexes),
|
58939
|
+
casing
|
58940
|
+
);
|
58941
|
+
statement += createTableFKs3(Object.values(filteredFKs), casing);
|
58942
|
+
statement += createTablePKs3(
|
58943
|
+
Object.values(table4.compositePrimaryKeys),
|
58944
|
+
casing
|
58945
|
+
);
|
58946
|
+
statement += createTableUniques3(
|
58947
|
+
Object.values(table4.uniqueConstraints),
|
58948
|
+
casing
|
58949
|
+
);
|
58950
|
+
statement += " }\n";
|
58951
|
+
statement += "}";
|
58768
58952
|
}
|
58769
|
-
|
58770
|
-
|
58953
|
+
statement += ");";
|
58954
|
+
return statement;
|
58955
|
+
});
|
58956
|
+
const uniqueMySqlImports = [
|
58957
|
+
"mysqlTable",
|
58958
|
+
"mysqlSchema",
|
58959
|
+
"AnyMySqlColumn",
|
58960
|
+
...new Set(imports.mysql)
|
58961
|
+
];
|
58962
|
+
let result = `import { ${uniqueMySqlImports.join(
|
58963
|
+
", "
|
58964
|
+
)} } from "drizzle-orm/mysql-core"
|
58965
|
+
import { sql } from "drizzle-orm"
|
58966
|
+
|
58967
|
+
`;
|
58968
|
+
result += schemaStatements;
|
58969
|
+
result += "\n";
|
58970
|
+
result += tableStatements.join("\n\n");
|
58971
|
+
return result;
|
58972
|
+
};
|
58973
|
+
isCyclic3 = (fk4) => {
|
58974
|
+
const key = `${fk4.tableFrom}-${fk4.tableTo}`;
|
58975
|
+
const reverse = `${fk4.tableTo}-${fk4.tableFrom}`;
|
58976
|
+
return relations3.has(key) && relations3.has(reverse);
|
58977
|
+
};
|
58978
|
+
isSelf3 = (fk4) => {
|
58979
|
+
return fk4.tableFrom === fk4.tableTo;
|
58980
|
+
};
|
58981
|
+
mapColumnDefault2 = (defaultValue, isExpression) => {
|
58982
|
+
if (isExpression) {
|
58983
|
+
return `sql\`${defaultValue}\``;
|
58771
58984
|
}
|
58985
|
+
return defaultValue;
|
58772
58986
|
};
|
58773
|
-
|
58774
|
-
|
58775
|
-
|
58776
|
-
if (typeof options.url === "undefined") {
|
58777
|
-
console.log(outputs.sqlite.connection.url("turso"));
|
58778
|
-
}
|
58779
|
-
if (typeof ((_a3 = options.dbCredentials) == null ? void 0 : _a3.authToken) === "undefined") {
|
58780
|
-
console.log(outputs.sqlite.connection.authToken("turso"));
|
58781
|
-
}
|
58782
|
-
} else if (options.driver === "libsql") {
|
58783
|
-
if (typeof ((_b = options.dbCredentials) == null ? void 0 : _b.url) === "undefined") {
|
58784
|
-
console.log(outputs.sqlite.connection.url("libsql"));
|
58785
|
-
}
|
58786
|
-
} else if (options.driver === "better-sqlite") {
|
58787
|
-
if (typeof ((_c = options.dbCredentials) == null ? void 0 : _c.url) === "undefined") {
|
58788
|
-
console.log(outputs.sqlite.connection.url("better-sqlite"));
|
58789
|
-
}
|
58790
|
-
} else {
|
58791
|
-
console.log(outputs.sqlite.connection.driver());
|
58987
|
+
mapColumnDefaultForJson = (defaultValue) => {
|
58988
|
+
if (typeof defaultValue === "string" && defaultValue.startsWith("('") && defaultValue.endsWith("')")) {
|
58989
|
+
return defaultValue.substring(2, defaultValue.length - 2);
|
58792
58990
|
}
|
58991
|
+
return defaultValue;
|
58793
58992
|
};
|
58794
|
-
|
58795
|
-
|
58796
|
-
if (!
|
58797
|
-
|
58798
|
-
process.exit(1);
|
58993
|
+
column6 = (type, name, defaultValue, autoincrement, onUpdate, casing, isExpression) => {
|
58994
|
+
let lowered = type;
|
58995
|
+
if (!type.startsWith("enum(")) {
|
58996
|
+
lowered = type.toLowerCase();
|
58799
58997
|
}
|
58800
|
-
if (
|
58801
|
-
|
58802
|
-
const configRes = sqliteCliConfigSchema.safeParse(drizzleConfig);
|
58803
|
-
if (!configRes.success) {
|
58804
|
-
printConfigConnectionIssues(drizzleConfig);
|
58805
|
-
process.exit(1);
|
58806
|
-
}
|
58807
|
-
return configRes.data;
|
58998
|
+
if (lowered === "serial") {
|
58999
|
+
return `${withCasing3(name, casing)}: serial("${name}")`;
|
58808
59000
|
}
|
58809
|
-
|
58810
|
-
|
58811
|
-
|
58812
|
-
|
59001
|
+
if (lowered.startsWith("int")) {
|
59002
|
+
const isUnsigned = lowered.startsWith("int unsigned");
|
59003
|
+
let out = `${withCasing3(name, casing)}: int("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
|
59004
|
+
out += autoincrement ? `.autoincrement()` : "";
|
59005
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59006
|
+
return out;
|
58813
59007
|
}
|
58814
|
-
if (
|
58815
|
-
const
|
58816
|
-
|
58817
|
-
|
58818
|
-
|
58819
|
-
|
58820
|
-
};
|
59008
|
+
if (lowered.startsWith("tinyint")) {
|
59009
|
+
const isUnsigned = lowered.startsWith("tinyint unsigned");
|
59010
|
+
let out = `${withCasing3(name, casing)}: tinyint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
|
59011
|
+
out += autoincrement ? `.autoincrement()` : "";
|
59012
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59013
|
+
return out;
|
58821
59014
|
}
|
58822
|
-
if (
|
58823
|
-
const
|
58824
|
-
|
58825
|
-
|
58826
|
-
|
58827
|
-
|
58828
|
-
};
|
59015
|
+
if (lowered.startsWith("smallint")) {
|
59016
|
+
const isUnsigned = lowered.startsWith("smallint unsigned");
|
59017
|
+
let out = `${withCasing3(name, casing)}: smallint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
|
59018
|
+
out += autoincrement ? `.autoincrement()` : "";
|
59019
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59020
|
+
return out;
|
58829
59021
|
}
|
58830
|
-
|
58831
|
-
|
58832
|
-
|
58833
|
-
|
58834
|
-
|
58835
|
-
|
58836
|
-
};
|
58837
|
-
validatePush = async (options) => {
|
58838
|
-
const collisionRes = checkCollisions(options, "push:sqlite");
|
58839
|
-
if (!collisionRes.success) {
|
58840
|
-
console.log(collisionRes.message);
|
58841
|
-
console.log();
|
58842
|
-
process.exit(1);
|
59022
|
+
if (lowered.startsWith("mediumint")) {
|
59023
|
+
const isUnsigned = lowered.startsWith("mediumint unsigned");
|
59024
|
+
let out = `${withCasing3(name, casing)}: mediumint("${name}"${isUnsigned ? ", { unsigned: true }" : ""})`;
|
59025
|
+
out += autoincrement ? `.autoincrement()` : "";
|
59026
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59027
|
+
return out;
|
58843
59028
|
}
|
58844
|
-
if (
|
58845
|
-
const
|
58846
|
-
|
58847
|
-
|
58848
|
-
|
58849
|
-
|
58850
|
-
}
|
58851
|
-
return configRes.data;
|
59029
|
+
if (lowered.startsWith("bigint")) {
|
59030
|
+
const isUnsigned = lowered.startsWith("bigint unsigned");
|
59031
|
+
let out = `${withCasing3(name, casing)}: bigint("${name}", { mode: "number"${isUnsigned ? ", unsigned: true" : ""} })`;
|
59032
|
+
out += autoincrement ? `.autoincrement()` : "";
|
59033
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59034
|
+
return out;
|
58852
59035
|
}
|
58853
|
-
|
58854
|
-
|
58855
|
-
|
58856
|
-
|
59036
|
+
if (lowered === "boolean") {
|
59037
|
+
let out = `${withCasing3(name, casing)}: boolean("${name}")`;
|
59038
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59039
|
+
return out;
|
59040
|
+
}
|
59041
|
+
if (lowered.startsWith("double")) {
|
59042
|
+
let params;
|
59043
|
+
if (lowered.length > 6) {
|
59044
|
+
const [precision, scale] = lowered.slice(7, lowered.length - 1).split(",");
|
59045
|
+
params = { precision, scale };
|
58857
59046
|
}
|
58858
|
-
|
58859
|
-
|
59047
|
+
let out = params ? `${withCasing3(name, casing)}: double("${name}", ${timeConfig2(params)})` : `${withCasing3(name, casing)}: double("${name}")`;
|
59048
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59049
|
+
return out;
|
58860
59050
|
}
|
58861
|
-
if (
|
58862
|
-
|
58863
|
-
|
59051
|
+
if (lowered === "float") {
|
59052
|
+
let out = `${withCasing3(name, casing)}: float("${name}")`;
|
59053
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59054
|
+
return out;
|
58864
59055
|
}
|
58865
|
-
|
58866
|
-
|
58867
|
-
|
58868
|
-
|
58869
|
-
});
|
58870
|
-
|
58871
|
-
// src/cli/validations/pg.ts
|
58872
|
-
var pgConnectionCli, pgConnectionConfig, pgConfigIntrospectSchema, pgCliIntrospectParams, pgCliPushParams, pgConfigPushParams, printCliConnectionIssues2, printConfigConnectionIssues2, validatePgIntrospect, validatePgPush;
|
58873
|
-
var init_pg = __esm({
|
58874
|
-
"src/cli/validations/pg.ts"() {
|
58875
|
-
init_lib();
|
58876
|
-
init_utils();
|
58877
|
-
init_common();
|
58878
|
-
init_outputs();
|
58879
|
-
pgConnectionCli = unionType([
|
58880
|
-
objectType({
|
58881
|
-
driver: literalType("pg"),
|
58882
|
-
host: stringType(),
|
58883
|
-
port: coerce.number().optional(),
|
58884
|
-
user: stringType().default("postgres"),
|
58885
|
-
password: stringType().optional(),
|
58886
|
-
database: stringType(),
|
58887
|
-
ssl: coerce.boolean().optional(),
|
58888
|
-
type: literalType("params").default("params")
|
58889
|
-
}),
|
58890
|
-
objectType({
|
58891
|
-
driver: literalType("pg"),
|
58892
|
-
connectionString: stringType(),
|
58893
|
-
type: literalType("url").default("url")
|
58894
|
-
})
|
58895
|
-
]);
|
58896
|
-
pgConnectionConfig = unionType([
|
58897
|
-
objectType({
|
58898
|
-
driver: literalType("pg"),
|
58899
|
-
dbCredentials: objectType({
|
58900
|
-
host: stringType(),
|
58901
|
-
port: coerce.number().optional(),
|
58902
|
-
user: stringType().default("postgres"),
|
58903
|
-
password: stringType().optional(),
|
58904
|
-
database: stringType(),
|
58905
|
-
ssl: coerce.boolean().optional(),
|
58906
|
-
type: literalType("params").default("params").optional()
|
58907
|
-
})
|
58908
|
-
}),
|
58909
|
-
objectType({
|
58910
|
-
driver: literalType("pg"),
|
58911
|
-
dbCredentials: objectType({
|
58912
|
-
connectionString: stringType(),
|
58913
|
-
type: literalType("url").default("url").optional()
|
58914
|
-
})
|
58915
|
-
})
|
58916
|
-
]);
|
58917
|
-
pgConfigIntrospectSchema = intersectionType(
|
58918
|
-
configIntrospectSchema,
|
58919
|
-
pgConnectionConfig
|
58920
|
-
);
|
58921
|
-
pgCliIntrospectParams = intersectionType(
|
58922
|
-
configIntrospectCliSchema,
|
58923
|
-
pgConnectionCli
|
58924
|
-
);
|
58925
|
-
pgCliPushParams = intersectionType(
|
58926
|
-
configPushSchema,
|
58927
|
-
pgConnectionCli
|
58928
|
-
);
|
58929
|
-
pgConfigPushParams = intersectionType(
|
58930
|
-
configPushSchema,
|
58931
|
-
pgConnectionConfig
|
58932
|
-
);
|
58933
|
-
printCliConnectionIssues2 = (options) => {
|
58934
|
-
if (options.driver === "pg") {
|
58935
|
-
if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
|
58936
|
-
console.log(outputs.postgres.connection.required());
|
58937
|
-
}
|
58938
|
-
} else {
|
58939
|
-
console.log(outputs.postgres.connection.driver());
|
59056
|
+
if (lowered === "real") {
|
59057
|
+
let out = `${withCasing3(name, casing)}: real("${name}")`;
|
59058
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59059
|
+
return out;
|
58940
59060
|
}
|
58941
|
-
|
58942
|
-
|
58943
|
-
|
58944
|
-
|
58945
|
-
|
58946
|
-
}
|
58947
|
-
|
58948
|
-
|
59061
|
+
if (lowered.startsWith("timestamp")) {
|
59062
|
+
const keyLength = "timestamp".length + 1;
|
59063
|
+
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59064
|
+
fsp = fsp ? fsp : null;
|
59065
|
+
const params = timeConfig2({ fsp, mode: "'string'" });
|
59066
|
+
let out = params ? `${withCasing3(name, casing)}: timestamp("${name}", ${params})` : `${withCasing3(name, casing)}: timestamp("${name}")`;
|
59067
|
+
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59068
|
+
out += defaultValue;
|
59069
|
+
let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
|
59070
|
+
out += onUpdateNow;
|
59071
|
+
return out;
|
58949
59072
|
}
|
58950
|
-
|
58951
|
-
|
58952
|
-
|
58953
|
-
|
58954
|
-
|
58955
|
-
|
59073
|
+
if (lowered.startsWith("time")) {
|
59074
|
+
const keyLength = "time".length + 1;
|
59075
|
+
let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59076
|
+
fsp = fsp ? fsp : null;
|
59077
|
+
const params = timeConfig2({ fsp });
|
59078
|
+
let out = params ? `${withCasing3(name, casing)}: time("${name}", ${params})` : `${withCasing3(name, casing)}: time("${name}")`;
|
59079
|
+
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59080
|
+
out += defaultValue;
|
59081
|
+
return out;
|
58956
59082
|
}
|
58957
|
-
if (
|
58958
|
-
|
58959
|
-
|
58960
|
-
|
58961
|
-
|
58962
|
-
|
58963
|
-
}
|
58964
|
-
|
59083
|
+
if (lowered === "date") {
|
59084
|
+
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
59085
|
+
${withCasing3(
|
59086
|
+
name,
|
59087
|
+
casing
|
59088
|
+
)}: date("${name}", { mode: 'string' })`;
|
59089
|
+
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59090
|
+
out += defaultValue;
|
59091
|
+
return out;
|
58965
59092
|
}
|
58966
|
-
|
58967
|
-
|
58968
|
-
|
58969
|
-
|
59093
|
+
if (lowered === "text") {
|
59094
|
+
let out = `${withCasing3(name, casing)}: text("${name}")`;
|
59095
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59096
|
+
return out;
|
58970
59097
|
}
|
58971
|
-
if (
|
58972
|
-
|
58973
|
-
|
58974
|
-
|
58975
|
-
dbCredentials: { connectionString, type: type2 },
|
58976
|
-
introspect: { casing: introspectCasing3 }
|
58977
|
-
};
|
59098
|
+
if (lowered === "tinytext") {
|
59099
|
+
let out = `${withCasing3(name, casing)}: tinytext("${name}")`;
|
59100
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59101
|
+
return out;
|
58978
59102
|
}
|
58979
|
-
|
58980
|
-
|
58981
|
-
|
58982
|
-
|
58983
|
-
database,
|
58984
|
-
ssl,
|
58985
|
-
user,
|
58986
|
-
introspectCasing: introspectCasing2,
|
58987
|
-
type,
|
58988
|
-
...rest
|
58989
|
-
} = cliRes.data;
|
58990
|
-
return {
|
58991
|
-
...rest,
|
58992
|
-
dbCredentials: { host, password, port, database, ssl, user, type },
|
58993
|
-
introspect: { casing: introspectCasing2 }
|
58994
|
-
};
|
58995
|
-
};
|
58996
|
-
validatePgPush = async (options) => {
|
58997
|
-
const collisionRes = checkCollisions(options, "push:pg");
|
58998
|
-
if (!collisionRes.success) {
|
58999
|
-
console.log(collisionRes.message);
|
59000
|
-
console.log();
|
59001
|
-
process.exit(1);
|
59103
|
+
if (lowered === "mediumtext") {
|
59104
|
+
let out = `${withCasing3(name, casing)}: mediumtext("${name}")`;
|
59105
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59106
|
+
return out;
|
59002
59107
|
}
|
59003
|
-
if (
|
59004
|
-
|
59005
|
-
|
59006
|
-
|
59007
|
-
printConfigConnectionIssues2(drizzleConfig);
|
59008
|
-
process.exit(1);
|
59009
|
-
}
|
59010
|
-
return configRes.data;
|
59108
|
+
if (lowered === "longtext") {
|
59109
|
+
let out = `${withCasing3(name, casing)}: longtext("${name}")`;
|
59110
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59111
|
+
return out;
|
59011
59112
|
}
|
59012
|
-
|
59013
|
-
|
59014
|
-
|
59015
|
-
|
59016
|
-
}
|
59017
|
-
printCliConnectionIssues2(options);
|
59018
|
-
process.exit(1);
|
59113
|
+
if (lowered === "year") {
|
59114
|
+
let out = `${withCasing3(name, casing)}: year("${name}")`;
|
59115
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59116
|
+
return out;
|
59019
59117
|
}
|
59020
|
-
if (
|
59021
|
-
|
59022
|
-
|
59023
|
-
|
59024
|
-
dbCredentials: { connectionString, type: type2 }
|
59025
|
-
};
|
59118
|
+
if (lowered === "json") {
|
59119
|
+
let out = `${withCasing3(name, casing)}: json("${name}")`;
|
59120
|
+
out += defaultValue ? `.default(${mapColumnDefaultForJson(defaultValue)})` : "";
|
59121
|
+
return out;
|
59026
59122
|
}
|
59027
|
-
|
59028
|
-
|
59029
|
-
|
59030
|
-
|
59031
|
-
|
59032
|
-
|
59033
|
-
|
59034
|
-
})
|
59035
|
-
|
59036
|
-
|
59037
|
-
|
59038
|
-
|
59039
|
-
|
59123
|
+
if (lowered.startsWith("varchar")) {
|
59124
|
+
let out = `${withCasing3(
|
59125
|
+
name,
|
59126
|
+
casing
|
59127
|
+
)}: varchar("${name}", { length: ${lowered.substring(
|
59128
|
+
"varchar".length + 1,
|
59129
|
+
lowered.length - 1
|
59130
|
+
)} })`;
|
59131
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59132
|
+
return out;
|
59133
|
+
}
|
59134
|
+
if (lowered.startsWith("char")) {
|
59135
|
+
let out = `${withCasing3(
|
59136
|
+
name,
|
59137
|
+
casing
|
59138
|
+
)}: char("${name}", { length: ${lowered.substring(
|
59139
|
+
"char".length + 1,
|
59140
|
+
lowered.length - 1
|
59141
|
+
)} })`;
|
59142
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59143
|
+
return out;
|
59144
|
+
}
|
59145
|
+
if (lowered.startsWith("datetime")) {
|
59146
|
+
let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
|
59147
|
+
`;
|
59148
|
+
const fsp = lowered.startsWith("datetime(") ? lowered.substring("datetime".length + 1, lowered.length - 1) : void 0;
|
59149
|
+
out = fsp ? `${withCasing3(
|
59150
|
+
name,
|
59151
|
+
casing
|
59152
|
+
)}: datetime("${name}", { mode: 'string', fsp: ${lowered.substring(
|
59153
|
+
"datetime".length + 1,
|
59154
|
+
lowered.length - 1
|
59155
|
+
)} })` : `${withCasing3(name, casing)}: datetime("${name}", { mode: 'string'})`;
|
59156
|
+
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59157
|
+
out += defaultValue;
|
59158
|
+
return out;
|
59159
|
+
}
|
59160
|
+
if (lowered.startsWith("decimal")) {
|
59161
|
+
let params;
|
59162
|
+
if (lowered.length > 7) {
|
59163
|
+
const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
|
59164
|
+
params = { precision, scale };
|
59165
|
+
}
|
59166
|
+
let out = params ? `${withCasing3(name, casing)}: decimal("${name}", ${timeConfig2(params)})` : `${withCasing3(name, casing)}: decimal("${name}")`;
|
59167
|
+
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59168
|
+
out += defaultValue;
|
59169
|
+
return out;
|
59170
|
+
}
|
59171
|
+
if (lowered.startsWith("binary")) {
|
59172
|
+
const keyLength = "binary".length + 1;
|
59173
|
+
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59174
|
+
length = length ? length : null;
|
59175
|
+
const params = binaryConfig({ length });
|
59176
|
+
let out = params ? `${withCasing3(name, casing)}: binary("${name}", ${params})` : `${withCasing3(name, casing)}: binary("${name}")`;
|
59177
|
+
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59178
|
+
out += defaultValue;
|
59179
|
+
return out;
|
59180
|
+
}
|
59181
|
+
if (lowered.startsWith("enum")) {
|
59182
|
+
const values = lowered.substring("enum".length + 1, lowered.length - 1);
|
59183
|
+
let out = `${withCasing3(name, casing)}: mysqlEnum("${name}", [${values}])`;
|
59184
|
+
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59185
|
+
return out;
|
59186
|
+
}
|
59187
|
+
if (lowered.startsWith("varbinary")) {
|
59188
|
+
const keyLength = "varbinary".length + 1;
|
59189
|
+
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59190
|
+
length = length ? length : null;
|
59191
|
+
const params = binaryConfig({ length });
|
59192
|
+
let out = params ? `${withCasing3(name, casing)}: varbinary("${name}", ${params})` : `${withCasing3(name, casing)}: varbinary("${name}")`;
|
59193
|
+
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59194
|
+
out += defaultValue;
|
59195
|
+
return out;
|
59196
|
+
}
|
59197
|
+
console.log("uknown", type);
|
59198
|
+
return `// Warning: Can't parse ${type} from database
|
59199
|
+
// ${type}Type: ${type}("${name}")`;
|
59200
|
+
};
|
59201
|
+
createTableColumns3 = (columns, fks, casing, tableName, schema4) => {
|
59202
|
+
let statement = "";
|
59203
|
+
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
59204
|
+
return !isSelf3(it);
|
59205
|
+
}).filter((it) => it.columnsFrom.length === 1);
|
59206
|
+
const fkByColumnName = oneColumnsFKs.reduce((res, it) => {
|
59207
|
+
const arr = res[it.columnsFrom[0]] || [];
|
59208
|
+
arr.push(it);
|
59209
|
+
res[it.columnsFrom[0]] = arr;
|
59210
|
+
return res;
|
59211
|
+
}, {});
|
59212
|
+
columns.forEach((it) => {
|
59213
|
+
var _a3, _b, _c;
|
59214
|
+
statement += " ";
|
59215
|
+
statement += column6(
|
59216
|
+
it.type,
|
59217
|
+
it.name,
|
59218
|
+
it.default,
|
59219
|
+
it.autoincrement,
|
59220
|
+
it.onUpdate,
|
59221
|
+
casing,
|
59222
|
+
((_c = (_b = (_a3 = schema4.internal) == null ? void 0 : _a3.tables[tableName]) == null ? void 0 : _b.columns[it.name]) == null ? void 0 : _c.isDefaultAnExpression) ?? false
|
59223
|
+
);
|
59224
|
+
statement += it.primaryKey ? ".primaryKey()" : "";
|
59225
|
+
statement += it.notNull ? ".notNull()" : "";
|
59226
|
+
const fks2 = fkByColumnName[it.name];
|
59227
|
+
if (fks2) {
|
59228
|
+
const fksStatement = fks2.map((it2) => {
|
59229
|
+
const onDelete = it2.onDelete && it2.onDelete !== "no action" ? it2.onDelete : null;
|
59230
|
+
const onUpdate = it2.onUpdate && it2.onUpdate !== "no action" ? it2.onUpdate : null;
|
59231
|
+
const params = { onDelete, onUpdate };
|
59232
|
+
const typeSuffix = isCyclic3(it2) ? ": AnyMySqlColumn" : "";
|
59233
|
+
const paramsStr = objToStatement23(params);
|
59234
|
+
if (paramsStr) {
|
59235
|
+
return `.references(()${typeSuffix} => ${withCasing3(
|
59236
|
+
it2.tableTo,
|
59237
|
+
casing
|
59238
|
+
)}.${withCasing3(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
59239
|
+
}
|
59240
|
+
return `.references(()${typeSuffix} => ${withCasing3(
|
59241
|
+
it2.tableTo,
|
59242
|
+
casing
|
59243
|
+
)}.${withCasing3(it2.columnsTo[0], casing)})`;
|
59244
|
+
}).join("");
|
59245
|
+
statement += fksStatement;
|
59246
|
+
}
|
59247
|
+
statement += ",\n";
|
59248
|
+
});
|
59249
|
+
return statement;
|
59250
|
+
};
|
59251
|
+
createTableIndexes3 = (tableName, idxs, casing) => {
|
59252
|
+
let statement = "";
|
59253
|
+
idxs.forEach((it) => {
|
59254
|
+
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
59255
|
+
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
59256
|
+
idxKey = withCasing3(idxKey, casing);
|
59257
|
+
const indexGeneratedName = indexName(tableName, it.columns);
|
59258
|
+
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
59259
|
+
statement += ` ${idxKey}: `;
|
59260
|
+
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
59261
|
+
statement += `${escapedIndexName})`;
|
59262
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
|
59263
|
+
statement += `
|
59264
|
+
`;
|
59265
|
+
});
|
59266
|
+
return statement;
|
59267
|
+
};
|
59268
|
+
createTableUniques3 = (unqs, casing) => {
|
59269
|
+
let statement = "";
|
59270
|
+
unqs.forEach((it) => {
|
59271
|
+
const idxKey = withCasing3(it.name, casing);
|
59272
|
+
statement += ` ${idxKey}: `;
|
59273
|
+
statement += "unique(";
|
59274
|
+
statement += `"${it.name}")`;
|
59275
|
+
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
|
59276
|
+
statement += `
|
59277
|
+
`;
|
59278
|
+
});
|
59279
|
+
return statement;
|
59280
|
+
};
|
59281
|
+
createTablePKs3 = (pks, casing) => {
|
59282
|
+
let statement = "";
|
59283
|
+
pks.forEach((it) => {
|
59284
|
+
let idxKey = withCasing3(it.name, casing);
|
59285
|
+
statement += ` ${idxKey}: `;
|
59286
|
+
statement += "primaryKey({ columns: [";
|
59287
|
+
statement += `${it.columns.map((c) => {
|
59288
|
+
return `table.${withCasing3(c, casing)}`;
|
59289
|
+
}).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
|
59290
|
+
statement += "),";
|
59291
|
+
statement += `
|
59292
|
+
`;
|
59293
|
+
});
|
59294
|
+
return statement;
|
59295
|
+
};
|
59296
|
+
createTableFKs3 = (fks, casing) => {
|
59297
|
+
let statement = "";
|
59298
|
+
fks.forEach((it) => {
|
59299
|
+
const isSelf4 = it.tableTo === it.tableFrom;
|
59300
|
+
const tableTo = isSelf4 ? "table" : `${withCasing3(it.tableTo, casing)}`;
|
59301
|
+
statement += ` ${withCasing3(it.name, casing)}: foreignKey({
|
59302
|
+
`;
|
59303
|
+
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing3(i, casing)}`).join(", ")}],
|
59304
|
+
`;
|
59305
|
+
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing3(i, casing)}`).join(", ")}],
|
59306
|
+
`;
|
59307
|
+
statement += ` name: "${it.name}"
|
59308
|
+
`;
|
59309
|
+
statement += ` })`;
|
59310
|
+
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
59311
|
+
statement += it.onDelete && it.onDelete !== "no action" ? `.onDelete("${it.onDelete}")` : "";
|
59312
|
+
statement += `,
|
59313
|
+
`;
|
59314
|
+
});
|
59315
|
+
return statement;
|
59316
|
+
};
|
59317
|
+
}
|
59318
|
+
});
|
59319
|
+
|
59320
|
+
// src/cli/commands/mysqlIntrospect.ts
|
59321
|
+
var mysqlIntrospect_exports = {};
|
59322
|
+
__export(mysqlIntrospect_exports, {
|
59323
|
+
connectToMySQL: () => connectToMySQL,
|
59324
|
+
mysqlIntrospect: () => mysqlIntrospect,
|
59325
|
+
mysqlPushIntrospect: () => mysqlPushIntrospect
|
59326
|
+
});
|
59327
|
+
var import_hanji8, import_promise, connectToMySQL, mysqlIntrospect, mysqlPushIntrospect;
|
59328
|
+
var init_mysqlIntrospect = __esm({
|
59329
|
+
"src/cli/commands/mysqlIntrospect.ts"() {
|
59330
|
+
import_hanji8 = __toESM(require_hanji());
|
59331
|
+
init_views();
|
59332
|
+
import_promise = __toESM(require_promise());
|
59333
|
+
init_mysqlSerializer();
|
59334
|
+
init_mysql_introspect();
|
59335
|
+
init_global();
|
59336
|
+
init_mjs();
|
59337
|
+
init_drivers();
|
59338
|
+
connectToMySQL = async (config) => {
|
59339
|
+
const client = await (0, import_promise.createConnection)(config.dbCredentials);
|
59340
|
+
let databaseName;
|
59341
|
+
if ("uri" in config.dbCredentials) {
|
59342
|
+
const connectionUrl = new URL(config.dbCredentials.uri);
|
59343
|
+
const pathname = connectionUrl.pathname;
|
59344
|
+
databaseName = pathname.split("/")[pathname.split("/").length - 1];
|
59345
|
+
if (!databaseName || databaseName === "") {
|
59346
|
+
throw Error(
|
59347
|
+
"You should specify a database name in connection string (mysql://USER:PASSWORD@HOST:PORT/DATABASE)"
|
59348
|
+
);
|
59349
|
+
}
|
59350
|
+
} else if ("database" in config.dbCredentials) {
|
59351
|
+
databaseName = config.dbCredentials.database;
|
59352
|
+
} else {
|
59353
|
+
throw Error(
|
59354
|
+
"Either `connectionString` or `host, port, etc.` params be provided in config file"
|
59355
|
+
);
|
59356
|
+
}
|
59357
|
+
await client.connect();
|
59358
|
+
return { client: new MySQL2Client(client), databaseName };
|
59359
|
+
};
|
59360
|
+
mysqlIntrospect = async (config, filters) => {
|
59361
|
+
const { client, databaseName } = await connectToMySQL(config);
|
59362
|
+
const matchers = filters.map((it) => {
|
59363
|
+
return new Minimatch(it);
|
59364
|
+
});
|
59365
|
+
const filter2 = (tableName) => {
|
59366
|
+
if (matchers.length === 0)
|
59367
|
+
return true;
|
59368
|
+
for (let i = 0; i < matchers.length; i++) {
|
59369
|
+
const matcher = matchers[i];
|
59370
|
+
if (matcher.match(tableName))
|
59371
|
+
return true;
|
59372
|
+
}
|
59373
|
+
return false;
|
59374
|
+
};
|
59375
|
+
const progress = new IntrospectProgress();
|
59376
|
+
const res = await (0, import_hanji8.renderWithTask)(
|
59377
|
+
progress,
|
59378
|
+
fromDatabase(client, databaseName, filter2, (stage, count, status) => {
|
59379
|
+
progress.update(stage, count, status);
|
59380
|
+
})
|
59381
|
+
);
|
59382
|
+
const schema4 = { id: originUUID, prevId: "", ...res };
|
59383
|
+
const ts = schemaToTypeScript3(schema4, config.introspect.casing);
|
59384
|
+
const { internal, ...schemaWithoutInternals } = schema4;
|
59385
|
+
return { schema: schemaWithoutInternals, ts };
|
59386
|
+
};
|
59387
|
+
mysqlPushIntrospect = async (connection, filters) => {
|
59388
|
+
const { client, databaseName } = connection;
|
59389
|
+
const matchers = filters.map((it) => {
|
59390
|
+
return new Minimatch(it);
|
59391
|
+
});
|
59392
|
+
const filter2 = (tableName) => {
|
59393
|
+
if (matchers.length === 0)
|
59394
|
+
return true;
|
59395
|
+
for (let i = 0; i < matchers.length; i++) {
|
59396
|
+
const matcher = matchers[i];
|
59397
|
+
if (matcher.match(tableName))
|
59398
|
+
return true;
|
59399
|
+
}
|
59400
|
+
return false;
|
59401
|
+
};
|
59402
|
+
const res = await fromDatabase(client, databaseName, filter2);
|
59403
|
+
const schema4 = { id: originUUID, prevId: "", ...res };
|
59404
|
+
const { internal, ...schemaWithoutInternals } = schema4;
|
59405
|
+
return { schema: schemaWithoutInternals };
|
59406
|
+
};
|
59407
|
+
}
|
59408
|
+
});
|
59409
|
+
|
59410
|
+
// src/utils.ts
|
59411
|
+
var import_fs8, import_path5, import_drizzle_orm15, assertV1OutFolder, dryJournal, snapshotsPriorV4, prepareOutFolder2, mapValues, validatorForDialect, validateWithReport, prepareMigrationFolder, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
|
59412
|
+
var init_utils5 = __esm({
|
59413
|
+
"src/utils.ts"() {
|
59414
|
+
import_fs8 = require("fs");
|
59415
|
+
init_views();
|
59416
|
+
init_mysqlSchema();
|
59417
|
+
init_pgSchema();
|
59418
|
+
init_sqliteSchema();
|
59419
|
+
init_source();
|
59420
|
+
import_path5 = require("path");
|
59421
|
+
init_global();
|
59422
|
+
init_upFolders();
|
59423
|
+
init_snapshotsDiffer();
|
59424
|
+
init_pgImports();
|
59425
|
+
init_pgSerializer();
|
59426
|
+
init_migrationPreparator();
|
59427
|
+
init_pgIntrospect();
|
59428
|
+
init_pgPushUtils();
|
59429
|
+
init_sqliteIntrospect();
|
59430
|
+
init_sqliteSerializer();
|
59431
|
+
init_pgSerializer();
|
59432
|
+
init_studioUtils();
|
59433
|
+
init_pgConnect();
|
59434
|
+
init_sqlitePushUtils();
|
59435
|
+
init_mysqlSerializer();
|
59436
|
+
init_mysqlIntrospect();
|
59437
|
+
import_drizzle_orm15 = require("drizzle-orm");
|
59438
|
+
assertV1OutFolder = (out, dialect6) => {
|
59439
|
+
if (!(0, import_fs8.existsSync)(out))
|
59440
|
+
return;
|
59441
|
+
const oldMigrationFolders = (0, import_fs8.readdirSync)(out).filter(
|
59442
|
+
(it) => it.length === 14 && /^\d+$/.test(it)
|
59443
|
+
);
|
59444
|
+
if (oldMigrationFolders.length > 0) {
|
59445
|
+
console.log(
|
59446
|
+
`Your migrations folder format is outdated, please run ${source_default.green.bold(
|
59447
|
+
`drizzle-kit up:${dialect6}`
|
59448
|
+
)}`
|
59449
|
+
);
|
59450
|
+
process.exit(1);
|
59451
|
+
}
|
59452
|
+
};
|
59453
|
+
dryJournal = (dialect6) => {
|
59454
|
+
return {
|
59455
|
+
version: snapshotVersion,
|
59456
|
+
dialect: dialect6,
|
59457
|
+
entries: []
|
59458
|
+
};
|
59459
|
+
};
|
59460
|
+
snapshotsPriorV4 = (out) => {
|
59461
|
+
const oldMigrationFolders = (0, import_fs8.readdirSync)(out).filter(
|
59462
|
+
(it) => it.length === 14 && /^\d+$/.test(it)
|
59463
|
+
);
|
59464
|
+
oldMigrationFolders.sort();
|
59465
|
+
return oldMigrationFolders.map((it) => {
|
59466
|
+
const pathJson = (0, import_path5.join)(out, it, "snapshot.json");
|
59467
|
+
console.log(pathJson);
|
59468
|
+
return pathJson;
|
59469
|
+
});
|
59470
|
+
};
|
59471
|
+
prepareOutFolder2 = (out, dialect6) => {
|
59472
|
+
const meta = (0, import_path5.join)(out, "meta");
|
59473
|
+
const journalPath = (0, import_path5.join)(meta, "_journal.json");
|
59474
|
+
if (!(0, import_fs8.existsSync)((0, import_path5.join)(out, "meta"))) {
|
59475
|
+
(0, import_fs8.mkdirSync)(meta, { recursive: true });
|
59476
|
+
(0, import_fs8.writeFileSync)(journalPath, JSON.stringify(dryJournal(dialect6)));
|
59477
|
+
}
|
59478
|
+
const journal = JSON.parse((0, import_fs8.readFileSync)(journalPath).toString());
|
59479
|
+
const snapshots = (0, import_fs8.readdirSync)(meta).filter((it) => !it.startsWith("_")).map((it) => (0, import_path5.join)(meta, it));
|
59480
|
+
snapshots.sort();
|
59481
|
+
return { meta, snapshots, journal };
|
59482
|
+
};
|
59483
|
+
mapValues = (obj, map) => {
|
59484
|
+
const result = Object.keys(obj).reduce(function(result2, key) {
|
59485
|
+
result2[key] = map(obj[key]);
|
59486
|
+
return result2;
|
59487
|
+
}, {});
|
59488
|
+
return result;
|
59489
|
+
};
|
59490
|
+
validatorForDialect = (dialect6) => {
|
59491
|
+
switch (dialect6) {
|
59492
|
+
case "pg":
|
59493
|
+
return { validator: backwardCompatiblePgSchema, version: 5 };
|
59494
|
+
case "sqlite":
|
59495
|
+
return { validator: backwardCompatibleSqliteSchema, version: 5 };
|
59496
|
+
case "mysql":
|
59497
|
+
return { validator: backwardCompatibleMysqlSchema, version: 5 };
|
59498
|
+
}
|
59499
|
+
};
|
59500
|
+
validateWithReport = (snapshots, dialect6) => {
|
59501
|
+
const { validator, version } = validatorForDialect(dialect6);
|
59502
|
+
const result = snapshots.reduce(
|
59503
|
+
(accum, it) => {
|
59504
|
+
const raw = JSON.parse((0, import_fs8.readFileSync)(`./${it}`).toString());
|
59505
|
+
accum.rawMap[it] = raw;
|
59506
|
+
if (raw["version"] && Number(raw["version"]) > version) {
|
59507
|
+
console.log(
|
59508
|
+
info(
|
59509
|
+
`${it} snapshot is of unsupported version, please update drizzle-kit`
|
59510
|
+
)
|
59511
|
+
);
|
59512
|
+
process.exit(0);
|
59513
|
+
}
|
59514
|
+
const result2 = validator.safeParse(raw);
|
59515
|
+
if (!result2.success) {
|
59516
|
+
accum.malformed.push(it);
|
59517
|
+
return accum;
|
59518
|
+
}
|
59519
|
+
const snapshot = result2.data;
|
59520
|
+
if (snapshot.version !== String(version)) {
|
59521
|
+
accum.nonLatest.push(it);
|
59522
|
+
return accum;
|
59523
|
+
}
|
59524
|
+
const idEntry = accum.idsMap[snapshot["prevId"]] ?? {
|
59525
|
+
parent: it,
|
59526
|
+
snapshots: []
|
59527
|
+
};
|
59528
|
+
idEntry.snapshots.push(it);
|
59529
|
+
accum.idsMap[snapshot["prevId"]] = idEntry;
|
59530
|
+
return accum;
|
59531
|
+
},
|
59532
|
+
{
|
59533
|
+
malformed: [],
|
59534
|
+
nonLatest: [],
|
59535
|
+
idToNameMap: {},
|
59536
|
+
idsMap: {},
|
59537
|
+
rawMap: {}
|
59538
|
+
}
|
59539
|
+
);
|
59540
|
+
return result;
|
59541
|
+
};
|
59542
|
+
prepareMigrationFolder = (outFolder = "drizzle", dialect6) => {
|
59543
|
+
const { snapshots, journal } = prepareOutFolder2(outFolder, dialect6);
|
59544
|
+
const report = validateWithReport(snapshots, dialect6);
|
59545
|
+
if (report.nonLatest.length > 0) {
|
59546
|
+
console.log(
|
59547
|
+
report.nonLatest.map((it) => {
|
59548
|
+
return `${it}/snapshot.json is not of the latest version`;
|
59549
|
+
}).concat(`Run ${source_default.green.bold(`drizzle-kit up:${dialect6}`)}`).join("\n")
|
59550
|
+
);
|
59551
|
+
process.exit(0);
|
59552
|
+
}
|
59553
|
+
if (report.malformed.length) {
|
59554
|
+
const message2 = report.malformed.map((it) => {
|
59555
|
+
return `${it} data is malformed`;
|
59556
|
+
}).join("\n");
|
59557
|
+
console.log(message2);
|
59558
|
+
}
|
59559
|
+
const collisionEntries = Object.entries(report.idsMap).filter(
|
59560
|
+
(it) => it[1].snapshots.length > 1
|
59561
|
+
);
|
59562
|
+
const message = collisionEntries.map((it) => {
|
59563
|
+
const data = it[1];
|
59564
|
+
return `[${data.snapshots.join(
|
59565
|
+
", "
|
59566
|
+
)}] are pointing to a parent snapshot: ${data.parent}/snapshot.json which is a collision.`;
|
59567
|
+
}).join("\n").trim();
|
59568
|
+
if (message) {
|
59569
|
+
console.log(source_default.red.bold("Error:"), message);
|
59570
|
+
}
|
59571
|
+
const abort = report.malformed.length || collisionEntries.length > 0;
|
59572
|
+
if (abort) {
|
59573
|
+
process.exit(0);
|
59574
|
+
}
|
59575
|
+
return { snapshots, journal };
|
59576
|
+
};
|
59577
|
+
prepareMigrationMeta = (schemas, tables, columns) => {
|
59578
|
+
const _meta = {
|
59579
|
+
schemas: {},
|
59580
|
+
tables: {},
|
59581
|
+
columns: {}
|
59582
|
+
};
|
59583
|
+
schemas.forEach((it) => {
|
59584
|
+
const from = schemaRenameKey(it.from);
|
59585
|
+
const to = schemaRenameKey(it.to);
|
59586
|
+
_meta.schemas[from] = to;
|
59587
|
+
});
|
59588
|
+
tables.forEach((it) => {
|
59589
|
+
const from = tableRenameKey(it.from);
|
59590
|
+
const to = tableRenameKey(it.to);
|
59591
|
+
_meta.tables[from] = to;
|
59592
|
+
});
|
59593
|
+
columns.forEach((it) => {
|
59594
|
+
const from = columnRenameKey(it.from.table, it.from.schema, it.from.column);
|
59595
|
+
const to = columnRenameKey(it.to.table, it.to.schema, it.to.column);
|
59596
|
+
_meta.columns[from] = to;
|
59597
|
+
});
|
59598
|
+
return _meta;
|
59599
|
+
};
|
59600
|
+
schemaRenameKey = (it) => {
|
59601
|
+
return it;
|
59602
|
+
};
|
59603
|
+
tableRenameKey = (it) => {
|
59604
|
+
const out = it.schema ? `"${it.schema}"."${it.name}"` : `"${it.name}"`;
|
59605
|
+
return out;
|
59606
|
+
};
|
59607
|
+
columnRenameKey = (table4, schema4, column7) => {
|
59608
|
+
const out = schema4 ? `"${schema4}"."${table4}"."${column7}"` : `"${table4}"."${column7}"`;
|
59609
|
+
return out;
|
59610
|
+
};
|
59611
|
+
(0, import_drizzle_orm15.eq)({}, 1);
|
59612
|
+
}
|
59613
|
+
});
|
59614
|
+
|
59615
|
+
// src/cli/commands/mysqlPushUtils.ts
|
59616
|
+
var import_hanji10, filterStatements, logSuggestionsAndReturn2;
|
59617
|
+
var init_mysqlPushUtils = __esm({
|
59618
|
+
"src/cli/commands/mysqlPushUtils.ts"() {
|
59619
|
+
init_source();
|
59620
|
+
import_hanji10 = __toESM(require_hanji());
|
59621
|
+
init_mysqlSchema();
|
59622
|
+
init_selector_ui();
|
59623
|
+
filterStatements = (statements, currentSchema, prevSchema) => {
|
59624
|
+
return statements.filter((statement) => {
|
59625
|
+
if (statement.type === "alter_table_alter_column_set_type") {
|
59626
|
+
if (statement.oldDataType.startsWith("tinyint") && statement.newDataType.startsWith("boolean")) {
|
59627
|
+
return false;
|
59628
|
+
}
|
59629
|
+
if (statement.oldDataType.startsWith("bigint unsigned") && statement.newDataType.startsWith("serial")) {
|
59630
|
+
return false;
|
59631
|
+
}
|
59632
|
+
if (statement.oldDataType.startsWith("serial") && statement.newDataType.startsWith("bigint unsigned")) {
|
59633
|
+
return false;
|
59634
|
+
}
|
59635
|
+
} else if (statement.type === "alter_table_alter_column_set_default") {
|
59636
|
+
if (statement.newDefaultValue === false && statement.oldDefaultValue === 0 && statement.newDataType === "boolean") {
|
59637
|
+
return false;
|
59638
|
+
}
|
59639
|
+
if (statement.newDefaultValue === true && statement.oldDefaultValue === 1 && statement.newDataType === "boolean") {
|
59640
|
+
return false;
|
59641
|
+
}
|
59642
|
+
} else if (statement.type === "delete_unique_constraint") {
|
59643
|
+
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
59644
|
+
if (unsquashed.columns.length === 1 && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && prevSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].name === unsquashed.columns[0]) {
|
59645
|
+
return false;
|
59646
|
+
}
|
59647
|
+
} else if (statement.type === "alter_table_alter_column_drop_notnull") {
|
59648
|
+
const serialStatement = statements.find(
|
59649
|
+
(it) => it.type === "alter_table_alter_column_set_type"
|
59650
|
+
);
|
59651
|
+
if ((serialStatement == null ? void 0 : serialStatement.oldDataType.startsWith("bigint unsigned")) && (serialStatement == null ? void 0 : serialStatement.newDataType.startsWith("serial")) && serialStatement.columnName === statement.columnName && serialStatement.tableName === statement.tableName) {
|
59652
|
+
return false;
|
59653
|
+
}
|
59654
|
+
if (statement.newDataType === "serial" && !statement.columnNotNull) {
|
59655
|
+
return false;
|
59656
|
+
}
|
59657
|
+
if (statement.columnAutoIncrement) {
|
59658
|
+
return false;
|
59659
|
+
}
|
59660
|
+
}
|
59661
|
+
return true;
|
59662
|
+
});
|
59663
|
+
};
|
59664
|
+
logSuggestionsAndReturn2 = async ({
|
59665
|
+
connection,
|
59666
|
+
statements
|
59667
|
+
}) => {
|
59668
|
+
let shouldAskForApprove = false;
|
59669
|
+
const statementsToExecute = [];
|
59670
|
+
const infoToPrint = [];
|
59671
|
+
const tablesToRemove = [];
|
59672
|
+
const columnsToRemove = [];
|
59673
|
+
const schemasToRemove = [];
|
59674
|
+
const tablesToTruncate = [];
|
59675
|
+
for (const statement of statements) {
|
59676
|
+
if (statement.type === "drop_table") {
|
59677
|
+
const res = await connection.query(
|
59678
|
+
`select count(*) as count from \`${statement.tableName}\``
|
59679
|
+
);
|
59680
|
+
const count = Number(res[0].count);
|
59681
|
+
if (count > 0) {
|
59682
|
+
infoToPrint.push(
|
59683
|
+
`\xB7 You're about to delete ${source_default.underline(
|
59684
|
+
statement.tableName
|
59685
|
+
)} table with ${count} items`
|
59686
|
+
);
|
59687
|
+
tablesToRemove.push(statement.tableName);
|
59688
|
+
shouldAskForApprove = true;
|
59689
|
+
}
|
59690
|
+
} else if (statement.type === "alter_table_drop_column") {
|
59691
|
+
const res = await connection.query(
|
59692
|
+
`select count(*) as count from \`${statement.tableName}\``
|
59693
|
+
);
|
59694
|
+
const count = Number(res[0].count);
|
59695
|
+
if (count > 0) {
|
59696
|
+
infoToPrint.push(
|
59697
|
+
`\xB7 You're about to delete ${source_default.underline(
|
59698
|
+
statement.columnName
|
59699
|
+
)} column in ${statement.tableName} table with ${count} items`
|
59700
|
+
);
|
59701
|
+
columnsToRemove.push(`${statement.tableName}_${statement.columnName}`);
|
59702
|
+
shouldAskForApprove = true;
|
59703
|
+
}
|
59704
|
+
} else if (statement.type === "drop_schema") {
|
59705
|
+
const res = await connection.query(
|
59706
|
+
`select count(*) as count from information_schema.tables where table_schema = \`${statement.name}\`;`
|
59707
|
+
);
|
59708
|
+
const count = Number(res[0].count);
|
59709
|
+
if (count > 0) {
|
59710
|
+
infoToPrint.push(
|
59711
|
+
`\xB7 You're about to delete ${source_default.underline(
|
59712
|
+
statement.name
|
59713
|
+
)} schema with ${count} tables`
|
59714
|
+
);
|
59715
|
+
schemasToRemove.push(statement.name);
|
59716
|
+
shouldAskForApprove = true;
|
59717
|
+
}
|
59718
|
+
} else if (statement.type === "alter_table_alter_column_set_type") {
|
59719
|
+
const res = await connection.query(
|
59720
|
+
`select count(*) as count from \`${statement.tableName}\``
|
59721
|
+
);
|
59722
|
+
const count = Number(res[0].count);
|
59723
|
+
if (count > 0) {
|
59724
|
+
infoToPrint.push(
|
59725
|
+
`\xB7 You're about to change ${source_default.underline(
|
59726
|
+
statement.columnName
|
59727
|
+
)} column type from ${source_default.underline(
|
59728
|
+
statement.oldDataType
|
59729
|
+
)} to ${source_default.underline(statement.newDataType)} with ${count} items`
|
59730
|
+
);
|
59731
|
+
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
59732
|
+
tablesToTruncate.push(statement.tableName);
|
59733
|
+
shouldAskForApprove = true;
|
59734
|
+
}
|
59735
|
+
} else if (statement.type === "alter_table_alter_column_drop_default") {
|
59736
|
+
if (statement.columnNotNull) {
|
59737
|
+
const res = await connection.query(
|
59738
|
+
`select count(*) as count from \`${statement.tableName}\``
|
59739
|
+
);
|
59740
|
+
const count = Number(res[0].count);
|
59741
|
+
if (count > 0) {
|
59742
|
+
infoToPrint.push(
|
59743
|
+
`\xB7 You're about to remove default value from ${source_default.underline(
|
59744
|
+
statement.columnName
|
59745
|
+
)} not-null column with ${count} items`
|
59746
|
+
);
|
59747
|
+
tablesToTruncate.push(statement.tableName);
|
59748
|
+
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
59749
|
+
shouldAskForApprove = true;
|
59750
|
+
}
|
59751
|
+
}
|
59752
|
+
shouldAskForApprove = true;
|
59753
|
+
} else if (statement.type === "alter_table_alter_column_set_notnull") {
|
59754
|
+
if (typeof statement.columnDefault === "undefined") {
|
59755
|
+
const res = await connection.query(
|
59756
|
+
`select count(*) as count from \`${statement.tableName}\``
|
59757
|
+
);
|
59758
|
+
const count = Number(res[0].count);
|
59759
|
+
if (count > 0) {
|
59760
|
+
infoToPrint.push(
|
59761
|
+
`\xB7 You're about to set not-null constraint to ${source_default.underline(
|
59762
|
+
statement.columnName
|
59763
|
+
)} column without default, which contains ${count} items`
|
59764
|
+
);
|
59765
|
+
tablesToTruncate.push(statement.tableName);
|
59766
|
+
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
59767
|
+
shouldAskForApprove = true;
|
59768
|
+
}
|
59769
|
+
}
|
59770
|
+
} else if (statement.type === "alter_table_alter_column_drop_pk") {
|
59771
|
+
const res = await connection.query(
|
59772
|
+
`select count(*) as count from \`${statement.tableName}\``
|
59773
|
+
);
|
59774
|
+
const count = Number(res[0].count);
|
59775
|
+
if (count > 0) {
|
59776
|
+
infoToPrint.push(
|
59777
|
+
`\xB7 You're about to change ${source_default.underline(
|
59778
|
+
statement.tableName
|
59779
|
+
)} primary key. This statements may fail and you table may left without primary key`
|
59780
|
+
);
|
59781
|
+
tablesToTruncate.push(statement.tableName);
|
59782
|
+
shouldAskForApprove = true;
|
59783
|
+
}
|
59784
|
+
} else if (statement.type === "alter_table_add_column") {
|
59785
|
+
if (statement.column.notNull && typeof statement.column.default === "undefined") {
|
59786
|
+
const res = await connection.query(
|
59787
|
+
`select count(*) as count from \`${statement.tableName}\``
|
59788
|
+
);
|
59789
|
+
const count = Number(res[0].count);
|
59790
|
+
if (count > 0) {
|
59791
|
+
infoToPrint.push(
|
59792
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
59793
|
+
statement.column.name
|
59794
|
+
)} column without default value, which contains ${count} items`
|
59795
|
+
);
|
59796
|
+
tablesToTruncate.push(statement.tableName);
|
59797
|
+
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
59798
|
+
shouldAskForApprove = true;
|
59799
|
+
}
|
59800
|
+
}
|
59801
|
+
} else if (statement.type === "create_unique_constraint") {
|
59802
|
+
const res = await connection.query(
|
59803
|
+
`select count(*) as count from \`${statement.tableName}\``
|
59804
|
+
);
|
59805
|
+
const count = Number(res[0].count);
|
59806
|
+
if (count > 0) {
|
59807
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(statement.data);
|
59808
|
+
console.log(
|
59809
|
+
`\xB7 You're about to add ${source_default.underline(
|
59810
|
+
unsquashedUnique.name
|
59811
|
+
)} unique constraint to the table, which contains ${count} items. If this statement fails, you will receive an error from the database. Do you want to truncate ${source_default.underline(
|
59812
|
+
statement.tableName
|
59813
|
+
)} table?
|
59814
|
+
`
|
59815
|
+
);
|
59816
|
+
const { status, data } = await (0, import_hanji10.render)(
|
59817
|
+
new Select([
|
59818
|
+
"No, add the constraint without truncating the table",
|
59819
|
+
`Yes, truncate the table`
|
59820
|
+
])
|
59821
|
+
);
|
59822
|
+
if ((data == null ? void 0 : data.index) === 1) {
|
59823
|
+
tablesToTruncate.push(statement.tableName);
|
59824
|
+
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
59825
|
+
shouldAskForApprove = true;
|
59826
|
+
}
|
59827
|
+
}
|
59828
|
+
}
|
59829
|
+
}
|
59830
|
+
return {
|
59831
|
+
statementsToExecute,
|
59832
|
+
shouldAskForApprove,
|
59833
|
+
infoToPrint,
|
59834
|
+
columnsToRemove: [...new Set(columnsToRemove)],
|
59835
|
+
schemasToRemove: [...new Set(schemasToRemove)],
|
59836
|
+
tablesToTruncate: [...new Set(tablesToTruncate)],
|
59837
|
+
tablesToRemove: [...new Set(tablesToRemove)]
|
59838
|
+
};
|
59839
|
+
};
|
59840
|
+
}
|
59841
|
+
});
|
59842
|
+
|
59843
|
+
// src/cli/commands/sqliteUtils.ts
|
59844
|
+
var sqliteConnectionSchema, sqliteCliConfigSchema;
|
59845
|
+
var init_sqliteUtils = __esm({
|
59846
|
+
"src/cli/commands/sqliteUtils.ts"() {
|
59040
59847
|
init_lib();
|
59041
59848
|
init_utils();
|
59042
|
-
|
59043
|
-
init_outputs();
|
59044
|
-
mysqlConnectionCli = unionType([
|
59849
|
+
sqliteConnectionSchema = unionType([
|
59045
59850
|
objectType({
|
59046
|
-
driver: literalType("
|
59047
|
-
|
59048
|
-
|
59049
|
-
|
59050
|
-
|
59051
|
-
database: stringType()
|
59851
|
+
driver: literalType("turso"),
|
59852
|
+
dbCredentials: objectType({
|
59853
|
+
url: stringType(),
|
59854
|
+
authToken: stringType().optional()
|
59855
|
+
})
|
59052
59856
|
}),
|
59053
59857
|
objectType({
|
59054
|
-
driver: literalType("
|
59055
|
-
|
59056
|
-
|
59858
|
+
driver: literalType("libsql"),
|
59859
|
+
dbCredentials: objectType({
|
59860
|
+
url: stringType()
|
59861
|
+
})
|
59862
|
+
}),
|
59863
|
+
objectType({
|
59864
|
+
driver: literalType("better-sqlite"),
|
59865
|
+
dbCredentials: objectType({
|
59866
|
+
url: stringType()
|
59867
|
+
})
|
59057
59868
|
})
|
59058
59869
|
]);
|
59059
|
-
|
59870
|
+
sqliteCliConfigSchema = intersectionType(
|
59871
|
+
configIntrospectSchema,
|
59872
|
+
sqliteConnectionSchema
|
59873
|
+
);
|
59874
|
+
}
|
59875
|
+
});
|
59876
|
+
|
59877
|
+
// src/cli/validations/common.ts
|
59878
|
+
var checkCollisions;
|
59879
|
+
var init_common = __esm({
|
59880
|
+
"src/cli/validations/common.ts"() {
|
59881
|
+
init_outputs();
|
59882
|
+
checkCollisions = (options, command, inputWhitelist = []) => {
|
59883
|
+
const { config, ...rest } = options;
|
59884
|
+
let atLeastOneParam = false;
|
59885
|
+
for (const key of Object.keys(rest)) {
|
59886
|
+
if (inputWhitelist.includes(key))
|
59887
|
+
continue;
|
59888
|
+
atLeastOneParam = true;
|
59889
|
+
}
|
59890
|
+
if (!atLeastOneParam && typeof config !== "undefined") {
|
59891
|
+
return {
|
59892
|
+
success: true,
|
59893
|
+
action: "config"
|
59894
|
+
};
|
59895
|
+
}
|
59896
|
+
if (typeof config === "undefined" && atLeastOneParam) {
|
59897
|
+
return {
|
59898
|
+
success: true,
|
59899
|
+
action: "cli"
|
59900
|
+
};
|
59901
|
+
}
|
59902
|
+
if (typeof config === "undefined" && !atLeastOneParam) {
|
59903
|
+
return {
|
59904
|
+
success: true,
|
59905
|
+
action: "config"
|
59906
|
+
};
|
59907
|
+
}
|
59908
|
+
return {
|
59909
|
+
success: false,
|
59910
|
+
message: outputs.common.ambiguousParams(command),
|
59911
|
+
action: "error"
|
59912
|
+
};
|
59913
|
+
};
|
59914
|
+
}
|
59915
|
+
});
|
59916
|
+
|
59917
|
+
// src/cli/validations/sqlite.ts
|
59918
|
+
var sqliteConnectionCli, sqliteCliIntrospectParams, sqliteCliPushParams, sqliteConfigPushParams, printCliConnectionIssues, printConfigConnectionIssues, validateIntrospect, validatePush;
|
59919
|
+
var init_sqlite = __esm({
|
59920
|
+
"src/cli/validations/sqlite.ts"() {
|
59921
|
+
init_lib();
|
59922
|
+
init_sqliteUtils();
|
59923
|
+
init_utils();
|
59924
|
+
init_common();
|
59925
|
+
init_outputs();
|
59926
|
+
sqliteConnectionCli = unionType([
|
59060
59927
|
objectType({
|
59061
|
-
|
59062
|
-
|
59063
|
-
|
59064
|
-
password: stringType().optional(),
|
59065
|
-
database: stringType()
|
59928
|
+
driver: literalType("turso"),
|
59929
|
+
url: stringType(),
|
59930
|
+
authToken: stringType()
|
59066
59931
|
}),
|
59067
59932
|
objectType({
|
59068
|
-
|
59069
|
-
|
59933
|
+
driver: literalType("better-sqlite"),
|
59934
|
+
url: stringType()
|
59935
|
+
}),
|
59936
|
+
objectType({
|
59937
|
+
driver: literalType("libsql"),
|
59938
|
+
url: stringType()
|
59070
59939
|
})
|
59071
59940
|
]);
|
59072
|
-
|
59073
|
-
driver: literalType("mysql2"),
|
59074
|
-
dbCredentials: mysql2credentials
|
59075
|
-
});
|
59076
|
-
mysqlConfigIntrospectSchema = intersectionType(
|
59077
|
-
configIntrospectSchema,
|
59078
|
-
mysqlConnectionConfig
|
59079
|
-
);
|
59080
|
-
mysqlCliIntrospectParams = intersectionType(
|
59941
|
+
sqliteCliIntrospectParams = intersectionType(
|
59081
59942
|
configIntrospectCliSchema,
|
59082
|
-
|
59943
|
+
sqliteConnectionCli
|
59083
59944
|
);
|
59084
|
-
|
59945
|
+
sqliteCliPushParams = intersectionType(
|
59085
59946
|
configPushSchema,
|
59086
|
-
|
59947
|
+
sqliteConnectionCli
|
59087
59948
|
);
|
59088
|
-
|
59949
|
+
sqliteConfigPushParams = intersectionType(
|
59089
59950
|
configPushSchema,
|
59090
|
-
|
59951
|
+
sqliteConnectionSchema
|
59091
59952
|
);
|
59092
|
-
|
59093
|
-
|
59094
|
-
|
59095
|
-
|
59096
|
-
|
59097
|
-
|
59098
|
-
|
59953
|
+
printCliConnectionIssues = (options) => {
|
59954
|
+
if (options.driver === "turso") {
|
59955
|
+
if (typeof options.url === "undefined") {
|
59956
|
+
console.log(outputs.sqlite.connection.url("turso"));
|
59957
|
+
}
|
59958
|
+
if (typeof options.authToken === "undefined") {
|
59959
|
+
console.log(outputs.sqlite.connection.authToken("turso"));
|
59960
|
+
}
|
59961
|
+
} else if (options.driver === "libsql") {
|
59962
|
+
if (typeof options.url === "undefined") {
|
59963
|
+
console.log(outputs.sqlite.connection.url("libsql"));
|
59964
|
+
}
|
59965
|
+
} else if (options.driver === "better-sqlite") {
|
59966
|
+
if (typeof options.url === "undefined") {
|
59967
|
+
console.log(outputs.sqlite.connection.url("better-sqlite"));
|
59968
|
+
}
|
59969
|
+
} else {
|
59970
|
+
console.log(outputs.sqlite.connection.driver());
|
59099
59971
|
}
|
59100
59972
|
};
|
59101
|
-
|
59102
|
-
|
59103
|
-
|
59104
|
-
|
59105
|
-
|
59106
|
-
|
59107
|
-
|
59973
|
+
printConfigConnectionIssues = (options) => {
|
59974
|
+
var _a3, _b, _c;
|
59975
|
+
if (options.driver === "turso") {
|
59976
|
+
if (typeof options.url === "undefined") {
|
59977
|
+
console.log(outputs.sqlite.connection.url("turso"));
|
59978
|
+
}
|
59979
|
+
if (typeof ((_a3 = options.dbCredentials) == null ? void 0 : _a3.authToken) === "undefined") {
|
59980
|
+
console.log(outputs.sqlite.connection.authToken("turso"));
|
59981
|
+
}
|
59982
|
+
} else if (options.driver === "libsql") {
|
59983
|
+
if (typeof ((_b = options.dbCredentials) == null ? void 0 : _b.url) === "undefined") {
|
59984
|
+
console.log(outputs.sqlite.connection.url("libsql"));
|
59985
|
+
}
|
59986
|
+
} else if (options.driver === "better-sqlite") {
|
59987
|
+
if (typeof ((_c = options.dbCredentials) == null ? void 0 : _c.url) === "undefined") {
|
59988
|
+
console.log(outputs.sqlite.connection.url("better-sqlite"));
|
59989
|
+
}
|
59990
|
+
} else {
|
59991
|
+
console.log(outputs.sqlite.connection.driver());
|
59108
59992
|
}
|
59109
59993
|
};
|
59110
|
-
|
59111
|
-
const collisionRes = checkCollisions(options, "introspect:
|
59994
|
+
validateIntrospect = async (options) => {
|
59995
|
+
const collisionRes = checkCollisions(options, "introspect:sqlite");
|
59112
59996
|
if (!collisionRes.success) {
|
59113
59997
|
console.log(collisionRes.message);
|
59114
59998
|
process.exit(1);
|
59115
59999
|
}
|
59116
60000
|
if (collisionRes.action === "config") {
|
59117
60001
|
const drizzleConfig = await readDrizzleConfig(options.config);
|
59118
|
-
const configRes =
|
60002
|
+
const configRes = sqliteCliConfigSchema.safeParse(drizzleConfig);
|
59119
60003
|
if (!configRes.success) {
|
59120
|
-
|
60004
|
+
printConfigConnectionIssues(drizzleConfig);
|
59121
60005
|
process.exit(1);
|
59122
60006
|
}
|
59123
60007
|
return configRes.data;
|
59124
60008
|
}
|
59125
|
-
const cliRes =
|
60009
|
+
const cliRes = sqliteCliIntrospectParams.safeParse(options);
|
59126
60010
|
if (!cliRes.success) {
|
59127
|
-
|
60011
|
+
printCliConnectionIssues(options);
|
59128
60012
|
process.exit(1);
|
59129
60013
|
}
|
59130
|
-
|
59131
|
-
|
59132
|
-
|
59133
|
-
|
59134
|
-
|
59135
|
-
|
59136
|
-
|
59137
|
-
|
59138
|
-
|
59139
|
-
|
60014
|
+
if (cliRes.data.driver === "turso") {
|
60015
|
+
const { authToken, url: url2, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
|
60016
|
+
return {
|
60017
|
+
...rest2,
|
60018
|
+
dbCredentials: { url: url2, authToken },
|
60019
|
+
introspect: { casing: introspectCasing3 }
|
60020
|
+
};
|
60021
|
+
}
|
60022
|
+
if (cliRes.data.driver === "libsql") {
|
60023
|
+
const { url: url2, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
|
60024
|
+
return {
|
60025
|
+
...rest2,
|
60026
|
+
dbCredentials: { url: url2 },
|
60027
|
+
introspect: { casing: introspectCasing3 }
|
60028
|
+
};
|
60029
|
+
}
|
60030
|
+
const { url, introspectCasing: introspectCasing2, ...rest } = cliRes.data;
|
59140
60031
|
return {
|
59141
|
-
|
59142
|
-
|
59143
|
-
|
59144
|
-
schemaFilter,
|
59145
|
-
tablesFilter,
|
59146
|
-
breakpoints,
|
59147
|
-
introspect: { casing: introspectCasing2 },
|
59148
|
-
dbCredentials: rest
|
60032
|
+
...rest,
|
60033
|
+
dbCredentials: { url },
|
60034
|
+
introspect: { casing: introspectCasing2 }
|
59149
60035
|
};
|
59150
60036
|
};
|
59151
|
-
|
59152
|
-
const collisionRes = checkCollisions(options, "push:
|
60037
|
+
validatePush = async (options) => {
|
60038
|
+
const collisionRes = checkCollisions(options, "push:sqlite");
|
59153
60039
|
if (!collisionRes.success) {
|
59154
60040
|
console.log(collisionRes.message);
|
59155
60041
|
console.log();
|
@@ -59157,858 +60043,538 @@ var init_mysql = __esm({
|
|
59157
60043
|
}
|
59158
60044
|
if (collisionRes.action === "config") {
|
59159
60045
|
const drizzleConfig = await readDrizzleConfig(options.config);
|
59160
|
-
const configRes =
|
60046
|
+
const configRes = sqliteConfigPushParams.safeParse(drizzleConfig);
|
59161
60047
|
if (!configRes.success) {
|
59162
|
-
|
60048
|
+
printConfigConnectionIssues(drizzleConfig);
|
59163
60049
|
process.exit(1);
|
59164
60050
|
}
|
59165
60051
|
return configRes.data;
|
59166
60052
|
}
|
59167
|
-
const cliRes =
|
60053
|
+
const cliRes = sqliteCliPushParams.safeParse(options);
|
59168
60054
|
if (!cliRes.success) {
|
59169
60055
|
if (typeof options.schema === "undefined") {
|
59170
|
-
console.log(outputs.common.schema("push:
|
60056
|
+
console.log(outputs.common.schema("push:sqlite"));
|
59171
60057
|
}
|
59172
|
-
|
60058
|
+
printCliConnectionIssues(options);
|
59173
60059
|
process.exit(1);
|
59174
60060
|
}
|
59175
|
-
|
59176
|
-
|
59177
|
-
|
59178
|
-
schema: schema4,
|
59179
|
-
driver,
|
59180
|
-
schemaFilter,
|
59181
|
-
tablesFilter,
|
59182
|
-
...rest
|
59183
|
-
} = cliRes.data;
|
59184
|
-
return {
|
59185
|
-
driver,
|
59186
|
-
schema: schema4,
|
59187
|
-
strict,
|
59188
|
-
verbose,
|
59189
|
-
tablesFilter,
|
59190
|
-
schemaFilter,
|
59191
|
-
dbCredentials: rest
|
59192
|
-
};
|
59193
|
-
};
|
59194
|
-
}
|
59195
|
-
});
|
59196
|
-
|
59197
|
-
// node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json
|
59198
|
-
var require_package = __commonJS({
|
59199
|
-
"node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json"(exports, module2) {
|
59200
|
-
module2.exports = {
|
59201
|
-
name: "dotenv",
|
59202
|
-
version: "16.0.3",
|
59203
|
-
description: "Loads environment variables from .env file",
|
59204
|
-
main: "lib/main.js",
|
59205
|
-
types: "lib/main.d.ts",
|
59206
|
-
exports: {
|
59207
|
-
".": {
|
59208
|
-
require: "./lib/main.js",
|
59209
|
-
types: "./lib/main.d.ts",
|
59210
|
-
default: "./lib/main.js"
|
59211
|
-
},
|
59212
|
-
"./config": "./config.js",
|
59213
|
-
"./config.js": "./config.js",
|
59214
|
-
"./lib/env-options": "./lib/env-options.js",
|
59215
|
-
"./lib/env-options.js": "./lib/env-options.js",
|
59216
|
-
"./lib/cli-options": "./lib/cli-options.js",
|
59217
|
-
"./lib/cli-options.js": "./lib/cli-options.js",
|
59218
|
-
"./package.json": "./package.json"
|
59219
|
-
},
|
59220
|
-
scripts: {
|
59221
|
-
"dts-check": "tsc --project tests/types/tsconfig.json",
|
59222
|
-
lint: "standard",
|
59223
|
-
"lint-readme": "standard-markdown",
|
59224
|
-
pretest: "npm run lint && npm run dts-check",
|
59225
|
-
test: "tap tests/*.js --100 -Rspec",
|
59226
|
-
prerelease: "npm test",
|
59227
|
-
release: "standard-version"
|
59228
|
-
},
|
59229
|
-
repository: {
|
59230
|
-
type: "git",
|
59231
|
-
url: "git://github.com/motdotla/dotenv.git"
|
59232
|
-
},
|
59233
|
-
keywords: [
|
59234
|
-
"dotenv",
|
59235
|
-
"env",
|
59236
|
-
".env",
|
59237
|
-
"environment",
|
59238
|
-
"variables",
|
59239
|
-
"config",
|
59240
|
-
"settings"
|
59241
|
-
],
|
59242
|
-
readmeFilename: "README.md",
|
59243
|
-
license: "BSD-2-Clause",
|
59244
|
-
devDependencies: {
|
59245
|
-
"@types/node": "^17.0.9",
|
59246
|
-
decache: "^4.6.1",
|
59247
|
-
dtslint: "^3.7.0",
|
59248
|
-
sinon: "^12.0.1",
|
59249
|
-
standard: "^16.0.4",
|
59250
|
-
"standard-markdown": "^7.1.0",
|
59251
|
-
"standard-version": "^9.3.2",
|
59252
|
-
tap: "^15.1.6",
|
59253
|
-
tar: "^6.1.11",
|
59254
|
-
typescript: "^4.5.4"
|
59255
|
-
},
|
59256
|
-
engines: {
|
59257
|
-
node: ">=12"
|
59258
|
-
}
|
59259
|
-
};
|
59260
|
-
}
|
59261
|
-
});
|
59262
|
-
|
59263
|
-
// node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js
|
59264
|
-
var require_main = __commonJS({
|
59265
|
-
"node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js"(exports, module2) {
|
59266
|
-
var fs8 = require("fs");
|
59267
|
-
var path4 = require("path");
|
59268
|
-
var os2 = require("os");
|
59269
|
-
var packageJson = require_package();
|
59270
|
-
var version = packageJson.version;
|
59271
|
-
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
59272
|
-
function parse(src) {
|
59273
|
-
const obj = {};
|
59274
|
-
let lines = src.toString();
|
59275
|
-
lines = lines.replace(/\r\n?/mg, "\n");
|
59276
|
-
let match2;
|
59277
|
-
while ((match2 = LINE.exec(lines)) != null) {
|
59278
|
-
const key = match2[1];
|
59279
|
-
let value = match2[2] || "";
|
59280
|
-
value = value.trim();
|
59281
|
-
const maybeQuote = value[0];
|
59282
|
-
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
59283
|
-
if (maybeQuote === '"') {
|
59284
|
-
value = value.replace(/\\n/g, "\n");
|
59285
|
-
value = value.replace(/\\r/g, "\r");
|
59286
|
-
}
|
59287
|
-
obj[key] = value;
|
59288
|
-
}
|
59289
|
-
return obj;
|
59290
|
-
}
|
59291
|
-
function _log(message) {
|
59292
|
-
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
59293
|
-
}
|
59294
|
-
function _resolveHome(envPath) {
|
59295
|
-
return envPath[0] === "~" ? path4.join(os2.homedir(), envPath.slice(1)) : envPath;
|
59296
|
-
}
|
59297
|
-
function config(options) {
|
59298
|
-
let dotenvPath = path4.resolve(process.cwd(), ".env");
|
59299
|
-
let encoding = "utf8";
|
59300
|
-
const debug = Boolean(options && options.debug);
|
59301
|
-
const override = Boolean(options && options.override);
|
59302
|
-
if (options) {
|
59303
|
-
if (options.path != null) {
|
59304
|
-
dotenvPath = _resolveHome(options.path);
|
59305
|
-
}
|
59306
|
-
if (options.encoding != null) {
|
59307
|
-
encoding = options.encoding;
|
59308
|
-
}
|
59309
|
-
}
|
59310
|
-
try {
|
59311
|
-
const parsed = DotenvModule.parse(fs8.readFileSync(dotenvPath, { encoding }));
|
59312
|
-
Object.keys(parsed).forEach(function(key) {
|
59313
|
-
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
|
59314
|
-
process.env[key] = parsed[key];
|
59315
|
-
} else {
|
59316
|
-
if (override === true) {
|
59317
|
-
process.env[key] = parsed[key];
|
59318
|
-
}
|
59319
|
-
if (debug) {
|
59320
|
-
if (override === true) {
|
59321
|
-
_log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
|
59322
|
-
} else {
|
59323
|
-
_log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
|
59324
|
-
}
|
59325
|
-
}
|
59326
|
-
}
|
59327
|
-
});
|
59328
|
-
return { parsed };
|
59329
|
-
} catch (e) {
|
59330
|
-
if (debug) {
|
59331
|
-
_log(`Failed to load ${dotenvPath} ${e.message}`);
|
59332
|
-
}
|
59333
|
-
return { error: e };
|
59334
|
-
}
|
59335
|
-
}
|
59336
|
-
var DotenvModule = {
|
59337
|
-
config,
|
59338
|
-
parse
|
59339
|
-
};
|
59340
|
-
module2.exports.config = DotenvModule.config;
|
59341
|
-
module2.exports.parse = DotenvModule.parse;
|
59342
|
-
module2.exports = DotenvModule;
|
59343
|
-
}
|
59344
|
-
});
|
59345
|
-
|
59346
|
-
// node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/env-options.js
|
59347
|
-
var require_env_options = __commonJS({
|
59348
|
-
"node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/env-options.js"(exports, module2) {
|
59349
|
-
var options = {};
|
59350
|
-
if (process.env.DOTENV_CONFIG_ENCODING != null) {
|
59351
|
-
options.encoding = process.env.DOTENV_CONFIG_ENCODING;
|
59352
|
-
}
|
59353
|
-
if (process.env.DOTENV_CONFIG_PATH != null) {
|
59354
|
-
options.path = process.env.DOTENV_CONFIG_PATH;
|
59355
|
-
}
|
59356
|
-
if (process.env.DOTENV_CONFIG_DEBUG != null) {
|
59357
|
-
options.debug = process.env.DOTENV_CONFIG_DEBUG;
|
59358
|
-
}
|
59359
|
-
if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
|
59360
|
-
options.override = process.env.DOTENV_CONFIG_OVERRIDE;
|
59361
|
-
}
|
59362
|
-
module2.exports = options;
|
59363
|
-
}
|
59364
|
-
});
|
59365
|
-
|
59366
|
-
// node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/cli-options.js
|
59367
|
-
var require_cli_options = __commonJS({
|
59368
|
-
"node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/cli-options.js"(exports, module2) {
|
59369
|
-
var re = /^dotenv_config_(encoding|path|debug|override)=(.+)$/;
|
59370
|
-
module2.exports = function optionMatcher(args) {
|
59371
|
-
return args.reduce(function(acc, cur) {
|
59372
|
-
const matches = cur.match(re);
|
59373
|
-
if (matches) {
|
59374
|
-
acc[matches[1]] = matches[2];
|
59375
|
-
}
|
59376
|
-
return acc;
|
59377
|
-
}, {});
|
59378
|
-
};
|
59379
|
-
}
|
59380
|
-
});
|
59381
|
-
|
59382
|
-
// src/mysql-introspect.ts
|
59383
|
-
var mysqlImportsList, objToStatement23, timeConfig2, binaryConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, mapColumnDefault2, mapColumnDefaultForJson, column6, createTableColumns3, createTableIndexes3, createTableUniques3, createTablePKs3, createTableFKs3;
|
59384
|
-
var init_mysql_introspect = __esm({
|
59385
|
-
"src/mysql-introspect.ts"() {
|
59386
|
-
init_utils2();
|
59387
|
-
init_mysqlSerializer();
|
59388
|
-
mysqlImportsList = /* @__PURE__ */ new Set([
|
59389
|
-
"mysqlTable",
|
59390
|
-
"mysqlEnum",
|
59391
|
-
"bigint",
|
59392
|
-
"binary",
|
59393
|
-
"boolean",
|
59394
|
-
"char",
|
59395
|
-
"date",
|
59396
|
-
"datetime",
|
59397
|
-
"decimal",
|
59398
|
-
"double",
|
59399
|
-
"float",
|
59400
|
-
"int",
|
59401
|
-
"json",
|
59402
|
-
"mediumint",
|
59403
|
-
"real",
|
59404
|
-
"serial",
|
59405
|
-
"smallint",
|
59406
|
-
"text",
|
59407
|
-
"tinytext",
|
59408
|
-
"mediumtext",
|
59409
|
-
"longtext",
|
59410
|
-
"time",
|
59411
|
-
"timestamp",
|
59412
|
-
"tinyint",
|
59413
|
-
"varbinary",
|
59414
|
-
"varchar",
|
59415
|
-
"year",
|
59416
|
-
"enum"
|
59417
|
-
]);
|
59418
|
-
objToStatement23 = (json) => {
|
59419
|
-
json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
|
59420
|
-
const keys = Object.keys(json);
|
59421
|
-
if (keys.length === 0)
|
59422
|
-
return;
|
59423
|
-
let statement = "{ ";
|
59424
|
-
statement += keys.map((it) => `${it}: "${json[it]}"`).join(", ");
|
59425
|
-
statement += " }";
|
59426
|
-
return statement;
|
59427
|
-
};
|
59428
|
-
timeConfig2 = (json) => {
|
59429
|
-
json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
|
59430
|
-
const keys = Object.keys(json);
|
59431
|
-
if (keys.length === 0)
|
59432
|
-
return;
|
59433
|
-
let statement = "{ ";
|
59434
|
-
statement += keys.map((it) => `${it}: ${json[it]}`).join(", ");
|
59435
|
-
statement += " }";
|
59436
|
-
return statement;
|
59437
|
-
};
|
59438
|
-
binaryConfig = (json) => {
|
59439
|
-
json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
|
59440
|
-
const keys = Object.keys(json);
|
59441
|
-
if (keys.length === 0)
|
59442
|
-
return;
|
59443
|
-
let statement = "{ ";
|
59444
|
-
statement += keys.map((it) => `${it}: ${json[it]}`).join(", ");
|
59445
|
-
statement += " }";
|
59446
|
-
return statement;
|
59447
|
-
};
|
59448
|
-
importsPatch2 = {
|
59449
|
-
"double precision": "doublePrecision",
|
59450
|
-
"timestamp without time zone": "timestamp"
|
59451
|
-
};
|
59452
|
-
relations3 = /* @__PURE__ */ new Set();
|
59453
|
-
withCasing3 = (value, casing) => {
|
59454
|
-
if (typeof casing === "undefined") {
|
59455
|
-
return value;
|
59456
|
-
}
|
59457
|
-
if (casing === "camel") {
|
59458
|
-
return value.camelCase();
|
59459
|
-
}
|
59460
|
-
return value;
|
59461
|
-
};
|
59462
|
-
schemaToTypeScript3 = (schema4, casing) => {
|
59463
|
-
Object.values(schema4.tables).forEach((table4) => {
|
59464
|
-
Object.values(table4.foreignKeys).forEach((fk4) => {
|
59465
|
-
const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
|
59466
|
-
relations3.add(relation);
|
59467
|
-
});
|
59468
|
-
});
|
59469
|
-
const schemas = Object.fromEntries(
|
59470
|
-
Object.entries(schema4.schemas).map((it) => {
|
59471
|
-
return [it[0], withCasing3(it[1], casing)];
|
59472
|
-
})
|
59473
|
-
);
|
59474
|
-
const imports = Object.values(schema4.tables).reduce(
|
59475
|
-
(res, it) => {
|
59476
|
-
const idxImports = Object.values(it.indexes).map(
|
59477
|
-
(idx) => idx.isUnique ? "uniqueIndex" : "index"
|
59478
|
-
);
|
59479
|
-
const fkImpots = Object.values(it.foreignKeys).map((it2) => "foreignKey");
|
59480
|
-
const pkImports = Object.values(it.compositePrimaryKeys).map(
|
59481
|
-
(it2) => "primaryKey"
|
59482
|
-
);
|
59483
|
-
const uniqueImports = Object.values(it.uniqueConstraints).map(
|
59484
|
-
(it2) => "unique"
|
59485
|
-
);
|
59486
|
-
res.mysql.push(...idxImports);
|
59487
|
-
res.mysql.push(...fkImpots);
|
59488
|
-
res.mysql.push(...pkImports);
|
59489
|
-
res.mysql.push(...uniqueImports);
|
59490
|
-
const columnImports = Object.values(it.columns).map((col) => {
|
59491
|
-
let patched = importsPatch2[col.type] ?? col.type;
|
59492
|
-
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
59493
|
-
patched = patched.startsWith("char(") ? "char" : patched;
|
59494
|
-
patched = patched.startsWith("binary(") ? "binary" : patched;
|
59495
|
-
patched = patched.startsWith("decimal(") ? "decimal" : patched;
|
59496
|
-
patched = patched.startsWith("smallint(") ? "smallint" : patched;
|
59497
|
-
patched = patched.startsWith("enum(") ? "mysqlEnum" : patched;
|
59498
|
-
patched = patched.startsWith("datetime(") ? "datetime" : patched;
|
59499
|
-
patched = patched.startsWith("varbinary(") ? "varbinary" : patched;
|
59500
|
-
patched = patched.startsWith("int(") ? "int" : patched;
|
59501
|
-
return patched;
|
59502
|
-
}).filter((type) => {
|
59503
|
-
return mysqlImportsList.has(type);
|
59504
|
-
});
|
59505
|
-
res.mysql.push(...columnImports);
|
59506
|
-
return res;
|
59507
|
-
},
|
59508
|
-
{ mysql: [] }
|
59509
|
-
);
|
59510
|
-
const schemaStatements = Object.entries(schemas).map((it) => {
|
59511
|
-
return `export const ${it[1]} = mysqlSchema("${it[0]}");
|
59512
|
-
`;
|
59513
|
-
}).join();
|
59514
|
-
const tableStatements = Object.values(schema4.tables).map((table4) => {
|
59515
|
-
const tableSchema = schemas[table4.schema];
|
59516
|
-
const func = tableSchema ? tableSchema : "mysqlTable";
|
59517
|
-
let statement = "";
|
59518
|
-
if (imports.mysql.includes(withCasing3(table4.name, casing))) {
|
59519
|
-
statement = `// Table name is in conflict with ${withCasing3(
|
59520
|
-
table4.name,
|
59521
|
-
casing
|
59522
|
-
)} import.
|
59523
|
-
// Please change to any other name, that is not in imports list
|
59524
|
-
`;
|
59525
|
-
}
|
59526
|
-
statement += `export const ${withCasing3(table4.name, casing)} = ${func}("${table4.name}", {
|
59527
|
-
`;
|
59528
|
-
statement += createTableColumns3(
|
59529
|
-
Object.values(table4.columns),
|
59530
|
-
Object.values(table4.foreignKeys),
|
59531
|
-
casing,
|
59532
|
-
table4.name,
|
59533
|
-
schema4
|
59534
|
-
);
|
59535
|
-
statement += "}";
|
59536
|
-
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
59537
|
-
return it.columnsFrom.length > 1 || isSelf3(it);
|
59538
|
-
});
|
59539
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
59540
|
-
statement += ",\n";
|
59541
|
-
statement += "(table) => {\n";
|
59542
|
-
statement += " return {\n";
|
59543
|
-
statement += createTableIndexes3(
|
59544
|
-
table4.name,
|
59545
|
-
Object.values(table4.indexes),
|
59546
|
-
casing
|
59547
|
-
);
|
59548
|
-
statement += createTableFKs3(Object.values(filteredFKs), casing);
|
59549
|
-
statement += createTablePKs3(
|
59550
|
-
Object.values(table4.compositePrimaryKeys),
|
59551
|
-
casing
|
59552
|
-
);
|
59553
|
-
statement += createTableUniques3(
|
59554
|
-
Object.values(table4.uniqueConstraints),
|
59555
|
-
casing
|
59556
|
-
);
|
59557
|
-
statement += " }\n";
|
59558
|
-
statement += "}";
|
59559
|
-
}
|
59560
|
-
statement += ");";
|
59561
|
-
return statement;
|
59562
|
-
});
|
59563
|
-
const uniqueMySqlImports = [
|
59564
|
-
"mysqlTable",
|
59565
|
-
"mysqlSchema",
|
59566
|
-
"AnyMySqlColumn",
|
59567
|
-
...new Set(imports.mysql)
|
59568
|
-
];
|
59569
|
-
let result = `import { ${uniqueMySqlImports.join(
|
59570
|
-
", "
|
59571
|
-
)} } from "drizzle-orm/mysql-core"
|
59572
|
-
import { sql } from "drizzle-orm"
|
59573
|
-
|
59574
|
-
`;
|
59575
|
-
result += schemaStatements;
|
59576
|
-
result += "\n";
|
59577
|
-
result += tableStatements.join("\n\n");
|
59578
|
-
return result;
|
59579
|
-
};
|
59580
|
-
isCyclic3 = (fk4) => {
|
59581
|
-
const key = `${fk4.tableFrom}-${fk4.tableTo}`;
|
59582
|
-
const reverse = `${fk4.tableTo}-${fk4.tableFrom}`;
|
59583
|
-
return relations3.has(key) && relations3.has(reverse);
|
59584
|
-
};
|
59585
|
-
isSelf3 = (fk4) => {
|
59586
|
-
return fk4.tableFrom === fk4.tableTo;
|
59587
|
-
};
|
59588
|
-
mapColumnDefault2 = (defaultValue, isExpression) => {
|
59589
|
-
if (isExpression) {
|
59590
|
-
return `sql\`${defaultValue}\``;
|
59591
|
-
}
|
59592
|
-
return defaultValue;
|
59593
|
-
};
|
59594
|
-
mapColumnDefaultForJson = (defaultValue) => {
|
59595
|
-
if (typeof defaultValue === "string" && defaultValue.startsWith("('") && defaultValue.endsWith("')")) {
|
59596
|
-
return defaultValue.substring(2, defaultValue.length - 2);
|
60061
|
+
if (cliRes.data.driver === "turso") {
|
60062
|
+
const { authToken, url: url2, ...rest2 } = cliRes.data;
|
60063
|
+
return { ...rest2, dbCredentials: { url: url2, authToken } };
|
59597
60064
|
}
|
59598
|
-
|
60065
|
+
const { url, ...rest } = cliRes.data;
|
60066
|
+
return { ...rest, dbCredentials: { url } };
|
59599
60067
|
};
|
59600
|
-
|
59601
|
-
|
59602
|
-
|
59603
|
-
|
59604
|
-
|
59605
|
-
|
59606
|
-
|
60068
|
+
}
|
60069
|
+
});
|
60070
|
+
|
60071
|
+
// src/cli/validations/pg.ts
|
60072
|
+
var pgConnectionCli, pgConnectionConfig, pgConfigIntrospectSchema, pgCliIntrospectParams, pgCliPushParams, pgConfigPushParams, printCliConnectionIssues2, printConfigConnectionIssues2, validatePgIntrospect, validatePgPush;
|
60073
|
+
var init_pg = __esm({
|
60074
|
+
"src/cli/validations/pg.ts"() {
|
60075
|
+
init_lib();
|
60076
|
+
init_utils();
|
60077
|
+
init_common();
|
60078
|
+
init_outputs();
|
60079
|
+
pgConnectionCli = unionType([
|
60080
|
+
objectType({
|
60081
|
+
driver: literalType("pg"),
|
60082
|
+
host: stringType(),
|
60083
|
+
port: coerce.number().optional(),
|
60084
|
+
user: stringType().default("postgres"),
|
60085
|
+
password: stringType().optional(),
|
60086
|
+
database: stringType(),
|
60087
|
+
ssl: coerce.boolean().optional(),
|
60088
|
+
type: literalType("params").default("params")
|
60089
|
+
}),
|
60090
|
+
objectType({
|
60091
|
+
driver: literalType("pg"),
|
60092
|
+
connectionString: stringType(),
|
60093
|
+
type: literalType("url").default("url")
|
60094
|
+
})
|
60095
|
+
]);
|
60096
|
+
pgConnectionConfig = unionType([
|
60097
|
+
objectType({
|
60098
|
+
driver: literalType("pg"),
|
60099
|
+
dbCredentials: objectType({
|
60100
|
+
host: stringType(),
|
60101
|
+
port: coerce.number().optional(),
|
60102
|
+
user: stringType().default("postgres"),
|
60103
|
+
password: stringType().optional(),
|
60104
|
+
database: stringType(),
|
60105
|
+
ssl: coerce.boolean().optional(),
|
60106
|
+
type: literalType("params").default("params").optional()
|
60107
|
+
})
|
60108
|
+
}),
|
60109
|
+
objectType({
|
60110
|
+
driver: literalType("pg"),
|
60111
|
+
dbCredentials: objectType({
|
60112
|
+
connectionString: stringType(),
|
60113
|
+
type: literalType("url").default("url").optional()
|
60114
|
+
})
|
60115
|
+
})
|
60116
|
+
]);
|
60117
|
+
pgConfigIntrospectSchema = intersectionType(
|
60118
|
+
configIntrospectSchema,
|
60119
|
+
pgConnectionConfig
|
60120
|
+
);
|
60121
|
+
pgCliIntrospectParams = intersectionType(
|
60122
|
+
configIntrospectCliSchema,
|
60123
|
+
pgConnectionCli
|
60124
|
+
);
|
60125
|
+
pgCliPushParams = intersectionType(
|
60126
|
+
configPushSchema,
|
60127
|
+
pgConnectionCli
|
60128
|
+
);
|
60129
|
+
pgConfigPushParams = intersectionType(
|
60130
|
+
configPushSchema,
|
60131
|
+
pgConnectionConfig
|
60132
|
+
);
|
60133
|
+
printCliConnectionIssues2 = (options) => {
|
60134
|
+
if (options.driver === "pg") {
|
60135
|
+
if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
|
60136
|
+
console.log(outputs.postgres.connection.required());
|
60137
|
+
}
|
60138
|
+
} else {
|
60139
|
+
console.log(outputs.postgres.connection.driver());
|
59607
60140
|
}
|
59608
|
-
|
59609
|
-
|
59610
|
-
|
59611
|
-
|
59612
|
-
|
59613
|
-
|
60141
|
+
};
|
60142
|
+
printConfigConnectionIssues2 = (options) => {
|
60143
|
+
if (options.driver === "pg") {
|
60144
|
+
if (typeof options.dbCredentials.connectionString === "undefined" && (typeof options.dbCredentials.host === "undefined" || typeof options.dbCredentials.database === "undefined")) {
|
60145
|
+
console.log(outputs.postgres.connection.required());
|
60146
|
+
}
|
60147
|
+
} else {
|
60148
|
+
console.log(outputs.postgres.connection.driver());
|
59614
60149
|
}
|
59615
|
-
|
59616
|
-
|
59617
|
-
|
59618
|
-
|
59619
|
-
|
59620
|
-
|
60150
|
+
};
|
60151
|
+
validatePgIntrospect = async (options) => {
|
60152
|
+
const collisionRes = checkCollisions(options, "introspect:pg");
|
60153
|
+
if (!collisionRes.success) {
|
60154
|
+
console.log(collisionRes.message);
|
60155
|
+
process.exit(1);
|
59621
60156
|
}
|
59622
|
-
if (
|
59623
|
-
const
|
59624
|
-
|
59625
|
-
|
59626
|
-
|
59627
|
-
|
60157
|
+
if (collisionRes.action === "config") {
|
60158
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
60159
|
+
const configRes = pgConfigIntrospectSchema.safeParse(drizzleConfig);
|
60160
|
+
if (!configRes.success) {
|
60161
|
+
printConfigConnectionIssues2(drizzleConfig);
|
60162
|
+
process.exit(1);
|
60163
|
+
}
|
60164
|
+
return configRes.data;
|
59628
60165
|
}
|
59629
|
-
|
59630
|
-
|
59631
|
-
|
59632
|
-
|
59633
|
-
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59634
|
-
return out;
|
60166
|
+
const cliRes = pgCliIntrospectParams.safeParse(options);
|
60167
|
+
if (!cliRes.success) {
|
60168
|
+
printCliConnectionIssues2(options);
|
60169
|
+
process.exit(1);
|
59635
60170
|
}
|
59636
|
-
if (
|
59637
|
-
const
|
59638
|
-
|
59639
|
-
|
59640
|
-
|
59641
|
-
|
60171
|
+
if (cliRes.data.type === "url") {
|
60172
|
+
const { connectionString, introspectCasing: introspectCasing3, type: type2, ...rest2 } = cliRes.data;
|
60173
|
+
return {
|
60174
|
+
...rest2,
|
60175
|
+
dbCredentials: { connectionString, type: type2 },
|
60176
|
+
introspect: { casing: introspectCasing3 }
|
60177
|
+
};
|
59642
60178
|
}
|
59643
|
-
|
59644
|
-
|
59645
|
-
|
59646
|
-
|
60179
|
+
const {
|
60180
|
+
host,
|
60181
|
+
password,
|
60182
|
+
port,
|
60183
|
+
database,
|
60184
|
+
ssl,
|
60185
|
+
user,
|
60186
|
+
introspectCasing: introspectCasing2,
|
60187
|
+
type,
|
60188
|
+
...rest
|
60189
|
+
} = cliRes.data;
|
60190
|
+
return {
|
60191
|
+
...rest,
|
60192
|
+
dbCredentials: { host, password, port, database, ssl, user, type },
|
60193
|
+
introspect: { casing: introspectCasing2 }
|
60194
|
+
};
|
60195
|
+
};
|
60196
|
+
validatePgPush = async (options) => {
|
60197
|
+
const collisionRes = checkCollisions(options, "push:pg");
|
60198
|
+
if (!collisionRes.success) {
|
60199
|
+
console.log(collisionRes.message);
|
60200
|
+
console.log();
|
60201
|
+
process.exit(1);
|
59647
60202
|
}
|
59648
|
-
if (
|
59649
|
-
|
59650
|
-
|
59651
|
-
|
59652
|
-
|
60203
|
+
if (collisionRes.action === "config") {
|
60204
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
60205
|
+
const configRes = pgConfigPushParams.safeParse(drizzleConfig);
|
60206
|
+
if (!configRes.success) {
|
60207
|
+
printConfigConnectionIssues2(drizzleConfig);
|
60208
|
+
process.exit(1);
|
59653
60209
|
}
|
59654
|
-
|
59655
|
-
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59656
|
-
return out;
|
59657
|
-
}
|
59658
|
-
if (lowered === "float") {
|
59659
|
-
let out = `${withCasing3(name, casing)}: float("${name}")`;
|
59660
|
-
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59661
|
-
return out;
|
60210
|
+
return configRes.data;
|
59662
60211
|
}
|
59663
|
-
|
59664
|
-
|
59665
|
-
|
59666
|
-
|
60212
|
+
const cliRes = pgCliPushParams.safeParse(options);
|
60213
|
+
if (!cliRes.success) {
|
60214
|
+
if (typeof options.schema === "undefined") {
|
60215
|
+
console.log(outputs.common.schema("push:pg"));
|
60216
|
+
}
|
60217
|
+
printCliConnectionIssues2(options);
|
60218
|
+
process.exit(1);
|
59667
60219
|
}
|
59668
|
-
if (
|
59669
|
-
const
|
59670
|
-
|
59671
|
-
|
59672
|
-
|
59673
|
-
|
59674
|
-
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59675
|
-
out += defaultValue;
|
59676
|
-
let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
|
59677
|
-
out += onUpdateNow;
|
59678
|
-
return out;
|
60220
|
+
if (cliRes.data.type === "url") {
|
60221
|
+
const { connectionString, type: type2, ...rest2 } = cliRes.data;
|
60222
|
+
return {
|
60223
|
+
...rest2,
|
60224
|
+
dbCredentials: { connectionString, type: type2 }
|
60225
|
+
};
|
59679
60226
|
}
|
59680
|
-
|
59681
|
-
|
59682
|
-
|
59683
|
-
|
59684
|
-
|
59685
|
-
|
59686
|
-
|
59687
|
-
|
59688
|
-
|
60227
|
+
const { host, password, port, database, user, type, ...rest } = cliRes.data;
|
60228
|
+
return {
|
60229
|
+
...rest,
|
60230
|
+
dbCredentials: { host, password, port, database, user, type }
|
60231
|
+
};
|
60232
|
+
};
|
60233
|
+
}
|
60234
|
+
});
|
60235
|
+
|
60236
|
+
// src/cli/validations/mysql.ts
|
60237
|
+
var mysqlConnectionCli, mysql2credentials, mysqlConnectionConfig, mysqlConfigIntrospectSchema, mysqlCliIntrospectParams, mysqlCliPushParams, mysqlConfigPushParams, printCliConnectionIssues3, printConfigConnectionIssues3, validateMySqlIntrospect, validateMySqlPush;
|
60238
|
+
var init_mysql = __esm({
|
60239
|
+
"src/cli/validations/mysql.ts"() {
|
60240
|
+
init_lib();
|
60241
|
+
init_utils();
|
60242
|
+
init_common();
|
60243
|
+
init_outputs();
|
60244
|
+
mysqlConnectionCli = unionType([
|
60245
|
+
objectType({
|
60246
|
+
driver: literalType("mysql2"),
|
60247
|
+
host: stringType(),
|
60248
|
+
port: coerce.number().optional(),
|
60249
|
+
user: stringType().default("mysql"),
|
60250
|
+
password: stringType().optional(),
|
60251
|
+
database: stringType()
|
60252
|
+
}),
|
60253
|
+
objectType({
|
60254
|
+
driver: literalType("mysql2"),
|
60255
|
+
uri: stringType()
|
60256
|
+
// TODO: change docs
|
60257
|
+
})
|
60258
|
+
]);
|
60259
|
+
mysql2credentials = unionType([
|
60260
|
+
objectType({
|
60261
|
+
host: stringType(),
|
60262
|
+
port: coerce.number().optional(),
|
60263
|
+
user: stringType().default("mysql"),
|
60264
|
+
password: stringType().optional(),
|
60265
|
+
database: stringType()
|
60266
|
+
}),
|
60267
|
+
objectType({
|
60268
|
+
uri: stringType()
|
60269
|
+
// TODO: change docs
|
60270
|
+
})
|
60271
|
+
]);
|
60272
|
+
mysqlConnectionConfig = objectType({
|
60273
|
+
driver: literalType("mysql2"),
|
60274
|
+
dbCredentials: mysql2credentials
|
60275
|
+
});
|
60276
|
+
mysqlConfigIntrospectSchema = intersectionType(
|
60277
|
+
configIntrospectSchema,
|
60278
|
+
mysqlConnectionConfig
|
60279
|
+
);
|
60280
|
+
mysqlCliIntrospectParams = intersectionType(
|
60281
|
+
configIntrospectCliSchema,
|
60282
|
+
mysqlConnectionCli
|
60283
|
+
);
|
60284
|
+
mysqlCliPushParams = intersectionType(
|
60285
|
+
configPushSchema,
|
60286
|
+
mysqlConnectionCli
|
60287
|
+
);
|
60288
|
+
mysqlConfigPushParams = intersectionType(
|
60289
|
+
configPushSchema,
|
60290
|
+
mysqlConnectionConfig
|
60291
|
+
);
|
60292
|
+
printCliConnectionIssues3 = (options) => {
|
60293
|
+
const { driver, uri, host, database } = options || {};
|
60294
|
+
if (driver !== "mysql2") {
|
60295
|
+
console.log(outputs.mysql.connection.driver());
|
59689
60296
|
}
|
59690
|
-
if (
|
59691
|
-
|
59692
|
-
${withCasing3(
|
59693
|
-
name,
|
59694
|
-
casing
|
59695
|
-
)}: date("${name}", { mode: 'string' })`;
|
59696
|
-
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59697
|
-
out += defaultValue;
|
59698
|
-
return out;
|
60297
|
+
if (!uri && (!host || !database)) {
|
60298
|
+
console.log(outputs.mysql.connection.required());
|
59699
60299
|
}
|
59700
|
-
|
59701
|
-
|
59702
|
-
|
59703
|
-
|
60300
|
+
};
|
60301
|
+
printConfigConnectionIssues3 = (options) => {
|
60302
|
+
if (options.driver !== "mysql2") {
|
60303
|
+
console.log(outputs.mysql.connection.driver());
|
59704
60304
|
}
|
59705
|
-
|
59706
|
-
|
59707
|
-
|
59708
|
-
return out;
|
60305
|
+
const { uri, host, database } = options.dbCredentials || {};
|
60306
|
+
if (!uri && (!host || !database)) {
|
60307
|
+
console.log(outputs.mysql.connection.required());
|
59709
60308
|
}
|
59710
|
-
|
59711
|
-
|
59712
|
-
|
59713
|
-
|
60309
|
+
};
|
60310
|
+
validateMySqlIntrospect = async (options) => {
|
60311
|
+
const collisionRes = checkCollisions(options, "introspect:mysql");
|
60312
|
+
if (!collisionRes.success) {
|
60313
|
+
console.log(collisionRes.message);
|
60314
|
+
process.exit(1);
|
59714
60315
|
}
|
59715
|
-
if (
|
59716
|
-
|
59717
|
-
|
59718
|
-
|
60316
|
+
if (collisionRes.action === "config") {
|
60317
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
60318
|
+
const configRes = mysqlConfigIntrospectSchema.safeParse(drizzleConfig);
|
60319
|
+
if (!configRes.success) {
|
60320
|
+
printConfigConnectionIssues3(drizzleConfig);
|
60321
|
+
process.exit(1);
|
60322
|
+
}
|
60323
|
+
return configRes.data;
|
59719
60324
|
}
|
59720
|
-
|
59721
|
-
|
59722
|
-
|
59723
|
-
|
60325
|
+
const cliRes = mysqlCliIntrospectParams.safeParse(options);
|
60326
|
+
if (!cliRes.success) {
|
60327
|
+
printCliConnectionIssues3(options);
|
60328
|
+
process.exit(1);
|
59724
60329
|
}
|
59725
|
-
|
59726
|
-
|
59727
|
-
|
59728
|
-
|
60330
|
+
const {
|
60331
|
+
out,
|
60332
|
+
schema: schema4,
|
60333
|
+
driver,
|
60334
|
+
schemaFilter,
|
60335
|
+
tablesFilter,
|
60336
|
+
breakpoints,
|
60337
|
+
introspectCasing: introspectCasing2,
|
60338
|
+
...rest
|
60339
|
+
} = cliRes.data;
|
60340
|
+
return {
|
60341
|
+
out,
|
60342
|
+
schema: schema4,
|
60343
|
+
driver,
|
60344
|
+
schemaFilter,
|
60345
|
+
tablesFilter,
|
60346
|
+
breakpoints,
|
60347
|
+
introspect: { casing: introspectCasing2 },
|
60348
|
+
dbCredentials: rest
|
60349
|
+
};
|
60350
|
+
};
|
60351
|
+
validateMySqlPush = async (options) => {
|
60352
|
+
const collisionRes = checkCollisions(options, "push:mysql");
|
60353
|
+
if (!collisionRes.success) {
|
60354
|
+
console.log(collisionRes.message);
|
60355
|
+
console.log();
|
60356
|
+
process.exit(1);
|
59729
60357
|
}
|
59730
|
-
if (
|
59731
|
-
|
59732
|
-
|
59733
|
-
|
59734
|
-
|
59735
|
-
|
59736
|
-
|
59737
|
-
|
59738
|
-
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59739
|
-
return out;
|
60358
|
+
if (collisionRes.action === "config") {
|
60359
|
+
const drizzleConfig = await readDrizzleConfig(options.config);
|
60360
|
+
const configRes = mysqlConfigPushParams.safeParse(drizzleConfig);
|
60361
|
+
if (!configRes.success) {
|
60362
|
+
printConfigConnectionIssues3(drizzleConfig);
|
60363
|
+
process.exit(1);
|
60364
|
+
}
|
60365
|
+
return configRes.data;
|
59740
60366
|
}
|
59741
|
-
|
59742
|
-
|
59743
|
-
|
59744
|
-
|
59745
|
-
|
59746
|
-
|
59747
|
-
|
59748
|
-
)} })`;
|
59749
|
-
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59750
|
-
return out;
|
60367
|
+
const cliRes = mysqlCliPushParams.safeParse(options);
|
60368
|
+
if (!cliRes.success) {
|
60369
|
+
if (typeof options.schema === "undefined") {
|
60370
|
+
console.log(outputs.common.schema("push:mysql"));
|
60371
|
+
}
|
60372
|
+
printCliConnectionIssues3(options);
|
60373
|
+
process.exit(1);
|
59751
60374
|
}
|
59752
|
-
|
59753
|
-
|
59754
|
-
|
59755
|
-
|
59756
|
-
|
59757
|
-
|
59758
|
-
|
59759
|
-
|
59760
|
-
|
59761
|
-
|
59762
|
-
|
59763
|
-
|
59764
|
-
|
59765
|
-
|
60375
|
+
const {
|
60376
|
+
strict,
|
60377
|
+
verbose,
|
60378
|
+
schema: schema4,
|
60379
|
+
driver,
|
60380
|
+
schemaFilter,
|
60381
|
+
tablesFilter,
|
60382
|
+
...rest
|
60383
|
+
} = cliRes.data;
|
60384
|
+
return {
|
60385
|
+
driver,
|
60386
|
+
schema: schema4,
|
60387
|
+
strict,
|
60388
|
+
verbose,
|
60389
|
+
tablesFilter,
|
60390
|
+
schemaFilter,
|
60391
|
+
dbCredentials: rest
|
60392
|
+
};
|
60393
|
+
};
|
60394
|
+
}
|
60395
|
+
});
|
60396
|
+
|
60397
|
+
// node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json
|
60398
|
+
var require_package = __commonJS({
|
60399
|
+
"node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json"(exports, module2) {
|
60400
|
+
module2.exports = {
|
60401
|
+
name: "dotenv",
|
60402
|
+
version: "16.0.3",
|
60403
|
+
description: "Loads environment variables from .env file",
|
60404
|
+
main: "lib/main.js",
|
60405
|
+
types: "lib/main.d.ts",
|
60406
|
+
exports: {
|
60407
|
+
".": {
|
60408
|
+
require: "./lib/main.js",
|
60409
|
+
types: "./lib/main.d.ts",
|
60410
|
+
default: "./lib/main.js"
|
60411
|
+
},
|
60412
|
+
"./config": "./config.js",
|
60413
|
+
"./config.js": "./config.js",
|
60414
|
+
"./lib/env-options": "./lib/env-options.js",
|
60415
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
60416
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
60417
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
60418
|
+
"./package.json": "./package.json"
|
60419
|
+
},
|
60420
|
+
scripts: {
|
60421
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
60422
|
+
lint: "standard",
|
60423
|
+
"lint-readme": "standard-markdown",
|
60424
|
+
pretest: "npm run lint && npm run dts-check",
|
60425
|
+
test: "tap tests/*.js --100 -Rspec",
|
60426
|
+
prerelease: "npm test",
|
60427
|
+
release: "standard-version"
|
60428
|
+
},
|
60429
|
+
repository: {
|
60430
|
+
type: "git",
|
60431
|
+
url: "git://github.com/motdotla/dotenv.git"
|
60432
|
+
},
|
60433
|
+
keywords: [
|
60434
|
+
"dotenv",
|
60435
|
+
"env",
|
60436
|
+
".env",
|
60437
|
+
"environment",
|
60438
|
+
"variables",
|
60439
|
+
"config",
|
60440
|
+
"settings"
|
60441
|
+
],
|
60442
|
+
readmeFilename: "README.md",
|
60443
|
+
license: "BSD-2-Clause",
|
60444
|
+
devDependencies: {
|
60445
|
+
"@types/node": "^17.0.9",
|
60446
|
+
decache: "^4.6.1",
|
60447
|
+
dtslint: "^3.7.0",
|
60448
|
+
sinon: "^12.0.1",
|
60449
|
+
standard: "^16.0.4",
|
60450
|
+
"standard-markdown": "^7.1.0",
|
60451
|
+
"standard-version": "^9.3.2",
|
60452
|
+
tap: "^15.1.6",
|
60453
|
+
tar: "^6.1.11",
|
60454
|
+
typescript: "^4.5.4"
|
60455
|
+
},
|
60456
|
+
engines: {
|
60457
|
+
node: ">=12"
|
59766
60458
|
}
|
59767
|
-
|
59768
|
-
|
59769
|
-
|
59770
|
-
|
59771
|
-
|
60459
|
+
};
|
60460
|
+
}
|
60461
|
+
});
|
60462
|
+
|
60463
|
+
// node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js
|
60464
|
+
var require_main = __commonJS({
|
60465
|
+
"node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js"(exports, module2) {
|
60466
|
+
var fs8 = require("fs");
|
60467
|
+
var path4 = require("path");
|
60468
|
+
var os2 = require("os");
|
60469
|
+
var packageJson = require_package();
|
60470
|
+
var version = packageJson.version;
|
60471
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
60472
|
+
function parse(src) {
|
60473
|
+
const obj = {};
|
60474
|
+
let lines = src.toString();
|
60475
|
+
lines = lines.replace(/\r\n?/mg, "\n");
|
60476
|
+
let match2;
|
60477
|
+
while ((match2 = LINE.exec(lines)) != null) {
|
60478
|
+
const key = match2[1];
|
60479
|
+
let value = match2[2] || "";
|
60480
|
+
value = value.trim();
|
60481
|
+
const maybeQuote = value[0];
|
60482
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
60483
|
+
if (maybeQuote === '"') {
|
60484
|
+
value = value.replace(/\\n/g, "\n");
|
60485
|
+
value = value.replace(/\\r/g, "\r");
|
59772
60486
|
}
|
59773
|
-
|
59774
|
-
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59775
|
-
out += defaultValue;
|
59776
|
-
return out;
|
59777
|
-
}
|
59778
|
-
if (lowered.startsWith("binary")) {
|
59779
|
-
const keyLength = "binary".length + 1;
|
59780
|
-
let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
|
59781
|
-
length = length ? length : null;
|
59782
|
-
const params = binaryConfig({ length });
|
59783
|
-
let out = params ? `${withCasing3(name, casing)}: binary("${name}", ${params})` : `${withCasing3(name, casing)}: binary("${name}")`;
|
59784
|
-
defaultValue = defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59785
|
-
out += defaultValue;
|
59786
|
-
return out;
|
59787
|
-
}
|
59788
|
-
if (lowered.startsWith("enum")) {
|
59789
|
-
const values = lowered.substring("enum".length + 1, lowered.length - 1);
|
59790
|
-
let out = `${withCasing3(name, casing)}: mysqlEnum("${name}", [${values}])`;
|
59791
|
-
out += defaultValue ? `.default(${mapColumnDefault2(defaultValue, isExpression)})` : "";
|
59792
|
-
return out;
|
60487
|
+
obj[key] = value;
|
59793
60488
|
}
|
59794
|
-
|
59795
|
-
|
59796
|
-
|
59797
|
-
|
59798
|
-
|
59799
|
-
|
59800
|
-
|
59801
|
-
|
59802
|
-
|
60489
|
+
return obj;
|
60490
|
+
}
|
60491
|
+
function _log(message) {
|
60492
|
+
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
60493
|
+
}
|
60494
|
+
function _resolveHome(envPath) {
|
60495
|
+
return envPath[0] === "~" ? path4.join(os2.homedir(), envPath.slice(1)) : envPath;
|
60496
|
+
}
|
60497
|
+
function config(options) {
|
60498
|
+
let dotenvPath = path4.resolve(process.cwd(), ".env");
|
60499
|
+
let encoding = "utf8";
|
60500
|
+
const debug = Boolean(options && options.debug);
|
60501
|
+
const override = Boolean(options && options.override);
|
60502
|
+
if (options) {
|
60503
|
+
if (options.path != null) {
|
60504
|
+
dotenvPath = _resolveHome(options.path);
|
60505
|
+
}
|
60506
|
+
if (options.encoding != null) {
|
60507
|
+
encoding = options.encoding;
|
60508
|
+
}
|
59803
60509
|
}
|
59804
|
-
|
59805
|
-
|
59806
|
-
|
59807
|
-
|
59808
|
-
|
59809
|
-
|
59810
|
-
|
59811
|
-
|
59812
|
-
}).filter((it) => it.columnsFrom.length === 1);
|
59813
|
-
const fkByColumnName = oneColumnsFKs.reduce((res, it) => {
|
59814
|
-
const arr = res[it.columnsFrom[0]] || [];
|
59815
|
-
arr.push(it);
|
59816
|
-
res[it.columnsFrom[0]] = arr;
|
59817
|
-
return res;
|
59818
|
-
}, {});
|
59819
|
-
columns.forEach((it) => {
|
59820
|
-
var _a3, _b, _c;
|
59821
|
-
statement += " ";
|
59822
|
-
statement += column6(
|
59823
|
-
it.type,
|
59824
|
-
it.name,
|
59825
|
-
it.default,
|
59826
|
-
it.autoincrement,
|
59827
|
-
it.onUpdate,
|
59828
|
-
casing,
|
59829
|
-
((_c = (_b = (_a3 = schema4.internal) == null ? void 0 : _a3.tables[tableName]) == null ? void 0 : _b.columns[it.name]) == null ? void 0 : _c.isDefaultAnExpression) ?? false
|
59830
|
-
);
|
59831
|
-
statement += it.primaryKey ? ".primaryKey()" : "";
|
59832
|
-
statement += it.notNull ? ".notNull()" : "";
|
59833
|
-
const fks2 = fkByColumnName[it.name];
|
59834
|
-
if (fks2) {
|
59835
|
-
const fksStatement = fks2.map((it2) => {
|
59836
|
-
const onDelete = it2.onDelete && it2.onDelete !== "no action" ? it2.onDelete : null;
|
59837
|
-
const onUpdate = it2.onUpdate && it2.onUpdate !== "no action" ? it2.onUpdate : null;
|
59838
|
-
const params = { onDelete, onUpdate };
|
59839
|
-
const typeSuffix = isCyclic3(it2) ? ": AnyMySqlColumn" : "";
|
59840
|
-
const paramsStr = objToStatement23(params);
|
59841
|
-
if (paramsStr) {
|
59842
|
-
return `.references(()${typeSuffix} => ${withCasing3(
|
59843
|
-
it2.tableTo,
|
59844
|
-
casing
|
59845
|
-
)}.${withCasing3(it2.columnsTo[0], casing)}, ${paramsStr} )`;
|
60510
|
+
try {
|
60511
|
+
const parsed = DotenvModule.parse(fs8.readFileSync(dotenvPath, { encoding }));
|
60512
|
+
Object.keys(parsed).forEach(function(key) {
|
60513
|
+
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
|
60514
|
+
process.env[key] = parsed[key];
|
60515
|
+
} else {
|
60516
|
+
if (override === true) {
|
60517
|
+
process.env[key] = parsed[key];
|
59846
60518
|
}
|
59847
|
-
|
59848
|
-
|
59849
|
-
|
59850
|
-
|
59851
|
-
|
59852
|
-
|
60519
|
+
if (debug) {
|
60520
|
+
if (override === true) {
|
60521
|
+
_log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
|
60522
|
+
} else {
|
60523
|
+
_log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
|
60524
|
+
}
|
60525
|
+
}
|
60526
|
+
}
|
60527
|
+
});
|
60528
|
+
return { parsed };
|
60529
|
+
} catch (e) {
|
60530
|
+
if (debug) {
|
60531
|
+
_log(`Failed to load ${dotenvPath} ${e.message}`);
|
59853
60532
|
}
|
59854
|
-
|
59855
|
-
}
|
59856
|
-
|
59857
|
-
|
59858
|
-
|
59859
|
-
|
59860
|
-
idxs.forEach((it) => {
|
59861
|
-
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
|
59862
|
-
idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
|
59863
|
-
idxKey = withCasing3(idxKey, casing);
|
59864
|
-
const indexGeneratedName = indexName(tableName, it.columns);
|
59865
|
-
const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
|
59866
|
-
statement += ` ${idxKey}: `;
|
59867
|
-
statement += it.isUnique ? "uniqueIndex(" : "index(";
|
59868
|
-
statement += `${escapedIndexName})`;
|
59869
|
-
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
|
59870
|
-
statement += `
|
59871
|
-
`;
|
59872
|
-
});
|
59873
|
-
return statement;
|
59874
|
-
};
|
59875
|
-
createTableUniques3 = (unqs, casing) => {
|
59876
|
-
let statement = "";
|
59877
|
-
unqs.forEach((it) => {
|
59878
|
-
const idxKey = withCasing3(it.name, casing);
|
59879
|
-
statement += ` ${idxKey}: `;
|
59880
|
-
statement += "unique(";
|
59881
|
-
statement += `"${it.name}")`;
|
59882
|
-
statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
|
59883
|
-
statement += `
|
59884
|
-
`;
|
59885
|
-
});
|
59886
|
-
return statement;
|
59887
|
-
};
|
59888
|
-
createTablePKs3 = (pks, casing) => {
|
59889
|
-
let statement = "";
|
59890
|
-
pks.forEach((it) => {
|
59891
|
-
let idxKey = withCasing3(it.name, casing);
|
59892
|
-
statement += ` ${idxKey}: `;
|
59893
|
-
statement += "primaryKey({ columns: [";
|
59894
|
-
statement += `${it.columns.map((c) => {
|
59895
|
-
return `table.${withCasing3(c, casing)}`;
|
59896
|
-
}).join(", ")}]${it.name ? `, name: "${it.name}"` : ""}}`;
|
59897
|
-
statement += "),";
|
59898
|
-
statement += `
|
59899
|
-
`;
|
59900
|
-
});
|
59901
|
-
return statement;
|
59902
|
-
};
|
59903
|
-
createTableFKs3 = (fks, casing) => {
|
59904
|
-
let statement = "";
|
59905
|
-
fks.forEach((it) => {
|
59906
|
-
const isSelf4 = it.tableTo === it.tableFrom;
|
59907
|
-
const tableTo = isSelf4 ? "table" : `${withCasing3(it.tableTo, casing)}`;
|
59908
|
-
statement += ` ${withCasing3(it.name, casing)}: foreignKey({
|
59909
|
-
`;
|
59910
|
-
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing3(i, casing)}`).join(", ")}],
|
59911
|
-
`;
|
59912
|
-
statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing3(i, casing)}`).join(", ")}],
|
59913
|
-
`;
|
59914
|
-
statement += ` name: "${it.name}"
|
59915
|
-
`;
|
59916
|
-
statement += ` })`;
|
59917
|
-
statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
|
59918
|
-
statement += it.onDelete && it.onDelete !== "no action" ? `.onDelete("${it.onDelete}")` : "";
|
59919
|
-
statement += `,
|
59920
|
-
`;
|
59921
|
-
});
|
59922
|
-
return statement;
|
60533
|
+
return { error: e };
|
60534
|
+
}
|
60535
|
+
}
|
60536
|
+
var DotenvModule = {
|
60537
|
+
config,
|
60538
|
+
parse
|
59923
60539
|
};
|
60540
|
+
module2.exports.config = DotenvModule.config;
|
60541
|
+
module2.exports.parse = DotenvModule.parse;
|
60542
|
+
module2.exports = DotenvModule;
|
59924
60543
|
}
|
59925
60544
|
});
|
59926
60545
|
|
59927
|
-
//
|
59928
|
-
var
|
59929
|
-
|
59930
|
-
|
59931
|
-
|
59932
|
-
|
60546
|
+
// node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/env-options.js
|
60547
|
+
var require_env_options = __commonJS({
|
60548
|
+
"node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/env-options.js"(exports, module2) {
|
60549
|
+
var options = {};
|
60550
|
+
if (process.env.DOTENV_CONFIG_ENCODING != null) {
|
60551
|
+
options.encoding = process.env.DOTENV_CONFIG_ENCODING;
|
60552
|
+
}
|
60553
|
+
if (process.env.DOTENV_CONFIG_PATH != null) {
|
60554
|
+
options.path = process.env.DOTENV_CONFIG_PATH;
|
60555
|
+
}
|
60556
|
+
if (process.env.DOTENV_CONFIG_DEBUG != null) {
|
60557
|
+
options.debug = process.env.DOTENV_CONFIG_DEBUG;
|
60558
|
+
}
|
60559
|
+
if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
|
60560
|
+
options.override = process.env.DOTENV_CONFIG_OVERRIDE;
|
60561
|
+
}
|
60562
|
+
module2.exports = options;
|
60563
|
+
}
|
59933
60564
|
});
|
59934
|
-
|
59935
|
-
|
59936
|
-
|
59937
|
-
|
59938
|
-
|
59939
|
-
|
59940
|
-
|
59941
|
-
|
59942
|
-
|
59943
|
-
|
59944
|
-
connectToMySQL = async (config) => {
|
59945
|
-
const client = await (0, import_promise.createConnection)(config.dbCredentials);
|
59946
|
-
let databaseName;
|
59947
|
-
if ("uri" in config.dbCredentials) {
|
59948
|
-
const connectionUrl = new URL(config.dbCredentials.uri);
|
59949
|
-
const pathname = connectionUrl.pathname;
|
59950
|
-
databaseName = pathname.split("/")[pathname.split("/").length - 1];
|
59951
|
-
if (!databaseName || databaseName === "") {
|
59952
|
-
throw Error(
|
59953
|
-
"You should specify a database name in connection string (mysql://USER:PASSWORD@HOST:PORT/DATABASE)"
|
59954
|
-
);
|
59955
|
-
}
|
59956
|
-
} else if ("database" in config.dbCredentials) {
|
59957
|
-
databaseName = config.dbCredentials.database;
|
59958
|
-
} else {
|
59959
|
-
throw Error(
|
59960
|
-
"Either `connectionString` or `host, port, etc.` params be provided in config file"
|
59961
|
-
);
|
59962
|
-
}
|
59963
|
-
await client.connect();
|
59964
|
-
return { client, databaseName };
|
59965
|
-
};
|
59966
|
-
mysqlIntrospect = async (config, filters) => {
|
59967
|
-
const { client, databaseName } = await connectToMySQL(config);
|
59968
|
-
const matchers = filters.map((it) => {
|
59969
|
-
return new Minimatch(it);
|
59970
|
-
});
|
59971
|
-
const filter2 = (tableName) => {
|
59972
|
-
if (matchers.length === 0)
|
59973
|
-
return true;
|
59974
|
-
for (let i = 0; i < matchers.length; i++) {
|
59975
|
-
const matcher = matchers[i];
|
59976
|
-
if (matcher.match(tableName))
|
59977
|
-
return true;
|
59978
|
-
}
|
59979
|
-
return false;
|
59980
|
-
};
|
59981
|
-
const progress = new IntrospectProgress();
|
59982
|
-
const res = await (0, import_hanji10.renderWithTask)(
|
59983
|
-
progress,
|
59984
|
-
fromDatabase(client, databaseName, filter2, (stage, count, status) => {
|
59985
|
-
progress.update(stage, count, status);
|
59986
|
-
})
|
59987
|
-
);
|
59988
|
-
const schema4 = { id: originUUID, prevId: "", ...res };
|
59989
|
-
const ts = schemaToTypeScript3(schema4, config.introspect.casing);
|
59990
|
-
const { internal, ...schemaWithoutInternals } = schema4;
|
59991
|
-
return { schema: schemaWithoutInternals, ts };
|
59992
|
-
};
|
59993
|
-
mysqlPushIntrospect = async (connection, filters) => {
|
59994
|
-
const { client, databaseName } = connection;
|
59995
|
-
const matchers = filters.map((it) => {
|
59996
|
-
return new Minimatch(it);
|
59997
|
-
});
|
59998
|
-
const filter2 = (tableName) => {
|
59999
|
-
if (matchers.length === 0)
|
60000
|
-
return true;
|
60001
|
-
for (let i = 0; i < matchers.length; i++) {
|
60002
|
-
const matcher = matchers[i];
|
60003
|
-
if (matcher.match(tableName))
|
60004
|
-
return true;
|
60565
|
+
|
60566
|
+
// node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/cli-options.js
|
60567
|
+
var require_cli_options = __commonJS({
|
60568
|
+
"node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/cli-options.js"(exports, module2) {
|
60569
|
+
var re = /^dotenv_config_(encoding|path|debug|override)=(.+)$/;
|
60570
|
+
module2.exports = function optionMatcher(args) {
|
60571
|
+
return args.reduce(function(acc, cur) {
|
60572
|
+
const matches = cur.match(re);
|
60573
|
+
if (matches) {
|
60574
|
+
acc[matches[1]] = matches[2];
|
60005
60575
|
}
|
60006
|
-
return
|
60007
|
-
};
|
60008
|
-
const res = await fromDatabase(client, databaseName, filter2);
|
60009
|
-
const schema4 = { id: originUUID, prevId: "", ...res };
|
60010
|
-
const { internal, ...schemaWithoutInternals } = schema4;
|
60011
|
-
return { schema: schemaWithoutInternals };
|
60576
|
+
return acc;
|
60577
|
+
}, {});
|
60012
60578
|
};
|
60013
60579
|
}
|
60014
60580
|
});
|
@@ -60141,7 +60707,7 @@ init_source();
|
|
60141
60707
|
// package.json
|
60142
60708
|
var package_default = {
|
60143
60709
|
name: "drizzle-kit",
|
60144
|
-
version: "0.20.
|
60710
|
+
version: "0.20.2",
|
60145
60711
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
60146
60712
|
author: "Drizzle Team",
|
60147
60713
|
license: "MIT",
|
@@ -60315,7 +60881,7 @@ init_mysqlSchema();
|
|
60315
60881
|
// src/cli/commands/drop.ts
|
60316
60882
|
init_source();
|
60317
60883
|
var import_fs10 = require("fs");
|
60318
|
-
var
|
60884
|
+
var import_hanji9 = __toESM(require_hanji());
|
60319
60885
|
var import_path6 = require("path");
|
60320
60886
|
init_views();
|
60321
60887
|
var dropMigration = async (out) => {
|
@@ -60327,7 +60893,7 @@ var dropMigration = async (out) => {
|
|
60327
60893
|
console.log(`[${source_default.blue("i")}] no migration entries found in ${metaFilePath}`);
|
60328
60894
|
return;
|
60329
60895
|
}
|
60330
|
-
const result = await (0,
|
60896
|
+
const result = await (0, import_hanji9.render)(new DropMigrationView(journal.entries));
|
60331
60897
|
if (result.status === "aborted")
|
60332
60898
|
return;
|
60333
60899
|
delete journal.entries[journal.entries.indexOf(result.data)];
|
@@ -60345,511 +60911,8 @@ var dropMigration = async (out) => {
|
|
60345
60911
|
|
60346
60912
|
// src/cli/index.ts
|
60347
60913
|
init_utils();
|
60348
|
-
|
60349
|
-
|
60350
|
-
init_source();
|
60351
|
-
var import_hanji9 = __toESM(require_hanji());
|
60352
|
-
init_mysqlSchema();
|
60353
|
-
init_selector_ui();
|
60354
|
-
var filterStatements = (statements, currentSchema, prevSchema) => {
|
60355
|
-
return statements.filter((statement) => {
|
60356
|
-
if (statement.type === "alter_table_alter_column_set_type") {
|
60357
|
-
if (statement.oldDataType.startsWith("tinyint") && statement.newDataType.startsWith("boolean")) {
|
60358
|
-
return false;
|
60359
|
-
}
|
60360
|
-
if (statement.oldDataType.startsWith("bigint unsigned") && statement.newDataType.startsWith("serial")) {
|
60361
|
-
return false;
|
60362
|
-
}
|
60363
|
-
if (statement.oldDataType.startsWith("serial") && statement.newDataType.startsWith("bigint unsigned")) {
|
60364
|
-
return false;
|
60365
|
-
}
|
60366
|
-
} else if (statement.type === "alter_table_alter_column_set_default") {
|
60367
|
-
if (statement.newDefaultValue === false && statement.oldDefaultValue === 0 && statement.newDataType === "boolean") {
|
60368
|
-
return false;
|
60369
|
-
}
|
60370
|
-
if (statement.newDefaultValue === true && statement.oldDefaultValue === 1 && statement.newDataType === "boolean") {
|
60371
|
-
return false;
|
60372
|
-
}
|
60373
|
-
} else if (statement.type === "delete_unique_constraint") {
|
60374
|
-
const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
|
60375
|
-
if (unsquashed.columns.length === 1 && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && prevSchema.tables[statement.tableName].columns[unsquashed.columns[0]].type === "serial" && currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]].name === unsquashed.columns[0]) {
|
60376
|
-
return false;
|
60377
|
-
}
|
60378
|
-
} else if (statement.type === "alter_table_alter_column_drop_notnull") {
|
60379
|
-
const serialStatement = statements.find(
|
60380
|
-
(it) => it.type === "alter_table_alter_column_set_type"
|
60381
|
-
);
|
60382
|
-
if ((serialStatement == null ? void 0 : serialStatement.oldDataType.startsWith("bigint unsigned")) && (serialStatement == null ? void 0 : serialStatement.newDataType.startsWith("serial")) && serialStatement.columnName === statement.columnName && serialStatement.tableName === statement.tableName) {
|
60383
|
-
return false;
|
60384
|
-
}
|
60385
|
-
if (statement.newDataType === "serial" && !statement.columnNotNull) {
|
60386
|
-
return false;
|
60387
|
-
}
|
60388
|
-
if (statement.columnAutoIncrement) {
|
60389
|
-
return false;
|
60390
|
-
}
|
60391
|
-
}
|
60392
|
-
return true;
|
60393
|
-
});
|
60394
|
-
};
|
60395
|
-
var logSuggestionsAndReturn = async ({
|
60396
|
-
connection,
|
60397
|
-
statements
|
60398
|
-
}) => {
|
60399
|
-
let shouldAskForApprove = false;
|
60400
|
-
const statementsToExecute = [];
|
60401
|
-
const infoToPrint = [];
|
60402
|
-
const tablesToRemove = [];
|
60403
|
-
const columnsToRemove = [];
|
60404
|
-
const schemasToRemove = [];
|
60405
|
-
const tablesToTruncate = [];
|
60406
|
-
for (const statement of statements) {
|
60407
|
-
if (statement.type === "drop_table") {
|
60408
|
-
const res = await connection.query(
|
60409
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60410
|
-
);
|
60411
|
-
const count = Number(res[0][0].count);
|
60412
|
-
if (count > 0) {
|
60413
|
-
infoToPrint.push(
|
60414
|
-
`\xB7 You're about to delete ${source_default.underline(
|
60415
|
-
statement.tableName
|
60416
|
-
)} table with ${count} items`
|
60417
|
-
);
|
60418
|
-
tablesToRemove.push(statement.tableName);
|
60419
|
-
shouldAskForApprove = true;
|
60420
|
-
}
|
60421
|
-
} else if (statement.type === "alter_table_drop_column") {
|
60422
|
-
const res = await connection.query(
|
60423
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60424
|
-
);
|
60425
|
-
const count = Number(res[0][0].count);
|
60426
|
-
if (count > 0) {
|
60427
|
-
infoToPrint.push(
|
60428
|
-
`\xB7 You're about to delete ${source_default.underline(
|
60429
|
-
statement.columnName
|
60430
|
-
)} column in ${statement.tableName} table with ${count} items`
|
60431
|
-
);
|
60432
|
-
columnsToRemove.push(`${statement.tableName}_${statement.columnName}`);
|
60433
|
-
shouldAskForApprove = true;
|
60434
|
-
}
|
60435
|
-
} else if (statement.type === "drop_schema") {
|
60436
|
-
const res = await connection.query(
|
60437
|
-
`select count(*) as count from information_schema.tables where table_schema = \`${statement.name}\`;`
|
60438
|
-
);
|
60439
|
-
const count = Number(res[0][0].count);
|
60440
|
-
if (count > 0) {
|
60441
|
-
infoToPrint.push(
|
60442
|
-
`\xB7 You're about to delete ${source_default.underline(
|
60443
|
-
statement.name
|
60444
|
-
)} schema with ${count} tables`
|
60445
|
-
);
|
60446
|
-
schemasToRemove.push(statement.name);
|
60447
|
-
shouldAskForApprove = true;
|
60448
|
-
}
|
60449
|
-
} else if (statement.type === "alter_table_alter_column_set_type") {
|
60450
|
-
const res = await connection.query(
|
60451
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60452
|
-
);
|
60453
|
-
const count = Number(res[0][0].count);
|
60454
|
-
if (count > 0) {
|
60455
|
-
infoToPrint.push(
|
60456
|
-
`\xB7 You're about to change ${source_default.underline(
|
60457
|
-
statement.columnName
|
60458
|
-
)} column type from ${source_default.underline(
|
60459
|
-
statement.oldDataType
|
60460
|
-
)} to ${source_default.underline(statement.newDataType)} with ${count} items`
|
60461
|
-
);
|
60462
|
-
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
60463
|
-
tablesToTruncate.push(statement.tableName);
|
60464
|
-
shouldAskForApprove = true;
|
60465
|
-
}
|
60466
|
-
} else if (statement.type === "alter_table_alter_column_drop_default") {
|
60467
|
-
if (statement.columnNotNull) {
|
60468
|
-
const res = await connection.query(
|
60469
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60470
|
-
);
|
60471
|
-
const count = Number(res[0][0].count);
|
60472
|
-
if (count > 0) {
|
60473
|
-
infoToPrint.push(
|
60474
|
-
`\xB7 You're about to remove default value from ${source_default.underline(
|
60475
|
-
statement.columnName
|
60476
|
-
)} not-null column with ${count} items`
|
60477
|
-
);
|
60478
|
-
tablesToTruncate.push(statement.tableName);
|
60479
|
-
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
60480
|
-
shouldAskForApprove = true;
|
60481
|
-
}
|
60482
|
-
}
|
60483
|
-
shouldAskForApprove = true;
|
60484
|
-
} else if (statement.type === "alter_table_alter_column_set_notnull") {
|
60485
|
-
if (typeof statement.columnDefault === "undefined") {
|
60486
|
-
const res = await connection.query(
|
60487
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60488
|
-
);
|
60489
|
-
const count = Number(res[0][0].count);
|
60490
|
-
if (count > 0) {
|
60491
|
-
infoToPrint.push(
|
60492
|
-
`\xB7 You're about to set not-null constraint to ${source_default.underline(
|
60493
|
-
statement.columnName
|
60494
|
-
)} column without default, which contains ${count} items`
|
60495
|
-
);
|
60496
|
-
tablesToTruncate.push(statement.tableName);
|
60497
|
-
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
60498
|
-
shouldAskForApprove = true;
|
60499
|
-
}
|
60500
|
-
}
|
60501
|
-
} else if (statement.type === "alter_table_alter_column_drop_pk") {
|
60502
|
-
const res = await connection.query(
|
60503
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60504
|
-
);
|
60505
|
-
const count = Number(res[0][0].count);
|
60506
|
-
if (count > 0) {
|
60507
|
-
infoToPrint.push(
|
60508
|
-
`\xB7 You're about to change ${source_default.underline(
|
60509
|
-
statement.tableName
|
60510
|
-
)} primary key. This statements may fail and you table may left without primary key`
|
60511
|
-
);
|
60512
|
-
tablesToTruncate.push(statement.tableName);
|
60513
|
-
shouldAskForApprove = true;
|
60514
|
-
}
|
60515
|
-
} else if (statement.type === "alter_table_add_column") {
|
60516
|
-
if (statement.column.notNull && typeof statement.column.default === "undefined") {
|
60517
|
-
const res = await connection.query(
|
60518
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60519
|
-
);
|
60520
|
-
const count = Number(res[0][0].count);
|
60521
|
-
if (count > 0) {
|
60522
|
-
infoToPrint.push(
|
60523
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
60524
|
-
statement.column.name
|
60525
|
-
)} column without default value, which contains ${count} items`
|
60526
|
-
);
|
60527
|
-
tablesToTruncate.push(statement.tableName);
|
60528
|
-
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
60529
|
-
shouldAskForApprove = true;
|
60530
|
-
}
|
60531
|
-
}
|
60532
|
-
} else if (statement.type === "create_unique_constraint") {
|
60533
|
-
const res = await connection.query(
|
60534
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60535
|
-
);
|
60536
|
-
const count = Number(res[0][0].count);
|
60537
|
-
if (count > 0) {
|
60538
|
-
const unsquashedUnique = MySqlSquasher.unsquashUnique(statement.data);
|
60539
|
-
console.log(
|
60540
|
-
`\xB7 You're about to add ${source_default.underline(
|
60541
|
-
unsquashedUnique.name
|
60542
|
-
)} unique constraint to the table, which contains ${count} items. If this statement fails, you will receive an error from the database. Do you want to truncate ${source_default.underline(
|
60543
|
-
statement.tableName
|
60544
|
-
)} table?
|
60545
|
-
`
|
60546
|
-
);
|
60547
|
-
const { status, data } = await (0, import_hanji9.render)(
|
60548
|
-
new Select([
|
60549
|
-
"No, add the constraint without truncating the table",
|
60550
|
-
`Yes, truncate the table`
|
60551
|
-
])
|
60552
|
-
);
|
60553
|
-
if ((data == null ? void 0 : data.index) === 1) {
|
60554
|
-
tablesToTruncate.push(statement.tableName);
|
60555
|
-
statementsToExecute.push(`truncate table ${statement.tableName};`);
|
60556
|
-
shouldAskForApprove = true;
|
60557
|
-
}
|
60558
|
-
}
|
60559
|
-
}
|
60560
|
-
}
|
60561
|
-
return {
|
60562
|
-
statementsToExecute,
|
60563
|
-
shouldAskForApprove,
|
60564
|
-
infoToPrint,
|
60565
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
60566
|
-
schemasToRemove: [...new Set(schemasToRemove)],
|
60567
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
60568
|
-
tablesToRemove: [...new Set(tablesToRemove)]
|
60569
|
-
};
|
60570
|
-
};
|
60571
|
-
|
60572
|
-
// src/cli/commands/sqlitePushUtils.ts
|
60573
|
-
init_source();
|
60574
|
-
init_sqliteSchema();
|
60575
|
-
init_sqlgenerator();
|
60576
|
-
var _moveDataStatements = (tableName, json, dataLoss = false) => {
|
60577
|
-
const statements = [];
|
60578
|
-
statements.push(
|
60579
|
-
new SqliteRenameTableConvertor().convert({
|
60580
|
-
type: "rename_table",
|
60581
|
-
tableNameFrom: tableName,
|
60582
|
-
tableNameTo: `__old_push_${tableName}`,
|
60583
|
-
fromSchema: "",
|
60584
|
-
toSchema: ""
|
60585
|
-
})
|
60586
|
-
);
|
60587
|
-
const tableColumns = Object.values(json.tables[tableName].columns);
|
60588
|
-
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
60589
|
-
const compositePKs = Object.values(
|
60590
|
-
json.tables[tableName].compositePrimaryKeys
|
60591
|
-
).map((it) => SQLiteSquasher.unsquashPK(it));
|
60592
|
-
statements.push(
|
60593
|
-
new SQLiteCreateTableConvertor().convert({
|
60594
|
-
type: "sqlite_create_table",
|
60595
|
-
tableName,
|
60596
|
-
columns: tableColumns,
|
60597
|
-
referenceData,
|
60598
|
-
compositePKs
|
60599
|
-
})
|
60600
|
-
);
|
60601
|
-
if (!dataLoss) {
|
60602
|
-
statements.push(
|
60603
|
-
`INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
|
60604
|
-
);
|
60605
|
-
}
|
60606
|
-
statements.push(
|
60607
|
-
new SQLiteDropTableConvertor().convert({
|
60608
|
-
type: "drop_table",
|
60609
|
-
tableName: `__old_push_${tableName}`,
|
60610
|
-
schema: ""
|
60611
|
-
})
|
60612
|
-
);
|
60613
|
-
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
60614
|
-
statements.push(
|
60615
|
-
new CreateSqliteIndexConvertor().convert({
|
60616
|
-
type: "create_index",
|
60617
|
-
tableName,
|
60618
|
-
schema: "",
|
60619
|
-
data: idx
|
60620
|
-
})
|
60621
|
-
);
|
60622
|
-
}
|
60623
|
-
return statements;
|
60624
|
-
};
|
60625
|
-
var getOldTableName = (tableName, meta) => {
|
60626
|
-
for (const key of Object.keys(meta.tables)) {
|
60627
|
-
const value = meta.tables[key];
|
60628
|
-
if (`"${tableName}"` === value) {
|
60629
|
-
return key.substring(1, key.length - 1);
|
60630
|
-
}
|
60631
|
-
}
|
60632
|
-
return tableName;
|
60633
|
-
};
|
60634
|
-
var getNewTableName = (tableName, meta) => {
|
60635
|
-
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
60636
|
-
return meta.tables[`"${tableName}"`].substring(
|
60637
|
-
1,
|
60638
|
-
meta.tables[`"${tableName}"`].length - 1
|
60639
|
-
);
|
60640
|
-
}
|
60641
|
-
return tableName;
|
60642
|
-
};
|
60643
|
-
var logSuggestionsAndReturn2 = async ({
|
60644
|
-
connection,
|
60645
|
-
statements,
|
60646
|
-
json1,
|
60647
|
-
json2,
|
60648
|
-
meta
|
60649
|
-
}) => {
|
60650
|
-
let shouldAskForApprove = false;
|
60651
|
-
const statementsToExecute = [];
|
60652
|
-
const infoToPrint = [];
|
60653
|
-
const tablesToRemove = [];
|
60654
|
-
const columnsToRemove = [];
|
60655
|
-
const schemasToRemove = [];
|
60656
|
-
const tablesToTruncate = [];
|
60657
|
-
const tablesContext = {};
|
60658
|
-
for (const statement of statements) {
|
60659
|
-
if (statement.type === "drop_table") {
|
60660
|
-
const res = await connection.query(
|
60661
|
-
`select count(*) as count from \`${statement.tableName}\``
|
60662
|
-
);
|
60663
|
-
const count = Number(res[0].count);
|
60664
|
-
if (count > 0) {
|
60665
|
-
infoToPrint.push(
|
60666
|
-
`\xB7 You're about to delete ${source_default.underline(
|
60667
|
-
statement.tableName
|
60668
|
-
)} table with ${count} items`
|
60669
|
-
);
|
60670
|
-
tablesToRemove.push(statement.tableName);
|
60671
|
-
shouldAskForApprove = true;
|
60672
|
-
}
|
60673
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
60674
|
-
statementsToExecute.push(stmnt);
|
60675
|
-
} else if (statement.type === "alter_table_drop_column") {
|
60676
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
60677
|
-
const columnIsPartOfPk = Object.values(
|
60678
|
-
json1.tables[newTableName].compositePrimaryKeys
|
60679
|
-
).find(
|
60680
|
-
(c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName)
|
60681
|
-
);
|
60682
|
-
const columnIsPartOfIndex = Object.values(
|
60683
|
-
json1.tables[newTableName].indexes
|
60684
|
-
).find(
|
60685
|
-
(c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName)
|
60686
|
-
);
|
60687
|
-
const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
|
60688
|
-
const columnIsPartOfFk = Object.values(
|
60689
|
-
json1.tables[newTableName].foreignKeys
|
60690
|
-
).find(
|
60691
|
-
(t) => SQLiteSquasher.unsquashFK(t).columnsFrom.includes(statement.columnName)
|
60692
|
-
);
|
60693
|
-
const res = await connection.query(
|
60694
|
-
`select count(*) as count from \`${newTableName}\``
|
60695
|
-
);
|
60696
|
-
const count = Number(res[0].count);
|
60697
|
-
if (count > 0) {
|
60698
|
-
infoToPrint.push(
|
60699
|
-
`\xB7 You're about to delete ${source_default.underline(
|
60700
|
-
statement.columnName
|
60701
|
-
)} column in ${newTableName} table with ${count} items`
|
60702
|
-
);
|
60703
|
-
columnsToRemove.push(`${newTableName}_${statement.columnName}`);
|
60704
|
-
shouldAskForApprove = true;
|
60705
|
-
}
|
60706
|
-
if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
|
60707
|
-
tablesContext[newTableName] = [
|
60708
|
-
..._moveDataStatements(statement.tableName, json2, true)
|
60709
|
-
];
|
60710
|
-
const tablesReferncingCurrent = [];
|
60711
|
-
for (const table4 of Object.values(json1.tables)) {
|
60712
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
60713
|
-
(t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName
|
60714
|
-
).map((t) => SQLiteSquasher.unsquashFK(t).tableFrom);
|
60715
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
60716
|
-
}
|
60717
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
60718
|
-
for (const table4 of uniqueTableRefs) {
|
60719
|
-
if (typeof tablesContext[table4] === "undefined") {
|
60720
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
60721
|
-
}
|
60722
|
-
}
|
60723
|
-
} else {
|
60724
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
60725
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
60726
|
-
statementsToExecute.push(stmnt);
|
60727
|
-
}
|
60728
|
-
}
|
60729
|
-
} else if (statement.type === "sqlite_alter_table_add_column") {
|
60730
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
60731
|
-
if (statement.column.notNull && !statement.column.default) {
|
60732
|
-
const res = await connection.query(
|
60733
|
-
`select count(*) as count from \`${newTableName}\``
|
60734
|
-
);
|
60735
|
-
const count = Number(res[0].count);
|
60736
|
-
if (count > 0) {
|
60737
|
-
infoToPrint.push(
|
60738
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
60739
|
-
statement.column.name
|
60740
|
-
)} column without default value, which contains ${count} items`
|
60741
|
-
);
|
60742
|
-
tablesToTruncate.push(newTableName);
|
60743
|
-
statementsToExecute.push(`delete from ${newTableName};`);
|
60744
|
-
shouldAskForApprove = true;
|
60745
|
-
}
|
60746
|
-
}
|
60747
|
-
if (statement.column.primaryKey) {
|
60748
|
-
tablesContext[newTableName] = [
|
60749
|
-
..._moveDataStatements(statement.tableName, json2, true)
|
60750
|
-
];
|
60751
|
-
const tablesReferncingCurrent = [];
|
60752
|
-
for (const table4 of Object.values(json1.tables)) {
|
60753
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
60754
|
-
(t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName
|
60755
|
-
).map((t) => SQLiteSquasher.unsquashFK(t).tableFrom);
|
60756
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
60757
|
-
}
|
60758
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
60759
|
-
for (const table4 of uniqueTableRefs) {
|
60760
|
-
if (typeof tablesContext[table4] === "undefined") {
|
60761
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
60762
|
-
}
|
60763
|
-
}
|
60764
|
-
} else {
|
60765
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
60766
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
60767
|
-
statementsToExecute.push(stmnt);
|
60768
|
-
}
|
60769
|
-
}
|
60770
|
-
} else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk") {
|
60771
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
60772
|
-
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
60773
|
-
const res = await connection.query(
|
60774
|
-
`select count(*) as count from \`${newTableName}\``
|
60775
|
-
);
|
60776
|
-
const count = Number(res[0].count);
|
60777
|
-
if (count > 0) {
|
60778
|
-
infoToPrint.push(
|
60779
|
-
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
60780
|
-
statement.columnName
|
60781
|
-
)} column without default value, which contains ${count} items`
|
60782
|
-
);
|
60783
|
-
tablesToTruncate.push(newTableName);
|
60784
|
-
shouldAskForApprove = true;
|
60785
|
-
}
|
60786
|
-
tablesContext[newTableName] = _moveDataStatements(
|
60787
|
-
statement.tableName,
|
60788
|
-
json2,
|
60789
|
-
true
|
60790
|
-
);
|
60791
|
-
} else {
|
60792
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
60793
|
-
tablesContext[newTableName] = _moveDataStatements(
|
60794
|
-
statement.tableName,
|
60795
|
-
json2
|
60796
|
-
);
|
60797
|
-
}
|
60798
|
-
}
|
60799
|
-
const tablesReferncingCurrent = [];
|
60800
|
-
for (const table4 of Object.values(json1.tables)) {
|
60801
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashFK(t).tableTo === newTableName).map((t) => {
|
60802
|
-
return getNewTableName(
|
60803
|
-
SQLiteSquasher.unsquashFK(t).tableFrom,
|
60804
|
-
meta
|
60805
|
-
);
|
60806
|
-
});
|
60807
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
60808
|
-
}
|
60809
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
60810
|
-
for (const table4 of uniqueTableRefs) {
|
60811
|
-
if (typeof tablesContext[table4] === "undefined") {
|
60812
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
60813
|
-
}
|
60814
|
-
}
|
60815
|
-
} else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
|
60816
|
-
const fk4 = SQLiteSquasher.unsquashFK(statement.data);
|
60817
|
-
if (typeof tablesContext[statement.tableName] === "undefined") {
|
60818
|
-
tablesContext[statement.tableName] = _moveDataStatements(
|
60819
|
-
statement.tableName,
|
60820
|
-
json2
|
60821
|
-
);
|
60822
|
-
}
|
60823
|
-
} else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
|
60824
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
60825
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
60826
|
-
tablesContext[newTableName] = _moveDataStatements(
|
60827
|
-
statement.tableName,
|
60828
|
-
json2
|
60829
|
-
);
|
60830
|
-
}
|
60831
|
-
} else {
|
60832
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
60833
|
-
if (typeof stmnt !== "undefined") {
|
60834
|
-
statementsToExecute.push(stmnt);
|
60835
|
-
}
|
60836
|
-
}
|
60837
|
-
}
|
60838
|
-
for (const context of Object.values(tablesContext)) {
|
60839
|
-
statementsToExecute.push(...context);
|
60840
|
-
}
|
60841
|
-
return {
|
60842
|
-
statementsToExecute,
|
60843
|
-
shouldAskForApprove,
|
60844
|
-
infoToPrint,
|
60845
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
60846
|
-
schemasToRemove: [...new Set(schemasToRemove)],
|
60847
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
60848
|
-
tablesToRemove: [...new Set(tablesToRemove)]
|
60849
|
-
};
|
60850
|
-
};
|
60851
|
-
|
60852
|
-
// src/cli/index.ts
|
60914
|
+
init_mysqlPushUtils();
|
60915
|
+
init_sqlitePushUtils();
|
60853
60916
|
init_serializer();
|
60854
60917
|
init_sqliteSchema();
|
60855
60918
|
init_sqlite();
|
@@ -60981,7 +61044,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
60981
61044
|
tablesToTruncate,
|
60982
61045
|
infoToPrint,
|
60983
61046
|
schemasToRemove
|
60984
|
-
} = await
|
61047
|
+
} = await logSuggestionsAndReturn2({
|
60985
61048
|
connection: connection.client,
|
60986
61049
|
statements: filteredStatements
|
60987
61050
|
});
|
@@ -61046,7 +61109,6 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
61046
61109
|
} catch (e) {
|
61047
61110
|
console.log(e);
|
61048
61111
|
}
|
61049
|
-
await connection.client.end();
|
61050
61112
|
process.exit(0);
|
61051
61113
|
});
|
61052
61114
|
var dbPushPgCommand = new import_commander.Command("push:pg").option(
|
@@ -61199,7 +61261,7 @@ var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
61199
61261
|
tablesToTruncate,
|
61200
61262
|
infoToPrint,
|
61201
61263
|
schemasToRemove
|
61202
|
-
} = await
|
61264
|
+
} = await logSuggestionsAndReturn({
|
61203
61265
|
connection: connection.client,
|
61204
61266
|
statements: statements.statements,
|
61205
61267
|
json1: statements.squashedPrev,
|