Add status file for migrations failure

This commit is contained in:
= 2024-09-16 14:54:43 -04:00
parent 40f753162f
commit 52a6e9ae59
3 changed files with 45 additions and 1 deletions

View File

@ -79,6 +79,7 @@ class Helpers:
self.translation = Translation(self)
self.update_available = False
self.migration_notifications = []
self.ignored_names = ["crafty_managed.txt", "db_stats"]
self.crafty_starting = False
self.minimum_password_length = 8
@ -619,6 +620,7 @@ class Helpers:
data = []
response = requests.get("https://craftycontrol.com/notify", timeout=2)
data = json.loads(response.content)
data.extend(self.migration_notifications)
if self.update_available:
data.append(self.update_available)
return data

View File

@ -1,4 +1,5 @@
import os
import json
import datetime
import uuid
import peewee
@ -166,10 +167,15 @@ def migrate(migrator: Migrator, database, **kwargs):
valid_backups = [
backup for backup in all_backups if is_valid_entry(backup, all_servers)
]
if len(valid_backups) < len(all_backups):
backup_migration_status = False
print("Orphan backup found")
Console.info("Cleaning up orphan schedules for all servers")
valid_schedules = [
schedule for schedule in all_schedules if is_valid_entry(schedule, all_servers)
]
if len(valid_schedules) > len(all_schedules):
schedule_migration_status = False
# Copy data from the existing backups table to the new one
for backup in valid_backups:
Console.info(f"Trying to get server for backup migration {backup.server_id}")
@ -266,6 +272,22 @@ def migrate(migrator: Migrator, database, **kwargs):
# Rename the new table to backups
migrator.rename_table("new_schedules", "schedules")
with open("status/20240308_multi-backup.json", "w", encoding="utf-8") as file:
file.write(
json.dumps(
{
"backup_migration": {
"status": backup_migration_status,
"pid": uuid.uuid4(),
},
"schedule_migration": {
"status": schedule_migration_status,
"pid": uuid.uuid4(),
},
}
)
)
def rollback(migrator: Migrator, database, **kwargs):
"""

22
main.py
View File

@ -115,6 +115,23 @@ def controller_setup():
controller.clear_support_status()
def get_migration_notifications():
migration_notifications = []
for file in os.listdir(
os.path.join(APPLICATION_PATH, "app", "migrations", "status")
):
if os.path.isfile(file):
with open(
os.path.join(APPLICATION_PATH, "app", "migrations", "status", file),
encoding="utf-8",
) as status_file:
status_json = json.load(status_file)
for item in status_json:
if not status_json[item].get("status"):
migration_notifications.append(item)
return migration_notifications
def tasks_starter():
"""
Method starts stats recording, app scheduler, and
@ -350,6 +367,9 @@ if __name__ == "__main__":
helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
)
database_proxy.initialize(database)
Helpers.ensure_dir_exists(
os.path.join(APPLICATION_PATH, "app", "migrations", "status")
)
migration_manager = MigrationManager(database, helper)
migration_manager.up() # Automatically runs migrations
@ -408,7 +428,7 @@ if __name__ == "__main__":
controller.set_project_root(APPLICATION_PATH)
tasks_manager = TasksManager(helper, controller, file_helper)
import3 = Import3(helper, controller)
helper.migration_notifications = get_migration_notifications()
# Check to see if client config.json version is different than the
# Master config.json in helpers.py
Console.info("Checking for remote changes to config.json")