mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
changing from AES-256-CTR to AES-128-CBC for note encryption
This commit is contained in:
@@ -4,8 +4,8 @@ const options = require('./options');
|
||||
const fs = require('fs-extra');
|
||||
const log = require('./log');
|
||||
|
||||
const APP_DB_VERSION = 29;
|
||||
const MIGRATIONS_DIR = "./migrations";
|
||||
const APP_DB_VERSION = 31;
|
||||
const MIGRATIONS_DIR = "migrations";
|
||||
|
||||
async function migrate() {
|
||||
const migrations = [];
|
||||
@@ -16,18 +16,20 @@ async function migrate() {
|
||||
const currentDbVersion = parseInt(await options.getOption('db_version'));
|
||||
|
||||
fs.readdirSync(MIGRATIONS_DIR).forEach(file => {
|
||||
const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.sql/);
|
||||
const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js)/);
|
||||
|
||||
if (match) {
|
||||
const dbVersion = parseInt(match[1]);
|
||||
|
||||
if (dbVersion > currentDbVersion) {
|
||||
const name = match[2];
|
||||
const type = match[3];
|
||||
|
||||
const migrationRecord = {
|
||||
dbVersion: dbVersion,
|
||||
name: name,
|
||||
file: file
|
||||
file: file,
|
||||
type: type
|
||||
};
|
||||
|
||||
migrations.push(migrationRecord);
|
||||
@@ -38,13 +40,26 @@ async function migrate() {
|
||||
migrations.sort((a, b) => a.dbVersion - b.dbVersion);
|
||||
|
||||
for (const mig of migrations) {
|
||||
const migrationSql = fs.readFileSync(MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
|
||||
|
||||
try {
|
||||
log.info("Attempting migration to version " + mig.dbVersion + " with script: " + migrationSql);
|
||||
log.info("Attempting migration to version " + mig.dbVersion);
|
||||
|
||||
await sql.doInTransaction(async () => {
|
||||
await sql.executeScript(migrationSql);
|
||||
if (mig.type === 'sql') {
|
||||
const migrationSql = fs.readFileSync(MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
|
||||
|
||||
console.log("Migration with SQL script: " + migrationSql);
|
||||
|
||||
await sql.executeScript(migrationSql);
|
||||
}
|
||||
else if (mig.type === 'js') {
|
||||
console.log("Migration with JS module");
|
||||
|
||||
const migrationModule = require("../" + MIGRATIONS_DIR + "/" + mig.file);
|
||||
await migrationModule();
|
||||
}
|
||||
else {
|
||||
throw new Error("Unknown migration type " + mig.type);
|
||||
}
|
||||
|
||||
await options.setOption("db_version", mig.dbVersion);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user