diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-15 00:10:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-15 00:10:36 +0300 |
commit | beabc7d164276a8bb35c2b497a0c4dc0dc824e3c (patch) | |
tree | be60f7d352225862e3404fe89c39374fd4e64a1e /spec/migrations | |
parent | 14160fad80415337f8c08755af53ee994b4a7518 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/swap_notes_id_to_bigint_for_gitlab_dot_com_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/migrations/swap_notes_id_to_bigint_for_gitlab_dot_com_spec.rb b/spec/migrations/swap_notes_id_to_bigint_for_gitlab_dot_com_spec.rb new file mode 100644 index 00000000000..d2e64296a70 --- /dev/null +++ b/spec/migrations/swap_notes_id_to_bigint_for_gitlab_dot_com_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe SwapNotesIdToBigintForGitlabDotCom, feature_category: :database do + describe '#up' do + before do + # A we call `schema_migrate_down!` before each example, and for this migration + # `#down` is same as `#up`, we need to ensure we start from the expected state. + connection = described_class.new.connection + connection.execute('ALTER TABLE notes ALTER COLUMN id TYPE integer') + connection.execute('ALTER TABLE notes ALTER COLUMN id_convert_to_bigint TYPE bigint') + end + + # rubocop: disable RSpec/AnyInstanceOf + it 'swaps the integer and bigint columns for GitLab.com, dev, or test' do + allow_any_instance_of(described_class).to receive(:com_or_dev_or_test_but_not_jh?).and_return(true) + + notes = table(:notes) + + disable_migrations_output do + reversible_migration do |migration| + migration.before -> { + notes.reset_column_information + + expect(notes.columns.find { |c| c.name == 'id' }.sql_type).to eq('integer') + expect(notes.columns.find { |c| c.name == 'id_convert_to_bigint' }.sql_type).to eq('bigint') + } + + migration.after -> { + notes.reset_column_information + + expect(notes.columns.find { |c| c.name == 'id' }.sql_type).to eq('bigint') + expect(notes.columns.find { |c| c.name == 'id_convert_to_bigint' }.sql_type).to eq('integer') + } + end + end + end + + it 'is a no-op for other instances' do + allow_any_instance_of(described_class).to receive(:com_or_dev_or_test_but_not_jh?).and_return(false) + + notes = table(:notes) + + disable_migrations_output do + reversible_migration do |migration| + migration.before -> { + notes.reset_column_information + + expect(notes.columns.find { |c| c.name == 'id' }.sql_type).to eq('integer') + expect(notes.columns.find { |c| c.name == 'id_convert_to_bigint' }.sql_type).to eq('bigint') + } + + migration.after -> { + notes.reset_column_information + + expect(notes.columns.find { |c| c.name == 'id' }.sql_type).to eq('integer') + expect(notes.columns.find { |c| c.name == 'id_convert_to_bigint' }.sql_type).to eq('bigint') + } + end + end + end + # rubocop: enable RSpec/AnyInstanceOf + end +end |