mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 02:30:42 +01:00
fix init of synced options in new database
This commit is contained in:
@@ -68,9 +68,18 @@ async function runSyncRowChecks(table, key, errorList) {
|
||||
${table}
|
||||
LEFT JOIN sync ON sync.entityName = '${table}' AND entityId = ${key}
|
||||
WHERE
|
||||
sync.id IS NULL`,
|
||||
sync.id IS NULL AND ` + (table === 'options' ? 'isSynced = 1' : '1'),
|
||||
`Missing sync records for ${key} in table ${table}`, errorList);
|
||||
|
||||
console.log(`
|
||||
SELECT
|
||||
${key}
|
||||
FROM
|
||||
${table}
|
||||
LEFT JOIN sync ON sync.entityName = '${table}' AND entityId = ${key}
|
||||
WHERE
|
||||
sync.id IS NULL AND ` + (table === 'options' ? 'isSynced = 1' : '1'));
|
||||
|
||||
await runCheck(`
|
||||
SELECT
|
||||
entityId
|
||||
@@ -224,6 +233,7 @@ async function runAllChecks() {
|
||||
await runSyncRowChecks("note_images", "noteImageId", errorList);
|
||||
await runSyncRowChecks("attributes", "attributeId", errorList);
|
||||
await runSyncRowChecks("api_tokens", "apiTokenId", errorList);
|
||||
await runSyncRowChecks("options", "name", errorList);
|
||||
|
||||
if (errorList.length === 0) {
|
||||
// we run this only if basic checks passed since this assumes basic data consistency
|
||||
|
||||
@@ -11,22 +11,22 @@ async function initDocumentOptions() {
|
||||
}
|
||||
|
||||
async function initSyncedOptions(username, password) {
|
||||
await optionService.createOption('protectedSessionTimeout', 600);
|
||||
await optionService.createOption('noteRevisionSnapshotTimeInterval', 600);
|
||||
await optionService.createOption('protectedSessionTimeout', 600, true);
|
||||
await optionService.createOption('noteRevisionSnapshotTimeInterval', 600, true);
|
||||
|
||||
await optionService.createOption('username', username);
|
||||
await optionService.createOption('username', username, true);
|
||||
|
||||
await optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32));
|
||||
await optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32));
|
||||
await optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32), true);
|
||||
await optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32), true);
|
||||
|
||||
const passwordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(password));
|
||||
await optionService.createOption('passwordVerificationHash', passwordVerificationKey);
|
||||
const passwordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(password), true);
|
||||
await optionService.createOption('passwordVerificationHash', passwordVerificationKey, true);
|
||||
|
||||
// passwordEncryptionService expects these options to already exist
|
||||
await optionService.createOption('encryptedDataKey', '');
|
||||
await optionService.createOption('encryptedDataKeyIv', '');
|
||||
await optionService.createOption('encryptedDataKey', '', true);
|
||||
await optionService.createOption('encryptedDataKeyIv', '', true);
|
||||
|
||||
await passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16));
|
||||
await passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16), true);
|
||||
}
|
||||
|
||||
async function initNotSyncedOptions(initialized, startNotePath = 'root', syncServerHost = '', syncProxy = '') {
|
||||
|
||||
@@ -111,7 +111,7 @@ async function createDatabaseForSync(options, syncServerHost = '', syncProxy = '
|
||||
await sql.transactional(async () => {
|
||||
await sql.executeScript(schema);
|
||||
|
||||
await require('./options_init').initNotSyncedOptions(false, '', syncServerHost, syncProxy);
|
||||
await require('./options_init').initNotSyncedOptions(false, 'root', syncServerHost, syncProxy);
|
||||
|
||||
// document options required for sync to kick off
|
||||
for (const opt of options) {
|
||||
|
||||
Reference in New Issue
Block a user