Merge pull request #128 from gabriel-samfira/set-on-delete-for-jobs

Set on delete for jobs
This commit is contained in:
Gabriel 2023-07-05 22:56:41 +03:00 committed by GitHub
commit 9e849ed8f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -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"`
@ -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 {
@ -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 {
@ -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 {

View file

@ -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
}
@ -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: