Skip to content

Commit 9e849ed

Browse files
Merge pull request #128 from gabriel-samfira/set-on-delete-for-jobs
Set on delete for jobs
2 parents 9a87735 + dea941d commit 9e849ed

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

database/sql/models.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type Pool struct {
7474
GitHubRunnerGroup string
7575

7676
RepoID *uuid.UUID `gorm:"index"`
77-
Repository Repository `gorm:"foreignKey:RepoID"`
77+
Repository Repository `gorm:"foreignKey:RepoID;"`
7878

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

9899
type Organization struct {
@@ -101,7 +102,8 @@ type Organization struct {
101102
CredentialsName string
102103
Name string `gorm:"index:idx_org_name_nocase,collate:nocase"`
103104
WebhookSecret []byte
104-
Pools []Pool `gorm:"foreignKey:OrgID"`
105+
Pools []Pool `gorm:"foreignKey:OrgID"`
106+
Jobs []WorkflowJob `gorm:"foreignKey:OrgID;constraint:OnDelete:SET NULL"`
105107
}
106108

107109
type Enterprise struct {
@@ -110,7 +112,8 @@ type Enterprise struct {
110112
CredentialsName string
111113
Name string `gorm:"index:idx_ent_name_nocase,collate:nocase"`
112114
WebhookSecret []byte
113-
Pools []Pool `gorm:"foreignKey:EnterpriseID"`
115+
Pools []Pool `gorm:"foreignKey:EnterpriseID"`
116+
Jobs []WorkflowJob `gorm:"foreignKey:EnterpriseID;constraint:OnDelete:SET NULL"`
114117
}
115118

116119
type Address struct {

database/sql/sql.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (s *sqlDatabase) cascadeMigrationSQLite(model interface{}, name string, jus
126126
}
127127
}
128128

129-
if strings.Contains(data, "ON DELETE CASCADE") {
129+
if strings.Contains(data, "ON DELETE") {
130130
return nil
131131
}
132132

@@ -178,6 +178,10 @@ func (s *sqlDatabase) cascadeMigration() error {
178178
if err := s.cascadeMigrationSQLite(&Tag{}, "pool_tags", false); err != nil {
179179
return fmt.Errorf("failed to migrate addresses: %w", err)
180180
}
181+
182+
if err := s.cascadeMigrationSQLite(&WorkflowJob{}, "workflow_jobs", false); err != nil {
183+
return fmt.Errorf("failed to migrate addresses: %w", err)
184+
}
181185
case config.MySQLBackend:
182186
return nil
183187
default:

0 commit comments

Comments
 (0)