diff --git a/database/sql/models.go b/database/sql/models.go index 2d900368..3404be69 100644 --- a/database/sql/models.go +++ b/database/sql/models.go @@ -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 { diff --git a/database/sql/sql.go b/database/sql/sql.go index 8f9b1185..ac3149e9 100644 --- a/database/sql/sql.go +++ b/database/sql/sql.go @@ -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: