Create relation between WorkflowJobs and Instances

Ensure that there is a foreign key constraint between runners and jobs.
Once a runner is associated with a job, we want the job to be removed along
with the runner.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2023-08-26 19:43:57 +00:00
parent d3479790d7
commit 59e6fb28c2
3 changed files with 57 additions and 18 deletions

View file

@ -162,6 +162,8 @@ type Instance struct {
Pool Pool `gorm:"foreignKey:PoolID"`
StatusMessages []InstanceStatusUpdate `gorm:"foreignKey:InstanceID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
Job *WorkflowJob `gorm:"foreignKey:InstanceID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
}
type User struct {
@ -201,8 +203,11 @@ type WorkflowJob struct {
StartedAt time.Time
CompletedAt time.Time
GithubRunnerID int64
RunnerName string
GithubRunnerID int64
InstanceID *uuid.UUID `gorm:"index:idx_instance_job"`
Instance Instance `gorm:"foreignKey:InstanceID"`
RunnerGroupID int64
RunnerGroupName string