Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-30 21:53:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-30 21:53:49 +0300
commit52c415c0aa74b27fb203e4c9c8d95d2c1566e870 (patch)
tree7576623c94d4668b635f1375a9beac29f0f2c12f /spec
parenta0111b1203b94b47e9d68be934b3a6f2ba01eed0 (diff)
Add latest changes from gitlab-org/gitlab@16-0-stable-ee
Diffstat (limited to 'spec')
-rw-r--r--spec/tasks/gitlab/db/migration_fix_15_11_rake_spec.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/tasks/gitlab/db/migration_fix_15_11_rake_spec.rb b/spec/tasks/gitlab/db/migration_fix_15_11_rake_spec.rb
new file mode 100644
index 00000000000..3ff07698ad4
--- /dev/null
+++ b/spec/tasks/gitlab/db/migration_fix_15_11_rake_spec.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+require 'rake_helper'
+
+RSpec.describe 'migration_fix_15_11', :reestablished_active_record_base, feature_category: :database do
+ let(:db) { ApplicationRecord.connection }
+ let(:target_init_schema) { '20220314184009' }
+ let(:earlier_init_schema) { '20210101010101' }
+
+ before :all do
+ Rake.application.rake_require 'active_record/railties/databases'
+ Rake.application.rake_require 'tasks/gitlab/db/migration_fix_15_11'
+
+ Rake::Task.define_task :environment
+ end
+
+ describe 'migration_fix_15_11' do
+ context 'when fix is needed' do
+ it 'patches init_schema' do
+ db.execute('DELETE FROM schema_migrations')
+ db.execute("INSERT INTO schema_migrations (version) VALUES ('#{target_init_schema}')")
+ run_rake_task(:migration_fix_15_11)
+ result = db.execute('SELECT * FROM schema_migrations')
+ expect(result.count).to eq(300)
+ end
+ end
+
+ context 'when fix is not needed because no migrations have been run' do
+ it 'does nothing' do
+ db.execute('DELETE FROM schema_migrations')
+ run_rake_task(:migration_fix_15_11)
+ result = db.execute('SELECT * FROM schema_migrations')
+ expect(result.count).to eq(0)
+ end
+ end
+
+ context 'when fix is not needed because DB has not been initialized' do
+ it 'does nothing' do
+ db.execute('DROP TABLE schema_migrations')
+ expect { run_rake_task(:migration_fix_15_11) }.not_to raise_error
+ end
+ end
+
+ context 'when fix is not needed because there is an earlier init_schema' do
+ it 'does nothing' do
+ db.execute('DELETE FROM schema_migrations')
+ db.execute("INSERT INTO schema_migrations (version) VALUES ('#{earlier_init_schema}')")
+ run_rake_task(:migration_fix_15_11)
+ result = db.execute('SELECT * FROM schema_migrations')
+ expect(result.pluck('version')).to match_array [earlier_init_schema]
+ end
+ end
+
+ context 'when fix is not needed because the fix has been run already' do
+ it 'does not affect the schema_migrations table' do
+ db.execute('DELETE FROM schema_migrations')
+ db.execute("INSERT INTO schema_migrations (version) VALUES ('#{target_init_schema}')")
+ run_rake_task(:migration_fix_15_11)
+ fixed_table = db.execute('SELECT version FROM schema_migrations').pluck('version')
+ run_rake_task(:migration_fix_15_11)
+ test_fixed_table = db.execute('SELECT version FROM schema_migrations').pluck('version')
+ expect(fixed_table).to match_array test_fixed_table
+ end
+ end
+ end
+end