Merge branch '54478-table_exists-not-compatible-with-rails-5-1' into 'master'

Resolve "table_exists? not compatible with Rails 5.1"

Closes #54478

See merge request gitlab-org/gitlab-ce!30832
This commit is contained in:
Douglas Barbosa Alexandre 2019-07-25 15:05:07 +00:00
commit aa9db9c869
7 changed files with 5 additions and 19 deletions

View file

@ -10,7 +10,7 @@ Gitlab.ee do
end
# 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)
if ::License.block_changes? && message.present?
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
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?
Gitlab::Database.disable_prepared_statements

View file

@ -55,7 +55,7 @@ module Gitlab
def ensure_temporary_tracking_table_exists
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|
t.string :path, limit: 600, null: false
t.index :path, unique: true

View file

@ -33,7 +33,7 @@ namespace :gitlab do
# Removes the entry from the array
tables.delete 'schema_migrations'
# 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
# PG: http://www.postgresql.org/docs/current/static/ddl-depend.html

View file

@ -14,10 +14,6 @@ module RspecProfiling
Result.establish_connection(results_url)
end
def prepared?
connection.data_source_exists?(table)
end
def results_url
ENV['RSPEC_PROFILING_POSTGRES_URL']
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
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
it 'drops the temporary tracking table after processing the batch, if there are no untracked rows left' do