diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-26 00:07:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-26 00:07:30 +0300 |
commit | 453fb3ab5c9b08fb04b9de8205e971e2769b9224 (patch) | |
tree | 797a08adfef39a2e353349b14146aa12522eec23 /spec/tasks | |
parent | 99a6475e08172adc2c300273e81fccb04b0a8b0e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/tasks')
-rw-r--r-- | spec/tasks/gitlab/db/migration_fix_15_11_rake_spec.rb | 66 |
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 |