mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-09-30 03:57:51 +00:00
Fix migration crashes.
This commit is contained in:
parent
650032bdab
commit
07cf926e79
|
@ -20,4 +20,9 @@ def run_migrations():
|
||||||
for migration in migrations:
|
for migration in migrations:
|
||||||
if migration.get_migration_name() not in skipped_migrations:
|
if migration.get_migration_name() not in skipped_migrations:
|
||||||
if migration.is_migration_needed():
|
if migration.is_migration_needed():
|
||||||
|
try:
|
||||||
migration.migrate()
|
migration.migrate()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error while migrating {migration.get_migration_name()}")
|
||||||
|
print(e)
|
||||||
|
print("Skipping this migration")
|
||||||
|
|
|
@ -17,13 +17,20 @@ class FixNixosConfigBranch(Migration):
|
||||||
|
|
||||||
def is_migration_needed(self):
|
def is_migration_needed(self):
|
||||||
"""Check the current branch of /etc/nixos and return True if it is rolling-testing"""
|
"""Check the current branch of /etc/nixos and return True if it is rolling-testing"""
|
||||||
|
current_working_directory = os.getcwd()
|
||||||
|
try:
|
||||||
|
os.chdir("/etc/nixos")
|
||||||
nixos_config_branch = subprocess.check_output(
|
nixos_config_branch = subprocess.check_output(
|
||||||
["git", "rev-parse", "--abbrev-ref", "HEAD"], start_new_session=True
|
["git", "rev-parse", "--abbrev-ref", "HEAD"], start_new_session=True
|
||||||
)
|
)
|
||||||
|
os.chdir(current_working_directory)
|
||||||
if nixos_config_branch.decode("utf-8").strip() == "rolling-testing":
|
if nixos_config_branch.decode("utf-8").strip() == "rolling-testing":
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
os.chdir(current_working_directory)
|
||||||
|
return False
|
||||||
|
|
||||||
def migrate(self):
|
def migrate(self):
|
||||||
"""Affected server pulled the config with the --single-branch flag.
|
"""Affected server pulled the config with the --single-branch flag.
|
||||||
|
@ -32,6 +39,7 @@ class FixNixosConfigBranch(Migration):
|
||||||
"""
|
"""
|
||||||
print("Fixing Nixos config branch")
|
print("Fixing Nixos config branch")
|
||||||
current_working_directory = os.getcwd()
|
current_working_directory = os.getcwd()
|
||||||
|
try:
|
||||||
os.chdir("/etc/nixos")
|
os.chdir("/etc/nixos")
|
||||||
|
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
|
@ -45,6 +53,9 @@ class FixNixosConfigBranch(Migration):
|
||||||
subprocess.check_output(["git", "fetch", "--all"])
|
subprocess.check_output(["git", "fetch", "--all"])
|
||||||
subprocess.check_output(["git", "pull"])
|
subprocess.check_output(["git", "pull"])
|
||||||
subprocess.check_output(["git", "checkout", "master"])
|
subprocess.check_output(["git", "checkout", "master"])
|
||||||
|
|
||||||
os.chdir(current_working_directory)
|
os.chdir(current_working_directory)
|
||||||
print("Done")
|
print("Done")
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
os.chdir(current_working_directory)
|
||||||
|
print("Error")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue