drizzle-kit 0.24.0-38d6dab → 0.24.0-6386ea9
Sign up to get free protection for your applications and to get access to all the features.
- package/api.js +411 -1242
- package/api.mjs +411 -1242
- package/bin.cjs +950 -1796
- package/package.json +3 -3
- package/utils.js +0 -9
- package/utils.mjs +0 -8
package/bin.cjs
CHANGED
@@ -6564,13 +6564,6 @@ var init_sqliteSchema = __esm({
|
|
6564
6564
|
function isPgArrayType(sqlType) {
|
6565
6565
|
return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
|
6566
6566
|
}
|
6567
|
-
function findAddedAndRemoved(columnNames1, columnNames2) {
|
6568
|
-
const set1 = new Set(columnNames1);
|
6569
|
-
const set2 = new Set(columnNames2);
|
6570
|
-
const addedColumns = columnNames2.filter((it) => !set1.has(it));
|
6571
|
-
const removedColumns = columnNames1.filter((it) => !set2.has(it));
|
6572
|
-
return { addedColumns, removedColumns };
|
6573
|
-
}
|
6574
6567
|
var import_fs, import_path, import_url, copy, objectValues, assertV1OutFolder, dryJournal, prepareOutFolder, validatorForDialect, validateWithReport, prepareMigrationFolder, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey, normaliseSQLiteUrl;
|
6575
6568
|
var init_utils = __esm({
|
6576
6569
|
"src/utils.ts"() {
|
@@ -11368,8 +11361,7 @@ var init_cli = __esm({
|
|
11368
11361
|
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
11369
11362
|
extensionsFilters: literalType("postgis").array().optional(),
|
11370
11363
|
verbose: booleanType().optional(),
|
11371
|
-
strict: booleanType().optional()
|
11372
|
-
driver: driver.optional()
|
11364
|
+
strict: booleanType().optional()
|
11373
11365
|
}).passthrough();
|
11374
11366
|
pullParams = objectType({
|
11375
11367
|
config: stringType().optional(),
|
@@ -17373,8 +17365,7 @@ var init_utils4 = __esm({
|
|
17373
17365
|
breakpoints: breakpoints || true,
|
17374
17366
|
schema: schema5,
|
17375
17367
|
out: out || "drizzle",
|
17376
|
-
bundle: driver2 === "expo"
|
17377
|
-
driver: driver2
|
17368
|
+
bundle: driver2 === "expo"
|
17378
17369
|
};
|
17379
17370
|
};
|
17380
17371
|
flattenDatabaseCredentials = (config) => {
|
@@ -17402,7 +17393,6 @@ var init_utils4 = __esm({
|
|
17402
17393
|
const raw2 = flattenDatabaseCredentials(
|
17403
17394
|
from === "config" ? await drizzleConfigFromFile(options.config) : options
|
17404
17395
|
);
|
17405
|
-
raw2.driver ||= options.driver;
|
17406
17396
|
raw2.verbose ||= options.verbose;
|
17407
17397
|
raw2.strict ||= options.strict;
|
17408
17398
|
const parsed = pushParams.safeParse(raw2);
|
@@ -17477,8 +17467,7 @@ var init_utils4 = __esm({
|
|
17477
17467
|
force: options.force ?? false,
|
17478
17468
|
credentials: parsed2.data,
|
17479
17469
|
tablesFilter,
|
17480
|
-
schemasFilter
|
17481
|
-
driver: config.driver
|
17470
|
+
schemasFilter
|
17482
17471
|
};
|
17483
17472
|
}
|
17484
17473
|
assertUnreachable(config.dialect);
|
@@ -22863,20 +22852,7 @@ var init_jsonDiffer = __esm({
|
|
22863
22852
|
});
|
22864
22853
|
|
22865
22854
|
// src/sqlgenerator.ts
|
22866
|
-
|
22867
|
-
const result = statements.flatMap((statement) => {
|
22868
|
-
const filtered = convertors.filter((it) => {
|
22869
|
-
return it.can(statement, dialect7, driver2);
|
22870
|
-
});
|
22871
|
-
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
22872
|
-
if (!convertor) {
|
22873
|
-
return "";
|
22874
|
-
}
|
22875
|
-
return convertor.convert(statement, json2, action);
|
22876
|
-
}).filter((it) => it !== "");
|
22877
|
-
return result;
|
22878
|
-
}
|
22879
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, LibSQLDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
22855
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, convertors, fromJson;
|
22880
22856
|
var init_sqlgenerator = __esm({
|
22881
22857
|
"src/sqlgenerator.ts"() {
|
22882
22858
|
"use strict";
|
@@ -23395,7 +23371,7 @@ var init_sqlgenerator = __esm({
|
|
23395
23371
|
}
|
23396
23372
|
convert(statement) {
|
23397
23373
|
const { tableName, oldColumnName, newColumnName } = statement;
|
23398
|
-
return `ALTER TABLE \`${tableName}\` RENAME COLUMN
|
23374
|
+
return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
|
23399
23375
|
}
|
23400
23376
|
};
|
23401
23377
|
PgAlterTableDropColumnConvertor = class extends Convertor {
|
@@ -23497,8 +23473,8 @@ var init_sqlgenerator = __esm({
|
|
23497
23473
|
}
|
23498
23474
|
};
|
23499
23475
|
SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
|
23500
|
-
can(statement, dialect7
|
23501
|
-
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite"
|
23476
|
+
can(statement, dialect7) {
|
23477
|
+
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
|
23502
23478
|
}
|
23503
23479
|
convert(statement) {
|
23504
23480
|
return `/*
|
@@ -23809,46 +23785,6 @@ var init_sqlgenerator = __esm({
|
|
23809
23785
|
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
|
23810
23786
|
}
|
23811
23787
|
};
|
23812
|
-
LibSQLModifyColumn = class extends Convertor {
|
23813
|
-
can(statement, dialect7, driver2) {
|
23814
|
-
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") && dialect7 === "sqlite" && driver2 === "turso";
|
23815
|
-
}
|
23816
|
-
convert(statement, json2) {
|
23817
|
-
const { tableName, columnName } = statement;
|
23818
|
-
let columnType = ``;
|
23819
|
-
let columnDefault = "";
|
23820
|
-
let columnNotNull = "";
|
23821
|
-
switch (statement.type) {
|
23822
|
-
case "alter_table_alter_column_set_type":
|
23823
|
-
columnType = ` ${statement.newDataType}`;
|
23824
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
23825
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
23826
|
-
break;
|
23827
|
-
case "alter_table_alter_column_drop_notnull":
|
23828
|
-
columnType = ` ${statement.newDataType}`;
|
23829
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
23830
|
-
columnNotNull = "";
|
23831
|
-
break;
|
23832
|
-
case "alter_table_alter_column_set_notnull":
|
23833
|
-
columnType = ` ${statement.newDataType}`;
|
23834
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
23835
|
-
columnNotNull = ` NOT NULL`;
|
23836
|
-
break;
|
23837
|
-
case "alter_table_alter_column_set_default":
|
23838
|
-
columnType = ` ${statement.newDataType}`;
|
23839
|
-
columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
|
23840
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
23841
|
-
break;
|
23842
|
-
case "alter_table_alter_column_drop_default":
|
23843
|
-
columnType = ` ${statement.newDataType}`;
|
23844
|
-
columnDefault = "";
|
23845
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
23846
|
-
break;
|
23847
|
-
}
|
23848
|
-
columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
|
23849
|
-
return `ALTER TABLE \`${tableName}\` ALTER COLUMN "${columnName}" TO "${columnName}"${columnType}${columnNotNull}${columnDefault};`;
|
23850
|
-
}
|
23851
|
-
};
|
23852
23788
|
MySqlModifyColumn = class extends Convertor {
|
23853
23789
|
can(statement, dialect7) {
|
23854
23790
|
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_on_update" || statement.type === "alter_table_alter_column_set_on_update" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_generated" || statement.type === "alter_table_alter_column_drop_generated") && dialect7 === "mysql";
|
@@ -24190,8 +24126,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24190
24126
|
}
|
24191
24127
|
};
|
24192
24128
|
SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
|
24193
|
-
can(statement, dialect7
|
24194
|
-
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite"
|
24129
|
+
can(statement, dialect7) {
|
24130
|
+
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
|
24195
24131
|
}
|
24196
24132
|
convert(statement) {
|
24197
24133
|
return `/*
|
@@ -24205,8 +24141,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24205
24141
|
}
|
24206
24142
|
};
|
24207
24143
|
SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
|
24208
|
-
can(statement, dialect7
|
24209
|
-
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite"
|
24144
|
+
can(statement, dialect7) {
|
24145
|
+
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
|
24210
24146
|
}
|
24211
24147
|
convert(statement) {
|
24212
24148
|
return `/*
|
@@ -24220,8 +24156,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24220
24156
|
}
|
24221
24157
|
};
|
24222
24158
|
SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
|
24223
|
-
can(statement, dialect7
|
24224
|
-
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite"
|
24159
|
+
can(statement, dialect7) {
|
24160
|
+
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
|
24225
24161
|
}
|
24226
24162
|
convert(statement) {
|
24227
24163
|
return `/*
|
@@ -24245,8 +24181,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24245
24181
|
}
|
24246
24182
|
};
|
24247
24183
|
SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
24248
|
-
can(statement, dialect7
|
24249
|
-
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite"
|
24184
|
+
can(statement, dialect7) {
|
24185
|
+
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
|
24250
24186
|
}
|
24251
24187
|
convert(statement) {
|
24252
24188
|
return `/*
|
@@ -24290,8 +24226,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24290
24226
|
}
|
24291
24227
|
};
|
24292
24228
|
SqliteCreateForeignKeyConvertor = class extends Convertor {
|
24293
|
-
can(statement, dialect7
|
24294
|
-
return statement.type === "create_reference" && dialect7 === "sqlite"
|
24229
|
+
can(statement, dialect7) {
|
24230
|
+
return statement.type === "create_reference" && dialect7 === "sqlite";
|
24295
24231
|
}
|
24296
24232
|
convert(statement) {
|
24297
24233
|
return `/*
|
@@ -24303,32 +24239,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24303
24239
|
*/`;
|
24304
24240
|
}
|
24305
24241
|
};
|
24306
|
-
LibSQLCreateForeignKeyConvertor = class extends Convertor {
|
24307
|
-
can(statement, dialect7, driver2) {
|
24308
|
-
return statement.type === "create_reference" && dialect7 === "sqlite" && driver2 === "turso";
|
24309
|
-
}
|
24310
|
-
convert(statement, json2, action) {
|
24311
|
-
const { columnsFrom, columnsTo, tableFrom, onDelete, onUpdate, tableTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
24312
|
-
const { columnDefault, columnNotNull, columnType, isMulticolumn } = statement;
|
24313
|
-
if (isMulticolumn) {
|
24314
|
-
return `/*
|
24315
|
-
LibSQL does not support "Creating foreign key on multiple columns" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
24316
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
24317
|
-
https://www.sqlite.org/lang_altertable.html
|
24318
|
-
|
24319
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
24320
|
-
*/`;
|
24321
|
-
}
|
24322
|
-
const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : "";
|
24323
|
-
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
24324
|
-
const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
|
24325
|
-
const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
|
24326
|
-
const columnTypeValue = columnType ? ` ${columnType}` : "";
|
24327
|
-
const columnFrom = columnsFrom[0];
|
24328
|
-
const columnTo = columnsTo[0];
|
24329
|
-
return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
|
24330
|
-
}
|
24331
|
-
};
|
24332
24242
|
MySqlCreateForeignKeyConvertor = class extends Convertor {
|
24333
24243
|
can(statement, dialect7) {
|
24334
24244
|
return statement.type === "create_reference" && dialect7 === "mysql";
|
@@ -24402,8 +24312,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24402
24312
|
}
|
24403
24313
|
};
|
24404
24314
|
SqliteDeleteForeignKeyConvertor = class extends Convertor {
|
24405
|
-
can(statement, dialect7
|
24406
|
-
return statement.type === "delete_reference" && dialect7 === "sqlite"
|
24315
|
+
can(statement, dialect7) {
|
24316
|
+
return statement.type === "delete_reference" && dialect7 === "sqlite";
|
24407
24317
|
}
|
24408
24318
|
convert(statement) {
|
24409
24319
|
return `/*
|
@@ -24415,29 +24325,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24415
24325
|
*/`;
|
24416
24326
|
}
|
24417
24327
|
};
|
24418
|
-
LibSQLDeleteForeignKeyConvertor = class extends Convertor {
|
24419
|
-
can(statement, dialect7, driver2) {
|
24420
|
-
return statement.type === "delete_reference" && dialect7 === "sqlite" && driver2 === "turso";
|
24421
|
-
}
|
24422
|
-
convert(statement, json2, action) {
|
24423
|
-
const { columnsFrom, tableFrom } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
24424
|
-
const { columnDefault, columnNotNull, columnType, isMulticolumn } = statement;
|
24425
|
-
if (isMulticolumn) {
|
24426
|
-
return `/*
|
24427
|
-
LibSQL does not support "Creating foreign key on multiple columns" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
24428
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
24429
|
-
https://www.sqlite.org/lang_altertable.html
|
24430
|
-
|
24431
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
24432
|
-
*/`;
|
24433
|
-
}
|
24434
|
-
const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
|
24435
|
-
const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
|
24436
|
-
const columnTypeValue = columnType ? ` ${columnType}` : "";
|
24437
|
-
const columnFrom = columnsFrom[0];
|
24438
|
-
return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue};`;
|
24439
|
-
}
|
24440
|
-
};
|
24441
24328
|
MySqlDeleteForeignKeyConvertor = class extends Convertor {
|
24442
24329
|
can(statement, dialect7) {
|
24443
24330
|
return statement.type === "delete_reference" && dialect7 === "mysql";
|
@@ -24603,90 +24490,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24603
24490
|
return `DROP INDEX \`${name}\` ON \`${statement.tableName}\`;`;
|
24604
24491
|
}
|
24605
24492
|
};
|
24606
|
-
SQLiteRecreateTableConvertor = class extends Convertor {
|
24607
|
-
can(statement, dialect7, driver2) {
|
24608
|
-
return statement.type === "recreate_table" && dialect7 === "sqlite" && !driver2;
|
24609
|
-
}
|
24610
|
-
convert(statement) {
|
24611
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
24612
|
-
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
24613
|
-
const sqlStatements = [];
|
24614
|
-
sqlStatements.push(
|
24615
|
-
new SqliteRenameTableConvertor().convert({
|
24616
|
-
fromSchema: "",
|
24617
|
-
tableNameFrom: tableName,
|
24618
|
-
tableNameTo: `__old__generate_${tableName}`,
|
24619
|
-
toSchema: "",
|
24620
|
-
type: "rename_table"
|
24621
|
-
})
|
24622
|
-
);
|
24623
|
-
sqlStatements.push(
|
24624
|
-
new SQLiteCreateTableConvertor().convert({
|
24625
|
-
type: "sqlite_create_table",
|
24626
|
-
tableName,
|
24627
|
-
columns,
|
24628
|
-
referenceData,
|
24629
|
-
compositePKs
|
24630
|
-
})
|
24631
|
-
);
|
24632
|
-
sqlStatements.push(
|
24633
|
-
`INSERT INTO \`${tableName}\`(${columnNames}) SELECT ${columnNames} FROM \`__old__generate_${tableName}\`;`
|
24634
|
-
);
|
24635
|
-
sqlStatements.push(
|
24636
|
-
new SQLiteDropTableConvertor().convert({
|
24637
|
-
type: "drop_table",
|
24638
|
-
tableName: `__old__generate_${tableName}`,
|
24639
|
-
schema: ""
|
24640
|
-
})
|
24641
|
-
);
|
24642
|
-
return sqlStatements;
|
24643
|
-
}
|
24644
|
-
};
|
24645
|
-
LibSQLRecreateTableConvertor = class extends Convertor {
|
24646
|
-
can(statement, dialect7, driver2) {
|
24647
|
-
return statement.type === "recreate_table" && dialect7 === "sqlite" && driver2 === "turso";
|
24648
|
-
}
|
24649
|
-
convert(statement) {
|
24650
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
24651
|
-
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
24652
|
-
const sqlStatements = [];
|
24653
|
-
sqlStatements.push(
|
24654
|
-
new SqliteRenameTableConvertor().convert({
|
24655
|
-
fromSchema: "",
|
24656
|
-
tableNameFrom: tableName,
|
24657
|
-
tableNameTo: `__old__generate_${tableName}`,
|
24658
|
-
toSchema: "",
|
24659
|
-
type: "rename_table"
|
24660
|
-
})
|
24661
|
-
);
|
24662
|
-
sqlStatements.push(
|
24663
|
-
new SQLiteCreateTableConvertor().convert({
|
24664
|
-
type: "sqlite_create_table",
|
24665
|
-
tableName,
|
24666
|
-
columns,
|
24667
|
-
referenceData,
|
24668
|
-
compositePKs
|
24669
|
-
})
|
24670
|
-
);
|
24671
|
-
sqlStatements.push(
|
24672
|
-
`INSERT INTO \`${tableName}\`(${columnNames}) SELECT ${columnNames} FROM \`__old__generate_${tableName}\`;`
|
24673
|
-
);
|
24674
|
-
sqlStatements.push(
|
24675
|
-
new SQLiteDropTableConvertor().convert({
|
24676
|
-
type: "drop_table",
|
24677
|
-
tableName: `__old__generate_${tableName}`,
|
24678
|
-
schema: ""
|
24679
|
-
})
|
24680
|
-
);
|
24681
|
-
return sqlStatements;
|
24682
|
-
}
|
24683
|
-
};
|
24684
24493
|
convertors = [];
|
24685
24494
|
convertors.push(new PgCreateTableConvertor());
|
24686
24495
|
convertors.push(new MySqlCreateTableConvertor());
|
24687
24496
|
convertors.push(new SQLiteCreateTableConvertor());
|
24688
|
-
convertors.push(new SQLiteRecreateTableConvertor());
|
24689
|
-
convertors.push(new LibSQLRecreateTableConvertor());
|
24690
24497
|
convertors.push(new CreateTypeEnumConvertor());
|
24691
24498
|
convertors.push(new CreatePgSequenceConvertor());
|
24692
24499
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -24734,7 +24541,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24734
24541
|
convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
|
24735
24542
|
convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
|
24736
24543
|
convertors.push(new MySqlModifyColumn());
|
24737
|
-
convertors.push(new LibSQLModifyColumn());
|
24738
24544
|
convertors.push(new PgCreateForeignKeyConvertor());
|
24739
24545
|
convertors.push(new MySqlCreateForeignKeyConvertor());
|
24740
24546
|
convertors.push(new PgAlterForeignKeyConvertor());
|
@@ -24749,9 +24555,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24749
24555
|
convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
|
24750
24556
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
24751
24557
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
24752
|
-
convertors.push(new LibSQLDeleteForeignKeyConvertor());
|
24753
24558
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
24754
|
-
convertors.push(new LibSQLCreateForeignKeyConvertor());
|
24755
24559
|
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
24756
24560
|
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
24757
24561
|
convertors.push(new PgAlterTableAlterColumnDropGenerated());
|
@@ -24774,6 +24578,19 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
24774
24578
|
convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
|
24775
24579
|
convertors.push(new MySqlAlterTableAddPk());
|
24776
24580
|
convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
|
24581
|
+
fromJson = (statements, dialect7) => {
|
24582
|
+
const result = statements.flatMap((statement) => {
|
24583
|
+
const filtered = convertors.filter((it) => {
|
24584
|
+
return it.can(statement, dialect7);
|
24585
|
+
});
|
24586
|
+
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
24587
|
+
if (!convertor) {
|
24588
|
+
return "";
|
24589
|
+
}
|
24590
|
+
return convertor.convert(statement);
|
24591
|
+
}).filter((it) => it !== "");
|
24592
|
+
return result;
|
24593
|
+
};
|
24777
24594
|
https:
|
24778
24595
|
`
|
24779
24596
|
create table users (
|
@@ -24801,237 +24618,12 @@ drop type __venum;
|
|
24801
24618
|
}
|
24802
24619
|
});
|
24803
24620
|
|
24804
|
-
// src/cli/commands/sqlitePushUtils.ts
|
24805
|
-
var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
|
24806
|
-
var init_sqlitePushUtils = __esm({
|
24807
|
-
"src/cli/commands/sqlitePushUtils.ts"() {
|
24808
|
-
"use strict";
|
24809
|
-
init_source();
|
24810
|
-
init_sqliteSchema();
|
24811
|
-
init_sqlgenerator();
|
24812
|
-
init_utils();
|
24813
|
-
_moveDataStatements = (tableName, json, dataLoss = false) => {
|
24814
|
-
const statements = [];
|
24815
|
-
statements.push(
|
24816
|
-
new SqliteRenameTableConvertor().convert({
|
24817
|
-
type: "rename_table",
|
24818
|
-
tableNameFrom: tableName,
|
24819
|
-
tableNameTo: `__old_push_${tableName}`,
|
24820
|
-
fromSchema: "",
|
24821
|
-
toSchema: ""
|
24822
|
-
})
|
24823
|
-
);
|
24824
|
-
const tableColumns = Object.values(json.tables[tableName].columns);
|
24825
|
-
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
24826
|
-
const compositePKs = Object.values(
|
24827
|
-
json.tables[tableName].compositePrimaryKeys
|
24828
|
-
).map((it) => SQLiteSquasher.unsquashPK(it));
|
24829
|
-
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
24830
|
-
statements.push(
|
24831
|
-
new SQLiteCreateTableConvertor().convert({
|
24832
|
-
type: "sqlite_create_table",
|
24833
|
-
tableName,
|
24834
|
-
columns: tableColumns,
|
24835
|
-
referenceData: fks,
|
24836
|
-
compositePKs
|
24837
|
-
})
|
24838
|
-
);
|
24839
|
-
if (!dataLoss) {
|
24840
|
-
const columns = Object.keys(json.tables[tableName].columns).map(
|
24841
|
-
(c) => `"${c}"`
|
24842
|
-
);
|
24843
|
-
statements.push(
|
24844
|
-
`INSERT INTO \`${tableName}\`(${columns.join(
|
24845
|
-
", "
|
24846
|
-
)}) SELECT (${columns.join(", ")}) FROM \`__old_push_${tableName}\`;`
|
24847
|
-
);
|
24848
|
-
}
|
24849
|
-
statements.push(
|
24850
|
-
new SQLiteDropTableConvertor().convert({
|
24851
|
-
type: "drop_table",
|
24852
|
-
tableName: `__old_push_${tableName}`,
|
24853
|
-
schema: ""
|
24854
|
-
})
|
24855
|
-
);
|
24856
|
-
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
24857
|
-
statements.push(
|
24858
|
-
new CreateSqliteIndexConvertor().convert({
|
24859
|
-
type: "create_index",
|
24860
|
-
tableName,
|
24861
|
-
schema: "",
|
24862
|
-
data: idx
|
24863
|
-
})
|
24864
|
-
);
|
24865
|
-
}
|
24866
|
-
return statements;
|
24867
|
-
};
|
24868
|
-
getOldTableName = (tableName, meta) => {
|
24869
|
-
for (const key of Object.keys(meta.tables)) {
|
24870
|
-
const value = meta.tables[key];
|
24871
|
-
if (`"${tableName}"` === value) {
|
24872
|
-
return key.substring(1, key.length - 1);
|
24873
|
-
}
|
24874
|
-
}
|
24875
|
-
return tableName;
|
24876
|
-
};
|
24877
|
-
getNewTableName = (tableName, meta) => {
|
24878
|
-
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
24879
|
-
return meta.tables[`"${tableName}"`].substring(
|
24880
|
-
1,
|
24881
|
-
meta.tables[`"${tableName}"`].length - 1
|
24882
|
-
);
|
24883
|
-
}
|
24884
|
-
return tableName;
|
24885
|
-
};
|
24886
|
-
logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
24887
|
-
let shouldAskForApprove = false;
|
24888
|
-
const statementsToExecute = [];
|
24889
|
-
const infoToPrint = [];
|
24890
|
-
const tablesToRemove = [];
|
24891
|
-
const columnsToRemove = [];
|
24892
|
-
const schemasToRemove = [];
|
24893
|
-
const tablesToTruncate = [];
|
24894
|
-
for (const statement of statements) {
|
24895
|
-
if (statement.type === "drop_table") {
|
24896
|
-
const res = await connection.query(
|
24897
|
-
`select count(*) as count from \`${statement.tableName}\``
|
24898
|
-
);
|
24899
|
-
const count = Number(res[0].count);
|
24900
|
-
if (count > 0) {
|
24901
|
-
infoToPrint.push(
|
24902
|
-
`\xB7 You're about to delete ${source_default.underline(
|
24903
|
-
statement.tableName
|
24904
|
-
)} table with ${count} items`
|
24905
|
-
);
|
24906
|
-
tablesToRemove.push(statement.tableName);
|
24907
|
-
shouldAskForApprove = true;
|
24908
|
-
}
|
24909
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
24910
|
-
statementsToExecute.push(
|
24911
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
24912
|
-
);
|
24913
|
-
} else if (statement.type === "alter_table_drop_column") {
|
24914
|
-
const tableName = statement.tableName;
|
24915
|
-
const columnName = statement.columnName;
|
24916
|
-
const res = await connection.query(
|
24917
|
-
`select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``
|
24918
|
-
);
|
24919
|
-
const count = Number(res[0].count);
|
24920
|
-
if (count > 0) {
|
24921
|
-
infoToPrint.push(
|
24922
|
-
`\xB7 You're about to delete ${source_default.underline(
|
24923
|
-
columnName
|
24924
|
-
)} column in ${tableName} table with ${count} items`
|
24925
|
-
);
|
24926
|
-
columnsToRemove.push(`${tableName}_${statement.columnName}`);
|
24927
|
-
shouldAskForApprove = true;
|
24928
|
-
}
|
24929
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
24930
|
-
statementsToExecute.push(
|
24931
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
24932
|
-
);
|
24933
|
-
} else if (statement.type === "sqlite_alter_table_add_column" && (statement.column.notNull && !statement.column.default)) {
|
24934
|
-
const tableName = statement.tableName;
|
24935
|
-
const columnName = statement.column.name;
|
24936
|
-
const res = await connection.query(
|
24937
|
-
`select count(*) as count from \`${tableName}\``
|
24938
|
-
);
|
24939
|
-
const count = Number(res[0].count);
|
24940
|
-
if (count > 0) {
|
24941
|
-
infoToPrint.push(
|
24942
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
24943
|
-
columnName
|
24944
|
-
)} column without default value, which contains ${count} items`
|
24945
|
-
);
|
24946
|
-
tablesToTruncate.push(tableName);
|
24947
|
-
statementsToExecute.push(`delete from ${tableName};`);
|
24948
|
-
shouldAskForApprove = true;
|
24949
|
-
}
|
24950
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
24951
|
-
statementsToExecute.push(
|
24952
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
24953
|
-
);
|
24954
|
-
} else if (statement.type === "recreate_table") {
|
24955
|
-
const tableName = statement.tableName;
|
24956
|
-
const oldTableName = getOldTableName(tableName, meta);
|
24957
|
-
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
24958
|
-
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
24959
|
-
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
24960
|
-
prevColumnNames,
|
24961
|
-
currentColumnNames
|
24962
|
-
);
|
24963
|
-
if (removedColumns.length) {
|
24964
|
-
for (const removedColumn of removedColumns) {
|
24965
|
-
const res = await connection.query(
|
24966
|
-
`select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
|
24967
|
-
);
|
24968
|
-
const count = Number(res[0].count);
|
24969
|
-
if (count > 0) {
|
24970
|
-
infoToPrint.push(
|
24971
|
-
`\xB7 You're about to delete ${source_default.underline(
|
24972
|
-
removedColumn
|
24973
|
-
)} column in ${tableName} table with ${count} items`
|
24974
|
-
);
|
24975
|
-
columnsToRemove.push(removedColumn);
|
24976
|
-
shouldAskForApprove = true;
|
24977
|
-
}
|
24978
|
-
}
|
24979
|
-
}
|
24980
|
-
if (addedColumns.length) {
|
24981
|
-
for (const addedColumn of addedColumns) {
|
24982
|
-
const [res] = await connection.query(
|
24983
|
-
`select count(*) as count from \`${tableName}\``
|
24984
|
-
);
|
24985
|
-
const columnConf = json2.tables[tableName].columns[addedColumn];
|
24986
|
-
const count = Number(res.count);
|
24987
|
-
if (count > 0 && columnConf.notNull && !columnConf.default) {
|
24988
|
-
infoToPrint.push(
|
24989
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
24990
|
-
addedColumn
|
24991
|
-
)} column without default value to table, which contains ${count} items`
|
24992
|
-
);
|
24993
|
-
shouldAskForApprove = true;
|
24994
|
-
tablesToTruncate.push(tableName);
|
24995
|
-
}
|
24996
|
-
}
|
24997
|
-
}
|
24998
|
-
statementsToExecute.push(..._moveDataStatements(tableName, json2));
|
24999
|
-
const tablesReferencingCurrent = [];
|
25000
|
-
for (const table4 of Object.values(json2.tables)) {
|
25001
|
-
const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t2) => SQLiteSquasher.unsquashPushFK(t2).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
|
25002
|
-
tablesReferencingCurrent.push(...tablesRefs);
|
25003
|
-
}
|
25004
|
-
const uniqueTableRefs = [...new Set(tablesReferencingCurrent)];
|
25005
|
-
for (const table4 of uniqueTableRefs) {
|
25006
|
-
statementsToExecute.push(..._moveDataStatements(table4, json2));
|
25007
|
-
}
|
25008
|
-
} else {
|
25009
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
25010
|
-
statementsToExecute.push(
|
25011
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
25012
|
-
);
|
25013
|
-
}
|
25014
|
-
}
|
25015
|
-
return {
|
25016
|
-
statementsToExecute,
|
25017
|
-
shouldAskForApprove,
|
25018
|
-
infoToPrint,
|
25019
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
25020
|
-
schemasToRemove: [...new Set(schemasToRemove)],
|
25021
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
25022
|
-
tablesToRemove: [...new Set(tablesToRemove)]
|
25023
|
-
};
|
25024
|
-
};
|
25025
|
-
}
|
25026
|
-
});
|
25027
|
-
|
25028
24621
|
// src/jsonStatements.ts
|
25029
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson,
|
24622
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
25030
24623
|
var init_jsonStatements = __esm({
|
25031
24624
|
"src/jsonStatements.ts"() {
|
25032
24625
|
"use strict";
|
25033
24626
|
init_source();
|
25034
|
-
init_sqlitePushUtils();
|
25035
24627
|
init_views();
|
25036
24628
|
init_mysqlSchema();
|
25037
24629
|
init_pgSchema();
|
@@ -25805,7 +25397,7 @@ var init_jsonStatements = __esm({
|
|
25805
25397
|
return [...dropPkStatements, ...setPkStatements, ...statements];
|
25806
25398
|
};
|
25807
25399
|
prepareSqliteAlterColumns = (tableName, schema5, columns, json2) => {
|
25808
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p
|
25400
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
25809
25401
|
let statements = [];
|
25810
25402
|
let dropPkStatements = [];
|
25811
25403
|
let setPkStatements = [];
|
@@ -25819,49 +25411,6 @@ var init_jsonStatements = __esm({
|
|
25819
25411
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
25820
25412
|
const columnGenerated = json2.tables[tableName].columns[columnName].generated;
|
25821
25413
|
const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
|
25822
|
-
if (((_a = column7.autoincrement) == null ? void 0 : _a.type) === "added") {
|
25823
|
-
statements.push({
|
25824
|
-
type: "alter_table_alter_column_set_autoincrement",
|
25825
|
-
tableName,
|
25826
|
-
columnName,
|
25827
|
-
schema: schema5,
|
25828
|
-
newDataType: columnType,
|
25829
|
-
columnDefault,
|
25830
|
-
columnOnUpdate,
|
25831
|
-
columnNotNull,
|
25832
|
-
columnAutoIncrement,
|
25833
|
-
columnPk
|
25834
|
-
});
|
25835
|
-
}
|
25836
|
-
if (((_b = column7.autoincrement) == null ? void 0 : _b.type) === "changed") {
|
25837
|
-
const type = column7.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
|
25838
|
-
statements.push({
|
25839
|
-
type,
|
25840
|
-
tableName,
|
25841
|
-
columnName,
|
25842
|
-
schema: schema5,
|
25843
|
-
newDataType: columnType,
|
25844
|
-
columnDefault,
|
25845
|
-
columnOnUpdate,
|
25846
|
-
columnNotNull,
|
25847
|
-
columnAutoIncrement,
|
25848
|
-
columnPk
|
25849
|
-
});
|
25850
|
-
}
|
25851
|
-
if (((_c = column7.autoincrement) == null ? void 0 : _c.type) === "deleted") {
|
25852
|
-
statements.push({
|
25853
|
-
type: "alter_table_alter_column_drop_autoincrement",
|
25854
|
-
tableName,
|
25855
|
-
columnName,
|
25856
|
-
schema: schema5,
|
25857
|
-
newDataType: columnType,
|
25858
|
-
columnDefault,
|
25859
|
-
columnOnUpdate,
|
25860
|
-
columnNotNull,
|
25861
|
-
columnAutoIncrement,
|
25862
|
-
columnPk
|
25863
|
-
});
|
25864
|
-
}
|
25865
25414
|
if (typeof column7.name !== "string") {
|
25866
25415
|
statements.push({
|
25867
25416
|
type: "alter_table_rename_column",
|
@@ -25871,7 +25420,7 @@ var init_jsonStatements = __esm({
|
|
25871
25420
|
schema: schema5
|
25872
25421
|
});
|
25873
25422
|
}
|
25874
|
-
if (((
|
25423
|
+
if (((_a = column7.type) == null ? void 0 : _a.type) === "changed") {
|
25875
25424
|
statements.push({
|
25876
25425
|
type: "alter_table_alter_column_set_type",
|
25877
25426
|
tableName,
|
@@ -25886,7 +25435,7 @@ var init_jsonStatements = __esm({
|
|
25886
25435
|
columnPk
|
25887
25436
|
});
|
25888
25437
|
}
|
25889
|
-
if (((
|
25438
|
+
if (((_b = column7.primaryKey) == null ? void 0 : _b.type) === "deleted" || ((_c = column7.primaryKey) == null ? void 0 : _c.type) === "changed" && !column7.primaryKey.new && typeof compositePk === "undefined") {
|
25890
25439
|
dropPkStatements.push({
|
25891
25440
|
////
|
25892
25441
|
type: "alter_table_alter_column_drop_pk",
|
@@ -25895,7 +25444,7 @@ var init_jsonStatements = __esm({
|
|
25895
25444
|
schema: schema5
|
25896
25445
|
});
|
25897
25446
|
}
|
25898
|
-
if (((
|
25447
|
+
if (((_d = column7.default) == null ? void 0 : _d.type) === "added") {
|
25899
25448
|
statements.push({
|
25900
25449
|
type: "alter_table_alter_column_set_default",
|
25901
25450
|
tableName,
|
@@ -25909,7 +25458,7 @@ var init_jsonStatements = __esm({
|
|
25909
25458
|
columnPk
|
25910
25459
|
});
|
25911
25460
|
}
|
25912
|
-
if (((
|
25461
|
+
if (((_e = column7.default) == null ? void 0 : _e.type) === "changed") {
|
25913
25462
|
statements.push({
|
25914
25463
|
type: "alter_table_alter_column_set_default",
|
25915
25464
|
tableName,
|
@@ -25924,7 +25473,7 @@ var init_jsonStatements = __esm({
|
|
25924
25473
|
columnPk
|
25925
25474
|
});
|
25926
25475
|
}
|
25927
|
-
if (((
|
25476
|
+
if (((_f = column7.default) == null ? void 0 : _f.type) === "deleted") {
|
25928
25477
|
statements.push({
|
25929
25478
|
type: "alter_table_alter_column_drop_default",
|
25930
25479
|
tableName,
|
@@ -25938,7 +25487,7 @@ var init_jsonStatements = __esm({
|
|
25938
25487
|
columnPk
|
25939
25488
|
});
|
25940
25489
|
}
|
25941
|
-
if (((
|
25490
|
+
if (((_g = column7.notNull) == null ? void 0 : _g.type) === "added") {
|
25942
25491
|
statements.push({
|
25943
25492
|
type: "alter_table_alter_column_set_notnull",
|
25944
25493
|
tableName,
|
@@ -25952,7 +25501,7 @@ var init_jsonStatements = __esm({
|
|
25952
25501
|
columnPk
|
25953
25502
|
});
|
25954
25503
|
}
|
25955
|
-
if (((
|
25504
|
+
if (((_h = column7.notNull) == null ? void 0 : _h.type) === "changed") {
|
25956
25505
|
const type = column7.notNull.new ? "alter_table_alter_column_set_notnull" : "alter_table_alter_column_drop_notnull";
|
25957
25506
|
statements.push({
|
25958
25507
|
type,
|
@@ -25967,7 +25516,7 @@ var init_jsonStatements = __esm({
|
|
25967
25516
|
columnPk
|
25968
25517
|
});
|
25969
25518
|
}
|
25970
|
-
if (((
|
25519
|
+
if (((_i = column7.notNull) == null ? void 0 : _i.type) === "deleted") {
|
25971
25520
|
statements.push({
|
25972
25521
|
type: "alter_table_alter_column_drop_notnull",
|
25973
25522
|
tableName,
|
@@ -25981,7 +25530,7 @@ var init_jsonStatements = __esm({
|
|
25981
25530
|
columnPk
|
25982
25531
|
});
|
25983
25532
|
}
|
25984
|
-
if (((
|
25533
|
+
if (((_j = column7.generated) == null ? void 0 : _j.type) === "added") {
|
25985
25534
|
if ((columnGenerated == null ? void 0 : columnGenerated.type) === "virtual") {
|
25986
25535
|
statements.push({
|
25987
25536
|
type: "alter_table_alter_column_set_generated",
|
@@ -26002,7 +25551,7 @@ var init_jsonStatements = __esm({
|
|
26002
25551
|
);
|
26003
25552
|
}
|
26004
25553
|
}
|
26005
|
-
if (((
|
25554
|
+
if (((_k = column7.generated) == null ? void 0 : _k.type) === "changed") {
|
26006
25555
|
if ((columnGenerated == null ? void 0 : columnGenerated.type) === "virtual") {
|
26007
25556
|
statements.push({
|
26008
25557
|
type: "alter_table_alter_column_alter_generated",
|
@@ -26023,7 +25572,7 @@ var init_jsonStatements = __esm({
|
|
26023
25572
|
);
|
26024
25573
|
}
|
26025
25574
|
}
|
26026
|
-
if (((
|
25575
|
+
if (((_l = column7.generated) == null ? void 0 : _l.type) === "deleted") {
|
26027
25576
|
statements.push({
|
26028
25577
|
type: "alter_table_alter_column_drop_generated",
|
26029
25578
|
tableName,
|
@@ -26038,7 +25587,7 @@ var init_jsonStatements = __esm({
|
|
26038
25587
|
columnGenerated
|
26039
25588
|
});
|
26040
25589
|
}
|
26041
|
-
if (((
|
25590
|
+
if (((_m = column7.primaryKey) == null ? void 0 : _m.type) === "added" || ((_n = column7.primaryKey) == null ? void 0 : _n.type) === "changed" && column7.primaryKey.new) {
|
26042
25591
|
const wasAutoincrement = statements.filter(
|
26043
25592
|
(it) => it.type === "alter_table_alter_column_set_autoincrement"
|
26044
25593
|
);
|
@@ -26051,7 +25600,7 @@ var init_jsonStatements = __esm({
|
|
26051
25600
|
});
|
26052
25601
|
}
|
26053
25602
|
}
|
26054
|
-
if (((
|
25603
|
+
if (((_o = column7.onUpdate) == null ? void 0 : _o.type) === "added") {
|
26055
25604
|
statements.push({
|
26056
25605
|
type: "alter_table_alter_column_set_on_update",
|
26057
25606
|
tableName,
|
@@ -26065,7 +25614,7 @@ var init_jsonStatements = __esm({
|
|
26065
25614
|
columnPk
|
26066
25615
|
});
|
26067
25616
|
}
|
26068
|
-
if (((
|
25617
|
+
if (((_p = column7.onUpdate) == null ? void 0 : _p.type) === "deleted") {
|
26069
25618
|
statements.push({
|
26070
25619
|
type: "alter_table_alter_column_drop_on_update",
|
26071
25620
|
tableName,
|
@@ -26125,37 +25674,6 @@ var init_jsonStatements = __esm({
|
|
26125
25674
|
};
|
26126
25675
|
});
|
26127
25676
|
};
|
26128
|
-
prepareLibSQLCreateReferencesJson = (tableName, schema5, foreignKeys, json2, action) => {
|
26129
|
-
return Object.values(foreignKeys).map((fkData) => {
|
26130
|
-
const { columnsFrom, tableFrom, columnsTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
26131
|
-
let isMulticolumn = false;
|
26132
|
-
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
26133
|
-
isMulticolumn = true;
|
26134
|
-
return {
|
26135
|
-
type: "create_reference",
|
26136
|
-
tableName,
|
26137
|
-
data: fkData,
|
26138
|
-
schema: schema5,
|
26139
|
-
isMulticolumn
|
26140
|
-
};
|
26141
|
-
}
|
26142
|
-
const columnFrom = columnsFrom[0];
|
26143
|
-
const {
|
26144
|
-
notNull: columnNotNull,
|
26145
|
-
default: columnDefault,
|
26146
|
-
type: columnType
|
26147
|
-
} = json2.tables[tableFrom].columns[columnFrom];
|
26148
|
-
return {
|
26149
|
-
type: "create_reference",
|
26150
|
-
tableName,
|
26151
|
-
data: fkData,
|
26152
|
-
schema: schema5,
|
26153
|
-
columnNotNull,
|
26154
|
-
columnDefault,
|
26155
|
-
columnType
|
26156
|
-
};
|
26157
|
-
});
|
26158
|
-
};
|
26159
25677
|
prepareDropReferencesJson = (tableName, schema5, foreignKeys) => {
|
26160
25678
|
return Object.values(foreignKeys).map((fkData) => {
|
26161
25679
|
return {
|
@@ -26166,54 +25684,6 @@ var init_jsonStatements = __esm({
|
|
26166
25684
|
};
|
26167
25685
|
});
|
26168
25686
|
};
|
26169
|
-
prepareLibSQLDropReferencesJson = (tableName, schema5, foreignKeys, json2, meta, action) => {
|
26170
|
-
const statements = Object.values(foreignKeys).map((fkData) => {
|
26171
|
-
const { columnsFrom, tableFrom, columnsTo, name, tableTo, onDelete, onUpdate } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
26172
|
-
const keys = Object.keys(json2.tables[tableName].columns);
|
26173
|
-
const filtered = columnsFrom.filter((it) => keys.includes(it));
|
26174
|
-
const fullDrop = filtered.length === 0;
|
26175
|
-
if (fullDrop)
|
26176
|
-
return;
|
26177
|
-
let isMulticolumn = false;
|
26178
|
-
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
26179
|
-
isMulticolumn = true;
|
26180
|
-
return {
|
26181
|
-
type: "delete_reference",
|
26182
|
-
tableName,
|
26183
|
-
data: fkData,
|
26184
|
-
schema: schema5,
|
26185
|
-
isMulticolumn
|
26186
|
-
};
|
26187
|
-
}
|
26188
|
-
const columnFrom = columnsFrom[0];
|
26189
|
-
const newTableName = getNewTableName(tableFrom, meta);
|
26190
|
-
const {
|
26191
|
-
notNull: columnNotNull,
|
26192
|
-
default: columnDefault,
|
26193
|
-
type: columnType
|
26194
|
-
} = json2.tables[newTableName].columns[columnFrom];
|
26195
|
-
const fkToSquash = {
|
26196
|
-
columnsFrom,
|
26197
|
-
columnsTo,
|
26198
|
-
name,
|
26199
|
-
tableFrom: newTableName,
|
26200
|
-
tableTo,
|
26201
|
-
onDelete,
|
26202
|
-
onUpdate
|
26203
|
-
};
|
26204
|
-
const foreignKey = action === "push" ? SQLiteSquasher.squashPushFK(fkToSquash) : SQLiteSquasher.squashFK(fkToSquash);
|
26205
|
-
return {
|
26206
|
-
type: "delete_reference",
|
26207
|
-
tableName,
|
26208
|
-
data: foreignKey,
|
26209
|
-
schema: schema5,
|
26210
|
-
columnNotNull,
|
26211
|
-
columnDefault,
|
26212
|
-
columnType
|
26213
|
-
};
|
26214
|
-
});
|
26215
|
-
return statements.filter((it) => it);
|
26216
|
-
};
|
26217
25687
|
prepareAlterReferencesJson = (tableName, schema5, foreignKeys) => {
|
26218
25688
|
const stmts = [];
|
26219
25689
|
Object.values(foreignKeys).map((val2) => {
|
@@ -26368,295 +25838,8 @@ var init_jsonStatements = __esm({
|
|
26368
25838
|
}
|
26369
25839
|
});
|
26370
25840
|
|
26371
|
-
// src/statementCombiner.ts
|
26372
|
-
var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
|
26373
|
-
var init_statementCombiner = __esm({
|
26374
|
-
"src/statementCombiner.ts"() {
|
26375
|
-
"use strict";
|
26376
|
-
init_jsonStatements();
|
26377
|
-
init_sqliteSchema();
|
26378
|
-
prepareLibSQLRecreateTable = (table4, action) => {
|
26379
|
-
const { name, columns, uniqueConstraints, indexes } = table4;
|
26380
|
-
const composites = Object.values(table4.compositePrimaryKeys).map(
|
26381
|
-
(it) => SQLiteSquasher.unsquashPK(it)
|
26382
|
-
);
|
26383
|
-
const references2 = Object.values(table4.foreignKeys);
|
26384
|
-
const fks = references2.map(
|
26385
|
-
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
26386
|
-
);
|
26387
|
-
const statements = [
|
26388
|
-
{
|
26389
|
-
type: "recreate_table",
|
26390
|
-
tableName: name,
|
26391
|
-
columns: Object.values(columns),
|
26392
|
-
compositePKs: composites,
|
26393
|
-
referenceData: fks,
|
26394
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
26395
|
-
}
|
26396
|
-
];
|
26397
|
-
if (Object.keys(indexes).length) {
|
26398
|
-
statements.push(...prepareCreateIndexesJson(name, "", indexes));
|
26399
|
-
}
|
26400
|
-
return statements;
|
26401
|
-
};
|
26402
|
-
prepareSQLiteRecreateTable = (table4, action) => {
|
26403
|
-
const { name, columns, uniqueConstraints, indexes } = table4;
|
26404
|
-
const composites = Object.values(table4.compositePrimaryKeys).map(
|
26405
|
-
(it) => SQLiteSquasher.unsquashPK(it)
|
26406
|
-
);
|
26407
|
-
const references2 = Object.values(table4.foreignKeys);
|
26408
|
-
const fks = references2.map(
|
26409
|
-
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
26410
|
-
);
|
26411
|
-
const statements = [
|
26412
|
-
{
|
26413
|
-
type: "recreate_table",
|
26414
|
-
tableName: name,
|
26415
|
-
columns: Object.values(columns),
|
26416
|
-
compositePKs: composites,
|
26417
|
-
referenceData: fks,
|
26418
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
26419
|
-
}
|
26420
|
-
];
|
26421
|
-
if (Object.keys(indexes).length) {
|
26422
|
-
statements.push(...prepareCreateIndexesJson(name, "", indexes));
|
26423
|
-
}
|
26424
|
-
return statements;
|
26425
|
-
};
|
26426
|
-
libSQLCombineStatements = (statements, json2, action) => {
|
26427
|
-
const newStatements = {};
|
26428
|
-
for (const statement of statements) {
|
26429
|
-
if (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" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
|
26430
|
-
const tableName2 = statement.tableName;
|
26431
|
-
const statementsForTable2 = newStatements[tableName2];
|
26432
|
-
if (!statementsForTable2) {
|
26433
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26434
|
-
continue;
|
26435
|
-
}
|
26436
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26437
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
26438
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26439
|
-
if (wasRename) {
|
26440
|
-
newStatements[tableName2].push(...preparedStatements);
|
26441
|
-
} else {
|
26442
|
-
newStatements[tableName2] = preparedStatements;
|
26443
|
-
}
|
26444
|
-
continue;
|
26445
|
-
}
|
26446
|
-
continue;
|
26447
|
-
}
|
26448
|
-
if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") {
|
26449
|
-
const { tableName: tableName2, columnName, columnPk } = statement;
|
26450
|
-
const columnIsPartOfUniqueIndex = Object.values(
|
26451
|
-
json2.tables[tableName2].indexes
|
26452
|
-
).some((it) => {
|
26453
|
-
const unsquashIndex = SQLiteSquasher.unsquashIdx(it);
|
26454
|
-
return unsquashIndex.columns.includes(columnName) && unsquashIndex.isUnique;
|
26455
|
-
});
|
26456
|
-
const columnIsPartOfForeignKey = Object.values(
|
26457
|
-
json2.tables[tableName2].foreignKeys
|
26458
|
-
).some((it) => {
|
26459
|
-
const unsquashFk = action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);
|
26460
|
-
return unsquashFk.columnsFrom.includes(columnName);
|
26461
|
-
});
|
26462
|
-
const statementsForTable2 = newStatements[tableName2];
|
26463
|
-
if (!statementsForTable2 && (columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
26464
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26465
|
-
continue;
|
26466
|
-
}
|
26467
|
-
if (statementsForTable2 && (columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
26468
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26469
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
26470
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26471
|
-
if (wasRename) {
|
26472
|
-
newStatements[tableName2].push(...preparedStatements);
|
26473
|
-
} else {
|
26474
|
-
newStatements[tableName2] = preparedStatements;
|
26475
|
-
}
|
26476
|
-
}
|
26477
|
-
continue;
|
26478
|
-
}
|
26479
|
-
if (statementsForTable2 && !(columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
26480
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26481
|
-
newStatements[tableName2].push(statement);
|
26482
|
-
}
|
26483
|
-
continue;
|
26484
|
-
}
|
26485
|
-
newStatements[tableName2] = [statement];
|
26486
|
-
continue;
|
26487
|
-
}
|
26488
|
-
if (statement.type === "create_reference") {
|
26489
|
-
const tableName2 = statement.tableName;
|
26490
|
-
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
26491
|
-
const statementsForTable2 = newStatements[tableName2];
|
26492
|
-
if (!statementsForTable2) {
|
26493
|
-
newStatements[tableName2] = statement.isMulticolumn ? prepareLibSQLRecreateTable(json2.tables[tableName2], action) : newStatements[tableName2] = [statement];
|
26494
|
-
continue;
|
26495
|
-
}
|
26496
|
-
if (!statement.isMulticolumn && statementsForTable2.some(
|
26497
|
-
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
26498
|
-
)) {
|
26499
|
-
continue;
|
26500
|
-
}
|
26501
|
-
if (statement.isMulticolumn) {
|
26502
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26503
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
26504
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26505
|
-
if (wasRename) {
|
26506
|
-
newStatements[tableName2].push(...preparedStatements);
|
26507
|
-
} else {
|
26508
|
-
newStatements[tableName2] = preparedStatements;
|
26509
|
-
}
|
26510
|
-
continue;
|
26511
|
-
}
|
26512
|
-
continue;
|
26513
|
-
}
|
26514
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26515
|
-
newStatements[tableName2].push(statement);
|
26516
|
-
}
|
26517
|
-
continue;
|
26518
|
-
}
|
26519
|
-
if (statement.type === "delete_reference") {
|
26520
|
-
const tableName2 = statement.tableName;
|
26521
|
-
const statementsForTable2 = newStatements[tableName2];
|
26522
|
-
if (!statementsForTable2) {
|
26523
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26524
|
-
continue;
|
26525
|
-
}
|
26526
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26527
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
26528
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26529
|
-
if (wasRename) {
|
26530
|
-
newStatements[tableName2].push(...preparedStatements);
|
26531
|
-
} else {
|
26532
|
-
newStatements[tableName2] = preparedStatements;
|
26533
|
-
}
|
26534
|
-
continue;
|
26535
|
-
}
|
26536
|
-
continue;
|
26537
|
-
}
|
26538
|
-
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
26539
|
-
const tableName2 = statement.tableName;
|
26540
|
-
const statementsForTable2 = newStatements[tableName2];
|
26541
|
-
if (!statementsForTable2) {
|
26542
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26543
|
-
continue;
|
26544
|
-
}
|
26545
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26546
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
26547
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26548
|
-
if (wasRename) {
|
26549
|
-
newStatements[tableName2].push(...preparedStatements);
|
26550
|
-
} else {
|
26551
|
-
newStatements[tableName2] = preparedStatements;
|
26552
|
-
}
|
26553
|
-
continue;
|
26554
|
-
}
|
26555
|
-
continue;
|
26556
|
-
}
|
26557
|
-
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
26558
|
-
const statementsForTable = newStatements[tableName];
|
26559
|
-
if (!statementsForTable) {
|
26560
|
-
newStatements[tableName] = [statement];
|
26561
|
-
continue;
|
26562
|
-
}
|
26563
|
-
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
26564
|
-
newStatements[tableName].push(statement);
|
26565
|
-
}
|
26566
|
-
}
|
26567
|
-
const combinedStatements = Object.values(newStatements).flat();
|
26568
|
-
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
26569
|
-
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
26570
|
-
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
26571
|
-
return [...renamedTables, ...renamedColumns, ...rest];
|
26572
|
-
};
|
26573
|
-
sqliteCombineStatements = (statements, json2, action) => {
|
26574
|
-
const newStatements = {};
|
26575
|
-
for (const statement of statements) {
|
26576
|
-
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" || statement.type === "delete_reference" || statement.type === "alter_reference" || 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") {
|
26577
|
-
const tableName2 = statement.tableName;
|
26578
|
-
const statementsForTable2 = newStatements[tableName2];
|
26579
|
-
if (!statementsForTable2) {
|
26580
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26581
|
-
continue;
|
26582
|
-
}
|
26583
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26584
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
26585
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26586
|
-
if (wasRename) {
|
26587
|
-
newStatements[tableName2].push(...preparedStatements);
|
26588
|
-
} else {
|
26589
|
-
newStatements[tableName2] = preparedStatements;
|
26590
|
-
}
|
26591
|
-
continue;
|
26592
|
-
}
|
26593
|
-
continue;
|
26594
|
-
}
|
26595
|
-
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
26596
|
-
const tableName2 = statement.tableName;
|
26597
|
-
const statementsForTable2 = newStatements[tableName2];
|
26598
|
-
if (!statementsForTable2) {
|
26599
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26600
|
-
continue;
|
26601
|
-
}
|
26602
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26603
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
26604
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26605
|
-
if (wasRename) {
|
26606
|
-
newStatements[tableName2].push(...preparedStatements);
|
26607
|
-
} else {
|
26608
|
-
newStatements[tableName2] = preparedStatements;
|
26609
|
-
}
|
26610
|
-
continue;
|
26611
|
-
}
|
26612
|
-
continue;
|
26613
|
-
}
|
26614
|
-
if (statement.type === "create_reference") {
|
26615
|
-
const tableName2 = statement.tableName;
|
26616
|
-
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
26617
|
-
const statementsForTable2 = newStatements[tableName2];
|
26618
|
-
if (!statementsForTable2) {
|
26619
|
-
newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
|
26620
|
-
continue;
|
26621
|
-
}
|
26622
|
-
if (data.columnsFrom.length === 1 && statementsForTable2.some(
|
26623
|
-
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
26624
|
-
)) {
|
26625
|
-
continue;
|
26626
|
-
}
|
26627
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
26628
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
26629
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
26630
|
-
if (wasRename) {
|
26631
|
-
newStatements[tableName2].push(...preparedStatements);
|
26632
|
-
} else {
|
26633
|
-
newStatements[tableName2] = preparedStatements;
|
26634
|
-
}
|
26635
|
-
continue;
|
26636
|
-
}
|
26637
|
-
continue;
|
26638
|
-
}
|
26639
|
-
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
26640
|
-
const statementsForTable = newStatements[tableName];
|
26641
|
-
if (!statementsForTable) {
|
26642
|
-
newStatements[tableName] = [statement];
|
26643
|
-
continue;
|
26644
|
-
}
|
26645
|
-
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
26646
|
-
newStatements[tableName].push(statement);
|
26647
|
-
}
|
26648
|
-
}
|
26649
|
-
const combinedStatements = Object.values(newStatements).flat();
|
26650
|
-
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
26651
|
-
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
26652
|
-
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
26653
|
-
return [...renamedTables, ...renamedColumns, ...rest];
|
26654
|
-
};
|
26655
|
-
}
|
26656
|
-
});
|
26657
|
-
|
26658
25841
|
// src/snapshotsDiffer.ts
|
26659
|
-
var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff
|
25842
|
+
var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
|
26660
25843
|
var init_snapshotsDiffer = __esm({
|
26661
25844
|
"src/snapshotsDiffer.ts"() {
|
26662
25845
|
"use strict";
|
@@ -26668,7 +25851,6 @@ var init_snapshotsDiffer = __esm({
|
|
26668
25851
|
init_mysqlSchema();
|
26669
25852
|
init_pgSchema();
|
26670
25853
|
init_sqliteSchema();
|
26671
|
-
init_statementCombiner();
|
26672
25854
|
init_utils();
|
26673
25855
|
makeChanged = (schema5) => {
|
26674
25856
|
return objectType({
|
@@ -27996,8 +27178,7 @@ var init_snapshotsDiffer = __esm({
|
|
27996
27178
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
27997
27179
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
27998
27180
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
27999
|
-
const
|
28000
|
-
const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
|
27181
|
+
const sqlStatements = fromJson(jsonStatements, "sqlite");
|
28001
27182
|
const uniqueSqlStatements = [];
|
28002
27183
|
sqlStatements.forEach((ss) => {
|
28003
27184
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -28009,298 +27190,7 @@ var init_snapshotsDiffer = __esm({
|
|
28009
27190
|
});
|
28010
27191
|
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
28011
27192
|
return {
|
28012
|
-
statements:
|
28013
|
-
sqlStatements: uniqueSqlStatements,
|
28014
|
-
_meta
|
28015
|
-
};
|
28016
|
-
};
|
28017
|
-
applyLibSQLSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
28018
|
-
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
28019
|
-
const {
|
28020
|
-
created: createdTables,
|
28021
|
-
deleted: deletedTables,
|
28022
|
-
renamed: renamedTables
|
28023
|
-
} = await tablesResolver2({
|
28024
|
-
created: tablesDiff.added,
|
28025
|
-
deleted: tablesDiff.deleted
|
28026
|
-
});
|
28027
|
-
const tablesPatchedSnap1 = copy(json1);
|
28028
|
-
tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_2, it) => {
|
28029
|
-
const { name } = nameChangeFor(it, renamedTables);
|
28030
|
-
it.name = name;
|
28031
|
-
return [name, it];
|
28032
|
-
});
|
28033
|
-
const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
|
28034
|
-
const columnRenames = [];
|
28035
|
-
const columnCreates = [];
|
28036
|
-
const columnDeletes = [];
|
28037
|
-
for (let entry of Object.values(res)) {
|
28038
|
-
const { renamed, created, deleted } = await columnsResolver2({
|
28039
|
-
tableName: entry.name,
|
28040
|
-
schema: entry.schema,
|
28041
|
-
deleted: entry.columns.deleted,
|
28042
|
-
created: entry.columns.added
|
28043
|
-
});
|
28044
|
-
if (created.length > 0) {
|
28045
|
-
columnCreates.push({
|
28046
|
-
table: entry.name,
|
28047
|
-
columns: created
|
28048
|
-
});
|
28049
|
-
}
|
28050
|
-
if (deleted.length > 0) {
|
28051
|
-
columnDeletes.push({
|
28052
|
-
table: entry.name,
|
28053
|
-
columns: deleted
|
28054
|
-
});
|
28055
|
-
}
|
28056
|
-
if (renamed.length > 0) {
|
28057
|
-
columnRenames.push({
|
28058
|
-
table: entry.name,
|
28059
|
-
renames: renamed
|
28060
|
-
});
|
28061
|
-
}
|
28062
|
-
}
|
28063
|
-
const columnRenamesDict = columnRenames.reduce(
|
28064
|
-
(acc, it) => {
|
28065
|
-
acc[it.table] = it.renames;
|
28066
|
-
return acc;
|
28067
|
-
},
|
28068
|
-
{}
|
28069
|
-
);
|
28070
|
-
const columnsPatchedSnap1 = copy(tablesPatchedSnap1);
|
28071
|
-
columnsPatchedSnap1.tables = mapEntries(
|
28072
|
-
columnsPatchedSnap1.tables,
|
28073
|
-
(tableKey2, tableValue) => {
|
28074
|
-
const patchedColumns = mapKeys(
|
28075
|
-
tableValue.columns,
|
28076
|
-
(columnKey, column7) => {
|
28077
|
-
const rens = columnRenamesDict[tableValue.name] || [];
|
28078
|
-
const newName = columnChangeFor(columnKey, rens);
|
28079
|
-
column7.name = newName;
|
28080
|
-
return newName;
|
28081
|
-
}
|
28082
|
-
);
|
28083
|
-
tableValue.columns = patchedColumns;
|
28084
|
-
return [tableKey2, tableValue];
|
28085
|
-
}
|
28086
|
-
);
|
28087
|
-
const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
|
28088
|
-
const typedResult = diffResultSchemeSQLite.parse(diffResult);
|
28089
|
-
const tablesMap = {};
|
28090
|
-
typedResult.alteredTablesWithColumns.forEach((obj) => {
|
28091
|
-
tablesMap[obj.name] = obj;
|
28092
|
-
});
|
28093
|
-
const jsonCreateTables = createdTables.map((it) => {
|
28094
|
-
return prepareSQLiteCreateTable(it, action);
|
28095
|
-
});
|
28096
|
-
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
28097
|
-
return prepareCreateIndexesJson(
|
28098
|
-
it.name,
|
28099
|
-
it.schema,
|
28100
|
-
it.indexes,
|
28101
|
-
curFull.internal
|
28102
|
-
);
|
28103
|
-
}).flat();
|
28104
|
-
const jsonDropTables = deletedTables.map((it) => {
|
28105
|
-
return prepareDropTableJson(it);
|
28106
|
-
});
|
28107
|
-
const jsonRenameTables = renamedTables.map((it) => {
|
28108
|
-
return prepareRenameTableJson(it.from, it.to);
|
28109
|
-
});
|
28110
|
-
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
28111
|
-
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
28112
|
-
const jsonAddColumnsStatemets = columnCreates.map((it) => {
|
28113
|
-
return _prepareSqliteAddColumns(
|
28114
|
-
it.table,
|
28115
|
-
it.columns,
|
28116
|
-
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
28117
|
-
);
|
28118
|
-
}).flat();
|
28119
|
-
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
28120
|
-
const tableName = it.tableName;
|
28121
|
-
const schema5 = it.schema;
|
28122
|
-
return {
|
28123
|
-
from: { schema: schema5, table: tableName, column: it.oldColumnName },
|
28124
|
-
to: { schema: schema5, table: tableName, column: it.newColumnName }
|
28125
|
-
};
|
28126
|
-
});
|
28127
|
-
const rTables = renamedTables.map((it) => {
|
28128
|
-
return { from: it.from, to: it.to };
|
28129
|
-
});
|
28130
|
-
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
28131
|
-
const allAltered = typedResult.alteredTablesWithColumns;
|
28132
|
-
const jsonAddedCompositePKs = [];
|
28133
|
-
const jsonDeletedCompositePKs = [];
|
28134
|
-
const jsonAlteredCompositePKs = [];
|
28135
|
-
const jsonAddedUniqueConstraints = [];
|
28136
|
-
const jsonDeletedUniqueConstraints = [];
|
28137
|
-
const jsonAlteredUniqueConstraints = [];
|
28138
|
-
allAltered.forEach((it) => {
|
28139
|
-
let addedColumns = [];
|
28140
|
-
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
28141
|
-
const addedPkColumns = it.addedCompositePKs[addedPkName];
|
28142
|
-
addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
|
28143
|
-
}
|
28144
|
-
let deletedColumns = [];
|
28145
|
-
for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
|
28146
|
-
const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
|
28147
|
-
deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
|
28148
|
-
}
|
28149
|
-
const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
|
28150
|
-
let addedCompositePKs = [];
|
28151
|
-
let deletedCompositePKs = [];
|
28152
|
-
let alteredCompositePKs = [];
|
28153
|
-
if (doPerformDeleteAndCreate) {
|
28154
|
-
addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
|
28155
|
-
it.name,
|
28156
|
-
it.addedCompositePKs
|
28157
|
-
);
|
28158
|
-
deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
|
28159
|
-
it.name,
|
28160
|
-
it.deletedCompositePKs
|
28161
|
-
);
|
28162
|
-
}
|
28163
|
-
alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
|
28164
|
-
it.name,
|
28165
|
-
it.alteredCompositePKs
|
28166
|
-
);
|
28167
|
-
let addedUniqueConstraints = [];
|
28168
|
-
let deletedUniqueConstraints = [];
|
28169
|
-
let alteredUniqueConstraints = [];
|
28170
|
-
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
28171
|
-
it.name,
|
28172
|
-
it.schema,
|
28173
|
-
it.addedUniqueConstraints
|
28174
|
-
);
|
28175
|
-
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
28176
|
-
it.name,
|
28177
|
-
it.schema,
|
28178
|
-
it.deletedUniqueConstraints
|
28179
|
-
);
|
28180
|
-
if (it.alteredUniqueConstraints) {
|
28181
|
-
const added = {};
|
28182
|
-
const deleted = {};
|
28183
|
-
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
28184
|
-
added[k] = it.alteredUniqueConstraints[k].__new;
|
28185
|
-
deleted[k] = it.alteredUniqueConstraints[k].__old;
|
28186
|
-
}
|
28187
|
-
addedUniqueConstraints.push(
|
28188
|
-
...prepareAddUniqueConstraintPg(it.name, it.schema, added)
|
28189
|
-
);
|
28190
|
-
deletedUniqueConstraints.push(
|
28191
|
-
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
28192
|
-
);
|
28193
|
-
}
|
28194
|
-
jsonAddedCompositePKs.push(...addedCompositePKs);
|
28195
|
-
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
28196
|
-
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
28197
|
-
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
28198
|
-
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
28199
|
-
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
28200
|
-
});
|
28201
|
-
const jsonTableAlternations = allAltered.map((it) => {
|
28202
|
-
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
28203
|
-
}).flat();
|
28204
|
-
const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
|
28205
|
-
return prepareCreateIndexesJson(
|
28206
|
-
it.name,
|
28207
|
-
it.schema,
|
28208
|
-
it.addedIndexes || {},
|
28209
|
-
curFull.internal
|
28210
|
-
);
|
28211
|
-
}).flat();
|
28212
|
-
const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
|
28213
|
-
return prepareDropIndexesJson(
|
28214
|
-
it.name,
|
28215
|
-
it.schema,
|
28216
|
-
it.deletedIndexes || {}
|
28217
|
-
);
|
28218
|
-
}).flat();
|
28219
|
-
allAltered.forEach((it) => {
|
28220
|
-
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
28221
|
-
(current, item) => {
|
28222
|
-
current[item] = it.alteredIndexes[item].__old;
|
28223
|
-
return current;
|
28224
|
-
},
|
28225
|
-
{}
|
28226
|
-
);
|
28227
|
-
const createdIndexes = Object.keys(it.alteredIndexes).reduce(
|
28228
|
-
(current, item) => {
|
28229
|
-
current[item] = it.alteredIndexes[item].__new;
|
28230
|
-
return current;
|
28231
|
-
},
|
28232
|
-
{}
|
28233
|
-
);
|
28234
|
-
jsonCreateIndexesForAllAlteredTables.push(
|
28235
|
-
...prepareCreateIndexesJson(
|
28236
|
-
it.name,
|
28237
|
-
it.schema,
|
28238
|
-
createdIndexes || {},
|
28239
|
-
curFull.internal
|
28240
|
-
)
|
28241
|
-
);
|
28242
|
-
jsonDropIndexesForAllAlteredTables.push(
|
28243
|
-
...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
|
28244
|
-
);
|
28245
|
-
});
|
28246
|
-
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
28247
|
-
const forAdded = prepareLibSQLCreateReferencesJson(
|
28248
|
-
it.name,
|
28249
|
-
it.schema,
|
28250
|
-
it.addedForeignKeys,
|
28251
|
-
json2,
|
28252
|
-
action
|
28253
|
-
);
|
28254
|
-
const forAltered = prepareLibSQLDropReferencesJson(
|
28255
|
-
it.name,
|
28256
|
-
it.schema,
|
28257
|
-
it.deletedForeignKeys,
|
28258
|
-
json2,
|
28259
|
-
_meta,
|
28260
|
-
action
|
28261
|
-
);
|
28262
|
-
const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
|
28263
|
-
return [...forAdded, ...forAltered, ...alteredFKs];
|
28264
|
-
}).flat();
|
28265
|
-
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
28266
|
-
(t2) => t2.type === "create_reference"
|
28267
|
-
);
|
28268
|
-
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
28269
|
-
(t2) => t2.type === "delete_reference"
|
28270
|
-
);
|
28271
|
-
const jsonStatements = [];
|
28272
|
-
jsonStatements.push(...jsonCreateTables);
|
28273
|
-
jsonStatements.push(...jsonDropTables);
|
28274
|
-
jsonStatements.push(...jsonRenameTables);
|
28275
|
-
jsonStatements.push(...jsonRenameColumnsStatements);
|
28276
|
-
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
28277
|
-
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
28278
|
-
jsonStatements.push(...jsonDeletedCompositePKs);
|
28279
|
-
jsonStatements.push(...jsonTableAlternations);
|
28280
|
-
jsonStatements.push(...jsonAddedCompositePKs);
|
28281
|
-
jsonStatements.push(...jsonAddColumnsStatemets);
|
28282
|
-
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
28283
|
-
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
28284
|
-
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
28285
|
-
jsonStatements.push(...jsonDropColumnsStatemets);
|
28286
|
-
jsonStatements.push(...jsonAlteredCompositePKs);
|
28287
|
-
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
28288
|
-
const combinedJsonStatements = libSQLCombineStatements(jsonStatements, json2, action);
|
28289
|
-
const sqlStatements = fromJson(
|
28290
|
-
combinedJsonStatements,
|
28291
|
-
"sqlite",
|
28292
|
-
action,
|
28293
|
-
"turso",
|
28294
|
-
json2
|
28295
|
-
);
|
28296
|
-
const uniqueSqlStatements = [];
|
28297
|
-
sqlStatements.forEach((ss) => {
|
28298
|
-
if (!uniqueSqlStatements.includes(ss)) {
|
28299
|
-
uniqueSqlStatements.push(ss);
|
28300
|
-
}
|
28301
|
-
});
|
28302
|
-
return {
|
28303
|
-
statements: combinedJsonStatements,
|
27193
|
+
statements: jsonStatements,
|
28304
27194
|
sqlStatements: uniqueSqlStatements,
|
28305
27195
|
_meta
|
28306
27196
|
};
|
@@ -29639,7 +28529,6 @@ __export(migrate_exports, {
|
|
29639
28529
|
prepareAndMigrateMysql: () => prepareAndMigrateMysql,
|
29640
28530
|
prepareAndMigratePg: () => prepareAndMigratePg,
|
29641
28531
|
prepareAndMigrateSqlite: () => prepareAndMigrateSqlite,
|
29642
|
-
prepareLibSQLPush: () => prepareLibSQLPush,
|
29643
28532
|
prepareMySQLPush: () => prepareMySQLPush,
|
29644
28533
|
preparePgPush: () => preparePgPush,
|
29645
28534
|
prepareSQLitePush: () => prepareSQLitePush,
|
@@ -29652,7 +28541,7 @@ __export(migrate_exports, {
|
|
29652
28541
|
tablesResolver: () => tablesResolver,
|
29653
28542
|
writeResult: () => writeResult
|
29654
28543
|
});
|
29655
|
-
var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, sequencesResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareSQLitePush,
|
28544
|
+
var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, sequencesResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareSQLitePush, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
|
29656
28545
|
var init_migrate = __esm({
|
29657
28546
|
"src/cli/commands/migrate.ts"() {
|
29658
28547
|
"use strict";
|
@@ -29904,7 +28793,6 @@ var init_migrate = __esm({
|
|
29904
28793
|
prepareAndMigrateSqlite = async (config) => {
|
29905
28794
|
const outFolder = config.out;
|
29906
28795
|
const schemaPath = config.schema;
|
29907
|
-
const driver2 = config.driver;
|
29908
28796
|
try {
|
29909
28797
|
assertV1OutFolder(outFolder);
|
29910
28798
|
const { snapshots, journal } = prepareMigrationFolder(outFolder, "sqlite");
|
@@ -29930,27 +28818,14 @@ var init_migrate = __esm({
|
|
29930
28818
|
}
|
29931
28819
|
const squashedPrev = squashSqliteScheme(validatedPrev);
|
29932
28820
|
const squashedCur = squashSqliteScheme(validatedCur);
|
29933
|
-
|
29934
|
-
|
29935
|
-
|
29936
|
-
|
29937
|
-
|
29938
|
-
|
29939
|
-
|
29940
|
-
|
29941
|
-
validatedPrev,
|
29942
|
-
validatedCur
|
29943
|
-
));
|
29944
|
-
} else {
|
29945
|
-
({ sqlStatements, _meta } = await applySqliteSnapshotsDiff(
|
29946
|
-
squashedPrev,
|
29947
|
-
squashedCur,
|
29948
|
-
tablesResolver,
|
29949
|
-
columnsResolver,
|
29950
|
-
validatedPrev,
|
29951
|
-
validatedCur
|
29952
|
-
));
|
29953
|
-
}
|
28821
|
+
const { sqlStatements, _meta } = await applySqliteSnapshotsDiff(
|
28822
|
+
squashedPrev,
|
28823
|
+
squashedCur,
|
28824
|
+
tablesResolver,
|
28825
|
+
columnsResolver,
|
28826
|
+
validatedPrev,
|
28827
|
+
validatedCur
|
28828
|
+
);
|
29954
28829
|
writeResult({
|
29955
28830
|
cur,
|
29956
28831
|
sqlStatements,
|
@@ -29966,51 +28841,13 @@ var init_migrate = __esm({
|
|
29966
28841
|
console.error(e2);
|
29967
28842
|
}
|
29968
28843
|
};
|
29969
|
-
prepareSQLitePush = async (schemaPath, snapshot
|
29970
|
-
const { prev, cur } = await prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
|
29971
|
-
const validatedPrev = sqliteSchema.parse(prev);
|
29972
|
-
const validatedCur = sqliteSchema.parse(cur);
|
29973
|
-
const squashedPrev = squashSqliteScheme(validatedPrev, "push");
|
29974
|
-
const squashedCur = squashSqliteScheme(validatedCur, "push");
|
29975
|
-
let sqlStatements;
|
29976
|
-
let statements;
|
29977
|
-
let _meta;
|
29978
|
-
if (driver2 === "turso") {
|
29979
|
-
({ sqlStatements, statements, _meta } = await applyLibSQLSnapshotsDiff(
|
29980
|
-
squashedPrev,
|
29981
|
-
squashedCur,
|
29982
|
-
tablesResolver,
|
29983
|
-
columnsResolver,
|
29984
|
-
validatedPrev,
|
29985
|
-
validatedCur,
|
29986
|
-
"push"
|
29987
|
-
));
|
29988
|
-
} else {
|
29989
|
-
({ sqlStatements, statements, _meta } = await applySqliteSnapshotsDiff(
|
29990
|
-
squashedPrev,
|
29991
|
-
squashedCur,
|
29992
|
-
tablesResolver,
|
29993
|
-
columnsResolver,
|
29994
|
-
validatedPrev,
|
29995
|
-
validatedCur,
|
29996
|
-
"push"
|
29997
|
-
));
|
29998
|
-
}
|
29999
|
-
return {
|
30000
|
-
sqlStatements,
|
30001
|
-
statements,
|
30002
|
-
squashedPrev,
|
30003
|
-
squashedCur,
|
30004
|
-
meta: _meta
|
30005
|
-
};
|
30006
|
-
};
|
30007
|
-
prepareLibSQLPush = async (schemaPath, snapshot) => {
|
28844
|
+
prepareSQLitePush = async (schemaPath, snapshot) => {
|
30008
28845
|
const { prev, cur } = await prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
|
30009
28846
|
const validatedPrev = sqliteSchema.parse(prev);
|
30010
28847
|
const validatedCur = sqliteSchema.parse(cur);
|
30011
28848
|
const squashedPrev = squashSqliteScheme(validatedPrev, "push");
|
30012
28849
|
const squashedCur = squashSqliteScheme(validatedCur, "push");
|
30013
|
-
const { sqlStatements, statements, _meta } = await
|
28850
|
+
const { sqlStatements, statements, _meta } = await applySqliteSnapshotsDiff(
|
30014
28851
|
squashedPrev,
|
30015
28852
|
squashedCur,
|
30016
28853
|
tablesResolver,
|
@@ -73368,259 +72205,8 @@ var init_selector_ui = __esm({
|
|
73368
72205
|
}
|
73369
72206
|
});
|
73370
72207
|
|
73371
|
-
// src/cli/commands/libSqlPushUtils.ts
|
73372
|
-
var getOldTableName3, _moveDataStatements2, libSqlLogSuggestionsAndReturn;
|
73373
|
-
var init_libSqlPushUtils = __esm({
|
73374
|
-
"src/cli/commands/libSqlPushUtils.ts"() {
|
73375
|
-
"use strict";
|
73376
|
-
init_source();
|
73377
|
-
init_utils();
|
73378
|
-
init_sqliteSchema();
|
73379
|
-
init_sqlgenerator();
|
73380
|
-
getOldTableName3 = (tableName, meta) => {
|
73381
|
-
for (const key of Object.keys(meta.tables)) {
|
73382
|
-
const value = meta.tables[key];
|
73383
|
-
if (`"${tableName}"` === value) {
|
73384
|
-
return key.substring(1, key.length - 1);
|
73385
|
-
}
|
73386
|
-
}
|
73387
|
-
return tableName;
|
73388
|
-
};
|
73389
|
-
_moveDataStatements2 = (tableName, json, dataLoss = false) => {
|
73390
|
-
const statements = [];
|
73391
|
-
statements.push(
|
73392
|
-
new SqliteRenameTableConvertor().convert({
|
73393
|
-
type: "rename_table",
|
73394
|
-
tableNameFrom: tableName,
|
73395
|
-
tableNameTo: `__old_push_${tableName}`,
|
73396
|
-
fromSchema: "",
|
73397
|
-
toSchema: ""
|
73398
|
-
})
|
73399
|
-
);
|
73400
|
-
const tableColumns = Object.values(json.tables[tableName].columns);
|
73401
|
-
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
73402
|
-
const compositePKs = Object.values(
|
73403
|
-
json.tables[tableName].compositePrimaryKeys
|
73404
|
-
).map((it) => SQLiteSquasher.unsquashPK(it));
|
73405
|
-
statements.push(
|
73406
|
-
new SQLiteCreateTableConvertor().convert({
|
73407
|
-
type: "sqlite_create_table",
|
73408
|
-
tableName,
|
73409
|
-
columns: tableColumns,
|
73410
|
-
referenceData: referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it)),
|
73411
|
-
compositePKs
|
73412
|
-
})
|
73413
|
-
);
|
73414
|
-
if (!dataLoss) {
|
73415
|
-
const columns = Object.keys(json.tables[tableName].columns).map(
|
73416
|
-
(c) => `"${c}"`
|
73417
|
-
);
|
73418
|
-
statements.push(
|
73419
|
-
`INSERT INTO \`${tableName}\`(${columns.join(
|
73420
|
-
", "
|
73421
|
-
)}) SELECT (${columns.join(", ")}) FROM \`__old_push_${tableName}\`;`
|
73422
|
-
);
|
73423
|
-
}
|
73424
|
-
statements.push(
|
73425
|
-
new SQLiteDropTableConvertor().convert({
|
73426
|
-
type: "drop_table",
|
73427
|
-
tableName: `__old_push_${tableName}`,
|
73428
|
-
schema: ""
|
73429
|
-
})
|
73430
|
-
);
|
73431
|
-
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
73432
|
-
statements.push(
|
73433
|
-
new CreateSqliteIndexConvertor().convert({
|
73434
|
-
type: "create_index",
|
73435
|
-
tableName,
|
73436
|
-
schema: "",
|
73437
|
-
data: idx
|
73438
|
-
})
|
73439
|
-
);
|
73440
|
-
}
|
73441
|
-
return statements;
|
73442
|
-
};
|
73443
|
-
libSqlLogSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
73444
|
-
let shouldAskForApprove = false;
|
73445
|
-
const statementsToExecute = [];
|
73446
|
-
const infoToPrint = [];
|
73447
|
-
const tablesToRemove = [];
|
73448
|
-
const columnsToRemove = [];
|
73449
|
-
const tablesToTruncate = [];
|
73450
|
-
for (const statement of statements) {
|
73451
|
-
if (statement.type === "drop_table") {
|
73452
|
-
const res = await connection.query(
|
73453
|
-
`select count(*) as count from \`${statement.tableName}\``
|
73454
|
-
);
|
73455
|
-
const count = Number(res[0].count);
|
73456
|
-
if (count > 0) {
|
73457
|
-
infoToPrint.push(
|
73458
|
-
`\xB7 You're about to delete ${source_default.underline(
|
73459
|
-
statement.tableName
|
73460
|
-
)} table with ${count} items`
|
73461
|
-
);
|
73462
|
-
tablesToRemove.push(statement.tableName);
|
73463
|
-
shouldAskForApprove = true;
|
73464
|
-
}
|
73465
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push", "turso", json2);
|
73466
|
-
statementsToExecute.push(
|
73467
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
73468
|
-
);
|
73469
|
-
} else if (statement.type === "alter_table_drop_column") {
|
73470
|
-
const tableName = statement.tableName;
|
73471
|
-
const res = await connection.query(
|
73472
|
-
`select count(*) as count from \`${tableName}\``
|
73473
|
-
);
|
73474
|
-
const count = Number(res[0].count);
|
73475
|
-
if (count > 0) {
|
73476
|
-
infoToPrint.push(
|
73477
|
-
`\xB7 You're about to delete ${source_default.underline(
|
73478
|
-
statement.columnName
|
73479
|
-
)} column in ${tableName} table with ${count} items`
|
73480
|
-
);
|
73481
|
-
columnsToRemove.push(`${tableName}_${statement.columnName}`);
|
73482
|
-
shouldAskForApprove = true;
|
73483
|
-
}
|
73484
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push", "turso", json2);
|
73485
|
-
statementsToExecute.push(
|
73486
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
73487
|
-
);
|
73488
|
-
} else if (statement.type === "sqlite_alter_table_add_column" && statement.column.notNull && !statement.column.default) {
|
73489
|
-
const newTableName = statement.tableName;
|
73490
|
-
const res = await connection.query(
|
73491
|
-
`select count(*) as count from \`${newTableName}\``
|
73492
|
-
);
|
73493
|
-
const count = Number(res[0].count);
|
73494
|
-
if (count > 0) {
|
73495
|
-
infoToPrint.push(
|
73496
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
73497
|
-
statement.column.name
|
73498
|
-
)} column without default value, which contains ${count} items`
|
73499
|
-
);
|
73500
|
-
tablesToTruncate.push(newTableName);
|
73501
|
-
statementsToExecute.push(`delete from ${newTableName};`);
|
73502
|
-
shouldAskForApprove = true;
|
73503
|
-
}
|
73504
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push", "turso", json2);
|
73505
|
-
statementsToExecute.push(
|
73506
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
73507
|
-
);
|
73508
|
-
} else if (statement.type === "alter_table_alter_column_set_notnull") {
|
73509
|
-
const tableName = statement.tableName;
|
73510
|
-
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
73511
|
-
const res = await connection.query(
|
73512
|
-
`select count(*) as count from \`${tableName}\``
|
73513
|
-
);
|
73514
|
-
const count = Number(res[0].count);
|
73515
|
-
if (count > 0) {
|
73516
|
-
infoToPrint.push(
|
73517
|
-
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
73518
|
-
statement.columnName
|
73519
|
-
)} column without default value, which contains ${count} items`
|
73520
|
-
);
|
73521
|
-
tablesToTruncate.push(tableName);
|
73522
|
-
statementsToExecute.push(`delete from \`${tableName}\``);
|
73523
|
-
shouldAskForApprove = true;
|
73524
|
-
}
|
73525
|
-
}
|
73526
|
-
const modifyStatements = new LibSQLModifyColumn().convert(statement, json2);
|
73527
|
-
statementsToExecute.push(
|
73528
|
-
...Array.isArray(modifyStatements) ? modifyStatements : [modifyStatements]
|
73529
|
-
);
|
73530
|
-
} else if (statement.type === "recreate_table") {
|
73531
|
-
const tableName = statement.tableName;
|
73532
|
-
const oldTableName = getOldTableName3(tableName, meta);
|
73533
|
-
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
73534
|
-
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
73535
|
-
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
73536
|
-
prevColumnNames,
|
73537
|
-
currentColumnNames
|
73538
|
-
);
|
73539
|
-
if (removedColumns.length) {
|
73540
|
-
for (const removedColumn of removedColumns) {
|
73541
|
-
const res = await connection.query(
|
73542
|
-
`select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
|
73543
|
-
);
|
73544
|
-
const count = Number(res[0].count);
|
73545
|
-
if (count > 0) {
|
73546
|
-
infoToPrint.push(
|
73547
|
-
`\xB7 You're about to delete ${source_default.underline(
|
73548
|
-
removedColumn
|
73549
|
-
)} column in ${tableName} table with ${count} items`
|
73550
|
-
);
|
73551
|
-
columnsToRemove.push(removedColumn);
|
73552
|
-
shouldAskForApprove = true;
|
73553
|
-
}
|
73554
|
-
}
|
73555
|
-
}
|
73556
|
-
if (addedColumns.length) {
|
73557
|
-
for (const addedColumn of addedColumns) {
|
73558
|
-
const [res] = await connection.query(
|
73559
|
-
`select count(\`${tableName}\`.\`${addedColumn}\`) as count from \`${tableName}\``
|
73560
|
-
);
|
73561
|
-
const columnConf = json2.tables[tableName].columns[addedColumn];
|
73562
|
-
const count = Number(res.count);
|
73563
|
-
if (count > 0 && columnConf.notNull && !columnConf.default) {
|
73564
|
-
infoToPrint.push(
|
73565
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
73566
|
-
addedColumn
|
73567
|
-
)} column without default value, which contains ${count} items`
|
73568
|
-
);
|
73569
|
-
shouldAskForApprove = true;
|
73570
|
-
tablesToTruncate.push(tableName);
|
73571
|
-
}
|
73572
|
-
}
|
73573
|
-
}
|
73574
|
-
statementsToExecute.push(..._moveDataStatements2(tableName, json2));
|
73575
|
-
const tablesReferencingCurrent = [];
|
73576
|
-
for (const table4 of Object.values(json2.tables)) {
|
73577
|
-
const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t2) => SQLiteSquasher.unsquashPushFK(t2).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
|
73578
|
-
tablesReferencingCurrent.push(...tablesRefs);
|
73579
|
-
}
|
73580
|
-
const uniqueTableRefs = [...new Set(tablesReferencingCurrent)];
|
73581
|
-
for (const table4 of uniqueTableRefs) {
|
73582
|
-
statementsToExecute.push(..._moveDataStatements2(table4, json2));
|
73583
|
-
}
|
73584
|
-
} else if (statement.type === "alter_table_alter_column_set_generated") {
|
73585
|
-
const tableName = statement.tableName;
|
73586
|
-
const res = await connection.query(
|
73587
|
-
`select count("${statement.columnName}") as count from \`${tableName}\``
|
73588
|
-
);
|
73589
|
-
const count = Number(res[0].count);
|
73590
|
-
if (count > 0) {
|
73591
|
-
infoToPrint.push(
|
73592
|
-
`\xB7 You're about to delete ${source_default.underline(
|
73593
|
-
statement.columnName
|
73594
|
-
)} column in ${tableName} table with ${count} items`
|
73595
|
-
);
|
73596
|
-
columnsToRemove.push(`${tableName}_${statement.columnName}`);
|
73597
|
-
shouldAskForApprove = true;
|
73598
|
-
}
|
73599
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push", "turso", json2);
|
73600
|
-
statementsToExecute.push(
|
73601
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
73602
|
-
);
|
73603
|
-
} else {
|
73604
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push", "turso", json2);
|
73605
|
-
statementsToExecute.push(
|
73606
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
73607
|
-
);
|
73608
|
-
}
|
73609
|
-
}
|
73610
|
-
return {
|
73611
|
-
statementsToExecute: [...new Set(statementsToExecute)],
|
73612
|
-
shouldAskForApprove,
|
73613
|
-
infoToPrint,
|
73614
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
73615
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
73616
|
-
tablesToRemove: [...new Set(tablesToRemove)]
|
73617
|
-
};
|
73618
|
-
};
|
73619
|
-
}
|
73620
|
-
});
|
73621
|
-
|
73622
72208
|
// src/cli/commands/mysqlPushUtils.ts
|
73623
|
-
var import_hanji6, filterStatements,
|
72209
|
+
var import_hanji6, filterStatements, logSuggestionsAndReturn;
|
73624
72210
|
var init_mysqlPushUtils = __esm({
|
73625
72211
|
"src/cli/commands/mysqlPushUtils.ts"() {
|
73626
72212
|
"use strict";
|
@@ -73670,7 +72256,7 @@ var init_mysqlPushUtils = __esm({
|
|
73670
72256
|
return true;
|
73671
72257
|
});
|
73672
72258
|
};
|
73673
|
-
|
72259
|
+
logSuggestionsAndReturn = async (db, statements, json2) => {
|
73674
72260
|
let shouldAskForApprove = false;
|
73675
72261
|
const statementsToExecute = [];
|
73676
72262
|
const infoToPrint = [];
|
@@ -74111,6 +72697,289 @@ var init_pgPushUtils = __esm({
|
|
74111
72697
|
}
|
74112
72698
|
});
|
74113
72699
|
|
72700
|
+
// src/cli/commands/sqlitePushUtils.ts
|
72701
|
+
var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn2;
|
72702
|
+
var init_sqlitePushUtils = __esm({
|
72703
|
+
"src/cli/commands/sqlitePushUtils.ts"() {
|
72704
|
+
"use strict";
|
72705
|
+
init_source();
|
72706
|
+
init_sqliteSchema();
|
72707
|
+
init_sqlgenerator();
|
72708
|
+
_moveDataStatements = (tableName, json, dataLoss = false) => {
|
72709
|
+
const statements = [];
|
72710
|
+
statements.push(
|
72711
|
+
new SqliteRenameTableConvertor().convert({
|
72712
|
+
type: "rename_table",
|
72713
|
+
tableNameFrom: tableName,
|
72714
|
+
tableNameTo: `__old_push_${tableName}`,
|
72715
|
+
fromSchema: "",
|
72716
|
+
toSchema: ""
|
72717
|
+
})
|
72718
|
+
);
|
72719
|
+
const tableColumns = Object.values(json.tables[tableName].columns);
|
72720
|
+
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
72721
|
+
const compositePKs = Object.values(
|
72722
|
+
json.tables[tableName].compositePrimaryKeys
|
72723
|
+
).map((it) => SQLiteSquasher.unsquashPK(it));
|
72724
|
+
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
72725
|
+
statements.push(
|
72726
|
+
new SQLiteCreateTableConvertor().convert({
|
72727
|
+
type: "sqlite_create_table",
|
72728
|
+
tableName,
|
72729
|
+
columns: tableColumns,
|
72730
|
+
referenceData: fks,
|
72731
|
+
compositePKs
|
72732
|
+
})
|
72733
|
+
);
|
72734
|
+
if (!dataLoss) {
|
72735
|
+
statements.push(
|
72736
|
+
`INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
|
72737
|
+
);
|
72738
|
+
}
|
72739
|
+
statements.push(
|
72740
|
+
new SQLiteDropTableConvertor().convert({
|
72741
|
+
type: "drop_table",
|
72742
|
+
tableName: `__old_push_${tableName}`,
|
72743
|
+
schema: ""
|
72744
|
+
})
|
72745
|
+
);
|
72746
|
+
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
72747
|
+
statements.push(
|
72748
|
+
new CreateSqliteIndexConvertor().convert({
|
72749
|
+
type: "create_index",
|
72750
|
+
tableName,
|
72751
|
+
schema: "",
|
72752
|
+
data: idx
|
72753
|
+
})
|
72754
|
+
);
|
72755
|
+
}
|
72756
|
+
return statements;
|
72757
|
+
};
|
72758
|
+
getOldTableName = (tableName, meta) => {
|
72759
|
+
for (const key of Object.keys(meta.tables)) {
|
72760
|
+
const value = meta.tables[key];
|
72761
|
+
if (`"${tableName}"` === value) {
|
72762
|
+
return key.substring(1, key.length - 1);
|
72763
|
+
}
|
72764
|
+
}
|
72765
|
+
return tableName;
|
72766
|
+
};
|
72767
|
+
getNewTableName = (tableName, meta) => {
|
72768
|
+
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
72769
|
+
return meta.tables[`"${tableName}"`].substring(
|
72770
|
+
1,
|
72771
|
+
meta.tables[`"${tableName}"`].length - 1
|
72772
|
+
);
|
72773
|
+
}
|
72774
|
+
return tableName;
|
72775
|
+
};
|
72776
|
+
logSuggestionsAndReturn2 = async (connection, statements, json1, json2, meta) => {
|
72777
|
+
let shouldAskForApprove = false;
|
72778
|
+
const statementsToExecute = [];
|
72779
|
+
const infoToPrint = [];
|
72780
|
+
const tablesToRemove = [];
|
72781
|
+
const columnsToRemove = [];
|
72782
|
+
const schemasToRemove = [];
|
72783
|
+
const tablesToTruncate = [];
|
72784
|
+
const tablesContext = {};
|
72785
|
+
for (const statement of statements) {
|
72786
|
+
if (statement.type === "drop_table") {
|
72787
|
+
const res = await connection.query(
|
72788
|
+
`select count(*) as count from \`${statement.tableName}\``
|
72789
|
+
);
|
72790
|
+
const count = Number(res[0].count);
|
72791
|
+
if (count > 0) {
|
72792
|
+
infoToPrint.push(
|
72793
|
+
`\xB7 You're about to delete ${source_default.underline(
|
72794
|
+
statement.tableName
|
72795
|
+
)} table with ${count} items`
|
72796
|
+
);
|
72797
|
+
tablesToRemove.push(statement.tableName);
|
72798
|
+
shouldAskForApprove = true;
|
72799
|
+
}
|
72800
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
72801
|
+
statementsToExecute.push(stmnt);
|
72802
|
+
} else if (statement.type === "alter_table_drop_column") {
|
72803
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
72804
|
+
const columnIsPartOfPk = Object.values(
|
72805
|
+
json1.tables[newTableName].compositePrimaryKeys
|
72806
|
+
).find((c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName));
|
72807
|
+
const columnIsPartOfIndex = Object.values(
|
72808
|
+
json1.tables[newTableName].indexes
|
72809
|
+
).find((c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName));
|
72810
|
+
const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
|
72811
|
+
const columnIsPartOfFk = Object.values(
|
72812
|
+
json1.tables[newTableName].foreignKeys
|
72813
|
+
).find(
|
72814
|
+
(t2) => SQLiteSquasher.unsquashPushFK(t2).columnsFrom.includes(
|
72815
|
+
statement.columnName
|
72816
|
+
)
|
72817
|
+
);
|
72818
|
+
const res = await connection.query(
|
72819
|
+
`select count(*) as count from \`${newTableName}\``
|
72820
|
+
);
|
72821
|
+
const count = Number(res[0].count);
|
72822
|
+
if (count > 0) {
|
72823
|
+
infoToPrint.push(
|
72824
|
+
`\xB7 You're about to delete ${source_default.underline(
|
72825
|
+
statement.columnName
|
72826
|
+
)} column in ${newTableName} table with ${count} items`
|
72827
|
+
);
|
72828
|
+
columnsToRemove.push(`${newTableName}_${statement.columnName}`);
|
72829
|
+
shouldAskForApprove = true;
|
72830
|
+
}
|
72831
|
+
if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
|
72832
|
+
tablesContext[newTableName] = [
|
72833
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
72834
|
+
];
|
72835
|
+
const tablesReferncingCurrent = [];
|
72836
|
+
for (const table4 of Object.values(json1.tables)) {
|
72837
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
72838
|
+
(t2) => SQLiteSquasher.unsquashPushFK(t2).tableTo === newTableName
|
72839
|
+
).map((t2) => SQLiteSquasher.unsquashPushFK(t2).tableFrom);
|
72840
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
72841
|
+
}
|
72842
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
72843
|
+
for (const table4 of uniqueTableRefs) {
|
72844
|
+
if (typeof tablesContext[table4] === "undefined") {
|
72845
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
72846
|
+
}
|
72847
|
+
}
|
72848
|
+
} else {
|
72849
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
72850
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
72851
|
+
statementsToExecute.push(stmnt);
|
72852
|
+
}
|
72853
|
+
}
|
72854
|
+
} else if (statement.type === "sqlite_alter_table_add_column") {
|
72855
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
72856
|
+
if (statement.column.notNull && !statement.column.default) {
|
72857
|
+
const res = await connection.query(
|
72858
|
+
`select count(*) as count from \`${newTableName}\``
|
72859
|
+
);
|
72860
|
+
const count = Number(res[0].count);
|
72861
|
+
if (count > 0) {
|
72862
|
+
infoToPrint.push(
|
72863
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
72864
|
+
statement.column.name
|
72865
|
+
)} column without default value, which contains ${count} items`
|
72866
|
+
);
|
72867
|
+
tablesToTruncate.push(newTableName);
|
72868
|
+
statementsToExecute.push(`delete from ${newTableName};`);
|
72869
|
+
shouldAskForApprove = true;
|
72870
|
+
}
|
72871
|
+
}
|
72872
|
+
if (statement.column.primaryKey) {
|
72873
|
+
tablesContext[newTableName] = [
|
72874
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
72875
|
+
];
|
72876
|
+
const tablesReferncingCurrent = [];
|
72877
|
+
for (const table4 of Object.values(json1.tables)) {
|
72878
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
72879
|
+
(t2) => SQLiteSquasher.unsquashPushFK(t2).tableTo === newTableName
|
72880
|
+
).map((t2) => SQLiteSquasher.unsquashPushFK(t2).tableFrom);
|
72881
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
72882
|
+
}
|
72883
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
72884
|
+
for (const table4 of uniqueTableRefs) {
|
72885
|
+
if (typeof tablesContext[table4] === "undefined") {
|
72886
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
72887
|
+
}
|
72888
|
+
}
|
72889
|
+
} else {
|
72890
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
72891
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
72892
|
+
statementsToExecute.push(stmnt);
|
72893
|
+
}
|
72894
|
+
}
|
72895
|
+
} 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") {
|
72896
|
+
if (!(statement.type === "alter_table_alter_column_set_notnull" && statement.columnPk)) {
|
72897
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
72898
|
+
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
72899
|
+
const res = await connection.query(
|
72900
|
+
`select count(*) as count from \`${newTableName}\``
|
72901
|
+
);
|
72902
|
+
const count = Number(res[0].count);
|
72903
|
+
if (count > 0) {
|
72904
|
+
infoToPrint.push(
|
72905
|
+
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
72906
|
+
statement.columnName
|
72907
|
+
)} column without default value, which contains ${count} items`
|
72908
|
+
);
|
72909
|
+
tablesToTruncate.push(newTableName);
|
72910
|
+
shouldAskForApprove = true;
|
72911
|
+
}
|
72912
|
+
tablesContext[newTableName] = _moveDataStatements(
|
72913
|
+
statement.tableName,
|
72914
|
+
json1,
|
72915
|
+
true
|
72916
|
+
);
|
72917
|
+
} else {
|
72918
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
72919
|
+
tablesContext[newTableName] = _moveDataStatements(
|
72920
|
+
statement.tableName,
|
72921
|
+
json1
|
72922
|
+
);
|
72923
|
+
}
|
72924
|
+
}
|
72925
|
+
const tablesReferncingCurrent = [];
|
72926
|
+
for (const table4 of Object.values(json1.tables)) {
|
72927
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
72928
|
+
(t2) => SQLiteSquasher.unsquashPushFK(t2).tableTo === newTableName
|
72929
|
+
).map((t2) => {
|
72930
|
+
return getNewTableName(
|
72931
|
+
SQLiteSquasher.unsquashPushFK(t2).tableFrom,
|
72932
|
+
meta
|
72933
|
+
);
|
72934
|
+
});
|
72935
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
72936
|
+
}
|
72937
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
72938
|
+
for (const table4 of uniqueTableRefs) {
|
72939
|
+
if (typeof tablesContext[table4] === "undefined") {
|
72940
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json1)];
|
72941
|
+
}
|
72942
|
+
}
|
72943
|
+
}
|
72944
|
+
} else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
|
72945
|
+
const fk4 = SQLiteSquasher.unsquashPushFK(statement.data);
|
72946
|
+
if (typeof tablesContext[statement.tableName] === "undefined") {
|
72947
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
72948
|
+
statement.tableName,
|
72949
|
+
json2
|
72950
|
+
);
|
72951
|
+
}
|
72952
|
+
} 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") {
|
72953
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
72954
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
72955
|
+
tablesContext[newTableName] = _moveDataStatements(
|
72956
|
+
statement.tableName,
|
72957
|
+
json2
|
72958
|
+
);
|
72959
|
+
}
|
72960
|
+
} else {
|
72961
|
+
const stmnt = fromJson([statement], "sqlite");
|
72962
|
+
if (typeof stmnt !== "undefined") {
|
72963
|
+
statementsToExecute.push(...stmnt);
|
72964
|
+
}
|
72965
|
+
}
|
72966
|
+
}
|
72967
|
+
for (const context of Object.values(tablesContext)) {
|
72968
|
+
statementsToExecute.push(...context);
|
72969
|
+
}
|
72970
|
+
return {
|
72971
|
+
statementsToExecute,
|
72972
|
+
shouldAskForApprove,
|
72973
|
+
infoToPrint,
|
72974
|
+
columnsToRemove: [...new Set(columnsToRemove)],
|
72975
|
+
schemasToRemove: [...new Set(schemasToRemove)],
|
72976
|
+
tablesToTruncate: [...new Set(tablesToTruncate)],
|
72977
|
+
tablesToRemove: [...new Set(tablesToRemove)]
|
72978
|
+
};
|
72979
|
+
};
|
72980
|
+
}
|
72981
|
+
});
|
72982
|
+
|
74114
72983
|
// ../node_modules/.pnpm/minimatch@7.4.6/node_modules/minimatch/dist/mjs/brace-expressions.js
|
74115
72984
|
var posixClasses, braceEscape, regexpEscape, rangesToString, parseClass;
|
74116
72985
|
var init_brace_expressions = __esm({
|
@@ -75673,12 +74542,11 @@ var init_sqliteIntrospect = __esm({
|
|
75673
74542
|
// src/cli/commands/push.ts
|
75674
74543
|
var push_exports = {};
|
75675
74544
|
__export(push_exports, {
|
75676
|
-
libSQLPush: () => libSQLPush,
|
75677
74545
|
mysqlPush: () => mysqlPush,
|
75678
74546
|
pgPush: () => pgPush,
|
75679
74547
|
sqlitePush: () => sqlitePush
|
75680
74548
|
});
|
75681
|
-
var import_hanji11, mysqlPush, pgPush, sqlitePush
|
74549
|
+
var import_hanji11, mysqlPush, pgPush, sqlitePush;
|
75682
74550
|
var init_push = __esm({
|
75683
74551
|
"src/cli/commands/push.ts"() {
|
75684
74552
|
"use strict";
|
@@ -75687,7 +74555,6 @@ var init_push = __esm({
|
|
75687
74555
|
init_sqlgenerator();
|
75688
74556
|
init_selector_ui();
|
75689
74557
|
init_outputs();
|
75690
|
-
init_libSqlPushUtils();
|
75691
74558
|
init_mysqlPushUtils();
|
75692
74559
|
init_pgPushUtils();
|
75693
74560
|
init_sqlitePushUtils();
|
@@ -75715,7 +74582,7 @@ var init_push = __esm({
|
|
75715
74582
|
tablesToTruncate,
|
75716
74583
|
infoToPrint,
|
75717
74584
|
schemasToRemove
|
75718
|
-
} = await
|
74585
|
+
} = await logSuggestionsAndReturn(
|
75719
74586
|
db,
|
75720
74587
|
filteredStatements,
|
75721
74588
|
statements.validatedCur
|
@@ -75734,6 +74601,7 @@ var init_push = __esm({
|
|
75734
74601
|
}
|
75735
74602
|
});
|
75736
74603
|
if (verbose) {
|
74604
|
+
console.log();
|
75737
74605
|
console.log(
|
75738
74606
|
withStyle.warning("You are about to execute current statements:")
|
75739
74607
|
);
|
@@ -75884,100 +74752,11 @@ var init_push = __esm({
|
|
75884
74752
|
tablesToTruncate,
|
75885
74753
|
infoToPrint,
|
75886
74754
|
schemasToRemove
|
75887
|
-
} = await
|
74755
|
+
} = await logSuggestionsAndReturn2(
|
75888
74756
|
db,
|
75889
74757
|
statements.statements,
|
75890
|
-
statements.squashedPrev,
|
75891
74758
|
statements.squashedCur,
|
75892
|
-
statements.meta
|
75893
|
-
);
|
75894
|
-
if (verbose && statementsToExecute.length > 0) {
|
75895
|
-
console.log();
|
75896
|
-
console.log(
|
75897
|
-
withStyle.warning("You are about to execute current statements:")
|
75898
|
-
);
|
75899
|
-
console.log();
|
75900
|
-
console.log(statementsToExecute.map((s2) => source_default.blue(s2)).join("\n"));
|
75901
|
-
console.log();
|
75902
|
-
}
|
75903
|
-
if (!force && strict) {
|
75904
|
-
if (!shouldAskForApprove) {
|
75905
|
-
const { status, data } = await (0, import_hanji11.render)(
|
75906
|
-
new Select(["No, abort", `Yes, I want to execute all statements`])
|
75907
|
-
);
|
75908
|
-
if ((data == null ? void 0 : data.index) === 0) {
|
75909
|
-
(0, import_hanji11.render)(`[${source_default.red("x")}] All changes were aborted`);
|
75910
|
-
process.exit(0);
|
75911
|
-
}
|
75912
|
-
}
|
75913
|
-
}
|
75914
|
-
if (!force && shouldAskForApprove) {
|
75915
|
-
console.log(withStyle.warning("Found data-loss statements:"));
|
75916
|
-
console.log(infoToPrint.join("\n"));
|
75917
|
-
console.log();
|
75918
|
-
console.log(
|
75919
|
-
source_default.red.bold(
|
75920
|
-
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
75921
|
-
)
|
75922
|
-
);
|
75923
|
-
console.log(source_default.white("Do you still want to push changes?"));
|
75924
|
-
const { status, data } = await (0, import_hanji11.render)(
|
75925
|
-
new Select([
|
75926
|
-
"No, abort",
|
75927
|
-
`Yes, I want to${tablesToRemove.length > 0 ? ` remove ${tablesToRemove.length} ${tablesToRemove.length > 1 ? "tables" : "table"},` : " "}${columnsToRemove.length > 0 ? ` remove ${columnsToRemove.length} ${columnsToRemove.length > 1 ? "columns" : "column"},` : " "}${tablesToTruncate.length > 0 ? ` truncate ${tablesToTruncate.length} ${tablesToTruncate.length > 1 ? "tables" : "table"}` : ""}`.trimEnd().replace(/(^,)|(,$)/g, "").replace(/ +(?= )/g, "")
|
75928
|
-
])
|
75929
|
-
);
|
75930
|
-
if ((data == null ? void 0 : data.index) === 0) {
|
75931
|
-
(0, import_hanji11.render)(`[${source_default.red("x")}] All changes were aborted`);
|
75932
|
-
process.exit(0);
|
75933
|
-
}
|
75934
|
-
}
|
75935
|
-
if (statementsToExecute.length === 0) {
|
75936
|
-
(0, import_hanji11.render)(`
|
75937
|
-
[${source_default.blue("i")}] No changes detected`);
|
75938
|
-
} else {
|
75939
|
-
if (!("driver" in credentials2)) {
|
75940
|
-
await db.query("begin");
|
75941
|
-
try {
|
75942
|
-
for (const dStmnt of statementsToExecute) {
|
75943
|
-
await db.query(dStmnt);
|
75944
|
-
}
|
75945
|
-
await db.query("commit");
|
75946
|
-
} catch (e2) {
|
75947
|
-
console.error(e2);
|
75948
|
-
await db.query("rollback");
|
75949
|
-
process.exit(1);
|
75950
|
-
}
|
75951
|
-
} else if (credentials2.driver === "turso") {
|
75952
|
-
await db.batch(statementsToExecute.map((it) => ({ query: it })));
|
75953
|
-
}
|
75954
|
-
(0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
75955
|
-
}
|
75956
|
-
}
|
75957
|
-
};
|
75958
|
-
libSQLPush = async (schemaPath, verbose, strict, credentials2, tablesFilter, force) => {
|
75959
|
-
const { connectToSQLite: connectToSQLite2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
75960
|
-
const { sqlitePushIntrospect: sqlitePushIntrospect2 } = await Promise.resolve().then(() => (init_sqliteIntrospect(), sqliteIntrospect_exports));
|
75961
|
-
const db = await connectToSQLite2(credentials2);
|
75962
|
-
const { schema: schema5 } = await sqlitePushIntrospect2(db, tablesFilter);
|
75963
|
-
const { prepareLibSQLPush: prepareLibSQLPush2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
75964
|
-
const statements = await prepareLibSQLPush2(schemaPath, schema5);
|
75965
|
-
if (statements.sqlStatements.length === 0) {
|
75966
|
-
(0, import_hanji11.render)(`
|
75967
|
-
[${source_default.blue("i")}] No changes detected`);
|
75968
|
-
} else {
|
75969
|
-
const {
|
75970
|
-
shouldAskForApprove,
|
75971
|
-
statementsToExecute,
|
75972
|
-
columnsToRemove,
|
75973
|
-
tablesToRemove,
|
75974
|
-
tablesToTruncate,
|
75975
|
-
infoToPrint
|
75976
|
-
} = await libSqlLogSuggestionsAndReturn(
|
75977
|
-
db,
|
75978
|
-
statements.statements,
|
75979
74759
|
statements.squashedPrev,
|
75980
|
-
statements.squashedCur,
|
75981
74760
|
statements.meta
|
75982
74761
|
);
|
75983
74762
|
if (verbose && statementsToExecute.length > 0) {
|
@@ -81740,7 +80519,7 @@ var init_studio2 = __esm({
|
|
81740
80519
|
}
|
81741
80520
|
});
|
81742
80521
|
|
81743
|
-
// ../node_modules/.pnpm/@drizzle-team+brocli@0.
|
80522
|
+
// ../node_modules/.pnpm/@drizzle-team+brocli@0.10.1/node_modules/@drizzle-team/brocli/index.js
|
81744
80523
|
var __create2 = Object.create;
|
81745
80524
|
var __defProp2 = Object.defineProperty;
|
81746
80525
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
@@ -82187,130 +80966,299 @@ var require_shell_quote = __commonJS2({
|
|
82187
80966
|
}
|
82188
80967
|
});
|
82189
80968
|
var BroCliError = class extends Error {
|
82190
|
-
constructor(message) {
|
80969
|
+
constructor(message, event) {
|
82191
80970
|
const errPrefix = "BroCli error: ";
|
82192
80971
|
super(message === void 0 ? message : `${errPrefix}${message}`);
|
80972
|
+
this.event = event;
|
82193
80973
|
}
|
82194
80974
|
};
|
82195
80975
|
var import_clone = __toESM2(require_clone(), 1);
|
82196
|
-
var
|
82197
|
-
|
82198
|
-
|
82199
|
-
|
82200
|
-
|
82201
|
-
|
82202
|
-
|
82203
|
-
|
82204
|
-
|
82205
|
-
|
82206
|
-
|
82207
|
-
|
82208
|
-
|
82209
|
-
|
82210
|
-
|
82211
|
-
|
82212
|
-
|
82213
|
-
|
82214
|
-
|
82215
|
-
|
82216
|
-
|
82217
|
-
|
82218
|
-
|
82219
|
-
|
82220
|
-
|
82221
|
-
}
|
82222
|
-
|
82223
|
-
|
82224
|
-
|
82225
|
-
|
82226
|
-
|
82227
|
-
|
82228
|
-
|
82229
|
-
|
80976
|
+
var getOptionTypeText = (option) => {
|
80977
|
+
let result = "";
|
80978
|
+
switch (option.type) {
|
80979
|
+
case "boolean":
|
80980
|
+
result = "";
|
80981
|
+
break;
|
80982
|
+
case "number": {
|
80983
|
+
if ((option.minVal ?? option.maxVal) !== void 0) {
|
80984
|
+
let text = "";
|
80985
|
+
if (option.isInt)
|
80986
|
+
text = text + `integer `;
|
80987
|
+
if (option.minVal !== void 0)
|
80988
|
+
text = text + `[${option.minVal};`;
|
80989
|
+
else
|
80990
|
+
text = text + `(\u221E;`;
|
80991
|
+
if (option.maxVal !== void 0)
|
80992
|
+
text = text + `${option.maxVal}]`;
|
80993
|
+
else
|
80994
|
+
text = text + `\u221E)`;
|
80995
|
+
result = text;
|
80996
|
+
break;
|
80997
|
+
}
|
80998
|
+
if (option.isInt) {
|
80999
|
+
result = "integer";
|
81000
|
+
break;
|
81001
|
+
}
|
81002
|
+
result = "number";
|
81003
|
+
break;
|
81004
|
+
}
|
81005
|
+
case "string": {
|
81006
|
+
if (option.enumVals) {
|
81007
|
+
result = "[ " + option.enumVals.join(" | ") + " ]";
|
81008
|
+
break;
|
81009
|
+
}
|
81010
|
+
result = "string";
|
81011
|
+
break;
|
81012
|
+
}
|
81013
|
+
case "positional": {
|
81014
|
+
result = `${option.isRequired ? "<" : "["}${option.enumVals ? option.enumVals.join("|") : option.name}${option.isRequired ? ">" : "]"}`;
|
81015
|
+
break;
|
81016
|
+
}
|
81017
|
+
}
|
81018
|
+
if (option.isRequired && option.type !== "positional")
|
81019
|
+
result = "!" + result.length ? " " : "" + result;
|
81020
|
+
return result;
|
81021
|
+
};
|
81022
|
+
var defaultEventHandler = async (event) => {
|
81023
|
+
var _a;
|
81024
|
+
switch (event.type) {
|
81025
|
+
case "command_help": {
|
81026
|
+
const command2 = event.command;
|
81027
|
+
const commandName = getCommandNameWithParents(command2);
|
81028
|
+
const cliName = event.name;
|
81029
|
+
const desc = command2.desc ?? command2.shortDesc;
|
81030
|
+
const subs = (_a = command2.subcommands) == null ? void 0 : _a.filter((s2) => !s2.hidden);
|
81031
|
+
const subcommands = subs && subs.length ? subs : void 0;
|
81032
|
+
if (desc !== void 0) {
|
81033
|
+
console.log(`
|
81034
|
+
${desc}`);
|
81035
|
+
}
|
81036
|
+
const opts = Object.values(command2.options ?? {}).filter(
|
81037
|
+
(opt) => !opt.config.isHidden
|
81038
|
+
);
|
81039
|
+
const positionals = opts.filter((opt) => opt.config.type === "positional");
|
81040
|
+
const options = opts.filter((opt) => opt.config.type !== "positional");
|
81041
|
+
console.log("\nUsage:");
|
81042
|
+
if (command2.handler) {
|
81043
|
+
console.log(
|
81044
|
+
` ${cliName ? cliName + " " : ""}${commandName}${positionals.length ? " " + positionals.map(({ config: p2 }) => getOptionTypeText(p2)).join(" ") : ""} [flags]`
|
81045
|
+
);
|
81046
|
+
} else
|
81047
|
+
console.log(` ${cliName ? cliName + " " : ""}${commandName} [command]`);
|
81048
|
+
if (command2.aliases) {
|
81049
|
+
console.log(`
|
81050
|
+
Aliases:`);
|
81051
|
+
console.log(` ${[command2.name, ...command2.aliases].join(", ")}`);
|
81052
|
+
}
|
81053
|
+
if (subcommands) {
|
81054
|
+
console.log("\nAvailable Commands:");
|
81055
|
+
const padding = 3;
|
81056
|
+
const maxLength = subcommands.reduce((p2, e2) => e2.name.length > p2 ? e2.name.length : p2, 0);
|
81057
|
+
const paddedLength = maxLength + padding;
|
81058
|
+
const preDescPad = 2 + paddedLength;
|
81059
|
+
const data = subcommands.map(
|
81060
|
+
(s2) => ` ${s2.name.padEnd(paddedLength)}${(() => {
|
81061
|
+
const description = s2.shortDesc ?? s2.desc;
|
81062
|
+
if (!(description == null ? void 0 : description.length))
|
81063
|
+
return "";
|
81064
|
+
const split = description.split("\n");
|
81065
|
+
const first = split.shift();
|
81066
|
+
const final = [first, ...split.map((s22) => "".padEnd(preDescPad) + s22)].join("\n");
|
81067
|
+
return final;
|
81068
|
+
})()}`
|
81069
|
+
).join("\n");
|
81070
|
+
console.log(data);
|
81071
|
+
}
|
81072
|
+
if (options.length) {
|
81073
|
+
const aliasLength = options.reduce((p2, e2) => {
|
81074
|
+
const currentLength = e2.config.aliases.reduce((pa, a) => pa + a.length, 0) + (e2.config.aliases.length - 1) * 2 + 1;
|
81075
|
+
return currentLength > p2 ? currentLength : p2;
|
81076
|
+
}, 0);
|
81077
|
+
const paddedAliasLength = aliasLength > 0 ? aliasLength + 1 : 0;
|
81078
|
+
const nameLength = options.reduce((p2, e2) => {
|
81079
|
+
const typeLen = getOptionTypeText(e2.config).length;
|
81080
|
+
const length = typeLen > 0 ? e2.config.name.length + 1 + typeLen : e2.config.name.length;
|
81081
|
+
return length > p2 ? length : p2;
|
81082
|
+
}, 0) + 3;
|
81083
|
+
const preDescPad = paddedAliasLength + nameLength + 2;
|
81084
|
+
const data = options.map(
|
81085
|
+
({ config: opt }) => ` ${`${opt.aliases.length ? opt.aliases.join(", ") + "," : ""}`.padEnd(paddedAliasLength)}${`${opt.name}${(() => {
|
81086
|
+
const typeText = getOptionTypeText(opt);
|
81087
|
+
return typeText.length ? " " + typeText : "";
|
81088
|
+
})()}`.padEnd(nameLength)}${(() => {
|
81089
|
+
var _a2;
|
81090
|
+
if (!((_a2 = opt.description) == null ? void 0 : _a2.length)) {
|
81091
|
+
return opt.default !== void 0 ? `default: ${JSON.stringify(opt.default)}` : "";
|
81092
|
+
}
|
81093
|
+
const split = opt.description.split("\n");
|
81094
|
+
const first = split.shift();
|
81095
|
+
const def = opt.default !== void 0 ? ` (default: ${JSON.stringify(opt.default)})` : "";
|
81096
|
+
const final = [first, ...split.map((s2) => "".padEnd(preDescPad) + s2)].join("\n") + def;
|
81097
|
+
return final;
|
81098
|
+
})()}`
|
81099
|
+
).join("\n");
|
81100
|
+
console.log("\nFlags:");
|
81101
|
+
console.log(data);
|
81102
|
+
}
|
81103
|
+
console.log("\nGlobal flags:");
|
81104
|
+
console.log(` -h, --help help for ${commandName}`);
|
81105
|
+
console.log(` -v, --version version${cliName ? ` for ${cliName}` : ""}`);
|
81106
|
+
if (subcommands) {
|
81107
|
+
console.log(
|
81108
|
+
`
|
81109
|
+
Use "${cliName ? cliName + " " : ""}${commandName} [command] --help" for more information about a command.
|
81110
|
+
`
|
81111
|
+
);
|
81112
|
+
}
|
81113
|
+
return true;
|
81114
|
+
}
|
81115
|
+
case "global_help": {
|
81116
|
+
const cliName = event.name;
|
81117
|
+
const desc = event.description;
|
81118
|
+
const commands = event.commands.filter((c) => !c.hidden);
|
81119
|
+
if (desc !== void 0) {
|
81120
|
+
console.log(`${desc}
|
81121
|
+
`);
|
81122
|
+
}
|
81123
|
+
console.log("Usage:");
|
81124
|
+
console.log(` ${cliName ? cliName + " " : ""}[command]`);
|
81125
|
+
if (commands.length) {
|
81126
|
+
console.log("\nAvailable Commands:");
|
81127
|
+
const padding = 3;
|
81128
|
+
const maxLength = commands.reduce((p2, e2) => e2.name.length > p2 ? e2.name.length : p2, 0);
|
81129
|
+
const paddedLength = maxLength + padding;
|
81130
|
+
const data = commands.map(
|
81131
|
+
(\u0441) => ` ${\u0441.name.padEnd(paddedLength)}${(() => {
|
81132
|
+
const desc2 = \u0441.shortDesc ?? \u0441.desc;
|
81133
|
+
if (!(desc2 == null ? void 0 : desc2.length))
|
81134
|
+
return "";
|
81135
|
+
const split = desc2.split("\n");
|
81136
|
+
const first = split.shift();
|
81137
|
+
const final = [first, ...split.map((s2) => "".padEnd(paddedLength + 2) + s2)].join("\n");
|
81138
|
+
return final;
|
81139
|
+
})()}`
|
81140
|
+
).join("\n");
|
81141
|
+
console.log(data);
|
81142
|
+
} else {
|
81143
|
+
console.log("\nNo available commands.");
|
81144
|
+
}
|
81145
|
+
console.log("\nFlags:");
|
81146
|
+
console.log(` -h, --help help${cliName ? ` for ${cliName}` : ""}`);
|
81147
|
+
console.log(` -v, --version version${cliName ? ` for ${cliName}` : ""}`);
|
81148
|
+
console.log("\n");
|
81149
|
+
return true;
|
81150
|
+
}
|
81151
|
+
case "version": {
|
81152
|
+
return true;
|
81153
|
+
}
|
81154
|
+
case "error": {
|
81155
|
+
let msg;
|
81156
|
+
switch (event.violation) {
|
81157
|
+
case "above_max": {
|
81158
|
+
const matchedName = event.offender.namePart;
|
81159
|
+
const data = event.offender.dataPart;
|
81160
|
+
const option = event.option;
|
81161
|
+
const max = option.maxVal;
|
81162
|
+
msg = `Invalid value: number type argument '${matchedName}' expects maximal value of ${max} as an input, got: ${data}`;
|
81163
|
+
break;
|
81164
|
+
}
|
81165
|
+
case "below_min": {
|
81166
|
+
const matchedName = event.offender.namePart;
|
81167
|
+
const data = event.offender.dataPart;
|
81168
|
+
const option = event.option;
|
81169
|
+
const min = option.minVal;
|
81170
|
+
msg = `Invalid value: number type argument '${matchedName}' expects minimal value of ${min} as an input, got: ${data}`;
|
81171
|
+
break;
|
81172
|
+
}
|
81173
|
+
case "expected_int": {
|
81174
|
+
const matchedName = event.offender.namePart;
|
81175
|
+
const data = event.offender.dataPart;
|
81176
|
+
msg = `Invalid value: number type argument '${matchedName}' expects an integer as an input, got: ${data}`;
|
81177
|
+
break;
|
81178
|
+
}
|
81179
|
+
case "invalid_boolean_syntax": {
|
81180
|
+
const matchedName = event.offender.namePart;
|
81181
|
+
const data = event.offender.dataPart;
|
81182
|
+
msg = `Invalid syntax: boolean type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value> | ${matchedName}.
|
81183
|
+
Allowed values: true, false, 0, 1`;
|
81184
|
+
break;
|
81185
|
+
}
|
81186
|
+
case "invalid_string_syntax": {
|
81187
|
+
const matchedName = event.offender.namePart;
|
81188
|
+
msg = `Invalid syntax: string type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value>`;
|
81189
|
+
break;
|
81190
|
+
}
|
81191
|
+
case "invalid_number_syntax": {
|
81192
|
+
const matchedName = event.offender.namePart;
|
81193
|
+
msg = `Invalid syntax: number type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value>`;
|
81194
|
+
break;
|
81195
|
+
}
|
81196
|
+
case "invalid_number_value": {
|
81197
|
+
const matchedName = event.offender.namePart;
|
81198
|
+
const data = event.offender.dataPart;
|
81199
|
+
msg = `Invalid value: number type argument '${matchedName}' expects a number as an input, got: ${data}`;
|
81200
|
+
break;
|
81201
|
+
}
|
81202
|
+
case "enum_violation": {
|
81203
|
+
const matchedName = event.offender.namePart;
|
81204
|
+
const data = event.offender.dataPart;
|
81205
|
+
const option = event.option;
|
81206
|
+
const values = option.enumVals;
|
81207
|
+
msg = option.type === "positional" ? `Invalid value: value for the positional argument '${option.name}' must be either one of the following: ${values.join(", ")}; Received: ${data}` : `Invalid value: value for the argument '${matchedName}' must be either one of the following: ${values.join(", ")}; Received: ${data}`;
|
81208
|
+
break;
|
81209
|
+
}
|
81210
|
+
case "unknown_command_error": {
|
81211
|
+
const msg2 = `Unknown command: '${event.offender}'.
|
81212
|
+
Type '--help' to get help on the cli.`;
|
81213
|
+
console.error(msg2);
|
81214
|
+
return true;
|
81215
|
+
}
|
81216
|
+
case "unknown_subcommand_error": {
|
81217
|
+
const cName = getCommandNameWithParents(event.command);
|
81218
|
+
const msg2 = `Unknown command: ${cName} ${event.offender}.
|
81219
|
+
Type '${cName} --help' to get the help on command.`;
|
81220
|
+
console.error(msg2);
|
81221
|
+
return true;
|
81222
|
+
}
|
81223
|
+
case "missing_args_error": {
|
81224
|
+
const missingOpts = event.missing;
|
81225
|
+
msg = `Command '${command.name}' is missing following required options: ${missingOpts.map((opt) => {
|
81226
|
+
const name = opt.shift();
|
81227
|
+
const aliases = opt;
|
81228
|
+
if (aliases.length)
|
81229
|
+
return `${name} [${aliases.join(", ")}]`;
|
81230
|
+
return name;
|
81231
|
+
}).join(", ")}`;
|
81232
|
+
break;
|
81233
|
+
}
|
81234
|
+
case "unrecognized_args_error": {
|
81235
|
+
const { command: command2, unrecognized } = event;
|
81236
|
+
msg = `Unrecognized options for command '${command2.name}': ${unrecognized.join(", ")}`;
|
81237
|
+
break;
|
81238
|
+
}
|
81239
|
+
case "unknown_error": {
|
81240
|
+
const e2 = event.error;
|
81241
|
+
console.error(typeof e2 === "object" && e2 !== null && "message" in e2 ? e2.message : e2);
|
81242
|
+
return true;
|
81243
|
+
}
|
81244
|
+
}
|
81245
|
+
console.error(msg);
|
81246
|
+
return true;
|
81247
|
+
}
|
82230
81248
|
}
|
81249
|
+
return false;
|
82231
81250
|
};
|
81251
|
+
var eventHandlerWrapper = (customEventHandler) => async (event) => await customEventHandler(event) ? true : await defaultEventHandler(event);
|
81252
|
+
var import_shell_quote = __toESM2(require_shell_quote(), 1);
|
82232
81253
|
function isInt(value) {
|
82233
81254
|
return value === Math.floor(value);
|
82234
81255
|
}
|
82235
|
-
var
|
82236
|
-
const msg = `Unknown command: '${caller}'.
|
82237
|
-
Type '--help' to get help on the cli.`;
|
82238
|
-
return new Error(msg);
|
82239
|
-
};
|
82240
|
-
var unknownSubcommand = (command2, caller) => {
|
82241
|
-
const name = getCommandNameRecursive(command2);
|
82242
|
-
const msg = `Unknown command: ${name} ${caller}.
|
82243
|
-
Type '${name} --help' to get the help on command.`;
|
82244
|
-
new Error(
|
82245
|
-
msg
|
82246
|
-
);
|
82247
|
-
return new Error(msg);
|
82248
|
-
};
|
82249
|
-
var missingRequired = (command2, missingOpts) => {
|
82250
|
-
const msg = `Command '${command2.name}' is missing following required options: ${missingOpts.map((opt) => {
|
82251
|
-
const name = opt.shift();
|
82252
|
-
const aliases = opt;
|
82253
|
-
if (aliases.length)
|
82254
|
-
return `${name} [${aliases.join(", ")}]`;
|
82255
|
-
return name;
|
82256
|
-
}).join(", ")}`;
|
82257
|
-
return new Error(msg);
|
82258
|
-
};
|
82259
|
-
var unrecognizedOptions = (command2, unrecognizedArgs) => {
|
82260
|
-
const msg = `Unrecognized options for command '${command2.name}': ${unrecognizedArgs.join(", ")}`;
|
82261
|
-
return new Error(msg);
|
82262
|
-
};
|
82263
|
-
var invalidBooleanSyntax = (matchedName) => {
|
82264
|
-
return new Error(
|
82265
|
-
`Invalid syntax: boolean type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value> | ${matchedName}.
|
82266
|
-
Allowed values: true, false, 0, 1`
|
82267
|
-
);
|
82268
|
-
};
|
82269
|
-
var invalidStringSyntax = (matchedName) => {
|
82270
|
-
return new Error(
|
82271
|
-
`Invalid syntax: string type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value>`
|
82272
|
-
);
|
82273
|
-
};
|
82274
|
-
var enumViolation = (matchedName, data, values) => {
|
82275
|
-
return new Error(
|
82276
|
-
`Invalid value: value for the argument '${matchedName}' must be either one of the following: ${values.join(", ")}; Received: ${data}`
|
82277
|
-
);
|
82278
|
-
};
|
82279
|
-
var enumViolationPos = (matchedName, data, values) => {
|
82280
|
-
return new Error(
|
82281
|
-
`Invalid value: value for the argument '${matchedName}' must be either one of the following: ${values.join(", ")}; Received: ${data}`
|
82282
|
-
);
|
82283
|
-
};
|
82284
|
-
var invalidNumberSyntax = (matchedName) => {
|
82285
|
-
return new Error(
|
82286
|
-
`Invalid syntax: number type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value>`
|
82287
|
-
);
|
82288
|
-
};
|
82289
|
-
var invalidNumberValue = (matchedName, data) => {
|
82290
|
-
return new Error(
|
82291
|
-
`Invalid value: number type argument '${matchedName}' expects a number as an input, got: ${data}`
|
82292
|
-
);
|
82293
|
-
};
|
82294
|
-
var invalidInteger = (matchedName, data) => {
|
82295
|
-
return new Error(
|
82296
|
-
`Invalid value: number type argument '${matchedName}' expects an integer as an input, got: ${data}`
|
82297
|
-
);
|
82298
|
-
};
|
82299
|
-
var belowMin = (matchedName, data, min) => {
|
82300
|
-
return new Error(
|
82301
|
-
`Invalid value: number type argument '${matchedName}' expects minimal value of ${min} as an input, got: ${data}`
|
82302
|
-
);
|
82303
|
-
};
|
82304
|
-
var aboveMax = (matchedName, data, max) => {
|
82305
|
-
return new Error(
|
82306
|
-
`Invalid value: number type argument '${matchedName}' expects maximal value of ${max} as an input, got: ${data}`
|
82307
|
-
);
|
82308
|
-
};
|
81256
|
+
var executeOrLog = async (target) => typeof target === "string" ? console.log(target) : target ? await target() : void 0;
|
82309
81257
|
var generatePrefix = (name) => name.startsWith("-") ? name : name.length > 1 ? `--${name}` : `-${name}`;
|
82310
81258
|
var validateOptions = (config) => {
|
82311
81259
|
const cloned = (0, import_clone.default)(config);
|
82312
81260
|
const entries = [];
|
82313
|
-
const storedNames =
|
81261
|
+
const storedNames = [];
|
82314
81262
|
const cfgEntries = Object.entries(cloned);
|
82315
81263
|
for (const [key, value] of cfgEntries) {
|
82316
81264
|
const cfg = value._.config;
|
@@ -82320,13 +81268,13 @@ var validateOptions = (config) => {
|
|
82320
81268
|
continue;
|
82321
81269
|
if (cfg.name.includes("=")) {
|
82322
81270
|
throw new BroCliError(
|
82323
|
-
`Can't define option ${cfg.name} - option names and aliases cannot contain '='!`
|
81271
|
+
`Can't define option '${generatePrefix(cfg.name)}' - option names and aliases cannot contain '='!`
|
82324
81272
|
);
|
82325
81273
|
}
|
82326
81274
|
for (const alias of cfg.aliases) {
|
82327
81275
|
if (alias.includes("=")) {
|
82328
81276
|
throw new BroCliError(
|
82329
|
-
`Can't define option ${cfg.name} - option names and aliases cannot contain '='!`
|
81277
|
+
`Can't define option '${generatePrefix(cfg.name)}' - option names and aliases cannot contain '='!`
|
82330
81278
|
);
|
82331
81279
|
}
|
82332
81280
|
}
|
@@ -82344,33 +81292,33 @@ var validateOptions = (config) => {
|
|
82344
81292
|
for (const name of allNames) {
|
82345
81293
|
const match2 = reservedNames.find((n) => n === name);
|
82346
81294
|
if (match2)
|
82347
|
-
throw new BroCliError(`Can't define option ${cfg.name} - name '${match2}' is reserved!`);
|
81295
|
+
throw new BroCliError(`Can't define option '${cfg.name}' - name '${match2}' is reserved!`);
|
82348
81296
|
}
|
82349
|
-
const
|
82350
|
-
for (const storage2 of storageVals) {
|
81297
|
+
for (const storage2 of storedNames) {
|
82351
81298
|
const nameOccupier = storage2.find((e2) => e2 === cfg.name);
|
82352
81299
|
if (!nameOccupier)
|
82353
81300
|
continue;
|
82354
81301
|
throw new BroCliError(
|
82355
|
-
`Can't define option '${cfg.name}'
|
81302
|
+
`Can't define option '${cfg.name}' - name is already in use by option '${storage2[0]}'!`
|
82356
81303
|
);
|
82357
81304
|
}
|
82358
81305
|
for (const alias of cfg.aliases) {
|
82359
|
-
for (const storage2 of
|
81306
|
+
for (const storage2 of storedNames) {
|
82360
81307
|
const nameOccupier = storage2.find((e2) => e2 === alias);
|
82361
81308
|
if (!nameOccupier)
|
82362
81309
|
continue;
|
82363
81310
|
throw new BroCliError(
|
82364
|
-
`Can't define option '${cfg.name}'
|
81311
|
+
`Can't define option '${cfg.name}' - alias '${alias}' is already in use by option '${storage2[0]}'!`
|
82365
81312
|
);
|
82366
81313
|
}
|
82367
81314
|
}
|
82368
|
-
|
82369
|
-
storedNames
|
82370
|
-
|
81315
|
+
const currentNames = [cfg.name, ...cfg.aliases];
|
81316
|
+
storedNames.push(currentNames);
|
81317
|
+
currentNames.forEach((name, idx) => {
|
81318
|
+
if (currentNames.findIndex((e2) => e2 === name) === idx)
|
82371
81319
|
return;
|
82372
81320
|
throw new BroCliError(
|
82373
|
-
`Can't define option '${cfg.name}'
|
81321
|
+
`Can't define option '${cfg.name}' - duplicate alias '${name}'!`
|
82374
81322
|
);
|
82375
81323
|
});
|
82376
81324
|
entries.push([key, { config: cfg, $output: void 0 }]);
|
@@ -82391,14 +81339,17 @@ var command = (command2) => {
|
|
82391
81339
|
`Can't define command '${cmd.name}' - command can't have subcommands and positional args at the same time!`
|
82392
81340
|
);
|
82393
81341
|
}
|
81342
|
+
if (!command2.handler && !command2.subcommands) {
|
81343
|
+
throw new BroCliError(
|
81344
|
+
`Can't define command '${cmd.name}' - command without subcommands must have a handler present!`
|
81345
|
+
);
|
81346
|
+
}
|
82394
81347
|
const processedOptions = command2.options ? validateOptions(command2.options) : void 0;
|
82395
81348
|
cmd.options = processedOptions;
|
82396
81349
|
cmd.name = cmd.name ?? ((_a = cmd.aliases) == null ? void 0 : _a.shift());
|
82397
81350
|
if (!cmd.name)
|
82398
81351
|
throw new BroCliError(`Can't define command without name!`);
|
82399
81352
|
cmd.aliases = ((_b = cmd.aliases) == null ? void 0 : _b.length) ? cmd.aliases : void 0;
|
82400
|
-
if (!cmd.handler)
|
82401
|
-
throw new BroCliError(`Can't define command '${cmd.name}' - command must have a handler!`);
|
82402
81353
|
if (cmd.name.startsWith("-")) {
|
82403
81354
|
throw new BroCliError(`Can't define command '${cmd.name}' - command name can't start with '-'!`);
|
82404
81355
|
}
|
@@ -82428,7 +81379,7 @@ var command = (command2) => {
|
|
82428
81379
|
}
|
82429
81380
|
return cmd;
|
82430
81381
|
};
|
82431
|
-
var getCommandInner = (commands, candidates, args) => {
|
81382
|
+
var getCommandInner = (commands, candidates, args, cliName, cliDescription) => {
|
82432
81383
|
const { data: arg, originalIndex: index4 } = candidates.shift();
|
82433
81384
|
const command2 = commands.find((c) => {
|
82434
81385
|
const names = c.aliases ? [c.name, ...c.aliases] : [c.name];
|
@@ -82449,12 +81400,20 @@ var getCommandInner = (commands, candidates, args) => {
|
|
82449
81400
|
};
|
82450
81401
|
}
|
82451
81402
|
const newCandidates = candidates.map((c) => ({ data: c.data, originalIndex: c.originalIndex - 1 }));
|
82452
|
-
const subcommand = getCommandInner(command2.subcommands, newCandidates, newArgs);
|
82453
|
-
if (!subcommand.command)
|
82454
|
-
throw
|
81403
|
+
const subcommand = getCommandInner(command2.subcommands, newCandidates, newArgs, cliName, cliDescription);
|
81404
|
+
if (!subcommand.command) {
|
81405
|
+
throw new BroCliError(void 0, {
|
81406
|
+
type: "error",
|
81407
|
+
violation: "unknown_subcommand_error",
|
81408
|
+
name: cliName,
|
81409
|
+
description: cliDescription,
|
81410
|
+
command: command2,
|
81411
|
+
offender: candidates[0].data
|
81412
|
+
});
|
81413
|
+
}
|
82455
81414
|
return subcommand;
|
82456
81415
|
};
|
82457
|
-
var getCommand = (commands, args) => {
|
81416
|
+
var getCommand = (commands, args, cliName, cliDescription) => {
|
82458
81417
|
var _a;
|
82459
81418
|
const candidates = [];
|
82460
81419
|
for (let i2 = 0; i2 < args.length; ++i2) {
|
@@ -82488,15 +81447,23 @@ var getCommand = (commands, args) => {
|
|
82488
81447
|
args: removeByIndex(args, firstCandidate.originalIndex)
|
82489
81448
|
};
|
82490
81449
|
}
|
82491
|
-
const { command: command2, args: argsRes } = getCommandInner(commands, candidates, args);
|
82492
|
-
if (!command2)
|
82493
|
-
throw
|
81450
|
+
const { command: command2, args: argsRes } = getCommandInner(commands, candidates, args, cliName, cliDescription);
|
81451
|
+
if (!command2) {
|
81452
|
+
throw new BroCliError(void 0, {
|
81453
|
+
type: "error",
|
81454
|
+
violation: "unknown_command_error",
|
81455
|
+
commands,
|
81456
|
+
name: cliName,
|
81457
|
+
description: cliDescription,
|
81458
|
+
offender: firstCandidate.data
|
81459
|
+
});
|
81460
|
+
}
|
82494
81461
|
return {
|
82495
81462
|
command: command2,
|
82496
81463
|
args: argsRes
|
82497
81464
|
};
|
82498
81465
|
};
|
82499
|
-
var parseArg = (options, positionals, arg, nextArg) => {
|
81466
|
+
var parseArg = (command2, options, positionals, arg, nextArg, cliName, cliDescription) => {
|
82500
81467
|
let data = void 0;
|
82501
81468
|
const argSplit = arg.split("=");
|
82502
81469
|
const hasEq = arg.includes("=");
|
@@ -82517,8 +81484,18 @@ var parseArg = (options, positionals, arg, nextArg) => {
|
|
82517
81484
|
if (!positionals.length)
|
82518
81485
|
return {};
|
82519
81486
|
const pos = positionals.shift();
|
82520
|
-
if (pos[1].enumVals && !pos[1].enumVals.find((val2) => val2 ===
|
82521
|
-
throw
|
81487
|
+
if (pos[1].enumVals && !pos[1].enumVals.find((val2) => val2 === arg)) {
|
81488
|
+
throw new BroCliError(void 0, {
|
81489
|
+
type: "error",
|
81490
|
+
name: cliName,
|
81491
|
+
description: cliDescription,
|
81492
|
+
violation: "enum_violation",
|
81493
|
+
command: command2,
|
81494
|
+
option: pos[1],
|
81495
|
+
offender: {
|
81496
|
+
dataPart: arg
|
81497
|
+
}
|
81498
|
+
});
|
82522
81499
|
}
|
82523
81500
|
data = arg;
|
82524
81501
|
return {
|
@@ -82553,32 +81530,126 @@ var parseArg = (options, positionals, arg, nextArg) => {
|
|
82553
81530
|
skipNext = false;
|
82554
81531
|
return true;
|
82555
81532
|
}
|
82556
|
-
throw
|
81533
|
+
throw new BroCliError(void 0, {
|
81534
|
+
type: "error",
|
81535
|
+
name: cliName,
|
81536
|
+
description: cliDescription,
|
81537
|
+
violation: "invalid_boolean_syntax",
|
81538
|
+
option: opt,
|
81539
|
+
command: command2,
|
81540
|
+
offender: {
|
81541
|
+
namePart,
|
81542
|
+
dataPart
|
81543
|
+
}
|
81544
|
+
});
|
82557
81545
|
} else {
|
82558
81546
|
const match2 = names.find((name) => name === namePart);
|
82559
81547
|
if (!match2)
|
82560
81548
|
return false;
|
82561
81549
|
if (opt.type === "string") {
|
82562
|
-
if (!hasEq && nextArg === void 0)
|
82563
|
-
throw
|
81550
|
+
if (!hasEq && nextArg === void 0) {
|
81551
|
+
throw new BroCliError(void 0, {
|
81552
|
+
type: "error",
|
81553
|
+
name: cliName,
|
81554
|
+
description: cliDescription,
|
81555
|
+
violation: "invalid_string_syntax",
|
81556
|
+
option: opt,
|
81557
|
+
command: command2,
|
81558
|
+
offender: {
|
81559
|
+
namePart,
|
81560
|
+
dataPart
|
81561
|
+
}
|
81562
|
+
});
|
81563
|
+
}
|
82564
81564
|
if (opt.enumVals && !opt.enumVals.find((val2) => val2 === dataPart)) {
|
82565
|
-
throw
|
81565
|
+
throw new BroCliError(void 0, {
|
81566
|
+
type: "error",
|
81567
|
+
name: cliName,
|
81568
|
+
description: cliDescription,
|
81569
|
+
violation: "enum_violation",
|
81570
|
+
option: opt,
|
81571
|
+
command: command2,
|
81572
|
+
offender: {
|
81573
|
+
namePart,
|
81574
|
+
dataPart
|
81575
|
+
}
|
81576
|
+
});
|
82566
81577
|
}
|
82567
81578
|
data = dataPart;
|
82568
81579
|
return true;
|
82569
81580
|
}
|
82570
|
-
if (!hasEq && nextArg === void 0)
|
82571
|
-
throw
|
81581
|
+
if (!hasEq && nextArg === void 0) {
|
81582
|
+
throw new BroCliError(void 0, {
|
81583
|
+
type: "error",
|
81584
|
+
name: cliName,
|
81585
|
+
description: cliDescription,
|
81586
|
+
violation: "invalid_number_syntax",
|
81587
|
+
option: opt,
|
81588
|
+
command: command2,
|
81589
|
+
offender: {
|
81590
|
+
namePart,
|
81591
|
+
dataPart
|
81592
|
+
}
|
81593
|
+
});
|
81594
|
+
}
|
82572
81595
|
const numData = Number(dataPart);
|
82573
|
-
if (isNaN(numData))
|
82574
|
-
throw
|
82575
|
-
|
82576
|
-
|
82577
|
-
|
82578
|
-
|
82579
|
-
|
82580
|
-
|
82581
|
-
|
81596
|
+
if (isNaN(numData)) {
|
81597
|
+
throw new BroCliError(void 0, {
|
81598
|
+
type: "error",
|
81599
|
+
name: cliName,
|
81600
|
+
description: cliDescription,
|
81601
|
+
violation: "invalid_number_value",
|
81602
|
+
option: opt,
|
81603
|
+
command: command2,
|
81604
|
+
offender: {
|
81605
|
+
namePart,
|
81606
|
+
dataPart
|
81607
|
+
}
|
81608
|
+
});
|
81609
|
+
}
|
81610
|
+
if (opt.isInt && !isInt(numData)) {
|
81611
|
+
throw new BroCliError(void 0, {
|
81612
|
+
type: "error",
|
81613
|
+
name: cliName,
|
81614
|
+
description: cliDescription,
|
81615
|
+
violation: "expected_int",
|
81616
|
+
option: opt,
|
81617
|
+
command: command2,
|
81618
|
+
offender: {
|
81619
|
+
namePart,
|
81620
|
+
dataPart
|
81621
|
+
}
|
81622
|
+
});
|
81623
|
+
}
|
81624
|
+
if (opt.minVal !== void 0 && numData < opt.minVal) {
|
81625
|
+
throw new BroCliError(void 0, {
|
81626
|
+
type: "error",
|
81627
|
+
name: cliName,
|
81628
|
+
description: cliDescription,
|
81629
|
+
violation: "below_min",
|
81630
|
+
option: opt,
|
81631
|
+
command: command2,
|
81632
|
+
offender: {
|
81633
|
+
namePart,
|
81634
|
+
dataPart
|
81635
|
+
}
|
81636
|
+
});
|
81637
|
+
}
|
81638
|
+
if (opt.maxVal !== void 0 && numData > opt.maxVal) {
|
81639
|
+
throw new BroCliError(void 0, {
|
81640
|
+
type: "error",
|
81641
|
+
name: cliName,
|
81642
|
+
description: cliDescription,
|
81643
|
+
violation: "above_max",
|
81644
|
+
option: opt,
|
81645
|
+
command: command2,
|
81646
|
+
offender: {
|
81647
|
+
namePart,
|
81648
|
+
dataPart
|
81649
|
+
}
|
81650
|
+
});
|
81651
|
+
}
|
81652
|
+
data = numData;
|
82582
81653
|
return true;
|
82583
81654
|
}
|
82584
81655
|
});
|
@@ -82589,7 +81660,7 @@ var parseArg = (options, positionals, arg, nextArg) => {
|
|
82589
81660
|
option: option == null ? void 0 : option[1]
|
82590
81661
|
};
|
82591
81662
|
};
|
82592
|
-
var parseOptions = (command2, args, omitKeysOfUndefinedOptions) => {
|
81663
|
+
var parseOptions = (command2, args, cliName, cliDescription, omitKeysOfUndefinedOptions) => {
|
82593
81664
|
const options = command2.options;
|
82594
81665
|
const optEntries = Object.entries(options ?? {}).map(
|
82595
81666
|
(opt) => [opt[0], opt[1].config]
|
@@ -82609,16 +81680,16 @@ var parseOptions = (command2, args, omitKeysOfUndefinedOptions) => {
|
|
82609
81680
|
skipNext,
|
82610
81681
|
isHelp,
|
82611
81682
|
isVersion
|
82612
|
-
} = parseArg(nonPositionalEntries, positionalEntries, arg, nextArg);
|
81683
|
+
} = parseArg(command2, nonPositionalEntries, positionalEntries, arg, nextArg, cliName, cliDescription);
|
82613
81684
|
if (!option)
|
82614
81685
|
unrecognizedArgsArr.push(arg.split("=")[0]);
|
82615
81686
|
if (skipNext)
|
82616
81687
|
++i2;
|
82617
|
-
result[name] = data;
|
82618
81688
|
if (isHelp)
|
82619
81689
|
return "help";
|
82620
81690
|
if (isVersion)
|
82621
81691
|
return "version";
|
81692
|
+
result[name] = data;
|
82622
81693
|
}
|
82623
81694
|
for (const [optKey, option] of optEntries) {
|
82624
81695
|
const data = result[optKey] ?? option.default;
|
@@ -82631,19 +81702,29 @@ var parseOptions = (command2, args, omitKeysOfUndefinedOptions) => {
|
|
82631
81702
|
if (option.isRequired && result[optKey] === void 0)
|
82632
81703
|
missingRequiredArr.push([option.name, ...option.aliases]);
|
82633
81704
|
}
|
82634
|
-
if (missingRequiredArr.length)
|
82635
|
-
throw
|
82636
|
-
|
82637
|
-
|
82638
|
-
|
82639
|
-
|
82640
|
-
|
82641
|
-
|
82642
|
-
|
82643
|
-
|
82644
|
-
|
81705
|
+
if (missingRequiredArr.length) {
|
81706
|
+
throw new BroCliError(void 0, {
|
81707
|
+
type: "error",
|
81708
|
+
violation: "missing_args_error",
|
81709
|
+
name: cliName,
|
81710
|
+
description: cliDescription,
|
81711
|
+
command: command2,
|
81712
|
+
missing: missingRequiredArr
|
81713
|
+
});
|
81714
|
+
}
|
81715
|
+
if (unrecognizedArgsArr.length) {
|
81716
|
+
throw new BroCliError(void 0, {
|
81717
|
+
type: "error",
|
81718
|
+
violation: "unrecognized_args_error",
|
81719
|
+
name: cliName,
|
81720
|
+
description: cliDescription,
|
81721
|
+
command: command2,
|
81722
|
+
unrecognized: unrecognizedArgsArr
|
81723
|
+
});
|
81724
|
+
}
|
81725
|
+
return Object.keys(result).length ? result : void 0;
|
82645
81726
|
};
|
82646
|
-
var
|
81727
|
+
var getCommandNameWithParents = (command2) => command2.parent ? `${getCommandNameWithParents(command2.parent)} ${command2.name}` : command2.name;
|
82647
81728
|
var validateCommands = (commands, parent) => {
|
82648
81729
|
const storedNames = {};
|
82649
81730
|
for (const cmd of commands) {
|
@@ -82652,8 +81733,8 @@ var validateCommands = (commands, parent) => {
|
|
82652
81733
|
const nameOccupier = storage2.find((e2) => e2 === cmd.name);
|
82653
81734
|
if (!nameOccupier)
|
82654
81735
|
continue;
|
82655
|
-
throw new
|
82656
|
-
`Can't define command '${
|
81736
|
+
throw new BroCliError(
|
81737
|
+
`Can't define command '${getCommandNameWithParents(cmd)}': name is already in use by command '${parent ? `${getCommandNameWithParents(parent)} ` : ""}${storage2[0]}'!`
|
82657
81738
|
);
|
82658
81739
|
}
|
82659
81740
|
if (cmd.aliases) {
|
@@ -82662,8 +81743,8 @@ var validateCommands = (commands, parent) => {
|
|
82662
81743
|
const nameOccupier = storage2.find((e2) => e2 === alias);
|
82663
81744
|
if (!nameOccupier)
|
82664
81745
|
continue;
|
82665
|
-
throw new
|
82666
|
-
`Can't define command '${
|
81746
|
+
throw new BroCliError(
|
81747
|
+
`Can't define command '${getCommandNameWithParents(cmd)}': alias '${alias}' is already in use by command '${parent ? `${getCommandNameWithParents(parent)} ` : ""}${storage2[0]}'!`
|
82667
81748
|
);
|
82668
81749
|
}
|
82669
81750
|
}
|
@@ -82675,53 +81756,135 @@ var validateCommands = (commands, parent) => {
|
|
82675
81756
|
return commands;
|
82676
81757
|
};
|
82677
81758
|
var removeByIndex = (arr, idx) => [...arr.slice(0, idx), ...arr.slice(idx + 1, arr.length)];
|
82678
|
-
var
|
82679
|
-
var rawCli = async (commands, config) => {
|
81759
|
+
var run = async (commands, config) => {
|
82680
81760
|
var _a, _b;
|
82681
|
-
const
|
81761
|
+
const eventHandler = (config == null ? void 0 : config.theme) ? eventHandlerWrapper(config.theme) : defaultEventHandler;
|
82682
81762
|
const argSource = (config == null ? void 0 : config.argSource) ?? process.argv;
|
82683
81763
|
const version3 = config == null ? void 0 : config.version;
|
82684
|
-
const
|
81764
|
+
const help = config == null ? void 0 : config.help;
|
82685
81765
|
const omitKeysOfUndefinedOptions = (config == null ? void 0 : config.omitKeysOfUndefinedOptions) ?? false;
|
82686
|
-
|
82687
|
-
|
82688
|
-
return await helpHandler(processedCmds);
|
82689
|
-
const helpIndex = args.findIndex((arg) => arg === "--help" || arg === "-h");
|
82690
|
-
if (helpIndex !== -1 && (helpIndex > 0 ? ((_a = args[helpIndex - 1]) == null ? void 0 : _a.startsWith("-")) && !args[helpIndex - 1].includes("=") ? false : true : true)) {
|
82691
|
-
const command3 = getCommand(processedCmds, args).command;
|
82692
|
-
return help(command3, processedCmds, helpHandler);
|
82693
|
-
}
|
82694
|
-
const versionIndex = args.findIndex((arg) => arg === "--version" || arg === "-v");
|
82695
|
-
if (versionIndex !== -1 && (versionIndex > 0 ? ((_b = args[versionIndex - 1]) == null ? void 0 : _b.startsWith("-")) ? false : true : true)) {
|
82696
|
-
return await executeOrLog(version3);
|
82697
|
-
}
|
82698
|
-
const { command: command2, args: newArgs } = getCommand(processedCmds, args);
|
82699
|
-
if (!command2)
|
82700
|
-
return helpHandler(processedCmds);
|
82701
|
-
if (command2 === "help") {
|
82702
|
-
const { command: helpCommand } = getCommand(processedCmds, newArgs);
|
82703
|
-
return help(helpCommand, processedCmds, helpHandler);
|
82704
|
-
}
|
82705
|
-
const optionResult = parseOptions(command2, newArgs, omitKeysOfUndefinedOptions);
|
82706
|
-
if (optionResult === "help")
|
82707
|
-
return await help(command2, commands, helpHandler);
|
82708
|
-
if (optionResult === "version")
|
82709
|
-
return await executeOrLog(version3);
|
82710
|
-
if (optionResult) {
|
82711
|
-
if (config == null ? void 0 : config.hook)
|
82712
|
-
await config.hook("pre", command2);
|
82713
|
-
await command2.handler(command2.transform ? await command2.transform(optionResult) : optionResult);
|
82714
|
-
if (config == null ? void 0 : config.hook)
|
82715
|
-
await config.hook("post", command2);
|
82716
|
-
}
|
82717
|
-
return void 0;
|
82718
|
-
};
|
82719
|
-
var run = async (commands, config) => {
|
81766
|
+
const cliName = config == null ? void 0 : config.name;
|
81767
|
+
const cliDescription = config == null ? void 0 : config.description;
|
82720
81768
|
try {
|
82721
|
-
|
81769
|
+
const processedCmds = validateCommands(commands);
|
81770
|
+
let args = argSource.slice(2, argSource.length);
|
81771
|
+
if (!args.length) {
|
81772
|
+
return help !== void 0 ? await executeOrLog(help) : await eventHandler({
|
81773
|
+
type: "global_help",
|
81774
|
+
description: cliDescription,
|
81775
|
+
name: cliName,
|
81776
|
+
commands: processedCmds
|
81777
|
+
});
|
81778
|
+
}
|
81779
|
+
const helpIndex = args.findIndex((arg) => arg === "--help" || arg === "-h");
|
81780
|
+
if (helpIndex !== -1 && (helpIndex > 0 ? ((_a = args[helpIndex - 1]) == null ? void 0 : _a.startsWith("-")) && !args[helpIndex - 1].includes("=") ? false : true : true)) {
|
81781
|
+
const command3 = getCommand(processedCmds, args, cliName, cliDescription).command;
|
81782
|
+
if (typeof command3 === "object") {
|
81783
|
+
return command3.help !== void 0 ? await executeOrLog(command3.help) : await eventHandler({
|
81784
|
+
type: "command_help",
|
81785
|
+
description: cliDescription,
|
81786
|
+
name: cliName,
|
81787
|
+
command: command3
|
81788
|
+
});
|
81789
|
+
} else {
|
81790
|
+
return help !== void 0 ? await executeOrLog(help) : await eventHandler({
|
81791
|
+
type: "global_help",
|
81792
|
+
description: cliDescription,
|
81793
|
+
name: cliName,
|
81794
|
+
commands: processedCmds
|
81795
|
+
});
|
81796
|
+
}
|
81797
|
+
}
|
81798
|
+
const versionIndex = args.findIndex((arg) => arg === "--version" || arg === "-v");
|
81799
|
+
if (versionIndex !== -1 && (versionIndex > 0 ? ((_b = args[versionIndex - 1]) == null ? void 0 : _b.startsWith("-")) ? false : true : true)) {
|
81800
|
+
return version3 !== void 0 ? await executeOrLog(version3) : await eventHandler({
|
81801
|
+
type: "version",
|
81802
|
+
name: cliName,
|
81803
|
+
description: cliDescription
|
81804
|
+
});
|
81805
|
+
}
|
81806
|
+
const { command: command2, args: newArgs } = getCommand(processedCmds, args, cliName, cliDescription);
|
81807
|
+
if (!command2) {
|
81808
|
+
return help !== void 0 ? await executeOrLog(help) : await eventHandler({
|
81809
|
+
type: "global_help",
|
81810
|
+
description: cliDescription,
|
81811
|
+
name: cliName,
|
81812
|
+
commands: processedCmds
|
81813
|
+
});
|
81814
|
+
}
|
81815
|
+
if (command2 === "help") {
|
81816
|
+
let helpCommand;
|
81817
|
+
let newestArgs = newArgs;
|
81818
|
+
do {
|
81819
|
+
const res = getCommand(processedCmds, newestArgs, cliName, cliDescription);
|
81820
|
+
helpCommand = res.command;
|
81821
|
+
newestArgs = res.args;
|
81822
|
+
} while (helpCommand === "help");
|
81823
|
+
return helpCommand ? helpCommand.help !== void 0 ? await executeOrLog(helpCommand.help) : await eventHandler({
|
81824
|
+
type: "command_help",
|
81825
|
+
description: cliDescription,
|
81826
|
+
name: cliName,
|
81827
|
+
command: helpCommand
|
81828
|
+
}) : help !== void 0 ? await executeOrLog(help) : await eventHandler({
|
81829
|
+
type: "global_help",
|
81830
|
+
description: cliDescription,
|
81831
|
+
name: cliName,
|
81832
|
+
commands: processedCmds
|
81833
|
+
});
|
81834
|
+
}
|
81835
|
+
const optionResult = parseOptions(command2, newArgs, cliName, cliDescription, omitKeysOfUndefinedOptions);
|
81836
|
+
if (optionResult === "help") {
|
81837
|
+
return command2.help !== void 0 ? await executeOrLog(command2.help) : await eventHandler({
|
81838
|
+
type: "command_help",
|
81839
|
+
description: cliDescription,
|
81840
|
+
name: cliName,
|
81841
|
+
command: command2
|
81842
|
+
});
|
81843
|
+
}
|
81844
|
+
if (optionResult === "version") {
|
81845
|
+
return version3 !== void 0 ? await executeOrLog(version3) : await eventHandler({
|
81846
|
+
type: "version",
|
81847
|
+
name: cliName,
|
81848
|
+
description: cliDescription
|
81849
|
+
});
|
81850
|
+
}
|
81851
|
+
if (command2.handler) {
|
81852
|
+
if (config == null ? void 0 : config.hook)
|
81853
|
+
await config.hook("before", command2);
|
81854
|
+
await command2.handler(command2.transform ? await command2.transform(optionResult) : optionResult);
|
81855
|
+
if (config == null ? void 0 : config.hook)
|
81856
|
+
await config.hook("after", command2);
|
81857
|
+
return;
|
81858
|
+
} else {
|
81859
|
+
return command2.help !== void 0 ? await executeOrLog(command2.help) : await eventHandler({
|
81860
|
+
type: "command_help",
|
81861
|
+
description: cliDescription,
|
81862
|
+
name: cliName,
|
81863
|
+
command: command2
|
81864
|
+
});
|
81865
|
+
}
|
82722
81866
|
} catch (e2) {
|
82723
|
-
|
82724
|
-
|
81867
|
+
if (e2 instanceof BroCliError) {
|
81868
|
+
if (e2.event)
|
81869
|
+
await eventHandler(e2.event);
|
81870
|
+
else {
|
81871
|
+
if (!(config == null ? void 0 : config.noExit))
|
81872
|
+
console.error(e2.message);
|
81873
|
+
else
|
81874
|
+
return e2.message;
|
81875
|
+
}
|
81876
|
+
} else {
|
81877
|
+
await eventHandler({
|
81878
|
+
type: "error",
|
81879
|
+
violation: "unknown_error",
|
81880
|
+
name: cliName,
|
81881
|
+
description: cliDescription,
|
81882
|
+
error: e2
|
81883
|
+
});
|
81884
|
+
}
|
81885
|
+
if (!(config == null ? void 0 : config.noExit))
|
81886
|
+
process.exit(1);
|
81887
|
+
return;
|
82725
81888
|
}
|
82726
81889
|
};
|
82727
81890
|
var OptionBuilderBase = class _OptionBuilderBase {
|
@@ -82799,7 +81962,7 @@ var OptionBuilderBase = class _OptionBuilderBase {
|
|
82799
81962
|
max(value) {
|
82800
81963
|
const config = this.config();
|
82801
81964
|
const minVal = config.minVal;
|
82802
|
-
if (minVal !== void 0 && minVal
|
81965
|
+
if (minVal !== void 0 && minVal > value) {
|
82803
81966
|
throw new BroCliError("Unable to define option's max value to be lower than min value!");
|
82804
81967
|
}
|
82805
81968
|
return new _OptionBuilderBase({ ...config, maxVal: value });
|
@@ -84330,7 +83493,7 @@ var push = command({
|
|
84330
83493
|
schemasFilter,
|
84331
83494
|
force
|
84332
83495
|
);
|
84333
|
-
} else if (dialect7 === "sqlite"
|
83496
|
+
} else if (dialect7 === "sqlite") {
|
84334
83497
|
const { sqlitePush: sqlitePush2 } = await Promise.resolve().then(() => (init_push(), push_exports));
|
84335
83498
|
await sqlitePush2(
|
84336
83499
|
schemaPath,
|
@@ -84340,16 +83503,6 @@ var push = command({
|
|
84340
83503
|
tablesFilter,
|
84341
83504
|
force
|
84342
83505
|
);
|
84343
|
-
} else if (dialect7 === "sqlite" && ("driver" in credentials2 && credentials2.driver === "turso")) {
|
84344
|
-
const { libSQLPush: libSQLPush2 } = await Promise.resolve().then(() => (init_push(), push_exports));
|
84345
|
-
await libSQLPush2(
|
84346
|
-
schemaPath,
|
84347
|
-
verbose,
|
84348
|
-
strict,
|
84349
|
-
credentials2,
|
84350
|
-
tablesFilter,
|
84351
|
-
force
|
84352
|
-
);
|
84353
83506
|
} else {
|
84354
83507
|
assertUnreachable(dialect7);
|
84355
83508
|
}
|
@@ -84633,7 +83786,7 @@ init_utils2();
|
|
84633
83786
|
var version2 = async () => {
|
84634
83787
|
const { npmVersion } = await ormCoreVersions();
|
84635
83788
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
84636
|
-
const envVersion = "0.24.0-
|
83789
|
+
const envVersion = "0.24.0-6386ea9";
|
84637
83790
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
84638
83791
|
const versions = `drizzle-kit: ${kitVersion}
|
84639
83792
|
${ormVersion}`;
|
@@ -84668,6 +83821,7 @@ var legacy = [
|
|
84668
83821
|
legacyCommand("check:sqlite", "check")
|
84669
83822
|
];
|
84670
83823
|
run([generate, migrate, pull, push, studio, up, check, drop, ...legacy], {
|
83824
|
+
name: "drizzle-kit",
|
84671
83825
|
version: version2
|
84672
83826
|
});
|
84673
83827
|
/*! Bundled license information:
|