Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for loading broken migrations during tag filtering #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/outrigger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions spec/db/migrate/20200108125306_legacy_broken_migration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class LegacyBrokenMigration < ActiveRecord::Migration[5.0]
tag :broken

BreakableChange.run

def change
UnresolvedModel.run
end
end
15 changes: 15 additions & 0 deletions spec/outrigger/outrigger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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