drizzle-kit 0.20.7-72b0933 → 0.20.7-80f4d39
Sign up to get free protection for your applications and to get access to all the features.
- package/bin.cjs +146 -73
- package/cli/commands/migrate.d.ts +10 -1
- package/cli/commands/utils.d.ts +9 -0
- package/cli/validations/mysql.d.ts +6 -6
- package/cli/validations/pg.d.ts +12 -12
- package/index.d.mts +2 -0
- package/index.d.ts +2 -0
- package/package.json +1 -1
- package/utils.js +97 -49
package/bin.cjs
CHANGED
@@ -11261,7 +11261,7 @@ var require_node2 = __commonJS({
|
|
11261
11261
|
});
|
11262
11262
|
|
11263
11263
|
// src/cli/commands/utils.ts
|
11264
|
-
var import_path, import_fs, import_hanji2, assertES5, safeRegister, prepareGenerateConfig, assertOutFolder, configCommonSchema, introspectCasing, configIntrospectSchema, configIntrospectCliSchema, configGenerateSchema, configPushSchema, mysqlConnectionSchema, mySqlCliConfigSchema, mySqlIntrospectConfigSchema, drizzleConfigFromFile, readDrizzleConfig;
|
11264
|
+
var import_path, import_fs, import_hanji2, assertES5, safeRegister, prepareGenerateConfig, assertOutFolder, driver, configCommonSchema, introspectCasing, configIntrospectSchema, configIntrospectCliSchema, configGenerateSchema, configPushSchema, mysqlConnectionSchema, mySqlCliConfigSchema, mySqlIntrospectConfigSchema, drizzleConfigFromFile, readDrizzleConfig;
|
11265
11265
|
var init_utils = __esm({
|
11266
11266
|
"src/cli/commands/utils.ts"() {
|
11267
11267
|
init_serializer();
|
@@ -11324,7 +11324,8 @@ var init_utils = __esm({
|
|
11324
11324
|
custom,
|
11325
11325
|
breakpoints: drizzleConfig.breakpoints ?? false,
|
11326
11326
|
schema: drizzleConfig.schema,
|
11327
|
-
out: drizzleConfig.out
|
11327
|
+
out: drizzleConfig.out,
|
11328
|
+
bundle: drizzleConfig.driver === "expo"
|
11328
11329
|
};
|
11329
11330
|
}
|
11330
11331
|
if (!schema4) {
|
@@ -11340,7 +11341,7 @@ var init_utils = __esm({
|
|
11340
11341
|
console.error(`'out' param must be set`);
|
11341
11342
|
process.exit(1);
|
11342
11343
|
}
|
11343
|
-
return { schema: schema4, out, breakpoints, custom };
|
11344
|
+
return { schema: schema4, out, breakpoints, custom, bundle: false };
|
11344
11345
|
};
|
11345
11346
|
assertOutFolder = async (it) => {
|
11346
11347
|
if ("out" in it)
|
@@ -11356,10 +11357,20 @@ var init_utils = __esm({
|
|
11356
11357
|
}
|
11357
11358
|
return cliConfig.out;
|
11358
11359
|
};
|
11360
|
+
driver = unionType([
|
11361
|
+
literalType("better-sqlite"),
|
11362
|
+
literalType("turso"),
|
11363
|
+
literalType("libsql"),
|
11364
|
+
literalType("d1"),
|
11365
|
+
literalType("expo"),
|
11366
|
+
literalType("pg"),
|
11367
|
+
literalType("mysql2")
|
11368
|
+
]);
|
11359
11369
|
configCommonSchema = objectType({
|
11360
11370
|
schema: unionType([stringType(), stringType().array()]),
|
11361
11371
|
out: stringType().optional(),
|
11362
11372
|
breakpoints: booleanType().default(true),
|
11373
|
+
driver: driver.optional(),
|
11363
11374
|
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
11364
11375
|
schemaFilter: unionType([stringType(), stringType().array()]).default(["public"])
|
11365
11376
|
});
|
@@ -11566,9 +11577,9 @@ var init_outputs = __esm({
|
|
11566
11577
|
driver: () => withStyle.error(
|
11567
11578
|
`Either "turso", "libsql", "better-sqlite" are available options for "--driver"`
|
11568
11579
|
),
|
11569
|
-
url: (
|
11570
|
-
authToken: (
|
11571
|
-
`"authToken" is a required option for driver "${
|
11580
|
+
url: (driver2) => withStyle.error(`"url" is a required option for driver "${driver2}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`),
|
11581
|
+
authToken: (driver2) => withStyle.error(
|
11582
|
+
`"authToken" is a required option for driver "${driver2}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`
|
11572
11583
|
)
|
11573
11584
|
},
|
11574
11585
|
introspect: {},
|
@@ -12180,6 +12191,7 @@ var init_pgSerializer = __esm({
|
|
12180
12191
|
};
|
12181
12192
|
generatePgSnapshot = (tables, enums, schemas, schemaFilter) => {
|
12182
12193
|
const result = {};
|
12194
|
+
const indexesInSchema = {};
|
12183
12195
|
for (const table4 of tables) {
|
12184
12196
|
const {
|
12185
12197
|
name: tableName,
|
@@ -12331,6 +12343,24 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12331
12343
|
return it.name;
|
12332
12344
|
}
|
12333
12345
|
});
|
12346
|
+
if (typeof indexesInSchema[schema4 ?? "public"] !== "undefined") {
|
12347
|
+
if (indexesInSchema[schema4 ?? "public"].includes(name)) {
|
12348
|
+
console.log(
|
12349
|
+
`
|
12350
|
+
${withStyle.errorWarning(
|
12351
|
+
`We've found duplicated index name across ${source_default.underline.blue(
|
12352
|
+
schema4 ?? "public"
|
12353
|
+
)} schema. Please rename your index in either the ${source_default.underline.blue(
|
12354
|
+
tableName
|
12355
|
+
)} table or the table with the duplicated index name`
|
12356
|
+
)}`
|
12357
|
+
);
|
12358
|
+
process.exit(1);
|
12359
|
+
}
|
12360
|
+
indexesInSchema[schema4 ?? "public"].push(name);
|
12361
|
+
} else {
|
12362
|
+
indexesInSchema[schema4 ?? "public"] = [name];
|
12363
|
+
}
|
12334
12364
|
indexesObject[name] = {
|
12335
12365
|
name,
|
12336
12366
|
columns: indexColumns,
|
@@ -14895,7 +14925,7 @@ __export(migrate_exports, {
|
|
14895
14925
|
prepareSnapshotFolderName: () => prepareSnapshotFolderName,
|
14896
14926
|
writeResult: () => writeResult
|
14897
14927
|
});
|
14898
|
-
var import_fs4, import_path3, import_hanji3, prepareAndMigratePg, prepareMySQLPush, prepareSQLitePush, preparePgPush, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, BREAKPOINT, writeResult, prepareSnapshotFolderName, two;
|
14928
|
+
var import_fs4, import_path3, import_hanji3, prepareAndMigratePg, prepareMySQLPush, prepareSQLitePush, preparePgPush, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
|
14899
14929
|
var init_migrate = __esm({
|
14900
14930
|
"src/cli/commands/migrate.ts"() {
|
14901
14931
|
import_fs4 = __toESM(require("fs"));
|
@@ -14924,19 +14954,14 @@ var init_migrate = __esm({
|
|
14924
14954
|
const validatedPrev = pgSchema.parse(prev);
|
14925
14955
|
const validatedCur = pgSchema.parse(cur);
|
14926
14956
|
if (config.custom) {
|
14927
|
-
writeResult(
|
14928
|
-
custom,
|
14929
|
-
[],
|
14957
|
+
writeResult({
|
14958
|
+
cur: custom,
|
14959
|
+
sqlStatements: [],
|
14930
14960
|
journal,
|
14931
|
-
{
|
14932
|
-
columns: {},
|
14933
|
-
schemas: {},
|
14934
|
-
tables: {}
|
14935
|
-
},
|
14936
14961
|
outFolder,
|
14937
|
-
config.breakpoints,
|
14938
|
-
"custom"
|
14939
|
-
);
|
14962
|
+
breakpoints: config.breakpoints,
|
14963
|
+
type: "custom"
|
14964
|
+
});
|
14940
14965
|
return;
|
14941
14966
|
}
|
14942
14967
|
const squashedPrev = squashPgScheme(validatedPrev);
|
@@ -14948,14 +14973,13 @@ var init_migrate = __esm({
|
|
14948
14973
|
validatedPrev,
|
14949
14974
|
validatedCur
|
14950
14975
|
);
|
14951
|
-
writeResult(
|
14976
|
+
writeResult({
|
14952
14977
|
cur,
|
14953
14978
|
sqlStatements,
|
14954
14979
|
journal,
|
14955
|
-
_meta,
|
14956
14980
|
outFolder,
|
14957
|
-
config.breakpoints
|
14958
|
-
);
|
14981
|
+
breakpoints: config.breakpoints
|
14982
|
+
});
|
14959
14983
|
} catch (e) {
|
14960
14984
|
console.error(e);
|
14961
14985
|
}
|
@@ -15049,19 +15073,14 @@ var init_migrate = __esm({
|
|
15049
15073
|
const validatedPrev = mysqlSchema.parse(prev);
|
15050
15074
|
const validatedCur = mysqlSchema.parse(cur);
|
15051
15075
|
if (config.custom) {
|
15052
|
-
writeResult(
|
15053
|
-
custom,
|
15054
|
-
[],
|
15076
|
+
writeResult({
|
15077
|
+
cur: custom,
|
15078
|
+
sqlStatements: [],
|
15055
15079
|
journal,
|
15056
|
-
{
|
15057
|
-
columns: {},
|
15058
|
-
schemas: {},
|
15059
|
-
tables: {}
|
15060
|
-
},
|
15061
15080
|
outFolder,
|
15062
|
-
config.breakpoints,
|
15063
|
-
"custom"
|
15064
|
-
);
|
15081
|
+
breakpoints: config.breakpoints,
|
15082
|
+
type: "custom"
|
15083
|
+
});
|
15065
15084
|
return;
|
15066
15085
|
}
|
15067
15086
|
const squashedPrev = squashMysqlScheme(validatedPrev);
|
@@ -15073,14 +15092,14 @@ var init_migrate = __esm({
|
|
15073
15092
|
validatedPrev,
|
15074
15093
|
validatedCur
|
15075
15094
|
);
|
15076
|
-
writeResult(
|
15095
|
+
writeResult({
|
15077
15096
|
cur,
|
15078
15097
|
sqlStatements,
|
15079
15098
|
journal,
|
15080
15099
|
_meta,
|
15081
15100
|
outFolder,
|
15082
|
-
config.breakpoints
|
15083
|
-
);
|
15101
|
+
breakpoints: config.breakpoints
|
15102
|
+
});
|
15084
15103
|
} catch (e) {
|
15085
15104
|
console.error(e);
|
15086
15105
|
}
|
@@ -15098,19 +15117,15 @@ var init_migrate = __esm({
|
|
15098
15117
|
const validatedPrev = sqliteSchema.parse(prev);
|
15099
15118
|
const validatedCur = sqliteSchema.parse(cur);
|
15100
15119
|
if (config.custom) {
|
15101
|
-
writeResult(
|
15102
|
-
custom,
|
15103
|
-
[],
|
15120
|
+
writeResult({
|
15121
|
+
cur: custom,
|
15122
|
+
sqlStatements: [],
|
15104
15123
|
journal,
|
15105
|
-
{
|
15106
|
-
columns: {},
|
15107
|
-
schemas: {},
|
15108
|
-
tables: {}
|
15109
|
-
},
|
15110
15124
|
outFolder,
|
15111
|
-
config.breakpoints,
|
15112
|
-
|
15113
|
-
|
15125
|
+
breakpoints: config.breakpoints,
|
15126
|
+
bundle: config.bundle,
|
15127
|
+
type: "custom"
|
15128
|
+
});
|
15114
15129
|
return;
|
15115
15130
|
}
|
15116
15131
|
const squashedPrev = squashSqliteScheme(validatedPrev);
|
@@ -15120,14 +15135,15 @@ var init_migrate = __esm({
|
|
15120
15135
|
squashedCur,
|
15121
15136
|
"sqlite"
|
15122
15137
|
);
|
15123
|
-
writeResult(
|
15138
|
+
writeResult({
|
15124
15139
|
cur,
|
15125
15140
|
sqlStatements,
|
15126
15141
|
journal,
|
15127
15142
|
_meta,
|
15128
15143
|
outFolder,
|
15129
|
-
config.breakpoints
|
15130
|
-
|
15144
|
+
breakpoints: config.breakpoints,
|
15145
|
+
bundle: config.bundle
|
15146
|
+
});
|
15131
15147
|
} catch (e) {
|
15132
15148
|
console.error(e);
|
15133
15149
|
}
|
@@ -15315,7 +15331,20 @@ var init_migrate = __esm({
|
|
15315
15331
|
return result;
|
15316
15332
|
};
|
15317
15333
|
BREAKPOINT = "--> statement-breakpoint\n";
|
15318
|
-
writeResult = (
|
15334
|
+
writeResult = ({
|
15335
|
+
cur,
|
15336
|
+
sqlStatements,
|
15337
|
+
journal,
|
15338
|
+
_meta = {
|
15339
|
+
columns: {},
|
15340
|
+
schemas: {},
|
15341
|
+
tables: {}
|
15342
|
+
},
|
15343
|
+
outFolder,
|
15344
|
+
breakpoints,
|
15345
|
+
bundle = false,
|
15346
|
+
type = "none"
|
15347
|
+
}) => {
|
15319
15348
|
if (type === "none") {
|
15320
15349
|
console.log(schema(cur));
|
15321
15350
|
if (sqlStatements.length === 0) {
|
@@ -15356,6 +15385,10 @@ ${sql2}
|
|
15356
15385
|
});
|
15357
15386
|
import_fs4.default.writeFileSync(metaJournal, JSON.stringify(journal, null, 2));
|
15358
15387
|
import_fs4.default.writeFileSync(`${outFolder}/${tag}.sql`, sql2);
|
15388
|
+
if (bundle) {
|
15389
|
+
const js = embeddedMigrations(journal);
|
15390
|
+
import_fs4.default.writeFileSync(`${outFolder}/migrations.js`, js);
|
15391
|
+
}
|
15359
15392
|
(0, import_hanji3.render)(
|
15360
15393
|
`[${source_default.green(
|
15361
15394
|
"\u2713"
|
@@ -15364,6 +15397,22 @@ ${sql2}
|
|
15364
15397
|
)} \u{1F680}`
|
15365
15398
|
);
|
15366
15399
|
};
|
15400
|
+
embeddedMigrations = (journal) => {
|
15401
|
+
let content = "import journal from './meta/_journal.json';\n";
|
15402
|
+
journal.entries.forEach((entry) => {
|
15403
|
+
content += `import m${entry.idx.toString().padStart(4, "0")} from './${entry.tag}.sql';
|
15404
|
+
`;
|
15405
|
+
});
|
15406
|
+
content += `
|
15407
|
+
export default {
|
15408
|
+
journal,
|
15409
|
+
migrations: {
|
15410
|
+
${journal.entries.map((it) => `m${it.idx.toString().padStart(4, "0")}`).join(",\n")}
|
15411
|
+
}
|
15412
|
+
}
|
15413
|
+
`;
|
15414
|
+
return content;
|
15415
|
+
};
|
15367
15416
|
prepareSnapshotFolderName = () => {
|
15368
15417
|
const now = /* @__PURE__ */ new Date();
|
15369
15418
|
return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
|
@@ -15458,7 +15507,7 @@ var init_sqlgenerator = __esm({
|
|
15458
15507
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
15459
15508
|
statement += ",\n";
|
15460
15509
|
const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
|
15461
|
-
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
15510
|
+
statement += ` CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
15462
15511
|
}
|
15463
15512
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
15464
15513
|
for (const uniqueConstraint4 of uniqueConstraints) {
|
@@ -17850,13 +17899,14 @@ var init_snapshotsDiffer = __esm({
|
|
17850
17899
|
jsonStatements.push(...jsonDropTables);
|
17851
17900
|
jsonStatements.push(...jsonRenameTables);
|
17852
17901
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
17853
|
-
jsonStatements.push(...jsonDeletedCompositePKs);
|
17854
17902
|
if (dialect6 !== "mysql") {
|
17855
17903
|
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
17856
17904
|
}
|
17857
17905
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
17858
17906
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
17907
|
+
jsonStatements.push(...jsonDeletedCompositePKs);
|
17859
17908
|
jsonStatements.push(...jsonTableAlternations.alterColumns);
|
17909
|
+
jsonStatements.push(...jsonAddedCompositePKs);
|
17860
17910
|
if (dialect6 === "mysql") {
|
17861
17911
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
17862
17912
|
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
@@ -17868,7 +17918,6 @@ var init_snapshotsDiffer = __esm({
|
|
17868
17918
|
jsonStatements.push(...jsonTableAlternations.dropColumns);
|
17869
17919
|
if (dialect6 !== "sqlite")
|
17870
17920
|
jsonStatements.push(...jsonCreateReferences);
|
17871
|
-
jsonStatements.push(...jsonAddedCompositePKs);
|
17872
17921
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
17873
17922
|
if (dialect6 !== "mysql") {
|
17874
17923
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
@@ -60321,8 +60370,8 @@ var init_studioUtils = __esm({
|
|
60321
60370
|
};
|
60322
60371
|
};
|
60323
60372
|
drizzleForSQLite = async (config, sqliteSchema2, relations4, ts, verbose) => {
|
60324
|
-
const { driver, dbCredentials: creds } = config;
|
60325
|
-
if (
|
60373
|
+
const { driver: driver2, dbCredentials: creds } = config;
|
60374
|
+
if (driver2 === "d1") {
|
60326
60375
|
const { drizzle: drizzle2 } = await Promise.resolve().then(() => (init_driver(), driver_exports));
|
60327
60376
|
const { execute: execute2 } = await Promise.resolve().then(() => (init_wrangler_client(), wrangler_client_exports));
|
60328
60377
|
const db = drizzle2(execute2, creds.wranglerConfigPath, creds.dbName, {
|
@@ -60340,7 +60389,7 @@ var init_studioUtils = __esm({
|
|
60340
60389
|
ts
|
60341
60390
|
};
|
60342
60391
|
}
|
60343
|
-
if (
|
60392
|
+
if (driver2 === "better-sqlite") {
|
60344
60393
|
assertPackages("better-sqlite3");
|
60345
60394
|
const { drizzle: drizzle2 } = await import("drizzle-orm/better-sqlite3");
|
60346
60395
|
const Database = await import("better-sqlite3");
|
@@ -60359,7 +60408,7 @@ var init_studioUtils = __esm({
|
|
60359
60408
|
ts
|
60360
60409
|
};
|
60361
60410
|
}
|
60362
|
-
if (
|
60411
|
+
if (driver2 === "libsql" || driver2 === "turso") {
|
60363
60412
|
assertPackages("@libsql/client");
|
60364
60413
|
const { drizzle: drizzle2 } = await import("drizzle-orm/libsql");
|
60365
60414
|
const { createClient } = await import("@libsql/client");
|
@@ -60383,7 +60432,7 @@ var init_studioUtils = __esm({
|
|
60383
60432
|
ts
|
60384
60433
|
};
|
60385
60434
|
}
|
60386
|
-
assertUnreachable(
|
60435
|
+
assertUnreachable(driver2);
|
60387
60436
|
};
|
60388
60437
|
drizzleDb = async (drizzleConfig, models, logger) => {
|
60389
60438
|
if (drizzleConfig.driver === "pg") {
|
@@ -61097,8 +61146,8 @@ var init_mysql = __esm({
|
|
61097
61146
|
mysqlConnectionConfig
|
61098
61147
|
);
|
61099
61148
|
printCliConnectionIssues3 = (options) => {
|
61100
|
-
const { driver, uri, host, database } = options || {};
|
61101
|
-
if (
|
61149
|
+
const { driver: driver2, uri, host, database } = options || {};
|
61150
|
+
if (driver2 !== "mysql2") {
|
61102
61151
|
console.log(outputs.mysql.connection.driver());
|
61103
61152
|
}
|
61104
61153
|
if (!uri && (!host || !database)) {
|
@@ -61137,7 +61186,7 @@ var init_mysql = __esm({
|
|
61137
61186
|
const {
|
61138
61187
|
out,
|
61139
61188
|
schema: schema4,
|
61140
|
-
driver,
|
61189
|
+
driver: driver2,
|
61141
61190
|
schemaFilter,
|
61142
61191
|
tablesFilter,
|
61143
61192
|
breakpoints,
|
@@ -61147,7 +61196,7 @@ var init_mysql = __esm({
|
|
61147
61196
|
return {
|
61148
61197
|
out,
|
61149
61198
|
schema: schema4,
|
61150
|
-
driver,
|
61199
|
+
driver: driver2,
|
61151
61200
|
schemaFilter,
|
61152
61201
|
tablesFilter,
|
61153
61202
|
breakpoints,
|
@@ -61183,13 +61232,13 @@ var init_mysql = __esm({
|
|
61183
61232
|
strict,
|
61184
61233
|
verbose,
|
61185
61234
|
schema: schema4,
|
61186
|
-
driver,
|
61235
|
+
driver: driver2,
|
61187
61236
|
schemaFilter,
|
61188
61237
|
tablesFilter,
|
61189
61238
|
...rest
|
61190
61239
|
} = cliRes.data;
|
61191
61240
|
return {
|
61192
|
-
driver,
|
61241
|
+
driver: driver2,
|
61193
61242
|
schema: schema4,
|
61194
61243
|
strict,
|
61195
61244
|
verbose,
|
@@ -62383,6 +62432,7 @@ init_source();
|
|
62383
62432
|
var import_hanji9 = __toESM(require_hanji());
|
62384
62433
|
init_mysqlSchema();
|
62385
62434
|
init_selector_ui();
|
62435
|
+
init_outputs();
|
62386
62436
|
var filterStatements = (statements, currentSchema, prevSchema) => {
|
62387
62437
|
return statements.filter((statement) => {
|
62388
62438
|
if (statement.type === "alter_table_alter_column_set_type") {
|
@@ -62426,7 +62476,8 @@ var filterStatements = (statements, currentSchema, prevSchema) => {
|
|
62426
62476
|
};
|
62427
62477
|
var logSuggestionsAndReturn = async ({
|
62428
62478
|
connection,
|
62429
|
-
statements
|
62479
|
+
statements,
|
62480
|
+
json2
|
62430
62481
|
}) => {
|
62431
62482
|
let shouldAskForApprove = false;
|
62432
62483
|
const statementsToExecute = [];
|
@@ -62533,6 +62584,16 @@ var logSuggestionsAndReturn = async ({
|
|
62533
62584
|
const res = await connection.query(
|
62534
62585
|
`select count(*) as count from \`${statement.tableName}\``
|
62535
62586
|
);
|
62587
|
+
if (Object.values(json2.tables[statement.tableName].columns).filter(
|
62588
|
+
(column7) => column7.autoincrement
|
62589
|
+
).length > 0) {
|
62590
|
+
console.log(
|
62591
|
+
`${withStyle.errorWarning(
|
62592
|
+
`You have removed the primary key from a ${statement.tableName} table without removing the auto-increment property from this table. As the database error states: 'there can be only one auto column, and it must be defined as a key. Make sure to remove autoincrement from ${statement.tableName} table`
|
62593
|
+
)}`
|
62594
|
+
);
|
62595
|
+
process.exit(1);
|
62596
|
+
}
|
62536
62597
|
const count = Number(res[0][0].count);
|
62537
62598
|
if (count > 0) {
|
62538
62599
|
infoToPrint.push(
|
@@ -62543,6 +62604,17 @@ var logSuggestionsAndReturn = async ({
|
|
62543
62604
|
tablesToTruncate.push(statement.tableName);
|
62544
62605
|
shouldAskForApprove = true;
|
62545
62606
|
}
|
62607
|
+
} else if (statement.type === "delete_composite_pk") {
|
62608
|
+
if (Object.values(json2.tables[statement.tableName].columns).filter(
|
62609
|
+
(column7) => column7.autoincrement
|
62610
|
+
).length > 0) {
|
62611
|
+
console.log(
|
62612
|
+
`${withStyle.errorWarning(
|
62613
|
+
`You have removed the primary key from a ${statement.tableName} table without removing the auto-increment property from this table. As the database error states: 'there can be only one auto column, and it must be defined as a key. Make sure to remove autoincrement from ${statement.tableName} table`
|
62614
|
+
)}`
|
62615
|
+
);
|
62616
|
+
process.exit(1);
|
62617
|
+
}
|
62546
62618
|
} else if (statement.type === "alter_table_add_column") {
|
62547
62619
|
if (statement.column.notNull && typeof statement.column.default === "undefined") {
|
62548
62620
|
const res = await connection.query(
|
@@ -63015,7 +63087,8 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
63015
63087
|
schemasToRemove
|
63016
63088
|
} = await logSuggestionsAndReturn({
|
63017
63089
|
connection: connection.client,
|
63018
|
-
statements: filteredStatements
|
63090
|
+
statements: filteredStatements,
|
63091
|
+
json2: statements == null ? void 0 : statements.validatedCur
|
63019
63092
|
});
|
63020
63093
|
const filteredSqlStatements = filteredStatements.map(
|
63021
63094
|
(filteredStatement) => fromJson([filteredStatement], "mysql")[0]
|
@@ -63608,9 +63681,9 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
|
|
63608
63681
|
prepareSQLiteSchema: prepareSQLiteSchema2,
|
63609
63682
|
drizzleForSQLite: drizzleForSQLite2
|
63610
63683
|
} = await Promise.resolve().then(() => (init_studioUtils(), studioUtils_exports));
|
63611
|
-
const { driver, schema: schemaPath } = drizzleConfig;
|
63684
|
+
const { driver: driver2, schema: schemaPath } = drizzleConfig;
|
63612
63685
|
let setup;
|
63613
|
-
if (
|
63686
|
+
if (driver2 === "pg") {
|
63614
63687
|
const { schemaToTypeScript: schemaToTypeScript4, relationsToTypeScript: relationsToTypeScript2 } = await Promise.resolve().then(() => (init_introspect_pg(), introspect_pg_exports));
|
63615
63688
|
const { serializePg: serializePg2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
|
63616
63689
|
const { schema: schema4, relations: relations4 } = await preparePgSchema2(schemaPath);
|
@@ -63628,7 +63701,7 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
|
|
63628
63701
|
},
|
63629
63702
|
Boolean(options.verbose)
|
63630
63703
|
);
|
63631
|
-
} else if (
|
63704
|
+
} else if (driver2 === "mysql2") {
|
63632
63705
|
const { schemaToTypeScript: schemaToTypeScript4 } = await Promise.resolve().then(() => (init_introspect_mysql(), introspect_mysql_exports));
|
63633
63706
|
const { schema: schema4, relations: relations4 } = await prepareMySqlSchema2(schemaPath);
|
63634
63707
|
const { serializeMySql: serializeMySql2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
|
@@ -63645,7 +63718,7 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
|
|
63645
63718
|
},
|
63646
63719
|
Boolean(options.verbose)
|
63647
63720
|
);
|
63648
|
-
} else if (
|
63721
|
+
} else if (driver2 === "better-sqlite" || driver2 === "d1" || driver2 === "libsql" || driver2 === "turso") {
|
63649
63722
|
const { schemaToTypeScript: schemaToTypeScript4 } = await Promise.resolve().then(() => (init_introspect_sqlite(), introspect_sqlite_exports));
|
63650
63723
|
const { schema: schema4, relations: relations4 } = await prepareSQLiteSchema2(schemaPath);
|
63651
63724
|
const { serializeSQLite: serializeSQLite2 } = await Promise.resolve().then(() => (init_serializer(), serializer_exports));
|
@@ -63663,7 +63736,7 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
|
|
63663
63736
|
Boolean(options.verbose)
|
63664
63737
|
);
|
63665
63738
|
} else {
|
63666
|
-
assertUnreachable(
|
63739
|
+
assertUnreachable(driver2);
|
63667
63740
|
}
|
63668
63741
|
const qeueryEngine = (0, import_studio.queryEngineForSetup)(setup);
|
63669
63742
|
const server = await (0, import_server.prepareServer)((_2) => {
|
@@ -63677,7 +63750,7 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
|
|
63677
63750
|
"Drizzle Studio is currently in Beta. If you find anything that is not working as expected or should be improved, feel free to create an issue on GitHub: https://github.com/drizzle-team/drizzle-kit-mirror/issues/new or write to us on Discord: https://discord.gg/WcRKz2FFxN"
|
63678
63751
|
)
|
63679
63752
|
);
|
63680
|
-
if (
|
63753
|
+
if (driver2 === "d1") {
|
63681
63754
|
console.log(
|
63682
63755
|
withStyle.fullWarning(
|
63683
63756
|
"It seems like you are trying to access your D1 Database. Please make sure to run 'wrangler login' before using Drizzle Studio to ensure it has your token for making requests to the D1 Database. If you encounter an error related to CLOUDFLARE_TOKEN, please run 'wrangler login' and restart the studio"
|
@@ -256,5 +256,14 @@ export declare const prepareSQL: (prev: CommonSquashedSchema, cur: CommonSquashe
|
|
256
256
|
} | undefined;
|
257
257
|
}>;
|
258
258
|
export declare const BREAKPOINT = "--> statement-breakpoint\n";
|
259
|
-
export declare const writeResult: (cur
|
259
|
+
export declare const writeResult: ({ cur, sqlStatements, journal, _meta, outFolder, breakpoints, bundle, type, }: {
|
260
|
+
cur: CommonSchema;
|
261
|
+
sqlStatements: string[];
|
262
|
+
journal: Journal;
|
263
|
+
_meta?: any;
|
264
|
+
outFolder: string;
|
265
|
+
breakpoints: boolean;
|
266
|
+
bundle?: boolean | undefined;
|
267
|
+
type?: "none" | "custom" | "introspect" | undefined;
|
268
|
+
}) => void;
|
260
269
|
export declare const prepareSnapshotFolderName: () => string;
|
package/cli/commands/utils.d.ts
CHANGED
@@ -7,6 +7,7 @@ export type GenerateConfig = {
|
|
7
7
|
out: string;
|
8
8
|
breakpoints: boolean;
|
9
9
|
custom: boolean;
|
10
|
+
bundle: boolean;
|
10
11
|
};
|
11
12
|
export declare const prepareGenerateConfig: (options: {
|
12
13
|
schema?: string | string[];
|
@@ -20,14 +21,17 @@ export declare const assertOutFolder: (it: {
|
|
20
21
|
} | {
|
21
22
|
out: string;
|
22
23
|
}) => Promise<string>;
|
24
|
+
export declare const driver: import("zod").ZodUnion<[import("zod").ZodLiteral<"better-sqlite">, import("zod").ZodLiteral<"turso">, import("zod").ZodLiteral<"libsql">, import("zod").ZodLiteral<"d1">, import("zod").ZodLiteral<"expo">, import("zod").ZodLiteral<"pg">, import("zod").ZodLiteral<"mysql2">]>;
|
23
25
|
export declare const configCommonSchema: import("zod").ZodObject<{
|
24
26
|
schema: import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString, "many">]>;
|
25
27
|
out: import("zod").ZodOptional<import("zod").ZodString>;
|
26
28
|
breakpoints: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
29
|
+
driver: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodLiteral<"better-sqlite">, import("zod").ZodLiteral<"turso">, import("zod").ZodLiteral<"libsql">, import("zod").ZodLiteral<"d1">, import("zod").ZodLiteral<"expo">, import("zod").ZodLiteral<"pg">, import("zod").ZodLiteral<"mysql2">]>>;
|
27
30
|
tablesFilter: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString, "many">]>>;
|
28
31
|
schemaFilter: import("zod").ZodDefault<import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString, "many">]>>;
|
29
32
|
}, "strip", import("zod").ZodTypeAny, {
|
30
33
|
out?: string | undefined;
|
34
|
+
driver?: "turso" | "better-sqlite" | "libsql" | "d1" | "pg" | "mysql2" | "expo" | undefined;
|
31
35
|
tablesFilter?: string | string[] | undefined;
|
32
36
|
schema: string | string[];
|
33
37
|
breakpoints: boolean;
|
@@ -35,6 +39,7 @@ export declare const configCommonSchema: import("zod").ZodObject<{
|
|
35
39
|
}, {
|
36
40
|
out?: string | undefined;
|
37
41
|
breakpoints?: boolean | undefined;
|
42
|
+
driver?: "turso" | "better-sqlite" | "libsql" | "d1" | "pg" | "mysql2" | "expo" | undefined;
|
38
43
|
tablesFilter?: string | string[] | undefined;
|
39
44
|
schemaFilter?: string | string[] | undefined;
|
40
45
|
schema: string | string[];
|
@@ -164,10 +169,12 @@ export declare const mySqlCliConfigSchema: import("zod").ZodIntersection<import(
|
|
164
169
|
schema: import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString, "many">]>;
|
165
170
|
out: import("zod").ZodOptional<import("zod").ZodString>;
|
166
171
|
breakpoints: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
172
|
+
driver: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodLiteral<"better-sqlite">, import("zod").ZodLiteral<"turso">, import("zod").ZodLiteral<"libsql">, import("zod").ZodLiteral<"d1">, import("zod").ZodLiteral<"expo">, import("zod").ZodLiteral<"pg">, import("zod").ZodLiteral<"mysql2">]>>;
|
167
173
|
tablesFilter: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString, "many">]>>;
|
168
174
|
schemaFilter: import("zod").ZodDefault<import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString, "many">]>>;
|
169
175
|
}, "strip", import("zod").ZodTypeAny, {
|
170
176
|
out?: string | undefined;
|
177
|
+
driver?: "turso" | "better-sqlite" | "libsql" | "d1" | "pg" | "mysql2" | "expo" | undefined;
|
171
178
|
tablesFilter?: string | string[] | undefined;
|
172
179
|
schema: string | string[];
|
173
180
|
breakpoints: boolean;
|
@@ -175,6 +182,7 @@ export declare const mySqlCliConfigSchema: import("zod").ZodIntersection<import(
|
|
175
182
|
}, {
|
176
183
|
out?: string | undefined;
|
177
184
|
breakpoints?: boolean | undefined;
|
185
|
+
driver?: "turso" | "better-sqlite" | "libsql" | "d1" | "pg" | "mysql2" | "expo" | undefined;
|
178
186
|
tablesFilter?: string | string[] | undefined;
|
179
187
|
schemaFilter?: string | string[] | undefined;
|
180
188
|
schema: string | string[];
|
@@ -261,5 +269,6 @@ export declare const mySqlIntrospectConfigSchema: import("zod").ZodIntersection<
|
|
261
269
|
}>, import("zod").ZodObject<{}, "strip", import("zod").ZodTypeAny, {}, {}>]>>;
|
262
270
|
export type MySqlCliConfig = TypeOf<typeof mySqlCliConfigSchema>;
|
263
271
|
export type CliConfig = MySqlCliConfig;
|
272
|
+
export type Driver = TypeOf<typeof driver>;
|
264
273
|
export declare const drizzleConfigFromFile: (configPath?: string) => Promise<CliConfig>;
|
265
274
|
export declare const readDrizzleConfig: (configPath?: string) => Promise<any>;
|
@@ -9,17 +9,17 @@ export declare const mysqlConnectionCli: import("zod").ZodUnion<[import("zod").Z
|
|
9
9
|
}, "strip", import("zod").ZodTypeAny, {
|
10
10
|
port?: number | undefined;
|
11
11
|
password?: string | undefined;
|
12
|
+
driver: "mysql2";
|
12
13
|
host: string;
|
13
14
|
user: string;
|
14
15
|
database: string;
|
15
|
-
driver: "mysql2";
|
16
16
|
}, {
|
17
17
|
port?: number | undefined;
|
18
18
|
user?: string | undefined;
|
19
19
|
password?: string | undefined;
|
20
|
+
driver: "mysql2";
|
20
21
|
host: string;
|
21
22
|
database: string;
|
22
|
-
driver: "mysql2";
|
23
23
|
}>, import("zod").ZodObject<{
|
24
24
|
driver: import("zod").ZodLiteral<"mysql2">;
|
25
25
|
uri: import("zod").ZodString;
|
@@ -217,17 +217,17 @@ export declare const mysqlCliIntrospectParams: import("zod").ZodIntersection<imp
|
|
217
217
|
}, "strip", import("zod").ZodTypeAny, {
|
218
218
|
port?: number | undefined;
|
219
219
|
password?: string | undefined;
|
220
|
+
driver: "mysql2";
|
220
221
|
host: string;
|
221
222
|
user: string;
|
222
223
|
database: string;
|
223
|
-
driver: "mysql2";
|
224
224
|
}, {
|
225
225
|
port?: number | undefined;
|
226
226
|
user?: string | undefined;
|
227
227
|
password?: string | undefined;
|
228
|
+
driver: "mysql2";
|
228
229
|
host: string;
|
229
230
|
database: string;
|
230
|
-
driver: "mysql2";
|
231
231
|
}>, import("zod").ZodObject<{
|
232
232
|
driver: import("zod").ZodLiteral<"mysql2">;
|
233
233
|
uri: import("zod").ZodString;
|
@@ -266,17 +266,17 @@ export declare const mysqlCliPushParams: import("zod").ZodIntersection<import("z
|
|
266
266
|
}, "strip", import("zod").ZodTypeAny, {
|
267
267
|
port?: number | undefined;
|
268
268
|
password?: string | undefined;
|
269
|
+
driver: "mysql2";
|
269
270
|
host: string;
|
270
271
|
user: string;
|
271
272
|
database: string;
|
272
|
-
driver: "mysql2";
|
273
273
|
}, {
|
274
274
|
port?: number | undefined;
|
275
275
|
user?: string | undefined;
|
276
276
|
password?: string | undefined;
|
277
|
+
driver: "mysql2";
|
277
278
|
host: string;
|
278
279
|
database: string;
|
279
|
-
driver: "mysql2";
|
280
280
|
}>, import("zod").ZodObject<{
|
281
281
|
driver: import("zod").ZodLiteral<"mysql2">;
|
282
282
|
uri: import("zod").ZodString;
|
package/cli/validations/pg.d.ts
CHANGED
@@ -13,31 +13,31 @@ export declare const pgConnectionCli: import("zod").ZodUnion<[import("zod").ZodO
|
|
13
13
|
password?: string | undefined;
|
14
14
|
ssl?: boolean | undefined;
|
15
15
|
type: "params";
|
16
|
+
driver: "pg";
|
16
17
|
host: string;
|
17
18
|
user: string;
|
18
19
|
database: string;
|
19
|
-
driver: "pg";
|
20
20
|
}, {
|
21
21
|
type?: "params" | undefined;
|
22
22
|
port?: number | undefined;
|
23
23
|
user?: string | undefined;
|
24
24
|
password?: string | undefined;
|
25
25
|
ssl?: boolean | undefined;
|
26
|
+
driver: "pg";
|
26
27
|
host: string;
|
27
28
|
database: string;
|
28
|
-
driver: "pg";
|
29
29
|
}>, import("zod").ZodObject<{
|
30
30
|
driver: import("zod").ZodLiteral<"pg">;
|
31
31
|
connectionString: import("zod").ZodString;
|
32
32
|
type: import("zod").ZodDefault<import("zod").ZodLiteral<"url">>;
|
33
33
|
}, "strip", import("zod").ZodTypeAny, {
|
34
34
|
type: "url";
|
35
|
-
connectionString: string;
|
36
35
|
driver: "pg";
|
36
|
+
connectionString: string;
|
37
37
|
}, {
|
38
38
|
type?: "url" | undefined;
|
39
|
-
connectionString: string;
|
40
39
|
driver: "pg";
|
40
|
+
connectionString: string;
|
41
41
|
}>]>;
|
42
42
|
export declare const pgConnectionConfig: import("zod").ZodUnion<[import("zod").ZodObject<{
|
43
43
|
driver: import("zod").ZodLiteral<"pg">;
|
@@ -253,31 +253,31 @@ export declare const pgCliIntrospectParams: import("zod").ZodIntersection<import
|
|
253
253
|
password?: string | undefined;
|
254
254
|
ssl?: boolean | undefined;
|
255
255
|
type: "params";
|
256
|
+
driver: "pg";
|
256
257
|
host: string;
|
257
258
|
user: string;
|
258
259
|
database: string;
|
259
|
-
driver: "pg";
|
260
260
|
}, {
|
261
261
|
type?: "params" | undefined;
|
262
262
|
port?: number | undefined;
|
263
263
|
user?: string | undefined;
|
264
264
|
password?: string | undefined;
|
265
265
|
ssl?: boolean | undefined;
|
266
|
+
driver: "pg";
|
266
267
|
host: string;
|
267
268
|
database: string;
|
268
|
-
driver: "pg";
|
269
269
|
}>, import("zod").ZodObject<{
|
270
270
|
driver: import("zod").ZodLiteral<"pg">;
|
271
271
|
connectionString: import("zod").ZodString;
|
272
272
|
type: import("zod").ZodDefault<import("zod").ZodLiteral<"url">>;
|
273
273
|
}, "strip", import("zod").ZodTypeAny, {
|
274
274
|
type: "url";
|
275
|
-
connectionString: string;
|
276
275
|
driver: "pg";
|
276
|
+
connectionString: string;
|
277
277
|
}, {
|
278
278
|
type?: "url" | undefined;
|
279
|
-
connectionString: string;
|
280
279
|
driver: "pg";
|
280
|
+
connectionString: string;
|
281
281
|
}>]>>;
|
282
282
|
export declare const pgCliPushParams: import("zod").ZodIntersection<import("zod").ZodObject<{
|
283
283
|
schema: import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString, "many">]>;
|
@@ -311,31 +311,31 @@ export declare const pgCliPushParams: import("zod").ZodIntersection<import("zod"
|
|
311
311
|
password?: string | undefined;
|
312
312
|
ssl?: boolean | undefined;
|
313
313
|
type: "params";
|
314
|
+
driver: "pg";
|
314
315
|
host: string;
|
315
316
|
user: string;
|
316
317
|
database: string;
|
317
|
-
driver: "pg";
|
318
318
|
}, {
|
319
319
|
type?: "params" | undefined;
|
320
320
|
port?: number | undefined;
|
321
321
|
user?: string | undefined;
|
322
322
|
password?: string | undefined;
|
323
323
|
ssl?: boolean | undefined;
|
324
|
+
driver: "pg";
|
324
325
|
host: string;
|
325
326
|
database: string;
|
326
|
-
driver: "pg";
|
327
327
|
}>, import("zod").ZodObject<{
|
328
328
|
driver: import("zod").ZodLiteral<"pg">;
|
329
329
|
connectionString: import("zod").ZodString;
|
330
330
|
type: import("zod").ZodDefault<import("zod").ZodLiteral<"url">>;
|
331
331
|
}, "strip", import("zod").ZodTypeAny, {
|
332
332
|
type: "url";
|
333
|
-
connectionString: string;
|
334
333
|
driver: "pg";
|
334
|
+
connectionString: string;
|
335
335
|
}, {
|
336
336
|
type?: "url" | undefined;
|
337
|
-
connectionString: string;
|
338
337
|
driver: "pg";
|
338
|
+
connectionString: string;
|
339
339
|
}>]>>;
|
340
340
|
export declare const pgConfigPushParams: import("zod").ZodIntersection<import("zod").ZodObject<{
|
341
341
|
schema: import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString, "many">]>;
|
package/index.d.mts
CHANGED
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/utils.js
CHANGED
@@ -11140,7 +11140,7 @@ var require_node2 = __commonJS({
|
|
11140
11140
|
});
|
11141
11141
|
|
11142
11142
|
// src/cli/commands/utils.ts
|
11143
|
-
var import_hanji2, assertES5, safeRegister, configCommonSchema, introspectCasing, configIntrospectSchema, configIntrospectCliSchema, configGenerateSchema, configPushSchema, mysqlConnectionSchema, mySqlCliConfigSchema, mySqlIntrospectConfigSchema;
|
11143
|
+
var import_hanji2, assertES5, safeRegister, driver, configCommonSchema, introspectCasing, configIntrospectSchema, configIntrospectCliSchema, configGenerateSchema, configPushSchema, mysqlConnectionSchema, mySqlCliConfigSchema, mySqlIntrospectConfigSchema;
|
11144
11144
|
var init_utils = __esm({
|
11145
11145
|
"src/cli/commands/utils.ts"() {
|
11146
11146
|
init_serializer();
|
@@ -11189,10 +11189,20 @@ var init_utils = __esm({
|
|
11189
11189
|
await assertES5(res.unregister);
|
11190
11190
|
return res;
|
11191
11191
|
};
|
11192
|
+
driver = unionType([
|
11193
|
+
literalType("better-sqlite"),
|
11194
|
+
literalType("turso"),
|
11195
|
+
literalType("libsql"),
|
11196
|
+
literalType("d1"),
|
11197
|
+
literalType("expo"),
|
11198
|
+
literalType("pg"),
|
11199
|
+
literalType("mysql2")
|
11200
|
+
]);
|
11192
11201
|
configCommonSchema = objectType({
|
11193
11202
|
schema: unionType([stringType(), stringType().array()]),
|
11194
11203
|
out: stringType().optional(),
|
11195
11204
|
breakpoints: booleanType().default(true),
|
11205
|
+
driver: driver.optional(),
|
11196
11206
|
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
11197
11207
|
schemaFilter: unionType([stringType(), stringType().array()]).default(["public"])
|
11198
11208
|
});
|
@@ -11906,6 +11916,7 @@ var init_pgSerializer = __esm({
|
|
11906
11916
|
};
|
11907
11917
|
generatePgSnapshot = (tables, enums, schemas, schemaFilter) => {
|
11908
11918
|
const result = {};
|
11919
|
+
const indexesInSchema = {};
|
11909
11920
|
for (const table4 of tables) {
|
11910
11921
|
const {
|
11911
11922
|
name: tableName,
|
@@ -12057,6 +12068,24 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12057
12068
|
return it.name;
|
12058
12069
|
}
|
12059
12070
|
});
|
12071
|
+
if (typeof indexesInSchema[schema4 ?? "public"] !== "undefined") {
|
12072
|
+
if (indexesInSchema[schema4 ?? "public"].includes(name)) {
|
12073
|
+
console.log(
|
12074
|
+
`
|
12075
|
+
${withStyle.errorWarning(
|
12076
|
+
`We've found duplicated index name across ${source_default.underline.blue(
|
12077
|
+
schema4 ?? "public"
|
12078
|
+
)} schema. Please rename your index in either the ${source_default.underline.blue(
|
12079
|
+
tableName
|
12080
|
+
)} table or the table with the duplicated index name`
|
12081
|
+
)}`
|
12082
|
+
);
|
12083
|
+
process.exit(1);
|
12084
|
+
}
|
12085
|
+
indexesInSchema[schema4 ?? "public"].push(name);
|
12086
|
+
} else {
|
12087
|
+
indexesInSchema[schema4 ?? "public"] = [name];
|
12088
|
+
}
|
12060
12089
|
indexesObject[name] = {
|
12061
12090
|
name,
|
12062
12091
|
columns: indexColumns,
|
@@ -14613,7 +14642,7 @@ __export(migrate_exports, {
|
|
14613
14642
|
prepareSnapshotFolderName: () => prepareSnapshotFolderName,
|
14614
14643
|
writeResult: () => writeResult
|
14615
14644
|
});
|
14616
|
-
var import_fs3, import_path2, import_hanji3, prepareAndMigratePg, prepareMySQLPush, prepareSQLitePush, preparePgPush, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, BREAKPOINT, writeResult, prepareSnapshotFolderName, two;
|
14645
|
+
var import_fs3, import_path2, import_hanji3, prepareAndMigratePg, prepareMySQLPush, prepareSQLitePush, preparePgPush, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
|
14617
14646
|
var init_migrate = __esm({
|
14618
14647
|
"src/cli/commands/migrate.ts"() {
|
14619
14648
|
import_fs3 = __toESM(require("fs"));
|
@@ -14642,19 +14671,14 @@ var init_migrate = __esm({
|
|
14642
14671
|
const validatedPrev = pgSchema.parse(prev);
|
14643
14672
|
const validatedCur = pgSchema.parse(cur);
|
14644
14673
|
if (config.custom) {
|
14645
|
-
writeResult(
|
14646
|
-
custom,
|
14647
|
-
[],
|
14674
|
+
writeResult({
|
14675
|
+
cur: custom,
|
14676
|
+
sqlStatements: [],
|
14648
14677
|
journal,
|
14649
|
-
{
|
14650
|
-
columns: {},
|
14651
|
-
schemas: {},
|
14652
|
-
tables: {}
|
14653
|
-
},
|
14654
14678
|
outFolder,
|
14655
|
-
config.breakpoints,
|
14656
|
-
"custom"
|
14657
|
-
);
|
14679
|
+
breakpoints: config.breakpoints,
|
14680
|
+
type: "custom"
|
14681
|
+
});
|
14658
14682
|
return;
|
14659
14683
|
}
|
14660
14684
|
const squashedPrev = squashPgScheme(validatedPrev);
|
@@ -14666,14 +14690,13 @@ var init_migrate = __esm({
|
|
14666
14690
|
validatedPrev,
|
14667
14691
|
validatedCur
|
14668
14692
|
);
|
14669
|
-
writeResult(
|
14693
|
+
writeResult({
|
14670
14694
|
cur,
|
14671
14695
|
sqlStatements,
|
14672
14696
|
journal,
|
14673
|
-
_meta,
|
14674
14697
|
outFolder,
|
14675
|
-
config.breakpoints
|
14676
|
-
);
|
14698
|
+
breakpoints: config.breakpoints
|
14699
|
+
});
|
14677
14700
|
} catch (e) {
|
14678
14701
|
console.error(e);
|
14679
14702
|
}
|
@@ -14767,19 +14790,14 @@ var init_migrate = __esm({
|
|
14767
14790
|
const validatedPrev = mysqlSchema.parse(prev);
|
14768
14791
|
const validatedCur = mysqlSchema.parse(cur);
|
14769
14792
|
if (config.custom) {
|
14770
|
-
writeResult(
|
14771
|
-
custom,
|
14772
|
-
[],
|
14793
|
+
writeResult({
|
14794
|
+
cur: custom,
|
14795
|
+
sqlStatements: [],
|
14773
14796
|
journal,
|
14774
|
-
{
|
14775
|
-
columns: {},
|
14776
|
-
schemas: {},
|
14777
|
-
tables: {}
|
14778
|
-
},
|
14779
14797
|
outFolder,
|
14780
|
-
config.breakpoints,
|
14781
|
-
"custom"
|
14782
|
-
);
|
14798
|
+
breakpoints: config.breakpoints,
|
14799
|
+
type: "custom"
|
14800
|
+
});
|
14783
14801
|
return;
|
14784
14802
|
}
|
14785
14803
|
const squashedPrev = squashMysqlScheme(validatedPrev);
|
@@ -14791,14 +14809,14 @@ var init_migrate = __esm({
|
|
14791
14809
|
validatedPrev,
|
14792
14810
|
validatedCur
|
14793
14811
|
);
|
14794
|
-
writeResult(
|
14812
|
+
writeResult({
|
14795
14813
|
cur,
|
14796
14814
|
sqlStatements,
|
14797
14815
|
journal,
|
14798
14816
|
_meta,
|
14799
14817
|
outFolder,
|
14800
|
-
config.breakpoints
|
14801
|
-
);
|
14818
|
+
breakpoints: config.breakpoints
|
14819
|
+
});
|
14802
14820
|
} catch (e) {
|
14803
14821
|
console.error(e);
|
14804
14822
|
}
|
@@ -14816,19 +14834,15 @@ var init_migrate = __esm({
|
|
14816
14834
|
const validatedPrev = sqliteSchema.parse(prev);
|
14817
14835
|
const validatedCur = sqliteSchema.parse(cur);
|
14818
14836
|
if (config.custom) {
|
14819
|
-
writeResult(
|
14820
|
-
custom,
|
14821
|
-
[],
|
14837
|
+
writeResult({
|
14838
|
+
cur: custom,
|
14839
|
+
sqlStatements: [],
|
14822
14840
|
journal,
|
14823
|
-
{
|
14824
|
-
columns: {},
|
14825
|
-
schemas: {},
|
14826
|
-
tables: {}
|
14827
|
-
},
|
14828
14841
|
outFolder,
|
14829
|
-
config.breakpoints,
|
14830
|
-
|
14831
|
-
|
14842
|
+
breakpoints: config.breakpoints,
|
14843
|
+
bundle: config.bundle,
|
14844
|
+
type: "custom"
|
14845
|
+
});
|
14832
14846
|
return;
|
14833
14847
|
}
|
14834
14848
|
const squashedPrev = squashSqliteScheme(validatedPrev);
|
@@ -14838,14 +14852,15 @@ var init_migrate = __esm({
|
|
14838
14852
|
squashedCur,
|
14839
14853
|
"sqlite"
|
14840
14854
|
);
|
14841
|
-
writeResult(
|
14855
|
+
writeResult({
|
14842
14856
|
cur,
|
14843
14857
|
sqlStatements,
|
14844
14858
|
journal,
|
14845
14859
|
_meta,
|
14846
14860
|
outFolder,
|
14847
|
-
config.breakpoints
|
14848
|
-
|
14861
|
+
breakpoints: config.breakpoints,
|
14862
|
+
bundle: config.bundle
|
14863
|
+
});
|
14849
14864
|
} catch (e) {
|
14850
14865
|
console.error(e);
|
14851
14866
|
}
|
@@ -15033,7 +15048,20 @@ var init_migrate = __esm({
|
|
15033
15048
|
return result;
|
15034
15049
|
};
|
15035
15050
|
BREAKPOINT = "--> statement-breakpoint\n";
|
15036
|
-
writeResult = (
|
15051
|
+
writeResult = ({
|
15052
|
+
cur,
|
15053
|
+
sqlStatements,
|
15054
|
+
journal,
|
15055
|
+
_meta = {
|
15056
|
+
columns: {},
|
15057
|
+
schemas: {},
|
15058
|
+
tables: {}
|
15059
|
+
},
|
15060
|
+
outFolder,
|
15061
|
+
breakpoints,
|
15062
|
+
bundle = false,
|
15063
|
+
type = "none"
|
15064
|
+
}) => {
|
15037
15065
|
if (type === "none") {
|
15038
15066
|
console.log(schema(cur));
|
15039
15067
|
if (sqlStatements.length === 0) {
|
@@ -15074,6 +15102,10 @@ ${sql2}
|
|
15074
15102
|
});
|
15075
15103
|
import_fs3.default.writeFileSync(metaJournal, JSON.stringify(journal, null, 2));
|
15076
15104
|
import_fs3.default.writeFileSync(`${outFolder}/${tag}.sql`, sql2);
|
15105
|
+
if (bundle) {
|
15106
|
+
const js = embeddedMigrations(journal);
|
15107
|
+
import_fs3.default.writeFileSync(`${outFolder}/migrations.js`, js);
|
15108
|
+
}
|
15077
15109
|
(0, import_hanji3.render)(
|
15078
15110
|
`[${source_default.green(
|
15079
15111
|
"\u2713"
|
@@ -15082,6 +15114,22 @@ ${sql2}
|
|
15082
15114
|
)} \u{1F680}`
|
15083
15115
|
);
|
15084
15116
|
};
|
15117
|
+
embeddedMigrations = (journal) => {
|
15118
|
+
let content = "import journal from './meta/_journal.json';\n";
|
15119
|
+
journal.entries.forEach((entry) => {
|
15120
|
+
content += `import m${entry.idx.toString().padStart(4, "0")} from './${entry.tag}.sql';
|
15121
|
+
`;
|
15122
|
+
});
|
15123
|
+
content += `
|
15124
|
+
export default {
|
15125
|
+
journal,
|
15126
|
+
migrations: {
|
15127
|
+
${journal.entries.map((it) => `m${it.idx.toString().padStart(4, "0")}`).join(",\n")}
|
15128
|
+
}
|
15129
|
+
}
|
15130
|
+
`;
|
15131
|
+
return content;
|
15132
|
+
};
|
15085
15133
|
prepareSnapshotFolderName = () => {
|
15086
15134
|
const now = /* @__PURE__ */ new Date();
|
15087
15135
|
return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
|
@@ -15176,7 +15224,7 @@ var init_sqlgenerator = __esm({
|
|
15176
15224
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
15177
15225
|
statement += ",\n";
|
15178
15226
|
const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
|
15179
|
-
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
15227
|
+
statement += ` CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
15180
15228
|
}
|
15181
15229
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
15182
15230
|
for (const uniqueConstraint4 of uniqueConstraints) {
|
@@ -17568,13 +17616,14 @@ var init_snapshotsDiffer = __esm({
|
|
17568
17616
|
jsonStatements.push(...jsonDropTables);
|
17569
17617
|
jsonStatements.push(...jsonRenameTables);
|
17570
17618
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
17571
|
-
jsonStatements.push(...jsonDeletedCompositePKs);
|
17572
17619
|
if (dialect6 !== "mysql") {
|
17573
17620
|
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
17574
17621
|
}
|
17575
17622
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
17576
17623
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
17624
|
+
jsonStatements.push(...jsonDeletedCompositePKs);
|
17577
17625
|
jsonStatements.push(...jsonTableAlternations.alterColumns);
|
17626
|
+
jsonStatements.push(...jsonAddedCompositePKs);
|
17578
17627
|
if (dialect6 === "mysql") {
|
17579
17628
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
17580
17629
|
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
@@ -17586,7 +17635,6 @@ var init_snapshotsDiffer = __esm({
|
|
17586
17635
|
jsonStatements.push(...jsonTableAlternations.dropColumns);
|
17587
17636
|
if (dialect6 !== "sqlite")
|
17588
17637
|
jsonStatements.push(...jsonCreateReferences);
|
17589
|
-
jsonStatements.push(...jsonAddedCompositePKs);
|
17590
17638
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
17591
17639
|
if (dialect6 !== "mysql") {
|
17592
17640
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|