try to revert back to old migrate history if failed

This commit is contained in:
Silversthorn 2024-02-16 20:04:12 +01:00
parent 875c9058b0
commit 90e0777b9b
2 changed files with 50 additions and 30 deletions

View File

@ -24,7 +24,7 @@ logger = logging.getLogger(__name__)
class Servers(BaseModel):
server_id = CharField(primary_key=True, default=Helpers.create_uuid())
created = DateTimeField(default=datetime.datetime.now)
server_uuid = CharField(default="", index=True)
# server_uuid = CharField(default="", index=True)
server_name = CharField(default="Server", index=True)
path = CharField(default="")
backup_path = CharField(default="")

View File

@ -4,7 +4,7 @@ import peewee
import logging
from app.classes.shared.console import Console
from app.classes.shared.migration import Migrator
from app.classes.shared.migration import Migrator, MigrateHistory
from app.classes.models.management import (
AuditLog,
Webhooks,
@ -53,6 +53,7 @@ def migrate(migrator: Migrator, database, **kwargs):
table_name = "servers"
database = db
try:
# Changes on Server Table
migrator.alter_column_type(
Servers,
@ -83,6 +84,17 @@ def migrate(migrator: Migrator, database, **kwargs):
),
)
except Exception as ex:
logger.error("Error while migrating Data from Int to UUID (Type Change)")
logger.error(ex)
Console.error("Error while migrating Data from Int to UUID (Type Change)")
Console.error(ex)
last_migration = (
MigrateHistory.select().order_by(MigrateHistory.id.desc()).get()
)
last_migration.delete()
return False
try:
# Changes on Audit Log Table
for audit_log in AuditLog.select():
@ -152,6 +164,10 @@ def migrate(migrator: Migrator, database, **kwargs):
logger.error(ex)
Console.error("Error while migrating Data from Int to UUID (Foreign Keys)")
Console.error(ex)
last_migration = (
MigrateHistory.select().order_by(MigrateHistory.id.desc()).get()
)
last_migration.delete()
return False
try:
@ -166,6 +182,10 @@ def migrate(migrator: Migrator, database, **kwargs):
logger.error(ex)
Console.error("Error while migrating Data from Int to UUID (Primary Keys)")
Console.error(ex)
last_migration = (
MigrateHistory.select().order_by(MigrateHistory.id.desc()).get()
)
last_migration.delete()
return False
# Changes on Server Table