Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion backend/app/orm/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ class EventParticipantORM(SQLModel, table=True):
)
)
participant_name: str
vm_id: uuid.UUID = Field(foreign_key="vms.id")
vm_id: uuid.UUID = Field(
sa_column=Column(
UUID(as_uuid=True),
ForeignKey("vms.id", ondelete="CASCADE"),
nullable=False,
)
)
created_at: datetime = Field(default_factory=datetime.utcnow)
11 changes: 11 additions & 0 deletions backend/app/services/vm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sqlmodel import Session, select, delete
from app.orm.vm import VmORM
from app.orm.vm_credential import VmCredentialORM
from app.orm.event import EventParticipantORM
from app.orm.slave import SlaveORM
from fastapi import status, HTTPException
from app.utils.vm import get_vm_ip
Expand Down Expand Up @@ -277,6 +278,11 @@ def remove(self):
rmtree(vm_dir)

with Session(engine) as session:
session.exec(
delete(EventParticipantORM).where(
EventParticipantORM.vm_id == self.id
)
)
session.exec(
delete(VmCredentialORM).where(
VmCredentialORM.vm_id == self.id
Expand Down Expand Up @@ -564,6 +570,11 @@ def remove_vm(vm_id: str):
slave_delete_vm(slave, vm_id)
# Remove the reference from master DB
with Session(engine) as session:
session.exec(
delete(EventParticipantORM).where(
EventParticipantORM.vm_id == uuid.UUID(vm_id)
)
)
session.exec(
delete(VmCredentialORM).where(
VmCredentialORM.vm_id == uuid.UUID(vm_id)
Expand Down
Loading