Skip to content

Commit

Permalink
readd db backup (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc authored Feb 15, 2024
1 parent e251e8a commit ecad957
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cashu/core/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit ecad957

Please sign in to comment.