Skip to content

Commit

Permalink
Cleanup after truncate packages
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap authored and ezr-ondrej committed Aug 12, 2024
1 parent c397b7b commit 63b9a5d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 46 deletions.
13 changes: 0 additions & 13 deletions cmd/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ func main() {
// List functions in manual package and execute them
errors = manual.Execute()

// Disable foreign key constraints when migrating to be able to delete the constraint
// TODO: delete this workaround once images are cleaned up properly
db.DB.Config.DisableForeignKeyConstraintWhenMigrating = true
if db.DB.Migrator().HasConstraint("commit_installed_packages", "fk_commit_installed_packages_installed_package") {
log.Info("Dropping foreign key constraint fk_commit_installed_packages_installed_package")
if err := db.DB.Migrator().DropConstraint("commit_installed_packages", "fk_commit_installed_packages_installed_package"); err != nil {
errors = append(errors, err)
}
}

// Automigration
log.Info("Auto migration started ...")

Expand Down Expand Up @@ -140,9 +130,6 @@ func main() {
}
}

constraintExists := db.DB.Migrator().HasConstraint("commit_installed_packages", "fk_commit_installed_packages_installed_package")
log.Infof("Foreign key constraint fk_commit_installed_packages_installed_package exists: %v", constraintExists)

// flush logger before app exit
l.FlushLogger()
if len(errors) > 0 {
Expand Down
28 changes: 0 additions & 28 deletions cmd/migrate/manual/000_truncate_packages.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/models/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Commit struct {
BuildNumber uint `json:"BuildNumber"`
BlueprintToml string `json:"BlueprintToml"`
Arch string `json:"Arch"`
InstalledPackages []InstalledPackage `json:"InstalledPackages,omitempty" gorm:"many2many:commit_installed_packages;"`
InstalledPackages []InstalledPackage `json:"InstalledPackages,omitempty" gorm:"constraint:OnDelete:CASCADE;many2many:commit_installed_packages;"`
ComposeJobID string `json:"ComposeJobID"`
Status string `json:"Status"`
RepoID *uint `json:"RepoID"`
Expand Down Expand Up @@ -75,7 +75,7 @@ type InstalledPackage struct {
Type string `json:"type"`
Version string `json:"version"`
Epoch string `json:"epoch,omitempty"`
Commits []Commit `gorm:"many2many:commit_installed_packages;save_association:false"`
Commits []Commit `gorm:"constraint:OnDelete:CASCADE;many2many:commit_installed_packages;save_association:false"`
}

type CommitInstalledPackages struct {
Expand Down
3 changes: 0 additions & 3 deletions unleash/features/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ var CleanUPDevices = &Flag{Name: "edge-management.cleanup_devices", EnvVar: "FEA
// CleanUPOrphanCommits is a feature flag to use for cleanup orphan commits
var CleanUPOrphanCommits = &Flag{Name: "edge-management.cleanup_orphan_commits", EnvVar: "FEATURE_CLEANUP_ORPHAN_COMMITS"}

// TruncatePackages enables the truncation of packages tables during migration
var TruncatePackages = &Flag{Name: "edge-management.truncate_packages", EnvVar: "TRUNCATE_PACKAGES"}

// STATIC DELTA FLAGS

// SkipUpdateRepo is a feature flag to skip the process of download and re-upload of update repositories
Expand Down

0 comments on commit 63b9a5d

Please sign in to comment.