From 13bf612600f126faddb4de5e8376a27a466ff830 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 22 May 2016 22:40:43 +0200 Subject: [PATCH 1/5] Test migration helpers using a migration class --- spec/lib/gitlab/database/migration_helpers_spec.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index ec43165bb5..642954f8d2 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -2,15 +2,13 @@ require 'spec_helper' describe Gitlab::Database::MigrationHelpers, lib: true do let(:model) do - Class.new do - include Gitlab::Database::MigrationHelpers - - def method_missing(name, *args, &block) - ActiveRecord::Base.connection.send(name, *args, &block) - end - end.new + ActiveRecord::Migration.new.extend( + Gitlab::Database::MigrationHelpers + ) end + before { allow(model).to receive(:puts) } + describe '#add_concurrent_index' do context 'outside a transaction' do before do From 9e92b0eead3c2b6dabf377f119cd1f91fd645a42 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 22 May 2016 22:41:14 +0200 Subject: [PATCH 2/5] Add specs for migration helpers and boolean values --- spec/lib/gitlab/database/migration_helpers_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 642954f8d2..35ade7a2be 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -58,6 +58,12 @@ describe Gitlab::Database::MigrationHelpers, lib: true do expect(Project.where(import_error: 'foo').count).to eq(5) end + + it 'updates boolean values correctly' do + model.update_column_in_batches(:projects, :archived, true) + + expect(Project.where(archived: true).count).to eq(5) + end end describe '#add_column_with_default' do From 2df8b48dbbe57f64d414e7c3395f9d34b01271b0 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 22 May 2016 22:44:59 +0200 Subject: [PATCH 3/5] Add MySQL compatibility fix in migration helpers --- lib/gitlab/database/migration_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 9b662d163f..1fe6c1143d 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -39,7 +39,8 @@ module Gitlab def update_column_in_batches(table, column, value) quoted_table = quote_table_name(table) quoted_column = quote_column_name(column) - quoted_value = quote(value) + # workaround for #17711 + quoted_value = connection.quote(value) processed = 0 total = exec_query("SELECT COUNT(*) AS count FROM #{quoted_table}"). From 7f9092da1e349c51af9febaa4db4995c851ef2d2 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 22 May 2016 23:31:33 +0200 Subject: [PATCH 4/5] Extend comment for migrations helper MySQL fix --- lib/gitlab/database/migration_helpers.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 1fe6c1143d..fd14234c55 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -39,7 +39,14 @@ module Gitlab def update_column_in_batches(table, column, value) quoted_table = quote_table_name(table) quoted_column = quote_column_name(column) - # workaround for #17711 + + ## + # Workaround for #17711 + # + # It looks like for MySQL `ActiveRecord::Base.conntection.quote(true)` + # returns correct value (1), but `ActiveRecord::Migration.new.quote` + # returns incorrect value ('true'), which causes migrations to fail. + # quoted_value = connection.quote(value) processed = 0 From 891888aa05bc9a0a156ea098205eb70150d53732 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 22 May 2016 23:33:08 +0200 Subject: [PATCH 5/5] Add Changelog entry for MySQL compatibility fix --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 01585ede58..13b937b8c4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ Please view this file on the master branch, on stable branches it's out of date. +v 8.8.1 (unreleased) + - Fix MySQL compatibility in zero downtime migrations helpers + v 8.8.0 (unreleased) - Implement GFM references for milestones (Alejandro Rodríguez) - Snippets tab under user profile. !4001 (Long Nguyen)