Skip to content

Commit

Permalink
feat(datastore): enable wal mode
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Oct 4, 2024
1 parent 95d8f16 commit a47db50
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ final class SQLiteStorageEngineAdapter: StorageEngineAdapter {
pragma auto_vacuum = full;
pragma encoding = "utf-8";
pragma foreign_keys = on;
pragma journal_mode = WAL;
pragma case_sensitive_like = off;
"""

Expand Down Expand Up @@ -507,6 +508,8 @@ final class SQLiteStorageEngineAdapter: StorageEngineAdapter {
let fileManager = FileManager.default
do {
try fileManager.removeItem(at: dbFilePath)
try fileManager.removeItem(at: dbFilePath.deletingPathExtension().appendingPathExtension("db-wal"))
try fileManager.removeItem(at: dbFilePath.deletingPathExtension().appendingPathExtension("db-shm"))
} catch {
log.error("Failed to delete database file located at: \(dbFilePath), error: \(error)")
completion(.failure(causedBy: DataStoreError.invalidDatabase(path: dbFilePath.absoluteString, error)))
Expand Down Expand Up @@ -543,6 +546,8 @@ final class SQLiteStorageEngineAdapter: StorageEngineAdapter {
log.verbose("\(#function) Warning: Schema change detected, removing your previous database")
do {
try fileManager.removeItem(at: dbFilePath)
try fileManager.removeItem(at: dbFilePath.deletingPathExtension().appendingPathExtension("db-wal"))
try fileManager.removeItem(at: dbFilePath.deletingPathExtension().appendingPathExtension("db-shm"))
} catch {
log.error("\(#function) Failed to delete database file located at: \(dbFilePath), error: \(error)")
throw DataStoreError.invalidDatabase(path: dbFilePath.path, error)
Expand Down

0 comments on commit a47db50

Please sign in to comment.