diff --git a/app.js b/app.js index 24bde8a..a85bba5 100644 --- a/app.js +++ b/app.js @@ -75,11 +75,15 @@ global.syzoj = { global.Promise = Sequelize.Promise; this.db.countQuery = async (sql, options) => (await this.db.query(`SELECT COUNT(*) FROM (${sql}) AS \`__tmp_table\``, options))[0][0]['COUNT(*)']; - if (this.config.db.dialect.toLowerCase() === 'mysql') { - await this.db.query('SET foreign_key_checks = 0;'); - } else if (this.config.db.dialect.toLowerCase() === 'sqlite') { - await this.db.query('PRAGMA foreign_keys = OFF;'); - } else { + this.db.workAroundForeignKeyChecks = async () => { + if (this.config.db.dialect.toLowerCase() === 'mysql') { + await this.db.query('SET foreign_key_checks = 0;'); + } else if (this.config.db.dialect.toLowerCase() === 'sqlite') { + await this.db.query('PRAGMA foreign_keys = OFF;'); + } + } + + if (!['mysql', 'sqlite'].includes(this.config.db.dialect.toLowerCase())) { this.log('Unsupported database: ' + this.config.db.dialect); process.exit(); } diff --git a/models/problem.js b/models/problem.js index 5cbaea7..bcba743 100644 --- a/models/problem.js +++ b/models/problem.js @@ -428,6 +428,7 @@ class Problem extends Model { async changeID(id) { id = parseInt(id); + await db.workAroundForeignKeyChecks(); await db.query('UPDATE `problem` SET `id` = ' + id + ' WHERE `id` = ' + this.id); await db.query('UPDATE `judge_state` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id); await db.query('UPDATE `problem_tag_map` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);