Skip to content

Commit

Permalink
Merge pull request #1788 from fractal-analytics-platform/1786-depreca…
Browse files Browse the repository at this point in the history
…te-use-of-users-slurm_user-cache_dir-and-slurm_accounts

Prepare `update-db-script` for v2.6.0
  • Loading branch information
ychiucco committed Sep 20, 2024
2 parents cfa8a44 + 1651b2a commit 7228364
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
49 changes: 49 additions & 0 deletions fractal_server/data_migrations/2_6_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import logging

from sqlalchemy import select

from fractal_server.app.db import get_sync_db
from fractal_server.app.models import UserOAuth
from fractal_server.app.models import UserSettings
from fractal_server.config import get_settings
from fractal_server.data_migrations.tools import _check_current_version
from fractal_server.syringe import Inject


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

global_settings = Inject(get_settings)

with next(get_sync_db()) as db:
users = db.execute(select(UserOAuth)).scalars().unique().all()
for user in sorted(users, key=lambda x: x.id):
logger.warning(f"START handling user {user.id}: '{user.email}'")
user_settings = UserSettings(
# SSH
ssh_host=global_settings.FRACTAL_SLURM_SSH_HOST,
ssh_username=global_settings.FRACTAL_SLURM_SSH_USER,
ssh_private_key_path=(
global_settings.FRACTAL_SLURM_SSH_PRIVATE_KEY_PATH
),
ssh_tasks_dir=(
global_settings.FRACTAL_SLURM_SSH_WORKING_BASE_DIR
),
ssh_jobs_dir=(
global_settings.FRACTAL_SLURM_SSH_WORKING_BASE_DIR
),
# SUDO
slurm_user=user.slurm_user,
slurm_accounts=user.slurm_accounts,
cache_dir=user.cache_dir,
)
user.settings = user_settings
db.add(user)
db.commit()
db.refresh(user)
logger.warning(f"New user {user.id} settings:\n{user.settings}")
logger.warning(f"END handling user {user.id}: '{user.email}'")

logger.warning("END of execution of fix_db function")
File renamed without changes.
17 changes: 17 additions & 0 deletions fractal_server/data_migrations/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from packaging.version import parse

import fractal_server


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__=}"
)

0 comments on commit 7228364

Please sign in to comment.