diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-27 15:09:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-27 15:09:41 +0300 |
commit | 45999bfdec535b959f46fa4ed8f761bb3eadfed4 (patch) | |
tree | 12dda4fdec530172f3d21da4cc667dd73c9df133 /spec/migrations | |
parent | 39fa1b598749be0aad699032bbf31450b3ff0098 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb b/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb new file mode 100644 index 00000000000..2f8237c1c1c --- /dev/null +++ b/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200427064130_cleanup_optimistic_locking_nulls_pt2_fixed.rb') + +describe CleanupOptimisticLockingNullsPt2Fixed, :migration do + TABLES = %w(ci_stages ci_builds ci_pipelines).freeze + TABLES.each do |table| + let(table.to_sym) { table(table.to_sym) } + end + let(:tables) { TABLES.map { |t| method(t.to_sym).call } } + + 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 |