d11f0e46c0
clean up and fixes - Heute gefixt - Code Cleanup NotificationScheduleItemViewModel -fixed NotificationScheduleItemViewModel for Windows compat push implementation Push fixes Push benachrichtungen eingebaut - Status bei push - Push auch in background - Toggle für symtome angepasst push system change exporter update Optionen fix - Optionen aufgeteilt auf 3 tabs - Anpassungen haben jetzt Farbslider Optimierung fix
73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using cfs_tracker.Models;
|
|
using cfs_tracker.Services;
|
|
using SQLite;
|
|
|
|
namespace cfs_tracker.Data;
|
|
|
|
public sealed class AppDatabase
|
|
{
|
|
private readonly DatabaseLocationService _databaseLocationService;
|
|
private readonly SemaphoreSlim _initLock = new(1, 1);
|
|
|
|
private SQLiteAsyncConnection? _connection;
|
|
private bool _initialized;
|
|
|
|
public AppDatabase(DatabaseLocationService databaseLocationService)
|
|
{
|
|
_databaseLocationService = databaseLocationService;
|
|
}
|
|
|
|
public async Task InitAsync()
|
|
{
|
|
if (_initialized)
|
|
return;
|
|
|
|
await _initLock.WaitAsync();
|
|
try
|
|
{
|
|
if (_initialized)
|
|
return;
|
|
|
|
var dbPath = _databaseLocationService.ResolveDatabasePath();
|
|
var directory = Path.GetDirectoryName(dbPath);
|
|
|
|
if (!string.IsNullOrWhiteSpace(directory))
|
|
Directory.CreateDirectory(directory);
|
|
|
|
_connection = new SQLiteAsyncConnection(dbPath);
|
|
|
|
await _connection.ExecuteAsync("PRAGMA foreign_keys = ON;");
|
|
|
|
await _connection.CreateTableAsync<ActivityItem>();
|
|
await _connection.CreateTableAsync<SymptomItem>();
|
|
await _connection.CreateTableAsync<HealthEntry>();
|
|
await _connection.CreateTableAsync<HealthEntrySymptom>();
|
|
await _connection.CreateTableAsync<AppearanceSetting>();
|
|
await _connection.CreateTableAsync<NotificationSchedule>();
|
|
|
|
await _connection.ExecuteAsync(@"
|
|
CREATE TABLE IF NOT EXISTS HealthEntrySymptom (
|
|
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
HealthEntryId INTEGER NOT NULL,
|
|
SymptomItemId INTEGER NOT NULL
|
|
);");
|
|
|
|
await _connection.ExecuteAsync(
|
|
"CREATE INDEX IF NOT EXISTS IX_HealthEntrySymptom_HealthEntryId ON HealthEntrySymptom(HealthEntryId);");
|
|
|
|
await _connection.ExecuteAsync(
|
|
"CREATE INDEX IF NOT EXISTS IX_HealthEntrySymptom_SymptomItemId ON HealthEntrySymptom(SymptomItemId);");
|
|
|
|
_initialized = true;
|
|
}
|
|
finally
|
|
{
|
|
_initLock.Release();
|
|
}
|
|
}
|
|
|
|
public string CurrentPath => _databaseLocationService.ResolveDatabasePath();
|
|
|
|
public SQLiteAsyncConnection Connection =>
|
|
_connection ?? throw new InvalidOperationException("Database has not been initialized yet.");
|
|
} |