revert: separation of write and read DBs

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan
2024-11-18 15:52:13 +02:00
parent 1bf94531fd
commit 3982ba7258
22 changed files with 78 additions and 161 deletions
+17 -3
View File
@@ -32,7 +32,7 @@ func backupPath(t time.Time) string {
)
}
func (d *db) backupOrRestore(ctx context.Context, isBackup bool, path string) error {
func backupOrRestore(ctx context.Context, isBackup bool, path string) error {
// heavily inspired by https://codingrabbits.dev/posts/go_and_sqlite_backup_and_maybe_restore/
backupDb, err := sql.Open(Driver, path)
if err != nil {
@@ -40,7 +40,7 @@ func (d *db) backupOrRestore(ctx context.Context, isBackup bool, path string) er
}
defer backupDb.Close()
existingConn, err := d.writeDB.Conn(ctx)
existingConn, err := Db().Conn(ctx)
if err != nil {
return err
}
@@ -100,7 +100,21 @@ func (d *db) backupOrRestore(ctx context.Context, isBackup bool, path string) er
return err
}
func prune(ctx context.Context) (int, error) {
func Backup(ctx context.Context) (string, error) {
destPath := backupPath(time.Now())
err := backupOrRestore(ctx, true, destPath)
if err != nil {
return "", err
}
return destPath, nil
}
func Restore(ctx context.Context, path string) error {
return backupOrRestore(ctx, false, path)
}
func Prune(ctx context.Context) (int, error) {
files, err := os.ReadDir(conf.Server.Backup.Path)
if err != nil {
return 0, fmt.Errorf("unable to read database backup entries: %w", err)