moved migration directory to db, fix sync records

This commit is contained in:
azivner 2018-01-28 21:00:54 -05:00
parent 75878c80a8
commit 9a0c2b6bcd
77 changed files with 20 additions and 17 deletions

View File

@ -0,0 +1,3 @@
UPDATE sync SET entityName = 'note_images' WHERE entityName = 'notes_image';
UPDATE sync SET entityName = 'note_tree' WHERE entityName = 'notes_tree';
UPDATE sync SET entityName = 'note_revisions' WHERE entityName = 'notes_history';

View File

@ -4,7 +4,7 @@ const express = require('express');
const router = express.Router();
const options = require('../../services/options');
const utils = require('../../services/utils');
const sourceId = require('../../services/source_id');
const source_id = require('../../services/source_id');
const auth = require('../../services/auth');
const password_encryption = require('../../services/password_encryption');
const protected_session = require('../../services/protected_session');
@ -43,7 +43,7 @@ router.post('/sync', wrap(async (req, res, next) => {
req.session.loggedIn = true;
res.send({
sourceId: sourceId.getCurrentSourceId()
sourceId: source_id.getCurrentSourceId()
});
}));

View File

@ -3,13 +3,13 @@
const express = require('express');
const router = express.Router();
const auth = require('../services/auth');
const sourceId = require('../services/source_id');
const source_id = require('../services/source_id');
const sql = require('../services/sql');
const wrap = require('express-promise-wrap').wrap;
router.get('', auth.checkAuth, wrap(async (req, res, next) => {
res.render('index', {
sourceId: await sourceId.generateSourceId(),
sourceId: await source_id.generateSourceId(),
maxSyncIdAtLoad: await sql.getFirstValue("SELECT MAX(id) FROM sync")
});
}));

View File

@ -3,7 +3,7 @@
const build = require('./build');
const packageJson = require('../package');
const APP_DB_VERSION = 70;
const APP_DB_VERSION = 71;
module.exports = {
app_version: packageJson.version,

View File

@ -4,13 +4,6 @@ const fs = require('fs');
const RESOURCE_DIR = path.resolve(__dirname, "..");
const MIGRATIONS_DIR = path.resolve(RESOURCE_DIR, "migrations");
if (!fs.existsSync(MIGRATIONS_DIR)) {
log.error("Could not find migration directory: " + MIGRATIONS_DIR);
process.exit(1);
}
const DB_INIT_DIR = path.resolve(RESOURCE_DIR, "db");
if (!fs.existsSync(DB_INIT_DIR)) {
@ -18,6 +11,13 @@ if (!fs.existsSync(DB_INIT_DIR)) {
process.exit(1);
}
const MIGRATIONS_DIR = path.resolve(DB_INIT_DIR, "migrations");
if (!fs.existsSync(MIGRATIONS_DIR)) {
log.error("Could not find migration directory: " + MIGRATIONS_DIR);
process.exit(1);
}
module.exports = {
RESOURCE_DIR,
MIGRATIONS_DIR,

View File

@ -5,7 +5,7 @@ const rp = require('request-promise');
const sql = require('./sql');
const options = require('./options');
const utils = require('./utils');
const sourceId = require('./source_id');
const source_id = require('./source_id');
const notes = require('./notes');
const syncUpdate = require('./sync_update');
const content_hash = require('./content_hash');
@ -80,7 +80,7 @@ async function login() {
hash: hash
});
if (sourceId.isLocalSourceId(resp.sourceId)) {
if (source_id.isLocalSourceId(resp.sourceId)) {
throw new Error(`Sync server has source ID ${resp.sourceId} which is also local. Try restarting sync server.`);
}
@ -109,7 +109,7 @@ async function pullSync(syncContext) {
log.info("Pulled " + syncRows.length + " changes from " + changesUri);
for (const sync of syncRows) {
if (sourceId.isLocalSourceId(sync.sourceId)) {
if (source_id.isLocalSourceId(sync.sourceId)) {
log.info(`Skipping pull #${sync.id} ${sync.entityName} ${sync.entityId} because ${sync.sourceId} is a local source id.`);
await setLastSyncedPull(sync.id);

View File

@ -1,5 +1,5 @@
const sql = require('./sql');
const sourceId = require('./source_id');
const source_id = require('./source_id');
const utils = require('./utils');
const sync_setup = require('./sync_setup');
const log = require('./log');
@ -45,7 +45,7 @@ async function addEntitySync(entityName, entityId, sourceId) {
entityName: entityName,
entityId: entityId,
syncDate: utils.nowDate(),
sourceId: sourceId || sourceId.getCurrentSourceId()
sourceId: sourceId || source_id.getCurrentSourceId()
});
if (!sync_setup.isSyncSetup) {