File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,5 +36,11 @@ class EventParticipantORM(SQLModel, table=True):
3636 )
3737 )
3838 participant_name : str
39- vm_id : uuid .UUID = Field (foreign_key = "vms.id" )
39+ vm_id : uuid .UUID = Field (
40+ sa_column = Column (
41+ UUID (as_uuid = True ),
42+ ForeignKey ("vms.id" , ondelete = "CASCADE" ),
43+ nullable = False ,
44+ )
45+ )
4046 created_at : datetime = Field (default_factory = datetime .utcnow )
Original file line number Diff line number Diff line change 1414from sqlmodel import Session , select , delete
1515from app .orm .vm import VmORM
1616from app .orm .vm_credential import VmCredentialORM
17+ from app .orm .event import EventParticipantORM
1718from app .orm .slave import SlaveORM
1819from fastapi import status , HTTPException
1920from app .utils .vm import get_vm_ip
@@ -277,6 +278,11 @@ def remove(self):
277278 rmtree (vm_dir )
278279
279280 with Session (engine ) as session :
281+ session .exec (
282+ delete (EventParticipantORM ).where (
283+ EventParticipantORM .vm_id == self .id
284+ )
285+ )
280286 session .exec (
281287 delete (VmCredentialORM ).where (
282288 VmCredentialORM .vm_id == self .id
@@ -564,6 +570,11 @@ def remove_vm(vm_id: str):
564570 slave_delete_vm (slave , vm_id )
565571 # Remove the reference from master DB
566572 with Session (engine ) as session :
573+ session .exec (
574+ delete (EventParticipantORM ).where (
575+ EventParticipantORM .vm_id == uuid .UUID (vm_id )
576+ )
577+ )
567578 session .exec (
568579 delete (VmCredentialORM ).where (
569580 VmCredentialORM .vm_id == uuid .UUID (vm_id )
You can’t perform that action at this time.
0 commit comments