Switch to WAL after cipher migration

This commit is contained in:
Fedor Indutny 2021-05-25 11:13:37 -07:00 committed by GitHub
parent 4a6132933c
commit 9693700dd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -329,7 +329,8 @@ function setUserVersion(db: Database, version: number): void {
function keyDatabase(db: Database, key: string): void { function keyDatabase(db: Database, key: string): void {
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key // https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
db.pragma(`key = "x'${key}'"`); db.pragma(`key = "x'${key}'"`);
}
function switchToWAL(db: Database): void {
// https://sqlite.org/wal.html // https://sqlite.org/wal.html
db.pragma('journal_mode = WAL'); db.pragma('journal_mode = WAL');
db.pragma('synchronous = NORMAL'); db.pragma('synchronous = NORMAL');
@ -384,6 +385,7 @@ function openAndMigrateDatabase(filePath: string, key: string) {
try { try {
db = new SQL(filePath); db = new SQL(filePath);
keyDatabase(db, key); keyDatabase(db, key);
switchToWAL(db);
migrateSchemaVersion(db); migrateSchemaVersion(db);
return db; return db;
@ -410,6 +412,7 @@ function openAndMigrateDatabase(filePath: string, key: string) {
keyDatabase(db, key); keyDatabase(db, key);
db.pragma('cipher_migrate'); db.pragma('cipher_migrate');
switchToWAL(db);
return db; return db;
} }