Commit 1f9004a8 authored by Stan Hu's avatar Stan Hu Committed by Robert Speicher

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
parent 1818e8a1
...@@ -4,6 +4,8 @@ v 8.8.0 ...@@ -4,6 +4,8 @@ v 8.8.0
v 8.8.1 (unreleased) v 8.8.1 (unreleased)
- Fix MySQL compatibility in zero downtime migrations helpers - Fix MySQL compatibility in zero downtime migrations helpers
- Fix the CI login to Container Registry (the gitlab-ci-token user) - Fix the CI login to Container Registry (the gitlab-ci-token user)
v 8.8.1 (unreleased)
- Fix MySQL compatibility in zero downtime migrations helpers
v 8.8.0 (unreleased) v 8.8.0 (unreleased)
- Implement GFM references for milestones (Alejandro Rodríguez) - Implement GFM references for milestones (Alejandro Rodríguez)
......
...@@ -39,7 +39,15 @@ module Gitlab ...@@ -39,7 +39,15 @@ module Gitlab
def update_column_in_batches(table, column, value) def update_column_in_batches(table, column, value)
quoted_table = quote_table_name(table) quoted_table = quote_table_name(table)
quoted_column = quote_column_name(column) 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 processed = 0
total = exec_query("SELECT COUNT(*) AS count FROM #{quoted_table}"). total = exec_query("SELECT COUNT(*) AS count FROM #{quoted_table}").
......
...@@ -2,15 +2,13 @@ require 'spec_helper' ...@@ -2,15 +2,13 @@ require 'spec_helper'
describe Gitlab::Database::MigrationHelpers, lib: true do describe Gitlab::Database::MigrationHelpers, lib: true do
let(:model) do let(:model) do
Class.new do ActiveRecord::Migration.new.extend(
include Gitlab::Database::MigrationHelpers Gitlab::Database::MigrationHelpers
)
def method_missing(name, *args, &block)
ActiveRecord::Base.connection.send(name, *args, &block)
end
end.new
end end
before { allow(model).to receive(:puts) }
describe '#add_concurrent_index' do describe '#add_concurrent_index' do
context 'outside a transaction' do context 'outside a transaction' do
before do before do
...@@ -60,6 +58,12 @@ describe Gitlab::Database::MigrationHelpers, lib: true do ...@@ -60,6 +58,12 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
expect(Project.where(import_error: 'foo').count).to eq(5) expect(Project.where(import_error: 'foo').count).to eq(5)
end 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 end
describe '#add_column_with_default' do describe '#add_column_with_default' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment