From 8f7fe2706bc45e5ea9e8fb5a6793d355336a0667 Mon Sep 17 00:00:00 2001 From: Alishan Ladhani Date: Mon, 21 Jun 2021 14:19:21 -0400 Subject: [PATCH 1/2] Don't display warnings for unrelated migrations --- .../migration-testing/expected-comment.txt | 1 + .../migration-testing/migration-stats.json | 16 ++++++++++++++++ .../fixtures/migration-testing/migrations.json | 7 +++++++ notifier/spec/warnings_spec.rb | 4 ++++ notifier/warnings.rb | 2 +- 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/notifier/spec/fixtures/migration-testing/expected-comment.txt b/notifier/spec/fixtures/migration-testing/expected-comment.txt index d5d0e224..350c9912 100644 --- a/notifier/spec/fixtures/migration-testing/expected-comment.txt +++ b/notifier/spec/fixtures/migration-testing/expected-comment.txt @@ -103,6 +103,7 @@ Migrations included in this change have been executed on gitlab.com data for tes | Migration | Type | Total runtime | Result | DB size change | | --------- | ---- | ------------- | ------ | -------------- | +| 20210601233122 - UnrelatedMigration | Regular | 10000.0 s | :warning: | +0.00 B | diff --git a/notifier/spec/fixtures/migration-testing/migration-stats.json b/notifier/spec/fixtures/migration-testing/migration-stats.json index 4320d5b4..ae821b4d 100644 --- a/notifier/spec/fixtures/migration-testing/migration-stats.json +++ b/notifier/spec/fixtures/migration-testing/migration-stats.json @@ -606,5 +606,21 @@ "rows": 0 } ] + }, + { + "migration": 20210601233122, + "walltime": 10000, + "success": true, + "total_database_size_change": 0, + "query_statistics": [ + { + "query": "select pg_database_size(current_database()) /*application:test*/", + "calls": 1, + "total_time": 84.903616, + "max_time": 84.903616, + "mean_time": 84.903616, + "rows": 1 + } + ] } ] diff --git a/notifier/spec/fixtures/migration-testing/migrations.json b/notifier/spec/fixtures/migration-testing/migrations.json index 11faadc1..b04a25c2 100644 --- a/notifier/spec/fixtures/migration-testing/migrations.json +++ b/notifier/spec/fixtures/migration-testing/migrations.json @@ -19,5 +19,12 @@ "name": "CreateTestTable", "type": "regular", "intro_on_current_branch": true + }, + "20210601233122": { + "version": 20210601233122, + "path": "db/migrate/20210601233122_unrelated_migration.rb", + "name": "UnrelatedMigration", + "type": "regular", + "intro_on_current_branch": false } } diff --git a/notifier/spec/warnings_spec.rb b/notifier/spec/warnings_spec.rb index 9d414cee..3bc6ad20 100644 --- a/notifier/spec/warnings_spec.rb +++ b/notifier/spec/warnings_spec.rb @@ -31,5 +31,9 @@ RSpec.describe Warnings do expect(subject.render).to include('should not exceed 100ms') expect(subject.render).to include('222.49203') end + + it 'excludes migrations not introduced on current branch' do + expect(subject.render).not_to include('UnrelatedMigration') + end end end diff --git a/notifier/warnings.rb b/notifier/warnings.rb index 72976b29..8e2b9484 100644 --- a/notifier/warnings.rb +++ b/notifier/warnings.rb @@ -4,7 +4,7 @@ class Warnings attr_reader :all def initialize(result) - @all = result.migrations.values.select(&:warning?).map(&:warnings).flatten + @all = result.migrations_from_branch.select(&:warning?).map(&:warnings).flatten end def count -- GitLab From 56a2dbef0fe306c228bfdf0bfe9fb51642158d87 Mon Sep 17 00:00:00 2001 From: Simon Tomlinson Date: Mon, 21 Jun 2021 19:05:58 +0000 Subject: [PATCH 2/2] Apply 1 suggestion(s) to 1 file(s) --- notifier/spec/warnings_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/notifier/spec/warnings_spec.rb b/notifier/spec/warnings_spec.rb index 3bc6ad20..40600774 100644 --- a/notifier/spec/warnings_spec.rb +++ b/notifier/spec/warnings_spec.rb @@ -33,7 +33,9 @@ RSpec.describe Warnings do end it 'excludes migrations not introduced on current branch' do - expect(subject.render).not_to include('UnrelatedMigration') + excluded_name = 'UnrelatedMigration' + expect(result.other_migrations.map(&:name)).to include(excluded_name) + expect(subject.render).not_to include(excluded_name) end end end -- GitLab