Skip to content
Draft
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
6 changes: 6 additions & 0 deletions lib/obs_deploy/check_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def migrations
GitDiffParser.parse(github_diff).files.select { |f| f =~ %r{db/migrate} }
end

def data_migrations
return [] unless data_migration?

GitDiffParser.parse(github_diff).files.select { |f| f =~ %r{db/data} }
end

def package_url
URI("#{@server}/public/build/#{@project}/#{@product}/x86_64/obs-server")
end
Expand Down
6 changes: 4 additions & 2 deletions lib/obs_deploy/cli/commands/get_pending_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def call(url:, targeturl:, ignore_certificate:, **)
end

migrations = ObsDeploy::CheckDiff.new(server: url, target_server: targeturl).migrations
data_migrations = ObsDeploy::CheckDiff.new(server: url, target_server: targeturl).data_migrations

if migrations.empty?
if migrations.empty? && data_migrations.empty?
puts 'No pending migrations'
exit(0)
else
puts migrations
puts migrations if migrations
puts data_migrations if data_migrations
exit(1)
end
end
Expand Down
36 changes: 36 additions & 0 deletions spec/check_diff_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,40 @@
end
end
end

describe '#data_migrations' do
subject { check_diff.data_migrations }

context 'no pending data migration' do
let(:diff_url) { "https://github.com/openSUSE/open-build-service/compare/#{running_commit}...#{package_commit}.diff" }
let(:fixture_file) { File.new('spec/fixtures/github_diff_without_migration.txt') }
let(:running_commit) { 'bc7f6c0' }
let(:package_commit) { '554e943' }
before do
allow(check_diff).to receive(:obs_running_commit).and_return(running_commit)
allow(check_diff).to receive(:package_commit).and_return(package_commit)
stub_request(:get, diff_url).to_return(fixture_file)
end

it { expect(check_diff.github_diff).not_to be_empty }
it { expect(check_diff.data_migration?).to be false }
end

context 'data is present' do
let(:diff_url) { "https://github.com/openSUSE/open-build-service/compare/#{running_commit}...#{package_commit}.diff" }
before do
allow(check_diff).to receive(:obs_running_commit).and_return(running_commit)
allow(check_diff).to receive(:package_commit).and_return(package_commit)
stub_request(:get, diff_url).to_return(fixture_file)
end

context 'pending data migration' do
let(:fixture_file) { File.new('spec/fixtures/github_diff_with_data_migration.txt') }
let(:data_migration_file) { 'db/data/20200424080753_generate_web_notifications.rb' }
let(:running_commit) { '2392177' }
let(:package_commit) { '8c6783b' }
it { expect(subject.first).to include(data_migration_file) }
end
end
end
end