Browse Source

Remove workaround for foreign keys

pull/6/head
Menci 7 years ago
parent
commit
80a617e332
  1. 2
      README.md
  2. 13
      app.js
  3. 1
      models/problem.js

2
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`

13
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() {

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

Loading…
Cancel
Save