mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix migration + cleanup unused Notecase tables in migration script
This commit is contained in:
parent
dcdabe79d1
commit
06328929ec
11
migrations/0001__cleanup_tables.sql
Normal file
11
migrations/0001__cleanup_tables.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
DROP TABLE anchors;
|
||||||
|
DROP TABLE attachments;
|
||||||
|
DROP TABLE bookmarks;
|
||||||
|
DROP TABLE custom_properties;
|
||||||
|
DROP TABLE deletions;
|
||||||
|
DROP TABLE deletions_attachments;
|
||||||
|
DROP TABLE formatting;
|
||||||
|
DROP TABLE icons;
|
||||||
|
DROP TABLE tags;
|
||||||
|
DROP TABLE tags_notes;
|
||||||
|
DROP TABLE tasks;
|
@ -59,7 +59,6 @@ $(document).ready(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function parseHtml(contents, note) {
|
function parseHtml(contents, note) {
|
||||||
note.formatting = [];
|
|
||||||
note.links = [];
|
note.links = [];
|
||||||
note.images = [];
|
note.images = [];
|
||||||
|
|
||||||
|
@ -3,68 +3,18 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const auth = require('../../services/auth');
|
const auth = require('../../services/auth');
|
||||||
const backup = require('../../services/backup');
|
|
||||||
const sql = require('../../services/sql');
|
const sql = require('../../services/sql');
|
||||||
const fs = require('fs-extra');
|
const migration = require('../../services/migration');
|
||||||
|
|
||||||
const APP_DB_VERSION = 0;
|
|
||||||
const MIGRATIONS_DIR = "../trilium-data/migrations";
|
|
||||||
|
|
||||||
router.get('', auth.checkApiAuth, async (req, res, next) => {
|
router.get('', auth.checkApiAuth, async (req, res, next) => {
|
||||||
res.send({
|
res.send({
|
||||||
'db_version': parseInt(await sql.getOption('db_version')),
|
'db_version': parseInt(await sql.getOption('db_version')),
|
||||||
'app_db_version': APP_DB_VERSION
|
'app_db_version': migration.APP_DB_VERSION
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('', auth.checkApiAuth, async (req, res, next) => {
|
router.post('', auth.checkApiAuth, async (req, res, next) => {
|
||||||
const migrations = [];
|
const migrations = await migration.migrate();
|
||||||
|
|
||||||
await backup.backupNow();
|
|
||||||
|
|
||||||
const currentDbVersion = parseInt(await sql.getOption('db_version'));
|
|
||||||
|
|
||||||
fs.readdirSync(MIGRATIONS_DIR).forEach(file => {
|
|
||||||
const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.sql/);
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
const dbVersion = parseInt(match.group(1));
|
|
||||||
|
|
||||||
if (dbVersion > currentDbVersion) {
|
|
||||||
const name = match.group(2);
|
|
||||||
|
|
||||||
const migrationRecord = {
|
|
||||||
'db_version': dbVersion,
|
|
||||||
'name': name,
|
|
||||||
'file': file
|
|
||||||
};
|
|
||||||
|
|
||||||
migrations.push(migrationRecord);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
migrations.sort((a, b) => a.db_version - b.db_version);
|
|
||||||
|
|
||||||
for (const mig of migrations) {
|
|
||||||
const migrationSql = fs.readFileSync(MIGRATIONS_DIR + "/" + mig.file);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await sql.beginTransaction();
|
|
||||||
|
|
||||||
await sql.executeScript(migrationSql);
|
|
||||||
|
|
||||||
await sql.commit();
|
|
||||||
|
|
||||||
mig['success'] = true;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
mig['success'] = false;
|
|
||||||
mig['error'] = e.stack;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
'migrations': migrations
|
'migrations': migrations
|
||||||
|
@ -21,7 +21,6 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
'detail': detail,
|
'detail': detail,
|
||||||
'formatting': await sql.getResults("select * from formatting where note_id = ? order by note_offset", [noteId]),
|
|
||||||
'links': await sql.getResults("select * from links where note_id = ? order by note_offset", [noteId]),
|
'links': await sql.getResults("select * from links where note_id = ? order by note_offset", [noteId]),
|
||||||
'images': await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId])
|
'images': await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId])
|
||||||
});
|
});
|
||||||
|
@ -3,9 +3,18 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const auth = require('../services/auth');
|
const auth = require('../services/auth');
|
||||||
|
const migration = require('../services/migration');
|
||||||
|
const sql = require('../services/sql');
|
||||||
|
|
||||||
router.get('', auth.checkAuth, (req, res, next) => {
|
router.get('', auth.checkAuth, async (req, res, next) => {
|
||||||
res.render('index', {});
|
const dbVersion = parseInt(await sql.getOption('db_version'))
|
||||||
|
|
||||||
|
if (dbVersion < migration.APP_DB_VERSION) {
|
||||||
|
res.redirect("migration");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.render('index', {});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
@ -38,7 +38,7 @@ async function cleanupOldBackups() {
|
|||||||
const match = file.match(/backup-([0-9 -:]+)\.db/);
|
const match = file.match(/backup-([0-9 -:]+)\.db/);
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
const date_str = match.group(1);
|
const date_str = match[1];
|
||||||
|
|
||||||
const date = Date.parse(date_str);
|
const date = Date.parse(date_str);
|
||||||
|
|
||||||
|
66
services/migration.js
Normal file
66
services/migration.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
const backup = require('./backup');
|
||||||
|
const sql = require('./sql');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
|
const APP_DB_VERSION = 1;
|
||||||
|
const MIGRATIONS_DIR = "./migrations";
|
||||||
|
|
||||||
|
async function migrate() {
|
||||||
|
const migrations = [];
|
||||||
|
|
||||||
|
await backup.backupNow();
|
||||||
|
|
||||||
|
const currentDbVersion = parseInt(await sql.getOption('db_version'));
|
||||||
|
|
||||||
|
fs.readdirSync(MIGRATIONS_DIR).forEach(file => {
|
||||||
|
const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.sql/);
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
const dbVersion = parseInt(match[1]);
|
||||||
|
|
||||||
|
if (dbVersion > currentDbVersion) {
|
||||||
|
const name = match[2];
|
||||||
|
|
||||||
|
const migrationRecord = {
|
||||||
|
'db_version': dbVersion,
|
||||||
|
'name': name,
|
||||||
|
'file': file
|
||||||
|
};
|
||||||
|
|
||||||
|
migrations.push(migrationRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
migrations.sort((a, b) => a.db_version - b.db_version);
|
||||||
|
|
||||||
|
for (const mig of migrations) {
|
||||||
|
const migrationSql = fs.readFileSync(MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log("Running script: ", migrationSql);
|
||||||
|
|
||||||
|
await sql.beginTransaction();
|
||||||
|
|
||||||
|
await sql.executeScript(migrationSql);
|
||||||
|
|
||||||
|
await sql.commit();
|
||||||
|
|
||||||
|
mig['success'] = true;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
mig['success'] = false;
|
||||||
|
mig['error'] = e.stack;
|
||||||
|
|
||||||
|
console.log("error during migration: ", e);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return migrations;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
migrate,
|
||||||
|
APP_DB_VERSION
|
||||||
|
};
|
@ -1,3 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
//setInterval();
|
function sync() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(sync, 60000);
|
@ -50,11 +50,11 @@
|
|||||||
<!-- Required for correct loading of scripts in Electron -->
|
<!-- Required for correct loading of scripts in Electron -->
|
||||||
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
|
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
|
||||||
|
|
||||||
<script src="stat/lib/jquery.min.js"></script>
|
<script src="libraries/jquery.min.js"></script>
|
||||||
|
|
||||||
<link href="stat/lib/bootstrap/css/bootstrap.css" rel="stylesheet">
|
<link href="libraries/bootstrap/css/bootstrap.css" rel="stylesheet">
|
||||||
<script src="stat/lib/bootstrap/js/bootstrap.js"></script>
|
<script src="libraries/bootstrap/js/bootstrap.js"></script>
|
||||||
|
|
||||||
<script src="stat/js/migration.js"></script>
|
<script src="javascripts/migration.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user