Commit 1ca5f054 authored by Douwe Maan's avatar Douwe Maan

Merge branch '29056-backport-ee-cleanup-database-file' into 'master'

removes redundant code from database.rb

Closes #29056

See merge request !10583
parents 50715a92 c41df676
---
title: Turns true value and false value database methods from instance to class methods
merge_request: 10583
author:
# rubocop:disable all
class ConvertClosedToStateInIssue < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
execute "UPDATE #{table_name} SET state = 'closed' WHERE closed = #{true_value}"
......
# rubocop:disable all
class ConvertClosedToStateInMergeRequest < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
execute "UPDATE #{table_name} SET state = 'merged' WHERE closed = #{true_value} AND merged = #{true_value}"
......
# rubocop:disable all
class ConvertClosedToStateInMilestone < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
execute "UPDATE #{table_name} SET state = 'closed' WHERE closed = #{true_value}"
......
# rubocop:disable all
class UserColorScheme < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
add_column :users, :color_scheme_id, :integer, null: false, default: 1
......
# rubocop:disable all
class AddVisibilityLevelToProjects < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def self.up
add_column :projects, :visibility_level, :integer, :default => 0, :null => false
......
# rubocop:disable all
class MigrateAlreadyImportedProjects < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
execute("UPDATE projects SET import_status = 'finished' WHERE imported = #{true_value}")
......
# rubocop:disable all
class AddVisibilityLevelToSnippet < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
add_column :snippets, :visibility_level, :integer, :default => 0, :null => false
......
# rubocop:disable all
class MigrateCiWebHooks < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
execute(
......
# rubocop:disable all
class MigrateCiEmails < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
# This inserts a new service: BuildsEmailService
......
# rubocop:disable all
class MigrateCiSlackService < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
properties_query = 'SELECT properties FROM ci_services ' \
......
# rubocop:disable all
class MigrateCiHipChatService < ActiveRecord::Migration
include Gitlab::Database
include Gitlab::Database::MigrationHelpers
def up
# From properties strip `hipchat_` key
......
class MigrateBuildEventsToPipelineEvents < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
include Gitlab::Database
DOWNTIME = false
......
......@@ -57,16 +57,16 @@ module Gitlab
postgresql? ? "RANDOM()" : "RAND()"
end
def true_value
if Gitlab::Database.postgresql?
def self.true_value
if postgresql?
"'t'"
else
1
end
end
def false_value
if Gitlab::Database.postgresql?
def self.false_value
if postgresql?
"'f'"
else
0
......
......@@ -114,6 +114,14 @@ module Gitlab
execute('SET statement_timeout TO 0') if Database.postgresql?
end
def true_value
Database.true_value
end
def false_value
Database.false_value
end
# Updates the value of a column in batches.
#
# This method updates the table in batches of 5% of the total row count.
......
......@@ -175,6 +175,50 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
end
end
describe '#true_value' do
context 'using PostgreSQL' do
before do
expect(Gitlab::Database).to receive(:postgresql?).and_return(true)
end
it 'returns the appropriate value' do
expect(model.true_value).to eq("'t'")
end
end
context 'using MySQL' do
before do
expect(Gitlab::Database).to receive(:postgresql?).and_return(false)
end
it 'returns the appropriate value' do
expect(model.true_value).to eq(1)
end
end
end
describe '#false_value' do
context 'using PostgreSQL' do
before do
expect(Gitlab::Database).to receive(:postgresql?).and_return(true)
end
it 'returns the appropriate value' do
expect(model.false_value).to eq("'f'")
end
end
context 'using MySQL' do
before do
expect(Gitlab::Database).to receive(:postgresql?).and_return(false)
end
it 'returns the appropriate value' do
expect(model.false_value).to eq(0)
end
end
end
describe '#update_column_in_batches' do
before do
create_list(:empty_project, 5)
......
......@@ -150,13 +150,13 @@ describe Gitlab::Database, lib: true do
it 'returns correct value for PostgreSQL' do
expect(described_class).to receive(:postgresql?).and_return(true)
expect(MigrationTest.new.true_value).to eq "'t'"
expect(described_class.true_value).to eq "'t'"
end
it 'returns correct value for MySQL' do
expect(described_class).to receive(:postgresql?).and_return(false)
expect(MigrationTest.new.true_value).to eq 1
expect(described_class.true_value).to eq 1
end
end
......@@ -164,13 +164,13 @@ describe Gitlab::Database, lib: true do
it 'returns correct value for PostgreSQL' do
expect(described_class).to receive(:postgresql?).and_return(true)
expect(MigrationTest.new.false_value).to eq "'f'"
expect(described_class.false_value).to eq "'f'"
end
it 'returns correct value for MySQL' do
expect(described_class).to receive(:postgresql?).and_return(false)
expect(MigrationTest.new.false_value).to eq 0
expect(described_class.false_value).to eq 0
end
end
end
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