2020-04-27 12:09:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'post_migrate', '20200427064130_cleanup_optimistic_locking_nulls_pt2_fixed.rb')
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe CleanupOptimisticLockingNullsPt2Fixed, :migration do
|
2020-05-14 21:07:52 +00:00
|
|
|
test_tables = %w(ci_stages ci_builds ci_pipelines).freeze
|
|
|
|
test_tables.each do |table|
|
2020-04-27 12:09:41 +00:00
|
|
|
let(table.to_sym) { table(table.to_sym) }
|
|
|
|
end
|
2020-05-14 21:07:52 +00:00
|
|
|
let(:tables) { test_tables.map { |t| method(t.to_sym).call } }
|
2020-04-27 12:09:41 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
# Create necessary rows
|
|
|
|
ci_stages.create!
|
|
|
|
ci_builds.create!
|
|
|
|
ci_pipelines.create!
|
|
|
|
|
|
|
|
# Nullify `lock_version` column for all rows
|
|
|
|
# Needs to be done with a SQL fragment, otherwise Rails will coerce it to 0
|
|
|
|
tables.each do |table|
|
|
|
|
table.update_all('lock_version = NULL')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly migrates nullified lock_version column', :sidekiq_might_not_need_inline do
|
|
|
|
tables.each do |table|
|
|
|
|
expect(table.where(lock_version: nil).count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
tables.each do |table|
|
|
|
|
expect(table.where(lock_version: 0).count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
migrate!
|
|
|
|
|
|
|
|
tables.each do |table|
|
|
|
|
expect(table.where(lock_version: nil).count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
tables.each do |table|
|
|
|
|
expect(table.where(lock_version: 0).count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|