mirror of
https://github.com/zadam/trilium.git
synced 2025-01-17 04:27:56 +08:00
crash if the DB has newer version than the application
This commit is contained in:
parent
91e3eb8ae7
commit
06be593fe4
1 changed files with 14 additions and 1 deletions
|
@ -6,6 +6,7 @@ const resourceDir = require('./resource_dir');
|
||||||
const appInfo = require('./app_info');
|
const appInfo = require('./app_info');
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const cls = require('./cls');
|
const cls = require('./cls');
|
||||||
|
const utils = require('./utils');
|
||||||
const optionService = require('./options');
|
const optionService = require('./options');
|
||||||
const Option = require('../entities/option');
|
const Option = require('../entities/option');
|
||||||
const ImportContext = require('../services/import_context');
|
const ImportContext = require('../services/import_context');
|
||||||
|
@ -58,6 +59,14 @@ async function initDbConnection() {
|
||||||
|
|
||||||
await sql.execute("PRAGMA foreign_keys = ON");
|
await sql.execute("PRAGMA foreign_keys = ON");
|
||||||
|
|
||||||
|
const currentDbVersion = await getDbVersion();
|
||||||
|
|
||||||
|
if (currentDbVersion > appInfo.dbVersion) {
|
||||||
|
log.error(`Current DB version ${currentDbVersion} is newer than app db version ${appInfo.dbVersion} which means that it was created by newer and incompatible version of Trilium. Upgrade to latest version of Trilium to resolve this issue.`);
|
||||||
|
|
||||||
|
utils.crash();
|
||||||
|
}
|
||||||
|
|
||||||
if (!await isDbUpToDate()) {
|
if (!await isDbUpToDate()) {
|
||||||
// avoiding circular dependency
|
// avoiding circular dependency
|
||||||
const migrationService = require('./migration');
|
const migrationService = require('./migration');
|
||||||
|
@ -147,8 +156,12 @@ async function createDatabaseForSync(options, syncServerHost = '', syncProxy = '
|
||||||
log.info("Schema and not synced options generated.");
|
log.info("Schema and not synced options generated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getDbVersion() {
|
||||||
|
return parseInt(await sql.getValue("SELECT value FROM options WHERE name = 'dbVersion'"));
|
||||||
|
}
|
||||||
|
|
||||||
async function isDbUpToDate() {
|
async function isDbUpToDate() {
|
||||||
const dbVersion = parseInt(await sql.getValue("SELECT value FROM options WHERE name = 'dbVersion'"));
|
const dbVersion = await getDbVersion();
|
||||||
|
|
||||||
const upToDate = dbVersion >= appInfo.dbVersion;
|
const upToDate = dbVersion >= appInfo.dbVersion;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue