mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-06-03 13:20:34 +00:00
Database fixes
This commit is contained in:
parent
b3e1931b1b
commit
df4564e975
2 changed files with 32 additions and 14 deletions
|
@ -363,16 +363,16 @@ class AppConfigProvider with ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveFromDb(Database dbInstance, Map<String, dynamic> dbData) {
|
void saveFromDb(Database dbInstance, Map<String, dynamic> dbData) {
|
||||||
_selectedTheme = dbData['theme'];
|
_selectedTheme = dbData['theme'] ?? 0;
|
||||||
_overrideSslCheck = dbData['overrideSslCheck'];
|
_overrideSslCheck = dbData['overrideSslCheck'] ?? 0;
|
||||||
_hideZeroValues = dbData['hideZeroValues'];
|
_hideZeroValues = dbData['hideZeroValues'];
|
||||||
_useDynamicColor = convertFromIntToBool(dbData['useDynamicColor'])!;
|
_useDynamicColor = convertFromIntToBool(dbData['useDynamicColor'])!;
|
||||||
_staticColor = dbData['staticColor'];
|
_staticColor = dbData['staticColor'] ?? 0;
|
||||||
_useThemeColorForStatus = dbData['useThemeColorForStatus'] != null ? convertFromIntToBool(dbData['useThemeColorForStatus'])! : false;
|
_useThemeColorForStatus = dbData['useThemeColorForStatus'] != null ? convertFromIntToBool(dbData['useThemeColorForStatus'])! : false;
|
||||||
_showTimeLogs = dbData['showTimeLogs'];
|
_showTimeLogs = dbData['showTimeLogs'] ?? 0;
|
||||||
_doNotRememberVersion = dbData['doNotRememberVersion'];
|
_doNotRememberVersion = dbData['doNotRememberVersion'];
|
||||||
_showIpLogs = dbData['showIpLogs'];
|
_showIpLogs = dbData['showIpLogs'] ?? 0;
|
||||||
_combinedChartHome = dbData['combinedChart'];
|
_combinedChartHome = dbData['combinedChart'] ?? 0;
|
||||||
|
|
||||||
_dbInstance = dbInstance;
|
_dbInstance = dbInstance;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
|
@ -4,6 +4,12 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
|
||||||
List<Map<String, Object?>>? servers;
|
List<Map<String, Object?>>? servers;
|
||||||
List<Map<String, Object?>>? appConfig;
|
List<Map<String, Object?>>? appConfig;
|
||||||
|
|
||||||
|
Future rebuildAppConfig(Database db) async {
|
||||||
|
await db.execute("DROP TABLE appConfig");
|
||||||
|
await db.execute("CREATE TABLE appConfig (theme NUMERIC, overrideSslCheck NUMERIC, hideZeroValues NUMERIC, useDynamicColor NUMERIC, staticColor NUMERIC, useThemeColorForStatus NUMERIC, showTimeLogs NUMERIC, showIpLogs NUMERIC, combinedChart NUMERIC, doNotRememberVersion TEXT)");
|
||||||
|
await db.execute("INSERT INTO appConfig (theme, overrideSslCheck, hideZeroValues, useDynamicColor, staticColor, useThemeColorForStatus, showTimeLogs, showIpLogs, combinedChart) VALUES (0, 0, 0, ${acceptsDynamicTheme == true ? 1 : 0}, 0, 0, 0, 0, 0)");
|
||||||
|
}
|
||||||
|
|
||||||
Future upgradeDbToV2(Database db) async {
|
Future upgradeDbToV2(Database db) async {
|
||||||
await db.execute("ALTER TABLE appConfig ADD COLUMN overrideSslCheck NUMERIC");
|
await db.execute("ALTER TABLE appConfig ADD COLUMN overrideSslCheck NUMERIC");
|
||||||
await db.execute("UPDATE appConfig SET overrideSslCheck = 0");
|
await db.execute("UPDATE appConfig SET overrideSslCheck = 0");
|
||||||
|
@ -72,16 +78,28 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future upgradeDbToV8(Database db) async {
|
Future upgradeDbToV8(Database db) async {
|
||||||
await db.execute("ALTER TABLE appConfig RENAME COLUMN showNameTimeLogs TO showTimeLogs");
|
try {
|
||||||
await db.execute("ALTER TABLE appConfig ADD COLUMN showIpLogs NUMERIC");
|
final data = await db.rawQuery(
|
||||||
await db.execute("ALTER TABLE appConfig ADD COLUMN combinedChart NUMERIC");
|
|
||||||
await db.execute("UPDATE appConfig SET showIpLogs = 0, combinedChart = 0");
|
|
||||||
|
|
||||||
await db.transaction((txn) async{
|
|
||||||
await txn.rawQuery(
|
|
||||||
'SELECT * FROM appConfig',
|
'SELECT * FROM appConfig',
|
||||||
);
|
);
|
||||||
});
|
await rebuildAppConfig(db);
|
||||||
|
await db.update(
|
||||||
|
'appConfig',
|
||||||
|
{
|
||||||
|
'theme': data[0]['theme'],
|
||||||
|
'overrideSslCheck': data[0]['overrideSslCheck'],
|
||||||
|
'hideZeroValues': data[0]['hideZeroValues'],
|
||||||
|
'useDynamicColor': data[0]['useDynamicColor'],
|
||||||
|
'staticColor': data[0]['staticColor'],
|
||||||
|
'useThemeColorForStatus': data[0]['useThemeColorForStatus'],
|
||||||
|
'showTimeLogs': data[0]['showNameTimeLogs'],
|
||||||
|
'showIpLogs': data[0]['showIpLogs'],
|
||||||
|
'combinedChart': data[0]['combinedChart'],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
await rebuildAppConfig(db);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Database db = await openDatabase(
|
Database db = await openDatabase(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue