vaccum db on app start and enable SECURE_DELETE

Fixes #1550
pull/1595/head
Audric Ackermann 4 years ago
parent 558761ba31
commit c516acdb2f
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -207,6 +207,14 @@ async function setSQLPassword(password) {
await db.run(`PRAGMA rekey = ${value};`); await db.run(`PRAGMA rekey = ${value};`);
} }
async function vacuumDatabase(instance) {
if (!instance) {
throw new Error('vacuum: db is not initialized');
}
console.warn('Vacuuming DB. This might take a while.');
await instance.run('VACUUM;');
}
async function updateToSchemaVersion1(currentVersion, instance) { async function updateToSchemaVersion1(currentVersion, instance) {
if (currentVersion >= 1) { if (currentVersion >= 1) {
return; return;
@ -761,6 +769,7 @@ const LOKI_SCHEMA_VERSIONS = [
updateToLokiSchemaVersion10, updateToLokiSchemaVersion10,
updateToLokiSchemaVersion11, updateToLokiSchemaVersion11,
updateToLokiSchemaVersion12, updateToLokiSchemaVersion12,
updateToLokiSchemaVersion13,
]; ];
const SERVERS_TOKEN_TABLE = 'servers'; const SERVERS_TOKEN_TABLE = 'servers';
@ -1094,6 +1103,28 @@ async function updateToLokiSchemaVersion12(currentVersion, instance) {
console.log('updateToLokiSchemaVersion12: success!'); console.log('updateToLokiSchemaVersion12: success!');
} }
async function updateToLokiSchemaVersion13(currentVersion, instance) {
if (currentVersion >= 13) {
return;
}
console.log('updateToLokiSchemaVersion13: starting...');
await instance.run('BEGIN TRANSACTION;');
// Clear any already deleted db entries.
// secure_delete = ON will make sure next deleted entries are overwritten with 0 right away
await instance.run('PRAGMA secure_delete = ON;');
await instance.run(
`INSERT INTO loki_schema (
version
) values (
13
);`
);
await instance.run('COMMIT TRANSACTION;');
console.log('updateToLokiSchemaVersion13: success!');
}
async function updateLokiSchema(instance) { async function updateLokiSchema(instance) {
const result = await instance.get( const result = await instance.get(
"SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema';" "SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema';"
@ -1200,6 +1231,8 @@ async function initialize({ configDir, key, messages, passwordAttempt }) {
throw new Error(`Integrity check failed: ${result}`); throw new Error(`Integrity check failed: ${result}`);
} }
// Clear any already deleted db entries on each app start.
await vacuumDatabase(db);
await getMessageCount(); await getMessageCount();
} catch (error) { } catch (error) {
if (passwordAttempt) { if (passwordAttempt) {

Loading…
Cancel
Save