diff --git a/dbUpdate.js b/dbUpdate.js index 62618583..1896d59c 100644 --- a/dbUpdate.js +++ b/dbUpdate.js @@ -17,10 +17,6 @@ const databaseVersions = [ { targetVersion: '8.0.0', queries: [ - `CREATE TABLE IF NOT EXISTS meta ( - version TEXT NOT NULL - );`, - 'INSERT OR IGNORE INTO meta ( version ) VALUES ( "8.0.0" );', `CREATE TABLE IF NOT EXISTS sounds_temp ( id INTEGER PRIMARY KEY, filename TEXT NOT NULL UNIQUE, @@ -63,6 +59,7 @@ const databaseVersions = [ ( "wahaha", "Wahaha", "Season 2", 0, "megumin" ); `, 'UPDATE sounds SET source = "no-source" WHERE source IS NULL;', + 'UPDATE sounds SET source = "no-source" WHERE source = "";', 'UPDATE sounds SET displayname = NULL where filename = "realname";', 'UPDATE sounds SET displayname = "Itai!" where filename = "itai";', 'UPDATE sounds SET displayname = "Yamero!" where filename = "yamero";', @@ -84,6 +81,12 @@ const databaseVersions = [ 'ALTER TABLE statistics_temp RENAME TO statistics;' ] }, + { + targetVersion: '8.0.1', + queries: [ + 'DROP TABLE meta;' + ] + } ]; const { Database } = require('sqlite3'); @@ -93,7 +96,8 @@ const { copyFile } = require('fs'); const { databasePath } = require('./src/config.json'); const db = new Database(join('src', databasePath)); -let currentVersion, newVersion, force; +let { version: currentVersion } = require('./package.json'); +let newVersion, force; const newVersionCLI = process.argv.filter(arg => arg.includes('newVersion='))[0]; const currentVersionCLI = process.argv.filter(arg => arg.includes('currentVersion='))[0]; @@ -103,7 +107,6 @@ if (newVersionCLI) newVersion = newVersionCLI.substr(newVersionCLI.indexOf('=') if (currentVersionCLI) currentVersion = currentVersionCLI.substr(currentVersionCLI.indexOf('=') + 1).trim(); if (forceCLI) force = true; - console.log('This is the megumin.love database migration tool.'); console.log('------------------------------------'); console.log('Creating database backup.'); @@ -115,39 +118,30 @@ copyFile(db.filename, `${db.filename}.bak`, err => { } }); -if (!currentVersion) { - db.get('SELECT version FROM meta', [], (selectErr, data) => { - if (selectErr || !data || (data && !data.version)) currentVersion = 'Unknown'; - else currentVersion = data.version; +if (!currentVersion) currentVersion = 'Unknown'; - console.log('------------------------------------'); - console.log(`Detected database version: ${currentVersion}`); - - if (currentVersion === 'Unknown') { - console.log('\nPlease enter your version of megumin.love before the update (e.g. 6.0.2 or 7.1.0).'); - - const currentVersionInput = createInterface({ - input: process.stdin, - output: process.stdout, - prompt: 'Starting database version: ' - }); - - currentVersionInput.prompt(); - - currentVersionInput.on('line', ver => { - currentVersion = ver.trim(); - currentVersionInput.close(); - }); - - currentVersionInput.on('close', () => { - if (!newVersion) promptNewVersion(); - else executeUpdateQueries(); - }); - } - else { - if (!newVersion) promptNewVersion(); // eslint-disable-line no-lonely-if - else executeUpdateQueries(); - } +console.log('------------------------------------'); +console.log(`Detected database version: ${currentVersion}`); + +if (currentVersion === 'Unknown') { + console.log('\nPlease enter your version of megumin.love before the update (e.g. 6.0.2 or 7.1.0).'); + + const currentVersionInput = createInterface({ + input: process.stdin, + output: process.stdout, + prompt: 'Starting database version: ' + }); + + currentVersionInput.prompt(); + + currentVersionInput.on('line', ver => { + currentVersion = ver.trim(); + currentVersionInput.close(); + }); + + currentVersionInput.on('close', () => { + if (!newVersion) promptNewVersion(); + else executeUpdateQueries(); }); } else { diff --git a/src/db/default.db b/src/db/default.db index 942b2df0..a4f292a3 100644 Binary files a/src/db/default.db and b/src/db/default.db differ diff --git a/src/server.js b/src/server.js index 310e70c5..7875aa24 100644 --- a/src/server.js +++ b/src/server.js @@ -10,10 +10,10 @@ const { join } = require('path'); const { readdirSync, unlink, rename, copyFile, existsSync, mkdir } = require('fs'); const Logger = require('./resources/js/Logger'); const config = require('./config.json'); -const { version: packageVersion } = require('../package.json'); +const { version } = require('../package.json'); let counter = 0, daily = 0, weekly = 0, monthly = 0, yearly = 0, average = 0, fetchedDaysAmount = 1; -let sounds = [], statistics = [], chartData = [], milestones = [], version = ''; +let sounds = [], statistics = [], chartData = [], milestones = []; // On-boot database interaction const db = new Database(config.databasePath, () => { @@ -23,16 +23,6 @@ const db = new Database(config.databasePath, () => { }); db.serialize(() => { - db.get('SELECT version FROM meta', [], (selectErr, row) => { - if (!row || !row.version) { - version = packageVersion; - return Logger.warn('No version number found, substituted by package.json value. You should consider fixing this in the database.'); - } - version = row.version; - - return Logger.info('Version number loaded.'); - }); - db.get('SELECT counter FROM main_counter', [], (selectErr, row) => { if (!row || row.counter === undefined) { db.run('INSERT INTO main_counter ( counter ) VALUES ( 0 )');