MCPcopy Create free account
hub / github.com/cloudbase/garm / migrateDB

Method migrateDB

database/sql/sql.go:797–886  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

795}
796
797func (s *sqlDatabase) migrateDB() error {
798 // Drop obsolete indexes
799 s.dropIndexIfExists(&Organization{}, "idx_organizations_name")
800 s.dropIndexIfExists(&Repository{}, "idx_owner")
801
802 // Run cascade migration
803 if err := s.cascadeMigration(); err != nil {
804 return fmt.Errorf("error running cascade migration: %w", err)
805 }
806
807 // Migrate pool null IDs
808 if err := s.migratePoolNullIDs(); err != nil {
809 return err
810 }
811
812 // Migrate workflows
813 if err := s.migrateWorkflow(); err != nil {
814 return fmt.Errorf("error migrating workflows: %w", err)
815 }
816
817 // Migrate GitHub endpoint type
818 if err := s.migrateGithubEndpointType(); err != nil {
819 return err
820 }
821
822 // Check if we need to migrate credentials and templates
823 needsCredentialMigration, migrateTemplates, hasMinAgeField, hasAgentURL := s.preMigrationChecks()
824
825 // Run main schema migration
826 s.conn.Exec("PRAGMA foreign_keys = OFF")
827 if err := s.conn.AutoMigrate(
828 &User{},
829 &GithubEndpoint{},
830 &GithubCredentials{},
831 &GiteaCredentials{},
832 &Tag{},
833 &Template{},
834 &Pool{},
835 &Repository{},
836 &Organization{},
837 &Enterprise{},
838 &EnterpriseEvent{},
839 &OrganizationEvent{},
840 &RepositoryEvent{},
841 &Address{},
842 &InstanceStatusUpdate{},
843 &Instance{},
844 &ControllerInfo{},
845 &WorkflowJob{},
846 &ScaleSet{},
847 ); err != nil {
848 return fmt.Errorf("error running auto migrate: %w", err)
849 }
850
851 // Migrate file object tables in the attached objectsdb schema
852 if err := s.migrateFileObjects(); err != nil {
853 return fmt.Errorf("error migrating file objects: %w", err)
854 }

Callers 1

NewSQLDatabaseFunction · 0.95

Calls 12

dropIndexIfExistsMethod · 0.95
cascadeMigrationMethod · 0.95
migratePoolNullIDsMethod · 0.95
migrateWorkflowMethod · 0.95
preMigrationChecksMethod · 0.95
migrateFileObjectsMethod · 0.95
migrateAutoVacuumMethod · 0.95
migrateControllerInfoMethod · 0.95
ensureGithubEndpointMethod · 0.95
ensureTemplatesMethod · 0.95

Tested by

no test coverage detected