@@ -21,7 +21,7 @@ class Emission(Base):
2121 gpu_energy = Column (Float )
2222 ram_energy = Column (Float )
2323 energy_consumed = Column (Float )
24- run_id = Column (UUID (as_uuid = True ), ForeignKey ("runs.id" ))
24+ run_id = Column (UUID (as_uuid = True ), ForeignKey ("runs.id" , ondelete = "CASCADE" ))
2525 run = relationship ("Run" , back_populates = "emissions" )
2626
2727 def __repr__ (self ):
@@ -37,7 +37,9 @@ class Run(Base):
3737 __tablename__ = "runs"
3838 id = Column (UUID (as_uuid = True ), primary_key = True , index = True , default = uuid .uuid4 )
3939 timestamp = Column (DateTime )
40- experiment_id = Column (UUID (as_uuid = True ), ForeignKey ("experiments.id" ))
40+ experiment_id = Column (
41+ UUID (as_uuid = True ), ForeignKey ("experiments.id" , ondelete = "CASCADE" )
42+ )
4143 os = Column (String , nullable = True )
4244 python_version = Column (String , nullable = True )
4345 codecarbon_version = Column (String , nullable = True )
@@ -52,7 +54,9 @@ class Run(Base):
5254 ram_total_size = Column (Float , nullable = True )
5355 tracking_mode = Column (String , nullable = True )
5456 experiment = relationship ("Experiment" , back_populates = "runs" )
55- emissions = relationship ("Emission" , back_populates = "run" )
57+ emissions = relationship (
58+ "Emission" , back_populates = "run" , cascade = "all, delete-orphan"
59+ )
5660
5761 def __repr__ (self ):
5862 return (
@@ -87,9 +91,13 @@ class Experiment(Base):
8791 on_cloud = Column (Boolean , default = False )
8892 cloud_provider = Column (String )
8993 cloud_region = Column (String )
90- project_id = Column (UUID (as_uuid = True ), ForeignKey ("projects.id" ))
94+ project_id = Column (
95+ UUID (as_uuid = True ), ForeignKey ("projects.id" , ondelete = "CASCADE" )
96+ )
9197 project = relationship ("Project" , back_populates = "experiments" )
92- runs = relationship ("Run" , back_populates = "experiment" )
98+ runs = relationship (
99+ "Run" , back_populates = "experiment" , cascade = "all, delete-orphan"
100+ )
93101
94102 def __repr__ (self ):
95103 return (
@@ -111,9 +119,13 @@ class Project(Base):
111119 description = Column (String )
112120 public = Column (Boolean , default = False )
113121 organization_id = Column (UUID (as_uuid = True ), ForeignKey ("organizations.id" ))
114- experiments = relationship ("Experiment" , back_populates = "project" )
122+ experiments = relationship (
123+ "Experiment" , back_populates = "project" , cascade = "all, delete-orphan"
124+ )
115125 organization = relationship ("Organization" , back_populates = "projects" )
116- project_tokens = relationship ("ProjectToken" , back_populates = "project" )
126+ project_tokens = relationship (
127+ "ProjectToken" , back_populates = "project" , cascade = "all, delete-orphan"
128+ )
117129
118130 def __repr__ (self ):
119131 return (
@@ -176,7 +188,9 @@ def __repr__(self):
176188class ProjectToken (Base ):
177189 __tablename__ = "project_tokens"
178190 id = Column (UUID (as_uuid = True ), primary_key = True , index = True , default = uuid .uuid4 )
179- project_id = Column (UUID (as_uuid = True ), ForeignKey ("projects.id" ))
191+ project_id = Column (
192+ UUID (as_uuid = True ), ForeignKey ("projects.id" , ondelete = "CASCADE" )
193+ )
180194 name = Column (String )
181195 hashed_token = Column (String , nullable = False )
182196 lookup_value = Column (
0 commit comments