diff --git a/src/entities/entity.js b/src/entities/entity.js index a5f1495d4..395cbae9c 100644 --- a/src/entities/entity.js +++ b/src/entities/entity.js @@ -21,10 +21,7 @@ class Entity { contentToHash += "|" + this[propertyName]; } - // this IF is to ease the migration from before hashed options, can be later removed - if (this.constructor.tableName !== 'options' || this.isSynced) { - this["hash"] = utils.hash(contentToHash).substr(0, 10); - } + this["hash"] = utils.hash(contentToHash).substr(0, 10); } async save() { diff --git a/src/public/javascripts/migration.js b/src/public/javascripts/migration.js deleted file mode 100644 index c743a4d19..000000000 --- a/src/public/javascripts/migration.js +++ /dev/null @@ -1,46 +0,0 @@ -import server from './services/server.js'; - -$(document).ready(async () => { - const {appDbVersion, dbVersion} = await server.get('migration'); - - console.log("HI", {appDbVersion, dbVersion}); - - if (appDbVersion === dbVersion) { - $("#up-to-date").show(); - } - else { - $("#need-to-migrate").show(); - - $("#app-db-version").html(appDbVersion); - $("#db-version").html(dbVersion); - } -}); - -$("#run-migration").click(async () => { - $("#run-migration").prop("disabled", true); - - $("#migration-result").show(); - - const result = await server.post('migration'); - - for (const migration of result.migrations) { - const row = $('') - .append($('').html(migration.dbVersion)) - .append($('').html(migration.name)) - .append($('').html(migration.success ? 'Yes' : 'No')) - .append($('').html(migration.success ? 'N/A' : migration.error)); - - if (!migration.success) { - row.addClass("danger"); - } - - $("#migration-table").append(row); - } -}); - -// copy of this shortcut to be able to debug migration problems -$(document).bind('keydown', 'ctrl+shift+i', () => { - require('electron').remote.getCurrentWindow().toggleDevTools(); - - return false; -}); \ No newline at end of file diff --git a/src/public/javascripts/services/server.js b/src/public/javascripts/services/server.js index a0619c6b1..86beca5aa 100644 --- a/src/public/javascripts/services/server.js +++ b/src/public/javascripts/services/server.js @@ -5,7 +5,7 @@ import infoService from "./info.js"; function getHeaders() { let protectedSessionId = null; - try { // this is because protected session might not be declared in some cases - like when it's included in migration page + try { // this is because protected session might not be declared in some cases protectedSessionId = protectedSessionHolder.getProtectedSessionId(); } catch(e) {} diff --git a/src/routes/api/migration.js b/src/routes/api/migration.js deleted file mode 100644 index 26121eb54..000000000 --- a/src/routes/api/migration.js +++ /dev/null @@ -1,25 +0,0 @@ -"use strict"; - -const optionService = require('../../services/options'); -const migrationService = require('../../services/migration'); -const appInfo = require('../../services/app_info'); - -async function getMigrationInfo() { - return { - dbVersion: parseInt(await optionService.getOption('dbVersion')), - appDbVersion: appInfo.dbVersion - }; -} - -async function executeMigration() { - const migrations = await migrationService.migrate(); - - return { - migrations: migrations - }; -} - -module.exports = { - getMigrationInfo, - executeMigration -}; \ No newline at end of file diff --git a/src/routes/migration.js b/src/routes/migration.js deleted file mode 100644 index 51045e4c9..000000000 --- a/src/routes/migration.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -function migrationPage(req, res) { - res.render('migration', {}); -} - -module.exports = { - migrationPage -}; diff --git a/src/routes/routes.js b/src/routes/routes.js index f899622e0..62bd76b9c 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -1,6 +1,5 @@ const indexRoute = require('./index'); const loginRoute = require('./login'); -const migrationRoute = require('./migration'); const setupRoute = require('./setup'); const multer = require('multer')(); @@ -14,7 +13,6 @@ const noteRevisionsApiRoute = require('./api/note_revisions'); const recentChangesApiRoute = require('./api/recent_changes'); const optionsApiRoute = require('./api/options'); const passwordApiRoute = require('./api/password'); -const migrationApiRoute = require('./api/migration'); const syncApiRoute = require('./api/sync'); const loginApiRoute = require('./api/login'); const eventLogRoute = require('./api/event_log'); @@ -96,7 +94,6 @@ function register(app) { route(GET, '/login', [], loginRoute.loginPage); route(POST, '/login', [], loginRoute.login); route(POST, '/logout', [auth.checkAuth], loginRoute.logout); - route(GET, '/migration', [auth.checkAuthForMigrationPage], migrationRoute.migrationPage); route(GET, '/setup', [auth.checkAppNotInitialized], setupRoute.setupPage); apiRoute(GET, '/api/tree', treeApiRoute.getTree); @@ -180,9 +177,6 @@ function register(app) { apiRoute(GET, '/api/search/:searchString', searchRoute.searchNotes); apiRoute(POST, '/api/search/:searchString', searchRoute.saveSearchToNote); - route(GET, '/api/migration', [auth.checkApiAuthForMigrationPage], migrationApiRoute.getMigrationInfo, apiResultHandler); - route(POST, '/api/migration', [auth.checkApiAuthForMigrationPage], migrationApiRoute.executeMigration, apiResultHandler); - route(POST, '/api/login/sync', [], loginApiRoute.loginSync, apiResultHandler); // this is for entering protected mode so user has to be already logged-in (that's the reason we don't require username) apiRoute(POST, '/api/login/protected', loginApiRoute.loginToProtectedSession); diff --git a/src/services/auth.js b/src/services/auth.js index a24b79784..33682a6db 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -12,18 +12,6 @@ async function checkAuth(req, res, next) { else if (!req.session.loggedIn && !utils.isElectron()) { res.redirect("login"); } - else if (!await sqlInit.isDbUpToDate()) { - res.redirect("migration"); - } - else { - next(); - } -} - -async function checkAuthForMigrationPage(req, res, next) { - if (!req.session.loggedIn && !utils.isElectron()) { - res.redirect("login"); - } else { next(); } @@ -35,27 +23,12 @@ async function checkApiAuthOrElectron(req, res, next) { if (!req.session.loggedIn && !utils.isElectron()) { res.status(401).send("Not authorized"); } - else if (await sqlInit.isDbUpToDate()) { - next(); - } else { - res.status(409).send("Mismatched app versions"); // need better response than that + next(); } } async function checkApiAuth(req, res, next) { - if (!req.session.loggedIn) { - res.status(401).send("Not authorized"); - } - else if (await sqlInit.isDbUpToDate()) { - next(); - } - else { - res.status(409).send("Mismatched app versions"); // need better response than that - } -} - -async function checkApiAuthForMigrationPage(req, res, next) { if (!req.session.loggedIn) { res.status(401).send("Not authorized"); } @@ -79,19 +52,14 @@ async function checkSenderToken(req, res, next) { if (await sql.getValue("SELECT COUNT(*) FROM api_tokens WHERE isDeleted = 0 AND token = ?", [token]) === 0) { res.status(401).send("Not authorized"); } - else if (await sqlInit.isDbUpToDate()) { - next(); - } else { - res.status(409).send("Mismatched app versions"); // need better response than that + next(); } } module.exports = { checkAuth, - checkAuthForMigrationPage, checkApiAuth, - checkApiAuthForMigrationPage, checkAppNotInitialized, checkApiAuthOrElectron, checkSenderToken diff --git a/src/services/options.js b/src/services/options.js index f0d56a70d..6c27e390f 100644 --- a/src/services/options.js +++ b/src/services/options.js @@ -2,7 +2,6 @@ const repository = require('./repository'); const utils = require('./utils'); const dateUtils = require('./date_utils'); const appInfo = require('./app_info'); -const Option = require('../entities/option'); async function getOption(name) { const option = await repository.getOption(name); @@ -27,6 +26,9 @@ async function setOption(name, value) { } async function createOption(name, value, isSynced) { + // to avoid circular dependency, need to find better solution + const Option = require('../entities/option'); + await new Option({ name: name, value: value, diff --git a/src/services/sql_init.js b/src/services/sql_init.js index 119db7415..ade464f2a 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -42,7 +42,10 @@ const dbReady = new Promise((resolve, reject) => { } if (!await isDbUpToDate()) { - return; + // avoiding circular dependency + const migrationService = require('./migration'); + + await migrationService.migrate(); } resolve(db); diff --git a/src/services/sync.js b/src/services/sync.js index ed254fc10..46def89eb 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -22,13 +22,6 @@ let syncServerCertificate = null; async function sync() { try { await syncMutexService.doExclusively(async () => { - if (!await sqlInit.isDbUpToDate()) { - return { - success: false, - message: "DB not up to date" - }; - } - const syncContext = await login(); await pushSync(syncContext); diff --git a/src/views/migration.ejs b/src/views/migration.ejs deleted file mode 100644 index 40f8e646f..000000000 --- a/src/views/migration.ejs +++ /dev/null @@ -1,72 +0,0 @@ - - - - - Migration - - -
-

Migration

- - - - - - -
- - - - - - - - - - - - - - \ No newline at end of file