diff options
author | Stan Hu <stanhu@gmail.com> | 2016-05-22 22:20:27 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-05-22 22:20:27 +0000 |
commit | b4c47368bfece10150293566b6bf5faeb324d5c4 (patch) | |
tree | 688ba1a1baf98b9a988851fc61265b3b3b38f876 | |
parent | 529c5821305cf152770e5cb762adc5ee2c0143b8 (diff) | |
parent | 891888aa05bc9a0a156ea098205eb70150d53732 (diff) | |
download | gitlab-ce-b4c47368bfece10150293566b6bf5faeb324d5c4.tar.gz |
Merge branch 'fix/migration-helpers-mysql-compatibility' into 'master'
Fix MySQL compatibility in zero downtime migration helpers
## What does this MR do?
This MR fixes MySQL for zero downtime migration helpers introduced in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3860
Closes #17711
See merge request !4239
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/database/migration_helpers_spec.rb | 18 |
3 files changed, 23 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG index 01585ede586..13b937b8c46 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) diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 9b662d163f0..fd14234c558 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -39,7 +39,15 @@ 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 + # + # 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 total = exec_query("SELECT COUNT(*) AS count FROM #{quoted_table}"). diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index ec43165bb53..35ade7a2be0 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 @@ -60,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 |