drizzle-kit 0.19.4-befd1c5 → 0.19.4
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 +490 -150
- package/package.json +2 -2
- package/utils.js +74 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-kit",
|
|
3
|
-
"version": "0.19.4
|
|
3
|
+
"version": "0.19.4",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Drizzle Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"better-sqlite3": "^8.4.0",
|
|
80
80
|
"dockerode": "^3.3.4",
|
|
81
81
|
"dotenv": "^16.0.3",
|
|
82
|
-
"drizzle-orm": "0.27.
|
|
82
|
+
"drizzle-orm": "0.27.1-8a21e7b",
|
|
83
83
|
"eslint": "^8.29.0",
|
|
84
84
|
"eslint-config-prettier": "^8.5.0",
|
|
85
85
|
"eslint-plugin-prettier": "^4.2.1",
|
package/utils.js
CHANGED
|
@@ -13237,12 +13237,17 @@ var tableV33 = objectType({
|
|
|
13237
13237
|
indexes: recordType(stringType(), index3),
|
|
13238
13238
|
foreignKeys: recordType(stringType(), fk3)
|
|
13239
13239
|
}).strict();
|
|
13240
|
+
var uniqueConstraint3 = objectType({
|
|
13241
|
+
name: stringType(),
|
|
13242
|
+
columns: stringType().array()
|
|
13243
|
+
}).strict();
|
|
13240
13244
|
var table3 = objectType({
|
|
13241
13245
|
name: stringType(),
|
|
13242
13246
|
columns: recordType(stringType(), column3),
|
|
13243
13247
|
indexes: recordType(stringType(), index3),
|
|
13244
13248
|
foreignKeys: recordType(stringType(), fk3),
|
|
13245
|
-
compositePrimaryKeys: recordType(stringType(), compositePK3)
|
|
13249
|
+
compositePrimaryKeys: recordType(stringType(), compositePK3),
|
|
13250
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
|
|
13246
13251
|
}).strict();
|
|
13247
13252
|
var dialect2 = enumType(["sqlite"]);
|
|
13248
13253
|
var schemaHash3 = objectType({
|
|
@@ -13303,6 +13308,13 @@ var SQLiteSquasher = {
|
|
|
13303
13308
|
});
|
|
13304
13309
|
return result;
|
|
13305
13310
|
},
|
|
13311
|
+
squashUnique: (unq) => {
|
|
13312
|
+
return `${unq.name};${unq.columns.join(",")}`;
|
|
13313
|
+
},
|
|
13314
|
+
unsquashUnique: (unq) => {
|
|
13315
|
+
const [name, columns] = unq.split(";");
|
|
13316
|
+
return { name, columns: columns.split(",") };
|
|
13317
|
+
},
|
|
13306
13318
|
squashFK: (fk4) => {
|
|
13307
13319
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
|
|
13308
13320
|
},
|
|
@@ -13666,9 +13678,9 @@ var PgCreateTableConvertor = class extends Convertor {
|
|
|
13666
13678
|
const primaryKeyStatement = column4.primaryKey ? " PRIMARY KEY" : "";
|
|
13667
13679
|
const notNullStatement = column4.notNull ? " NOT NULL" : "";
|
|
13668
13680
|
const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
|
|
13669
|
-
const
|
|
13681
|
+
const uniqueConstraint4 = column4.isUnique ? ` CONSTRAINT "${column4.uniqueName}" UNIQUE${column4.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
|
|
13670
13682
|
const type = isPgNativeType(column4.type) ? column4.type : `"${column4.type}"`;
|
|
13671
|
-
statement += ` "${column4.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${
|
|
13683
|
+
statement += ` "${column4.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint4}`;
|
|
13672
13684
|
statement += i === columns.length - 1 ? "" : ",\n";
|
|
13673
13685
|
}
|
|
13674
13686
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
@@ -13677,10 +13689,10 @@ var PgCreateTableConvertor = class extends Convertor {
|
|
|
13677
13689
|
statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
13678
13690
|
}
|
|
13679
13691
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
13680
|
-
for (const
|
|
13692
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
13681
13693
|
statement += ",\n";
|
|
13682
|
-
const unsquashedUnique = PgSquasher.unsquashUnique(
|
|
13683
|
-
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE("${unsquashedUnique.columns.join(`","`)}")`;
|
|
13694
|
+
const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint4);
|
|
13695
|
+
statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
|
|
13684
13696
|
}
|
|
13685
13697
|
}
|
|
13686
13698
|
statement += `
|
|
@@ -13713,13 +13725,13 @@ var MySqlCreateTableConvertor = class extends Convertor {
|
|
|
13713
13725
|
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
13714
13726
|
statement += ",\n";
|
|
13715
13727
|
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
13716
|
-
statement += ` CONSTRAINT
|
|
13728
|
+
statement += ` CONSTRAINT \`${st.compositePkName}\` PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
|
|
13717
13729
|
}
|
|
13718
13730
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
13719
|
-
for (const
|
|
13731
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
13720
13732
|
statement += ",\n";
|
|
13721
|
-
const unsquashedUnique = MySqlSquasher.unsquashUnique(
|
|
13722
|
-
statement += ` CONSTRAINT
|
|
13733
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
|
13734
|
+
statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
13723
13735
|
}
|
|
13724
13736
|
}
|
|
13725
13737
|
statement += `
|
|
@@ -13734,21 +13746,28 @@ var SQLiteCreateTableConvertor = class extends Convertor {
|
|
|
13734
13746
|
return statement.type === "sqlite_create_table" && dialect3 === "sqlite";
|
|
13735
13747
|
}
|
|
13736
13748
|
convert(st) {
|
|
13737
|
-
const {
|
|
13749
|
+
const {
|
|
13750
|
+
tableName,
|
|
13751
|
+
columns,
|
|
13752
|
+
referenceData,
|
|
13753
|
+
compositePKs,
|
|
13754
|
+
uniqueConstraints
|
|
13755
|
+
} = st;
|
|
13738
13756
|
let statement = "";
|
|
13739
|
-
statement += `CREATE TABLE \`${tableName}\` (
|
|
13757
|
+
statement += `CREATE TABLE \`${tableName}\` (
|
|
13758
|
+
`;
|
|
13740
13759
|
for (let i = 0; i < columns.length; i++) {
|
|
13741
13760
|
const column4 = columns[i];
|
|
13742
13761
|
const primaryKeyStatement = column4.primaryKey ? " PRIMARY KEY" : "";
|
|
13743
13762
|
const notNullStatement = column4.notNull ? " NOT NULL" : "";
|
|
13744
13763
|
const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
|
|
13745
13764
|
const autoincrementStatement = column4.autoincrement ? " AUTOINCREMENT" : "";
|
|
13746
|
-
statement += "
|
|
13765
|
+
statement += " ";
|
|
13747
13766
|
statement += `\`${column4.name}\` ${column4.type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}`;
|
|
13748
|
-
statement += "
|
|
13767
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
|
13749
13768
|
}
|
|
13750
13769
|
compositePKs.forEach((it) => {
|
|
13751
|
-
statement += "
|
|
13770
|
+
statement += ",\n ";
|
|
13752
13771
|
statement += `PRIMARY KEY(${it.map((it2) => `\`${it2}\``).join(", ")}),`;
|
|
13753
13772
|
});
|
|
13754
13773
|
for (let i = 0; i < referenceData.length; i++) {
|
|
@@ -13766,11 +13785,17 @@ var SQLiteCreateTableConvertor = class extends Convertor {
|
|
|
13766
13785
|
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
|
13767
13786
|
const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
|
|
13768
13787
|
const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
|
|
13788
|
+
statement += ",";
|
|
13769
13789
|
statement += "\n ";
|
|
13770
13790
|
statement += `FOREIGN KEY (${fromColumnsString}) REFERENCES \`${tableTo}\`(${toColumnsString})${onUpdateStatement}${onDeleteStatement}`;
|
|
13771
|
-
statement += ",";
|
|
13772
13791
|
}
|
|
13773
|
-
|
|
13792
|
+
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
|
13793
|
+
for (const uniqueConstraint4 of uniqueConstraints) {
|
|
13794
|
+
statement += ",\n";
|
|
13795
|
+
const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
|
|
13796
|
+
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
|
13797
|
+
}
|
|
13798
|
+
}
|
|
13774
13799
|
statement += `
|
|
13775
13800
|
`;
|
|
13776
13801
|
statement += `);`;
|
|
@@ -13786,7 +13811,7 @@ var PgAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
|
13786
13811
|
convert(statement) {
|
|
13787
13812
|
const unsquashed = PgSquasher.unsquashUnique(statement.data);
|
|
13788
13813
|
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
|
13789
|
-
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE("${unsquashed.columns.join('","')}");`;
|
|
13814
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE${unsquashed.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashed.columns.join('","')}");`;
|
|
13790
13815
|
}
|
|
13791
13816
|
};
|
|
13792
13817
|
var PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
@@ -13819,6 +13844,32 @@ var MySQLAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
|
13819
13844
|
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
|
|
13820
13845
|
}
|
|
13821
13846
|
};
|
|
13847
|
+
var SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
|
13848
|
+
can(statement, dialect3) {
|
|
13849
|
+
return statement.type === "create_unique_constraint" && dialect3 === "sqlite";
|
|
13850
|
+
}
|
|
13851
|
+
convert(statement) {
|
|
13852
|
+
return `/*
|
|
13853
|
+
SQLite does not support "Adding unique constraint to an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
|
13854
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
|
13855
|
+
|
|
13856
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
|
13857
|
+
*/`;
|
|
13858
|
+
}
|
|
13859
|
+
};
|
|
13860
|
+
var SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
|
13861
|
+
can(statement, dialect3) {
|
|
13862
|
+
return statement.type === "delete_unique_constraint" && dialect3 === "sqlite";
|
|
13863
|
+
}
|
|
13864
|
+
convert(statement) {
|
|
13865
|
+
return `/*
|
|
13866
|
+
SQLite does not support "Dropping unique constraint from an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
|
13867
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
|
13868
|
+
|
|
13869
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
|
13870
|
+
*/`;
|
|
13871
|
+
}
|
|
13872
|
+
};
|
|
13822
13873
|
var CreateTypeEnumConvertor = class extends Convertor {
|
|
13823
13874
|
can(statement) {
|
|
13824
13875
|
return statement.type === "create_type_enum";
|
|
@@ -14812,6 +14863,8 @@ convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
|
|
|
14812
14863
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
|
14813
14864
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
|
14814
14865
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
|
14866
|
+
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
|
14867
|
+
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
|
14815
14868
|
convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
|
|
14816
14869
|
convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
|
|
14817
14870
|
convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
|
|
@@ -14900,7 +14953,7 @@ var prepareMySqlCreateTableJson = (table4, json2) => {
|
|
|
14900
14953
|
};
|
|
14901
14954
|
};
|
|
14902
14955
|
var prepareSQLiteCreateTable = (table4) => {
|
|
14903
|
-
const { name, columns } = table4;
|
|
14956
|
+
const { name, columns, uniqueConstraints } = table4;
|
|
14904
14957
|
const references2 = Object.values(table4.foreignKeys);
|
|
14905
14958
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
|
14906
14959
|
(it) => SQLiteSquasher.unsquashPK(it)
|
|
@@ -14910,7 +14963,8 @@ var prepareSQLiteCreateTable = (table4) => {
|
|
|
14910
14963
|
tableName: name,
|
|
14911
14964
|
columns: Object.values(columns),
|
|
14912
14965
|
referenceData: references2,
|
|
14913
|
-
compositePKs: composites
|
|
14966
|
+
compositePKs: composites,
|
|
14967
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
|
14914
14968
|
};
|
|
14915
14969
|
};
|
|
14916
14970
|
var prepareDropTableJson = (table4) => {
|