Remove unneeded monkey-patch

Changes all calls to data_source_exists? to table_exists?
since that is the intent of these calls
This commit is contained in:
Heinrich Lee Yu 2019-07-17 11:51:22 +08:00
parent 046c85ed60
commit 2b3d00a778
7 changed files with 5 additions and 19 deletions

View File

@ -10,7 +10,7 @@ Gitlab.ee do
end end
# Needed to run migration # Needed to run migration
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses') if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('licenses')
message = LicenseHelper.license_message(signed_in: true, is_admin: true, in_html: false) message = LicenseHelper.license_message(signed_in: true, is_admin: true, in_html: false)
if ::License.block_changes? && message.present? if ::License.block_changes? && message.present?
warn "WARNING: #{message}" warn "WARNING: #{message}"

View File

@ -1,10 +0,0 @@
require 'active_record/migration'
module ActiveRecord
class Migration
# data_source_exists? is not available in 4.2.10, table_exists deprecated in 5.0
def table_exists?(table_name)
ActiveRecord::Base.connection.data_source_exists?(table_name)
end
end
end

View File

@ -3,7 +3,7 @@
# We need to run this initializer after migrations are done so it doesn't fail on CI # We need to run this initializer after migrations are done so it doesn't fail on CI
Gitlab.ee do Gitlab.ee do
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses') if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('licenses')
if Gitlab::Database::LoadBalancing.enable? if Gitlab::Database::LoadBalancing.enable?
Gitlab::Database.disable_prepared_statements Gitlab::Database.disable_prepared_statements

View File

@ -55,7 +55,7 @@ module Gitlab
def ensure_temporary_tracking_table_exists def ensure_temporary_tracking_table_exists
table_name = :untracked_files_for_uploads table_name = :untracked_files_for_uploads
unless ActiveRecord::Base.connection.data_source_exists?(table_name) unless ActiveRecord::Base.connection.table_exists?(table_name)
UntrackedFile.connection.create_table table_name do |t| UntrackedFile.connection.create_table table_name do |t|
t.string :path, limit: 600, null: false t.string :path, limit: 600, null: false
t.index :path, unique: true t.index :path, unique: true

View File

@ -33,7 +33,7 @@ namespace :gitlab do
# Removes the entry from the array # Removes the entry from the array
tables.delete 'schema_migrations' tables.delete 'schema_migrations'
# Truncate schema_migrations to ensure migrations re-run # Truncate schema_migrations to ensure migrations re-run
connection.execute('TRUNCATE schema_migrations') if connection.data_source_exists? 'schema_migrations' connection.execute('TRUNCATE schema_migrations') if connection.table_exists? 'schema_migrations'
# Drop tables with cascade to avoid dependent table errors # Drop tables with cascade to avoid dependent table errors
# PG: http://www.postgresql.org/docs/current/static/ddl-depend.html # PG: http://www.postgresql.org/docs/current/static/ddl-depend.html

View File

@ -14,10 +14,6 @@ module RspecProfiling
Result.establish_connection(results_url) Result.establish_connection(results_url)
end end
def prepared?
connection.data_source_exists?(table)
end
def results_url def results_url
ENV['RSPEC_PROFILING_POSTGRES_URL'] ENV['RSPEC_PROFILING_POSTGRES_URL']
end end

View File

@ -114,7 +114,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :sidekiq, :migra
it 'does not drop the temporary tracking table after processing the batch, if there are still untracked rows' do it 'does not drop the temporary tracking table after processing the batch, if there are still untracked rows' do
subject.perform(1, untracked_files_for_uploads.last.id - 1) subject.perform(1, untracked_files_for_uploads.last.id - 1)
expect(ActiveRecord::Base.connection.data_source_exists?(:untracked_files_for_uploads)).to be_truthy expect(ActiveRecord::Base.connection.table_exists?(:untracked_files_for_uploads)).to be_truthy
end end
it 'drops the temporary tracking table after processing the batch, if there are no untracked rows left' do it 'drops the temporary tracking table after processing the batch, if there are no untracked rows left' do