Update migration

Add backup return function
This commit is contained in:
amcmanu3 2024-03-08 23:22:54 -05:00
parent 1a8d351fbd
commit eec9432118
3 changed files with 32 additions and 1 deletions

View File

@ -181,6 +181,10 @@ class ManagementController:
def get_backup_config(server_id):
return HelpersManagement.get_backup_config(server_id)
@staticmethod
def get_backups_by_server(server_id, model=False):
return HelpersManagement.get_backups_by_server(server_id, model)
def set_backup_config(
self,
server_id: int,

View File

@ -132,6 +132,7 @@ class Backups(BaseModel):
shutdown = BooleanField(default=False)
before = CharField(default="")
after = CharField(default="")
enabled = BooleanField(default=True)
class Meta:
table_name = "backups"
@ -390,7 +391,7 @@ class HelpersManagement:
Backups.select().where(Backups.server_id == server_id).join(Servers)[0]
)
conf = {
"backup_path": row.server_id.backup_path,
"backup_path": row.backup_location,
"excluded_dirs": row.excluded_dirs,
"max_backups": row.max_backups,
"server_id": row.server_id_id,
@ -412,6 +413,29 @@ class HelpersManagement:
}
return conf
@staticmethod
def get_backups_by_server(server_id, model):
if not model:
data = {}
for backup in (
Backups.select().where(Backups.server_id == server_id).execute()
):
data[str(backup.backup_id)] = {
"backup_id": backup.backup_id,
"backup_name": backup.backup_name,
"backup_path": backup.backup_location,
"excluded_dirs": backup.excluded_dirs,
"max_backups": backup.max_backups,
"server_id": backup.server_id_id,
"compress": backup.compress,
"shutdown": backup.shutdown,
"before": backup.before,
"after": backup.after,
}
else:
data = Backups.select().where(Backups.server_id == server_id).execute()
return data
@staticmethod
def remove_backup_config(server_id):
Backups.delete().where(Backups.server_id == server_id).execute()

View File

@ -19,6 +19,7 @@ def migrate(migrator: Migrator, database, **kwargs):
migrator.add_columns("backups", backup_id=peewee.UUIDField(default=uuid.uuid4))
migrator.add_columns("backups", backup_name=peewee.CharField(default="Default"))
migrator.add_columns("backups", backup_location=peewee.CharField(default=""))
migrator.add_columns("backups", enabled=peewee.BooleanField(default=True))
class Servers(peewee.Model):
server_id = peewee.CharField(primary_key=True, default=str(uuid.uuid4()))
@ -58,6 +59,7 @@ def migrate(migrator: Migrator, database, **kwargs):
shutdown = peewee.BooleanField(default=False)
before = peewee.CharField(default="")
after = peewee.CharField(default="")
enabled = peewee.BooleanField(default=True)
class Meta:
table_name = "new_backups"
@ -83,6 +85,7 @@ def migrate(migrator: Migrator, database, **kwargs):
shutdown=backup.shutdown,
before=backup.before,
after=backup.after,
enabled=True,
)
# Drop the existing backups table