Browse Source

Fix workaround foreign key checks

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

14
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();
}

1
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);

Loading…
Cancel
Save