Add the remove commands.

Fixed deleting to remove destinations with a backup plan.
This commit is contained in:
2025-01-09 21:55:54 +02:00
parent ea5d98490d
commit ea0cc3dab0
5 changed files with 89 additions and 1 deletions
@@ -0,0 +1,3 @@
from .remove_all_backup_plans_command import RemoveAllBackupBackupPlansCommand
__all__ = ['RemoveAllBackupBackupPlansCommand']
@@ -0,0 +1,8 @@
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
class RemoveAllBackupBackupPlansCommand:
def execute(self) -> bool:
rows = BackupPlanModel.delete().execute()
rows = DestinationModel.delete().execute() + rows
return rows != 0
@@ -7,7 +7,7 @@ from .backup_plan_repository_port import BackupPlanRepositoryPort
from tui_rsync.core.components.backup_plan.domain import BackupPlan
from tui_rsync.core.shared_kernel.components.common import UUID
from tui_rsync.infrastructure.orm.models import BackupPlanModel
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
class BackupPlanRepository(BackupPlanRepositoryPort):
@@ -34,4 +34,5 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
def delete(self, uuid: UUID) -> bool:
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
deleted = DestinationModel.delete().where(DestinationModel.source == uuid.id).execute() | deleted
return bool(deleted)