Skip to content

Commit

Permalink
Merge pull request #128 from gabriel-samfira/set-on-delete-for-jobs
Browse files Browse the repository at this point in the history
Set on delete for jobs
  • Loading branch information
gabriel-samfira authored Jul 5, 2023
2 parents 9a87735 + dea941d commit 9e849ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions database/sql/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type Pool struct {
GitHubRunnerGroup string

RepoID *uuid.UUID `gorm:"index"`
Repository Repository `gorm:"foreignKey:RepoID"`
Repository Repository `gorm:"foreignKey:RepoID;"`

OrgID *uuid.UUID `gorm:"index"`
Organization Organization `gorm:"foreignKey:OrgID"`
Expand All @@ -92,7 +92,8 @@ type Repository struct {
Owner string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
Name string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
WebhookSecret []byte
Pools []Pool `gorm:"foreignKey:RepoID"`
Pools []Pool `gorm:"foreignKey:RepoID"`
Jobs []WorkflowJob `gorm:"foreignKey:RepoID;constraint:OnDelete:SET NULL"`
}

type Organization struct {
Expand All @@ -101,7 +102,8 @@ type Organization struct {
CredentialsName string
Name string `gorm:"index:idx_org_name_nocase,collate:nocase"`
WebhookSecret []byte
Pools []Pool `gorm:"foreignKey:OrgID"`
Pools []Pool `gorm:"foreignKey:OrgID"`
Jobs []WorkflowJob `gorm:"foreignKey:OrgID;constraint:OnDelete:SET NULL"`
}

type Enterprise struct {
Expand All @@ -110,7 +112,8 @@ type Enterprise struct {
CredentialsName string
Name string `gorm:"index:idx_ent_name_nocase,collate:nocase"`
WebhookSecret []byte
Pools []Pool `gorm:"foreignKey:EnterpriseID"`
Pools []Pool `gorm:"foreignKey:EnterpriseID"`
Jobs []WorkflowJob `gorm:"foreignKey:EnterpriseID;constraint:OnDelete:SET NULL"`
}

type Address struct {
Expand Down
6 changes: 5 additions & 1 deletion database/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (s *sqlDatabase) cascadeMigrationSQLite(model interface{}, name string, jus
}
}

if strings.Contains(data, "ON DELETE CASCADE") {
if strings.Contains(data, "ON DELETE") {
return nil
}

Expand Down Expand Up @@ -178,6 +178,10 @@ func (s *sqlDatabase) cascadeMigration() error {
if err := s.cascadeMigrationSQLite(&Tag{}, "pool_tags", false); err != nil {
return fmt.Errorf("failed to migrate addresses: %w", err)
}

if err := s.cascadeMigrationSQLite(&WorkflowJob{}, "workflow_jobs", false); err != nil {
return fmt.Errorf("failed to migrate addresses: %w", err)
}
case config.MySQLBackend:
return nil
default:
Expand Down

0 comments on commit 9e849ed

Please sign in to comment.