From 80a617e332efb784a65281c4f24e6f92a8d55c61 Mon Sep 17 00:00:00 2001 From: Menci Date: Sun, 16 Apr 2017 16:37:29 +0800 Subject: [PATCH] Remove workaround for foreign keys --- README.md | 2 +- app.js | 13 ------------- models/problem.js | 1 - 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/README.md b/README.md index 4fb62b9..243e2f4 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Install dependencies with `npm install` or `yarn`. Copy the `config-example.json` file to `config.json`, and change the configures. ## Database -SYZOJ 2 uses [Sequelize](http://sequelizejs.com), which supports many database systems, including MySQL and Sqlite. But SYZOJ 2 supports **only** MySQL and Sqlite. +SYZOJ 2 uses [Sequelize](http://sequelizejs.com), which supports many database systems, including MySQL and Sqlite. By default it use the Sqlite database `syzoj.db`, you can change it in `config.json` diff --git a/app.js b/app.js index a85bba5..46f10df 100644 --- a/app.js +++ b/app.js @@ -75,19 +75,6 @@ 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(*)']; - 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(); - } - this.loadModels(); }, loadModules() { diff --git a/models/problem.js b/models/problem.js index bcba743..5cbaea7 100644 --- a/models/problem.js +++ b/models/problem.js @@ -428,7 +428,6 @@ 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);