@strapi/database 5.0.0-beta.5 → 5.0.0-beta.7
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/dist/index.mjs
CHANGED
|
@@ -1144,14 +1144,6 @@ const createHelpers = (db) => {
|
|
|
1144
1144
|
};
|
|
1145
1145
|
const alterTable = async (schemaBuilder, table) => {
|
|
1146
1146
|
await schemaBuilder.alterTable(table.name, (tableBuilder) => {
|
|
1147
|
-
for (const removedIndex of table.indexes.removed) {
|
|
1148
|
-
debug$2(`Dropping index ${removedIndex.name} on ${table.name}`);
|
|
1149
|
-
dropIndex(tableBuilder, removedIndex);
|
|
1150
|
-
}
|
|
1151
|
-
for (const updateddIndex of table.indexes.updated) {
|
|
1152
|
-
debug$2(`Dropping updated index ${updateddIndex.name} on ${table.name}`);
|
|
1153
|
-
dropIndex(tableBuilder, updateddIndex.object);
|
|
1154
|
-
}
|
|
1155
1147
|
for (const removedForeignKey of table.foreignKeys.removed) {
|
|
1156
1148
|
debug$2(`Dropping foreign key ${removedForeignKey.name} on ${table.name}`);
|
|
1157
1149
|
dropForeignKey(tableBuilder, removedForeignKey);
|
|
@@ -1164,6 +1156,23 @@ const createHelpers = (db) => {
|
|
|
1164
1156
|
debug$2(`Dropping column ${removedColumn.name} on ${table.name}`);
|
|
1165
1157
|
dropColumn(tableBuilder, removedColumn);
|
|
1166
1158
|
}
|
|
1159
|
+
const isMySQL = db.config.connection.client === "mysql";
|
|
1160
|
+
const ignoreForeignKeyNames = isMySQL ? [
|
|
1161
|
+
...table.foreignKeys.removed.map((fk) => fk.name),
|
|
1162
|
+
...table.foreignKeys.updated.map((fk) => fk.name)
|
|
1163
|
+
] : [];
|
|
1164
|
+
for (const removedIndex of table.indexes.removed) {
|
|
1165
|
+
if (!ignoreForeignKeyNames.includes(removedIndex.name)) {
|
|
1166
|
+
debug$2(`Dropping index ${removedIndex.name} on ${table.name}`);
|
|
1167
|
+
dropIndex(tableBuilder, removedIndex);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
for (const updatedIndex of table.indexes.updated) {
|
|
1171
|
+
if (!ignoreForeignKeyNames.includes(updatedIndex.name)) {
|
|
1172
|
+
debug$2(`Dropping updated index ${updatedIndex.name} on ${table.name}`);
|
|
1173
|
+
dropIndex(tableBuilder, updatedIndex.object);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1167
1176
|
for (const updatedColumn of table.columns.updated) {
|
|
1168
1177
|
debug$2(`Updating column ${updatedColumn.name} on ${table.name}`);
|
|
1169
1178
|
const { object } = updatedColumn;
|
|
@@ -5986,15 +5995,13 @@ const migrateDocumentIdsWithLocalizations = async (db, knex2, meta) => {
|
|
|
5986
5995
|
} while (ids.length > 0);
|
|
5987
5996
|
};
|
|
5988
5997
|
const migrationDocumentIds = async (db, knex2, meta) => {
|
|
5989
|
-
let
|
|
5998
|
+
let updatedRows;
|
|
5990
5999
|
do {
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
}
|
|
5997
|
-
} while (run);
|
|
6000
|
+
updatedRows = await knex2(meta.tableName).update({ document_id: createId() }).whereIn(
|
|
6001
|
+
"id",
|
|
6002
|
+
knex2(meta.tableName).select("id").from(knex2(meta.tableName).select("id").whereNull("document_id").limit(1).as("sub_query"))
|
|
6003
|
+
);
|
|
6004
|
+
} while (updatedRows > 0);
|
|
5998
6005
|
};
|
|
5999
6006
|
const createDocumentIdColumn = async (knex2, tableName) => {
|
|
6000
6007
|
await knex2.schema.alterTable(tableName, (table) => {
|