Skip to content

Commit

Permalink
data migration script 2_6_0
Browse files Browse the repository at this point in the history
  • Loading branch information
ychiucco committed Sep 20, 2024
1 parent a1a7651 commit 47f0b99
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions fractal_server/data_migrations/2_6_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import logging

from packaging.version import parse
from sqlalchemy import select

import fractal_server
from fractal_server.app.db import get_sync_db
from fractal_server.app.models import UserOAuth
from fractal_server.app.models import UserSettings


def _check_current_version(*, expected_version: str):
# Check that this module matches with the current version
module_version = parse(expected_version)
current_version = parse(fractal_server.__VERSION__)
if (
current_version.major != module_version.major
or current_version.minor != module_version.minor
or current_version.micro != module_version.micro
):
raise RuntimeError(
f"{fractal_server.__VERSION__=} not matching with {__file__=}"
)


def fix_db():
logger = logging.getLogger("fix_db")
logger.warning("START execution of fix_db function")
_check_current_version(expected_version="2.6.0")

with next(get_sync_db()) as db:
for user in db.execute(select(UserOAuth)).scalars().unique().all():
user.settings = UserSettings(
slurm_user=user.slurm_user,
slurm_accounts=user.slurm_accounts,
cache_dir=user.cache_dir,
)
db.add(user)
logger.warning(f"Added UserSettings for User {user.id} ")
db.commit()
logger.warning("Commited UserSettings to the database")

logger.warning("END of execution of fix_db function")
File renamed without changes.

0 comments on commit 47f0b99

Please sign in to comment.