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

Method migrateControllerInfo

database/sql/sql.go:746–777  ·  view source on GitHub ↗

migrateControllerInfo updates controller info with new fields

(hasMinAgeField, hasAgentURL bool)

Source from the content-addressed store, hash-verified

744
745// migrateControllerInfo updates controller info with new fields
746func (s *sqlDatabase) migrateControllerInfo(hasMinAgeField, hasAgentURL bool) error {
747 if hasMinAgeField && hasAgentURL {
748 return nil
749 }
750
751 var controller ControllerInfo
752 if err := s.conn.First(&controller).Error; err != nil {
753 if errors.Is(err, gorm.ErrRecordNotFound) {
754 return nil
755 }
756 return fmt.Errorf("error fetching controller info: %w", err)
757 }
758
759 if !hasMinAgeField {
760 controller.MinimumJobAgeBackoff = 30
761 }
762
763 if controller.GARMAgentReleasesURL == "" {
764 controller.GARMAgentReleasesURL = appdefaults.GARMAgentDefaultReleasesURL
765 }
766
767 if !hasAgentURL && controller.WebhookBaseURL != "" {
768 matchWebhooksPath := regexp.MustCompile(`/webhooks(/)?$`)
769 controller.AgentURL = matchWebhooksPath.ReplaceAllLiteralString(controller.WebhookBaseURL, `/agent`)
770 }
771
772 if err := s.conn.Save(&controller).Error; err != nil {
773 return fmt.Errorf("error updating controller info: %w", err)
774 }
775
776 return nil
777}
778
779// preMigrationChecks performs checks before running migrations
780func (s *sqlDatabase) preMigrationChecks() (needsCredentialMigration, migrateTemplates, hasMinAgeField, hasAgentURL bool) {

Callers 1

migrateDBMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected