1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

feat(MySQL): option to disable foreign key checks when empty a table

This commit is contained in:
2022-06-29 10:48:21 +02:00
parent 5f57a9f60d
commit 902c29ffa5
10 changed files with 51 additions and 22 deletions

View File

@ -912,8 +912,15 @@ export class MySQLClient extends AntaresCore {
return await this.raw(sql);
}
async truncateTable (params: { schema: string; table: string }) {
const sql = `TRUNCATE TABLE \`${params.schema}\`.\`${params.table}\``;
async truncateTable (params: { schema: string; table: string; force: boolean }) {
let sql = `TRUNCATE TABLE \`${params.schema}\`.\`${params.table}\`;`;
if (params.force) {
sql = `
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
${sql}
SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1);
`;
}
return await this.raw(sql);
}