From 61b630468c6ad6c9bf06be8e9b02785c995f7a5a Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 11 Oct 2023 02:58:47 +0000 Subject: Add latest changes from gitlab-org/gitlab@16-4-stable-ee --- ...wap_notes_id_to_bigint_for_self_managed_spec.rb | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'spec/migrations') diff --git a/spec/migrations/20230726144458_swap_notes_id_to_bigint_for_self_managed_spec.rb b/spec/migrations/20230726144458_swap_notes_id_to_bigint_for_self_managed_spec.rb index b4552cebc58..96151de1148 100644 --- a/spec/migrations/20230726144458_swap_notes_id_to_bigint_for_self_managed_spec.rb +++ b/spec/migrations/20230726144458_swap_notes_id_to_bigint_for_self_managed_spec.rb @@ -115,6 +115,42 @@ RSpec.describe SwapNotesIdToBigintForSelfManaged, feature_category: :database do end end end + + context 'when having different naming for fk_d83a918cb1 foreign key' do + before do + connection.execute('ALTER TABLE system_note_metadata DROP CONSTRAINT IF EXISTS fk_d83a918cb1') + connection.execute('ALTER TABLE system_note_metadata DROP CONSTRAINT IF EXISTS fk_rails_d83a918cb1') + connection.execute('ALTER TABLE system_note_metadata ADD CONSTRAINT fk_rails_d83a918cb1 FOREIGN KEY (note_id) + REFERENCES notes(id) ON DELETE CASCADE') + end + + after do + connection.execute('ALTER TABLE system_note_metadata DROP CONSTRAINT IF EXISTS fk_rails_d83a918cb1') + connection.execute('ALTER TABLE system_note_metadata DROP CONSTRAINT IF EXISTS fk_d83a918cb1_tmp') + connection.execute('ALTER TABLE system_note_metadata ADD CONSTRAINT fk_d83a918cb1 FOREIGN KEY (note_id) + REFERENCES notes(id) ON DELETE CASCADE') + end + + it 'swaps the columns' do + disable_migrations_output do + reversible_migration do |migration| + migration.before -> { + notes_table.reset_column_information + + expect(notes_table.columns.find { |c| c.name == 'id' }.sql_type).to eq('integer') + expect(notes_table.columns.find { |c| c.name == 'id_convert_to_bigint' }.sql_type).to eq('bigint') + } + + migration.after -> { + notes_table.reset_column_information + + expect(notes_table.columns.find { |c| c.name == 'id' }.sql_type).to eq('bigint') + expect(notes_table.columns.find { |c| c.name == 'id_convert_to_bigint' }.sql_type).to eq('integer') + } + end + end + end + end end end end -- cgit v1.2.3