From ecad95715f7059545478a3c4f164729e65aa4eaf Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Thu, 15 Feb 2024 15:58:40 +0100 Subject: [PATCH] readd db backup (#424) --- cashu/core/migrations.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cashu/core/migrations.py b/cashu/core/migrations.py index d92edafd..7bab5eeb 100644 --- a/cashu/core/migrations.py +++ b/cashu/core/migrations.py @@ -56,12 +56,18 @@ async def set_migration_version(conn, db_name, version): async def run_migration(db, migrations_module): db_name = migrations_module.__name__.split(".")[-2] # we first check whether any migration is needed and create a backup if so + migration_needed = False for key, migrate in migrations_module.__dict__.items(): match = matcher.match(key) if match: version = int(match.group(1)) if version > current_versions.get(db_name, 0): + migration_needed = True break + if migration_needed and settings.db_backup_path: + logger.debug(f"Creating backup of {db_name} db") + current_version = current_versions.get(db_name, 0) + await backup_database(db, current_version) # then we run the migrations for key, migrate in migrations_module.__dict__.items():