Browse Source

Fix workaround foreign key checks

pull/6/head
Menci 8 years ago
parent
commit
0f6324f704
  1. 6
      app.js
  2. 1
      models/problem.js

6
app.js

@ -75,11 +75,15 @@ global.syzoj = {
global.Promise = Sequelize.Promise; 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(*)']; this.db.countQuery = async (sql, options) => (await this.db.query(`SELECT COUNT(*) FROM (${sql}) AS \`__tmp_table\``, options))[0][0]['COUNT(*)'];
this.db.workAroundForeignKeyChecks = async () => {
if (this.config.db.dialect.toLowerCase() === 'mysql') { if (this.config.db.dialect.toLowerCase() === 'mysql') {
await this.db.query('SET foreign_key_checks = 0;'); await this.db.query('SET foreign_key_checks = 0;');
} else if (this.config.db.dialect.toLowerCase() === 'sqlite') { } else if (this.config.db.dialect.toLowerCase() === 'sqlite') {
await this.db.query('PRAGMA foreign_keys = OFF;'); await this.db.query('PRAGMA foreign_keys = OFF;');
} else { }
}
if (!['mysql', 'sqlite'].includes(this.config.db.dialect.toLowerCase())) {
this.log('Unsupported database: ' + this.config.db.dialect); this.log('Unsupported database: ' + this.config.db.dialect);
process.exit(); process.exit();
} }

1
models/problem.js

@ -428,6 +428,7 @@ class Problem extends Model {
async changeID(id) { async changeID(id) {
id = parseInt(id); id = parseInt(id);
await db.workAroundForeignKeyChecks();
await db.query('UPDATE `problem` SET `id` = ' + id + ' WHERE `id` = ' + this.id); 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 `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); await db.query('UPDATE `problem_tag_map` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id);

Loading…
Cancel
Save