mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-03-18 20:39:46 +00:00
Fix migration crashes.
This commit is contained in:
parent
650032bdab
commit
07cf926e79
2 changed files with 37 additions and 21 deletions
|
@ -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():
|
||||||
migration.migrate()
|
try:
|
||||||
|
migration.migrate()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error while migrating {migration.get_migration_name()}")
|
||||||
|
print(e)
|
||||||
|
print("Skipping this migration")
|
||||||
|
|
|
@ -17,12 +17,19 @@ 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"""
|
||||||
nixos_config_branch = subprocess.check_output(
|
current_working_directory = os.getcwd()
|
||||||
["git", "rev-parse", "--abbrev-ref", "HEAD"], start_new_session=True
|
try:
|
||||||
)
|
os.chdir("/etc/nixos")
|
||||||
if nixos_config_branch.decode("utf-8").strip() == "rolling-testing":
|
nixos_config_branch = subprocess.check_output(
|
||||||
return True
|
["git", "rev-parse", "--abbrev-ref", "HEAD"], start_new_session=True
|
||||||
else:
|
)
|
||||||
|
os.chdir(current_working_directory)
|
||||||
|
if nixos_config_branch.decode("utf-8").strip() == "rolling-testing":
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
os.chdir(current_working_directory)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def migrate(self):
|
def migrate(self):
|
||||||
|
@ -32,19 +39,23 @@ class FixNixosConfigBranch(Migration):
|
||||||
"""
|
"""
|
||||||
print("Fixing Nixos config branch")
|
print("Fixing Nixos config branch")
|
||||||
current_working_directory = os.getcwd()
|
current_working_directory = os.getcwd()
|
||||||
os.chdir("/etc/nixos")
|
try:
|
||||||
|
os.chdir("/etc/nixos")
|
||||||
|
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
"git",
|
"git",
|
||||||
"config",
|
"config",
|
||||||
"remote.origin.fetch",
|
"remote.origin.fetch",
|
||||||
"+refs/heads/*:refs/remotes/origin/*",
|
"+refs/heads/*:refs/remotes/origin/*",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
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)
|
||||||
|
print("Done")
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
os.chdir(current_working_directory)
|
||||||
|
print("Error")
|
||||||
|
|
||||||
os.chdir(current_working_directory)
|
|
||||||
print("Done")
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue