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:
parent
d3479790d7
commit
59e6fb28c2
3 changed files with 57 additions and 18 deletions
|
|
@ -221,6 +221,19 @@ func (s *sqlDatabase) migrateDB() error {
|
|||
}
|
||||
}
|
||||
|
||||
if s.conn.Migrator().HasTable(&WorkflowJob{}) {
|
||||
if s.conn.Migrator().HasColumn(&WorkflowJob{}, "runner_name") {
|
||||
// Remove jobs that are not in "queued" status. We really only care about queued jobs. Once they transition
|
||||
// to something else, we don't really consume them anyway.
|
||||
if err := s.conn.Exec("delete from workflow_jobs where status is not 'queued'").Error; err != nil {
|
||||
return errors.Wrap(err, "updating workflow_jobs")
|
||||
}
|
||||
if err := s.conn.Migrator().DropColumn(&WorkflowJob{}, "runner_name"); err != nil {
|
||||
return errors.Wrap(err, "updating workflow_jobs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.conn.AutoMigrate(
|
||||
&Tag{},
|
||||
&Pool{},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue