Skip to content

Commit f198ced

Browse files
committed
Consider data migration as pending migration
When asking for pending migrations, it might take into account the data migrations as well.
1 parent 126560e commit f198ced

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

lib/obs_deploy/check_diff.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ def migrations
4949
GitDiffParser.parse(github_diff).files.select { |f| f =~ %r{db/migrate} }
5050
end
5151

52+
def data_migrations
53+
return [] unless data_migration?
54+
55+
GitDiffParser.parse(github_diff).files.select { |f| f =~ %r{db/data} }
56+
end
57+
5258
def package_url
5359
URI("#{@server}/public/build/#{@project}/#{@product}/x86_64/obs-server")
5460
end

lib/obs_deploy/cli/commands/get_pending_migration.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ def call(url:, targeturl:, ignore_certificate:, **)
1818
end
1919

2020
migrations = ObsDeploy::CheckDiff.new(server: url, target_server: targeturl).migrations
21+
data_migrations = ObsDeploy::CheckDiff.new(server: url, target_server: targeturl).data_migrations
2122

22-
if migrations.empty?
23+
if migrations.empty? && data_migrations.empty?
2324
puts 'No pending migrations'
2425
exit(0)
2526
else
26-
puts migrations
27+
puts migrations if migrations
28+
puts data_migrations if data_migrations
2729
exit(1)
2830
end
2931
end

spec/check_diff_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,40 @@
140140
end
141141
end
142142
end
143+
144+
describe '#data_migrations' do
145+
subject { check_diff.data_migrations }
146+
147+
context 'no pending data migration' do
148+
let(:diff_url) { "https://github.com/openSUSE/open-build-service/compare/#{running_commit}...#{package_commit}.diff" }
149+
let(:fixture_file) { File.new('spec/fixtures/github_diff_without_migration.txt') }
150+
let(:running_commit) { 'bc7f6c0' }
151+
let(:package_commit) { '554e943' }
152+
before do
153+
allow(check_diff).to receive(:obs_running_commit).and_return(running_commit)
154+
allow(check_diff).to receive(:package_commit).and_return(package_commit)
155+
stub_request(:get, diff_url).to_return(fixture_file)
156+
end
157+
158+
it { expect(check_diff.github_diff).not_to be_empty }
159+
it { expect(check_diff.data_migration?).to be false }
160+
end
161+
162+
context 'data is present' do
163+
let(:diff_url) { "https://github.com/openSUSE/open-build-service/compare/#{running_commit}...#{package_commit}.diff" }
164+
before do
165+
allow(check_diff).to receive(:obs_running_commit).and_return(running_commit)
166+
allow(check_diff).to receive(:package_commit).and_return(package_commit)
167+
stub_request(:get, diff_url).to_return(fixture_file)
168+
end
169+
170+
context 'pending data migration' do
171+
let(:fixture_file) { File.new('spec/fixtures/github_diff_with_data_migration.txt') }
172+
let(:data_migration_file) { 'db/data/20200424080753_generate_web_notifications.rb' }
173+
let(:running_commit) { '2392177' }
174+
let(:package_commit) { '8c6783b' }
175+
it { expect(subject.first).to include(data_migration_file) }
176+
end
177+
end
178+
end
143179
end

0 commit comments

Comments
 (0)