From 34e7f88f5367e133285bd0e05e14cf8329374b50 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Tue, 21 Jun 2022 09:12:55 -0600 Subject: [PATCH] add cyclo complexity, update migrate() to use defer (#3257) --- mattermost-plugin/.golangci.yml | 1 + server/.golangci.yml | 1 + server/services/store/sqlstore/migrate.go | 28 ++++------------------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/mattermost-plugin/.golangci.yml b/mattermost-plugin/.golangci.yml index 90dbb3596..e8163d76b 100644 --- a/mattermost-plugin/.golangci.yml +++ b/mattermost-plugin/.golangci.yml @@ -67,6 +67,7 @@ linters: - unconvert - unused - whitespace + - gocyclo issues: exclude-rules: diff --git a/server/.golangci.yml b/server/.golangci.yml index b336a462a..c1381759f 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -65,3 +65,4 @@ linters: - unconvert - unused - whitespace + - gocyclo diff --git a/server/services/store/sqlstore/migrate.go b/server/services/store/sqlstore/migrate.go index 3153eb862..bb037537b 100644 --- a/server/services/store/sqlstore/migrate.go +++ b/server/services/store/sqlstore/migrate.go @@ -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() }