drizzle-kit 0.19.4 → 0.19.5-10646d0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +62 -18
- package/package.json +1 -1
- package/utils.js +37 -8
package/index.cjs
CHANGED
|
@@ -4656,7 +4656,8 @@ var init_mysqlSchema = __esm({
|
|
|
4656
4656
|
columns: recordType(stringType(), column),
|
|
4657
4657
|
indexes: recordType(stringType(), stringType()),
|
|
4658
4658
|
foreignKeys: recordType(stringType(), stringType()),
|
|
4659
|
-
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
4659
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
|
4660
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
|
4660
4661
|
}).strict();
|
|
4661
4662
|
schemaSquashed = objectType({
|
|
4662
4663
|
version: literalType("5"),
|
|
@@ -5228,7 +5229,8 @@ var init_sqliteSchema = __esm({
|
|
|
5228
5229
|
columns: recordType(stringType(), column3),
|
|
5229
5230
|
indexes: recordType(stringType(), stringType()),
|
|
5230
5231
|
foreignKeys: recordType(stringType(), stringType()),
|
|
5231
|
-
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
5232
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
|
5233
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
|
5232
5234
|
}).strict();
|
|
5233
5235
|
schemaSquashed2 = objectType({
|
|
5234
5236
|
version: latestVersion,
|
|
@@ -11690,7 +11692,6 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11690
11692
|
let tablesCount = /* @__PURE__ */ new Set();
|
|
11691
11693
|
let indexesCount = 0;
|
|
11692
11694
|
let foreignKeysCount = 0;
|
|
11693
|
-
const tableToPk = {};
|
|
11694
11695
|
for (const column7 of response) {
|
|
11695
11696
|
if (!tablesFilter(column7["TABLE_NAME"]))
|
|
11696
11697
|
continue;
|
|
@@ -11719,13 +11720,6 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11719
11720
|
isAutoincrement = column7["EXTRA"] === "auto_increment";
|
|
11720
11721
|
isDefaultAnExpression = column7["EXTRA"].includes("DEFAULT_GENERATED");
|
|
11721
11722
|
}
|
|
11722
|
-
if (isPrimary) {
|
|
11723
|
-
if (typeof tableToPk[tableName] === "undefined") {
|
|
11724
|
-
tableToPk[tableName] = [columnName];
|
|
11725
|
-
} else {
|
|
11726
|
-
tableToPk[tableName].push(columnName);
|
|
11727
|
-
}
|
|
11728
|
-
}
|
|
11729
11723
|
if (schema4 !== inputSchema) {
|
|
11730
11724
|
schemas.push(schema4);
|
|
11731
11725
|
}
|
|
@@ -11763,6 +11757,26 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11763
11757
|
result[tableName].columns[columnName] = newColumn;
|
|
11764
11758
|
}
|
|
11765
11759
|
}
|
|
11760
|
+
const tablePks = await db.execute(
|
|
11761
|
+
`SELECT table_name, column_name
|
|
11762
|
+
FROM information_schema.table_constraints t
|
|
11763
|
+
LEFT JOIN information_schema.key_column_usage k
|
|
11764
|
+
USING(constraint_name,table_schema,table_name)
|
|
11765
|
+
WHERE t.constraint_type='PRIMARY KEY'
|
|
11766
|
+
AND t.table_schema='${inputSchema}'`,
|
|
11767
|
+
[]
|
|
11768
|
+
);
|
|
11769
|
+
const tableToPk = {};
|
|
11770
|
+
const tableToPkRows = tablePks[0];
|
|
11771
|
+
for (const tableToPkRow of tableToPkRows) {
|
|
11772
|
+
const tableName = tableToPkRow["TABLE_NAME"];
|
|
11773
|
+
const columnName = tableToPkRow["COLUMN_NAME"];
|
|
11774
|
+
if (typeof tableToPk[tableName] === "undefined") {
|
|
11775
|
+
tableToPk[tableName] = [columnName];
|
|
11776
|
+
} else {
|
|
11777
|
+
tableToPk[tableName].push(columnName);
|
|
11778
|
+
}
|
|
11779
|
+
}
|
|
11766
11780
|
for (const [key, value] of Object.entries(tableToPk)) {
|
|
11767
11781
|
if (value.length > 1) {
|
|
11768
11782
|
result[key].compositePrimaryKeys = {
|
|
@@ -15011,7 +15025,7 @@ var init_sqlgenerator = __esm({
|
|
|
15011
15025
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
15012
15026
|
statement += ",\n";
|
|
15013
15027
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
15014
|
-
statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(
|
|
15028
|
+
statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(\`${compositePK4.columns.join(`\`,\``)}\`)`;
|
|
15015
15029
|
}
|
|
15016
15030
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
15017
15031
|
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
@@ -15054,7 +15068,7 @@ var init_sqlgenerator = __esm({
|
|
|
15054
15068
|
}
|
|
15055
15069
|
compositePKs.forEach((it) => {
|
|
15056
15070
|
statement += ",\n ";
|
|
15057
|
-
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")})
|
|
15071
|
+
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")})`;
|
|
15058
15072
|
});
|
|
15059
15073
|
for (let i = 0; i < referenceData.length; i++) {
|
|
15060
15074
|
const referenceAsString = referenceData[i];
|
|
@@ -15657,7 +15671,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
|
15657
15671
|
}
|
|
15658
15672
|
convert(statement) {
|
|
15659
15673
|
const { tableName, columnName } = statement;
|
|
15660
|
-
console.log(statement);
|
|
15661
15674
|
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
15662
15675
|
return `ALTER TABLE ${tableNameWithSchema} ADD PRIMARY KEY ("${columnName}");`;
|
|
15663
15676
|
}
|
|
@@ -16954,7 +16967,37 @@ var init_snapshotsDiffer = __esm({
|
|
|
16954
16967
|
}).strict();
|
|
16955
16968
|
applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
|
|
16956
16969
|
var _a, _b;
|
|
16957
|
-
|
|
16970
|
+
let diffResult;
|
|
16971
|
+
if (dialect6 === "mysql") {
|
|
16972
|
+
for (const tableName in json1.tables) {
|
|
16973
|
+
const table4 = json1.tables[tableName];
|
|
16974
|
+
for (const indexName4 in table4.indexes) {
|
|
16975
|
+
const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName4]);
|
|
16976
|
+
if (index4.isUnique) {
|
|
16977
|
+
table4.uniqueConstraints[indexName4] = MySqlSquasher.squashUnique({
|
|
16978
|
+
name: index4.name,
|
|
16979
|
+
columns: index4.columns
|
|
16980
|
+
});
|
|
16981
|
+
delete json1.tables[tableName].indexes[index4.name];
|
|
16982
|
+
}
|
|
16983
|
+
}
|
|
16984
|
+
}
|
|
16985
|
+
for (const tableName in json2.tables) {
|
|
16986
|
+
const table4 = json2.tables[tableName];
|
|
16987
|
+
for (const indexName4 in table4.indexes) {
|
|
16988
|
+
const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName4]);
|
|
16989
|
+
if (index4.isUnique) {
|
|
16990
|
+
table4.uniqueConstraints[indexName4] = MySqlSquasher.squashUnique({
|
|
16991
|
+
name: index4.name,
|
|
16992
|
+
columns: index4.columns
|
|
16993
|
+
});
|
|
16994
|
+
delete json2.tables[tableName].indexes[index4.name];
|
|
16995
|
+
}
|
|
16996
|
+
}
|
|
16997
|
+
}
|
|
16998
|
+
diffResult = applyJsonDiff(json1, json2);
|
|
16999
|
+
}
|
|
17000
|
+
diffResult = applyJsonDiff(json1, json2);
|
|
16958
17001
|
if (Object.keys(diffResult).length === 0) {
|
|
16959
17002
|
return { statements: [], sqlStatements: [], _meta: void 0 };
|
|
16960
17003
|
}
|
|
@@ -17125,7 +17168,6 @@ var init_snapshotsDiffer = __esm({
|
|
|
17125
17168
|
prevFull
|
|
17126
17169
|
);
|
|
17127
17170
|
}
|
|
17128
|
-
;
|
|
17129
17171
|
alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
|
|
17130
17172
|
it.name,
|
|
17131
17173
|
it.alteredCompositePKs,
|
|
@@ -17319,7 +17361,6 @@ var init_snapshotsDiffer = __esm({
|
|
|
17319
17361
|
jsonStatements.push(...jsonSQLiteCreateTables);
|
|
17320
17362
|
} else if (dialect6 === "pg") {
|
|
17321
17363
|
const jsonPgCreateTables = created.map((it) => {
|
|
17322
|
-
console.log(it);
|
|
17323
17364
|
return preparePgCreateTableJson(it, curFull);
|
|
17324
17365
|
});
|
|
17325
17366
|
jsonStatements.push(...jsonPgCreateTables);
|
|
@@ -37657,6 +37698,9 @@ import { sql } from "drizzle-orm"
|
|
|
37657
37698
|
if (typeof defaultValue === "string" && defaultValue.startsWith("(") && defaultValue.endsWith(")")) {
|
|
37658
37699
|
return `sql\`${defaultValue}\``;
|
|
37659
37700
|
}
|
|
37701
|
+
if (defaultValue === "NULL") {
|
|
37702
|
+
return `sql\`NULL\``;
|
|
37703
|
+
}
|
|
37660
37704
|
return defaultValue;
|
|
37661
37705
|
};
|
|
37662
37706
|
column5 = (type, name, defaultValue, autoincrement, casing) => {
|
|
@@ -51858,7 +51902,7 @@ init_source();
|
|
|
51858
51902
|
// package.json
|
|
51859
51903
|
var package_default = {
|
|
51860
51904
|
name: "drizzle-kit",
|
|
51861
|
-
version: "0.19.
|
|
51905
|
+
version: "0.19.5",
|
|
51862
51906
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
51863
51907
|
author: "Drizzle Team",
|
|
51864
51908
|
license: "MIT",
|
|
@@ -52700,7 +52744,7 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
|
|
|
52700
52744
|
var dbPushSqliteCommand = new import_commander.Command("push:sqlite").option(
|
|
52701
52745
|
"--config <config>",
|
|
52702
52746
|
"Path to a config.ts file, drizzle.config.ts by default"
|
|
52703
|
-
).option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "SQLite connection string").option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database path").option("--auth-token <authToken>", "SQLite database path").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
|
|
52747
|
+
).option("--schema <schema>", "Path to a schema file or folder").option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "SQLite connection string").option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database path").option("--auth-token <authToken>", "SQLite database path").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
|
|
52704
52748
|
printVersions();
|
|
52705
52749
|
assertPackages("drizzle-orm");
|
|
52706
52750
|
assertOrmCoreVersion();
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -12822,7 +12822,8 @@ var tableSquashed = objectType({
|
|
|
12822
12822
|
columns: recordType(stringType(), column),
|
|
12823
12823
|
indexes: recordType(stringType(), stringType()),
|
|
12824
12824
|
foreignKeys: recordType(stringType(), stringType()),
|
|
12825
|
-
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
12825
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
|
12826
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
|
12826
12827
|
}).strict();
|
|
12827
12828
|
var schemaSquashed = objectType({
|
|
12828
12829
|
version: literalType("5"),
|
|
@@ -13285,7 +13286,8 @@ var tableSquashed3 = objectType({
|
|
|
13285
13286
|
columns: recordType(stringType(), column3),
|
|
13286
13287
|
indexes: recordType(stringType(), stringType()),
|
|
13287
13288
|
foreignKeys: recordType(stringType(), stringType()),
|
|
13288
|
-
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
13289
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
|
13290
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
|
13289
13291
|
}).strict();
|
|
13290
13292
|
var schemaSquashed2 = objectType({
|
|
13291
13293
|
version: latestVersion,
|
|
@@ -13725,7 +13727,7 @@ var MySqlCreateTableConvertor = class extends Convertor {
|
|
|
13725
13727
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
13726
13728
|
statement += ",\n";
|
|
13727
13729
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
13728
|
-
statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(
|
|
13730
|
+
statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY(\`${compositePK4.columns.join(`\`,\``)}\`)`;
|
|
13729
13731
|
}
|
|
13730
13732
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
13731
13733
|
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
@@ -13768,7 +13770,7 @@ var SQLiteCreateTableConvertor = class extends Convertor {
|
|
|
13768
13770
|
}
|
|
13769
13771
|
compositePKs.forEach((it) => {
|
|
13770
13772
|
statement += ",\n ";
|
|
13771
|
-
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")})
|
|
13773
|
+
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")})`;
|
|
13772
13774
|
});
|
|
13773
13775
|
for (let i = 0; i < referenceData.length; i++) {
|
|
13774
13776
|
const referenceAsString = referenceData[i];
|
|
@@ -14371,7 +14373,6 @@ var PgAlterTableAlterColumnSetPrimaryKeyConvertor = class extends Convertor {
|
|
|
14371
14373
|
}
|
|
14372
14374
|
convert(statement) {
|
|
14373
14375
|
const { tableName, columnName } = statement;
|
|
14374
|
-
console.log(statement);
|
|
14375
14376
|
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
14376
14377
|
return `ALTER TABLE ${tableNameWithSchema} ADD PRIMARY KEY ("${columnName}");`;
|
|
14377
14378
|
}
|
|
@@ -15651,7 +15652,37 @@ var diffResultScheme = objectType({
|
|
|
15651
15652
|
}).strict();
|
|
15652
15653
|
var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
|
|
15653
15654
|
var _a, _b;
|
|
15654
|
-
|
|
15655
|
+
let diffResult;
|
|
15656
|
+
if (dialect3 === "mysql") {
|
|
15657
|
+
for (const tableName in json1.tables) {
|
|
15658
|
+
const table4 = json1.tables[tableName];
|
|
15659
|
+
for (const indexName in table4.indexes) {
|
|
15660
|
+
const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName]);
|
|
15661
|
+
if (index4.isUnique) {
|
|
15662
|
+
table4.uniqueConstraints[indexName] = MySqlSquasher.squashUnique({
|
|
15663
|
+
name: index4.name,
|
|
15664
|
+
columns: index4.columns
|
|
15665
|
+
});
|
|
15666
|
+
delete json1.tables[tableName].indexes[index4.name];
|
|
15667
|
+
}
|
|
15668
|
+
}
|
|
15669
|
+
}
|
|
15670
|
+
for (const tableName in json2.tables) {
|
|
15671
|
+
const table4 = json2.tables[tableName];
|
|
15672
|
+
for (const indexName in table4.indexes) {
|
|
15673
|
+
const index4 = MySqlSquasher.unsquashIdx(table4.indexes[indexName]);
|
|
15674
|
+
if (index4.isUnique) {
|
|
15675
|
+
table4.uniqueConstraints[indexName] = MySqlSquasher.squashUnique({
|
|
15676
|
+
name: index4.name,
|
|
15677
|
+
columns: index4.columns
|
|
15678
|
+
});
|
|
15679
|
+
delete json2.tables[tableName].indexes[index4.name];
|
|
15680
|
+
}
|
|
15681
|
+
}
|
|
15682
|
+
}
|
|
15683
|
+
diffResult = applyJsonDiff(json1, json2);
|
|
15684
|
+
}
|
|
15685
|
+
diffResult = applyJsonDiff(json1, json2);
|
|
15655
15686
|
if (Object.keys(diffResult).length === 0) {
|
|
15656
15687
|
return { statements: [], sqlStatements: [], _meta: void 0 };
|
|
15657
15688
|
}
|
|
@@ -15822,7 +15853,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15822
15853
|
prevFull
|
|
15823
15854
|
);
|
|
15824
15855
|
}
|
|
15825
|
-
;
|
|
15826
15856
|
alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
|
|
15827
15857
|
it.name,
|
|
15828
15858
|
it.alteredCompositePKs,
|
|
@@ -16016,7 +16046,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
16016
16046
|
jsonStatements.push(...jsonSQLiteCreateTables);
|
|
16017
16047
|
} else if (dialect3 === "pg") {
|
|
16018
16048
|
const jsonPgCreateTables = created.map((it) => {
|
|
16019
|
-
console.log(it);
|
|
16020
16049
|
return preparePgCreateTableJson(it, curFull);
|
|
16021
16050
|
});
|
|
16022
16051
|
jsonStatements.push(...jsonPgCreateTables);
|