()
| 795 | } |
| 796 | |
| 797 | func (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 | } |
no test coverage detected