add cyclo complexity, update migrate() to use defer (#3257)

This commit is contained in:
Scott Bishel 2022-06-21 09:12:55 -06:00 committed by GitHub
parent 3e9219ab0f
commit 34e7f88f53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 24 deletions

View file

@ -67,6 +67,7 @@ linters:
- unconvert
- unused
- whitespace
- gocyclo
issues:
exclude-rules:

View file

@ -65,3 +65,4 @@ linters:
- unconvert
- unused
- whitespace
- gocyclo

View file

@ -204,11 +204,13 @@ func (s *SQLStore) Migrate() error {
if mutexErr != nil {
return fmt.Errorf("error creating database mutex: %w", mutexErr)
}
}
if s.isPlugin {
s.logger.Debug("Acquiring cluster lock for Unique IDs migration")
mutex.Lock()
defer func() {
s.logger.Debug("Releasing cluster lock for Unique IDs migration")
mutex.Unlock()
}()
}
if err := s.migrateSchemaVersionTable(src.Migrations()); err != nil {
@ -220,10 +222,6 @@ func (s *SQLStore) Migrate() error {
}
if err := s.runUniqueIDsMigration(); err != nil {
if s.isPlugin {
s.logger.Debug("Releasing cluster lock for Unique IDs migration")
mutex.Unlock()
}
return fmt.Errorf("error running unique IDs migration: %w", err)
}
@ -232,39 +230,21 @@ func (s *SQLStore) Migrate() error {
}
if err := s.runCategoryUUIDIDMigration(); err != nil {
if s.isPlugin {
s.logger.Debug("Releasing cluster lock for Unique IDs migration")
mutex.Unlock()
}
return fmt.Errorf("error running categoryID migration: %w", err)
}
if err := s.deleteOldSchemaMigrationTable(); err != nil {
if s.isPlugin {
mutex.Unlock()
}
return err
}
if err := ensureMigrationsAppliedUpToVersion(engine, driver, teamsAndBoardsMigrationRequiredVersion); err != nil {
if s.isPlugin {
mutex.Unlock()
}
return err
}
if err := s.migrateTeamLessBoards(); err != nil {
if s.isPlugin {
mutex.Unlock()
}
return err
}
if s.isPlugin {
s.logger.Debug("Releasing cluster lock for Unique IDs migration")
mutex.Unlock()
}
return engine.ApplyAll()
}