mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
Merge branch 'main' into enhancement/date-time-picker-ds-in-strapi
This commit is contained in:
commit
412533434c
@ -198,12 +198,11 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle databases that don't support window function ROW_NUMBER
|
switch (strapi.db.dialect.client) {
|
||||||
if (!strapi.db.dialect.supportsWindowFunctions()) {
|
case 'mysql':
|
||||||
await cleanOrderColumnsForOldDatabases({ id, attribute, db, inverseRelIds, transaction: trx });
|
await cleanOrderColumnsForInnoDB({ id, attribute, db, inverseRelIds, transaction: trx });
|
||||||
return;
|
break;
|
||||||
}
|
default: {
|
||||||
|
|
||||||
const { joinTable } = attribute;
|
const { joinTable } = attribute;
|
||||||
const { joinColumn, inverseJoinColumn, orderColumnName, inverseOrderColumnName } = joinTable;
|
const { joinColumn, inverseJoinColumn, orderColumnName, inverseOrderColumnName } = joinTable;
|
||||||
const update = [];
|
const update = [];
|
||||||
@ -231,27 +230,10 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
|
|||||||
whereBinding.push(inverseJoinColumn.name, ...inverseRelIds);
|
whereBinding.push(inverseJoinColumn.name, ...inverseRelIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const joinTableName = addSchema(joinTable.name);
|
||||||
|
|
||||||
// raw query as knex doesn't allow updating from a subquery
|
// raw query as knex doesn't allow updating from a subquery
|
||||||
// https://github.com/knex/knex/issues/2504
|
// https://github.com/knex/knex/issues/2504
|
||||||
switch (strapi.db.dialect.client) {
|
|
||||||
case 'mysql':
|
|
||||||
await db.connection
|
|
||||||
.raw(
|
|
||||||
`UPDATE
|
|
||||||
?? as a,
|
|
||||||
(
|
|
||||||
SELECT ${select.join(', ')}
|
|
||||||
FROM ??
|
|
||||||
WHERE ${where.join(' OR ')}
|
|
||||||
) AS b
|
|
||||||
SET ${update.join(', ')}
|
|
||||||
WHERE b.id = a.id`,
|
|
||||||
[joinTable.name, ...selectBinding, joinTable.name, ...whereBinding, ...updateBinding]
|
|
||||||
)
|
|
||||||
.transacting(trx);
|
|
||||||
break;
|
|
||||||
default: {
|
|
||||||
const joinTableName = addSchema(joinTable.name);
|
|
||||||
await db.connection
|
await db.connection
|
||||||
.raw(
|
.raw(
|
||||||
`UPDATE ?? as a
|
`UPDATE ?? as a
|
||||||
@ -265,7 +247,7 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
|
|||||||
[joinTableName, ...updateBinding, ...selectBinding, joinTableName, ...whereBinding]
|
[joinTableName, ...updateBinding, ...selectBinding, joinTableName, ...whereBinding]
|
||||||
)
|
)
|
||||||
.transacting(trx);
|
.transacting(trx);
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
`UPDATE :joinTable: as a
|
`UPDATE :joinTable: as a
|
||||||
SET :orderColumn: = b.src_order, :inverseOrderColumn: = b.inv_order
|
SET :orderColumn: = b.src_order, :inverseOrderColumn: = b.inv_order
|
||||||
@ -280,9 +262,14 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
|
|||||||
WHERE b.id = a.id`,
|
WHERE b.id = a.id`,
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const cleanOrderColumnsForOldDatabases = async ({
|
/*
|
||||||
|
* Ensure that orders are following a 1, 2, 3 sequence, without gap.
|
||||||
|
* The use of a temporary table instead of a window function makes the query compatible with MySQL 5 and prevents some deadlocks to happen in innoDB databases
|
||||||
|
*/
|
||||||
|
const cleanOrderColumnsForInnoDB = async ({
|
||||||
id,
|
id,
|
||||||
attribute,
|
attribute,
|
||||||
db,
|
db,
|
||||||
@ -319,6 +306,9 @@ const cleanOrderColumnsForOldDatabases = async ({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.transacting(trx);
|
.transacting(trx);
|
||||||
|
|
||||||
|
// raw query as knex doesn't allow updating from a subquery
|
||||||
|
// https://github.com/knex/knex/issues/2504
|
||||||
await db.connection
|
await db.connection
|
||||||
.raw(
|
.raw(
|
||||||
`UPDATE ?? as a, (SELECT * FROM ??) AS b
|
`UPDATE ?? as a, (SELECT * FROM ??) AS b
|
||||||
|
Loading…
x
Reference in New Issue
Block a user