diff --git a/lib/outrigger.rb b/lib/outrigger.rb index 8f42c1d..7c9cc66 100644 --- a/lib/outrigger.rb +++ b/lib/outrigger.rb @@ -8,6 +8,13 @@ module Outrigger def self.filter(*tags) tags = tags.flatten.map(&:to_sym) - proc { |migration| (tags - migration.tags).empty? } + proc do |migration| + begin + # check if migration.tags have complete intersection with requested tags + (tags - migration.tags).empty? + rescue StandardError + false + end + end end end diff --git a/spec/db/migrate/20200108125306_legacy_broken_migration.rb b/spec/db/migrate/20200108125306_legacy_broken_migration.rb new file mode 100644 index 0000000..72bc866 --- /dev/null +++ b/spec/db/migrate/20200108125306_legacy_broken_migration.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class LegacyBrokenMigration < ActiveRecord::Migration[5.0] + tag :broken + + BreakableChange.run + + def change + UnresolvedModel.run + end +end diff --git a/spec/outrigger/outrigger_spec.rb b/spec/outrigger/outrigger_spec.rb index aa8a25c..f84d130 100644 --- a/spec/outrigger/outrigger_spec.rb +++ b/spec/outrigger/outrigger_spec.rb @@ -14,5 +14,20 @@ expect(filter.call(MultiMigration)).to eq(true) expect(filter.call(PreDeployMigration)).to eq(false) end + + it 'should handle broken migrations' do + filter = Outrigger.filter(:broken) + + ActiveRecord::Migration.send :include, Outrigger::Taggable + ActiveRecord::MigrationProxy.send :include, Outrigger::TaggableProxy + legacy_migration = ActiveRecord::MigrationProxy.new( + 'LegacyBrokenMigration', + '20200108125306', + 'spec/db/migrate/20200108125306_legacy_broken_migration.rb', + nil + ) + + expect(filter.call(legacy_migration)).to eq(false) + end end end