mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
fix: backup-compatible db location on all platforms (#2721)
* fix: backup-compatible db location on all platforms * sync io for db move
This commit is contained in:
@@ -4,18 +4,25 @@ import 'dart:io';
|
||||
import 'package:cw_core/root_dir.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
|
||||
late Database db;
|
||||
late Database db;
|
||||
|
||||
Future<void> initDb({String? pathOverride}) async {
|
||||
if (Platform.isLinux || Platform.isWindows) {
|
||||
if (Platform.isLinux || Platform.isWindows) {
|
||||
databaseFactory = databaseFactoryFfi;
|
||||
}
|
||||
if (Platform.isWindows) {
|
||||
pathOverride ??= "${(await getAppDir()).path}/cake.db";
|
||||
|
||||
// getAppDir is predictable on all platforms and ensures the db gets included in backups.
|
||||
final dbFileOld = File("${await getDatabasesPath()}/cake.db");
|
||||
final dbFile = File("${(await getAppDir()).path}/cake.db");
|
||||
|
||||
if (dbFileOld.existsSync()) {
|
||||
final copied = dbFileOld.copySync(dbFile.path);
|
||||
if (copied.existsSync()) {
|
||||
dbFileOld.deleteSync();
|
||||
}
|
||||
}
|
||||
db = await openDatabase(
|
||||
pathOverride ?? "cake.db",
|
||||
version: 1,
|
||||
|
||||
db = await openDatabase(dbFile.path, version: 1,
|
||||
onCreate: (Database db, int version) async {
|
||||
await db.execute(
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user