@@ -311,38 +311,35 @@ def collation
311311 end
312312
313313 def tables # :nodoc:
314- ActiveSupport ::Deprecation . warn ( <<-MSG . squish )
315- #tables currently returns both tables and views.
316- This behavior is deprecated and will be changed with Rails 5.1 to only return tables.
317- Use #data_sources instead.
318- MSG
314+ sql = "SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE'"
315+ sql << " AND table_schema = #{ quote ( @config [ :database ] ) } "
319316
320- data_sources
317+ select_values ( sql , "SCHEMA" )
318+ end
319+
320+ def views # :nodoc:
321+ select_values ( "SHOW FULL TABLES WHERE table_type = 'VIEW'" , "SCHEMA" )
321322 end
322323
323- def data_sources
324+ def data_sources # :nodoc:
324325 sql = "SELECT table_name FROM information_schema.tables "
325326 sql << "WHERE table_schema = #{ quote ( @config [ :database ] ) } "
326327
327328 select_values ( sql , "SCHEMA" )
328329 end
329330
330- def truncate ( table_name , name = nil )
331- execute "TRUNCATE TABLE #{ quote_table_name ( table_name ) } " , name
332- end
331+ def table_exists? ( table_name ) # :nodoc:
332+ return false unless table_name . present?
333333
334- def table_exists? ( table_name )
335- # Update lib/active_record/internal_metadata.rb when this gets removed
336- ActiveSupport ::Deprecation . warn ( <<-MSG . squish )
337- #table_exists? currently checks both tables and views.
338- This behavior is deprecated and will be changed with Rails 5.1 to only check tables.
339- Use #data_source_exists? instead.
340- MSG
334+ schema , name = extract_schema_qualified_name ( table_name )
341335
342- data_source_exists? ( table_name )
336+ sql = "SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE'"
337+ sql << " AND table_schema = #{ quote ( schema ) } AND table_name = #{ quote ( name ) } "
338+
339+ select_values ( sql , "SCHEMA" ) . any?
343340 end
344341
345- def data_source_exists? ( table_name )
342+ def data_source_exists? ( table_name ) # :nodoc:
346343 return false unless table_name . present?
347344
348345 schema , name = extract_schema_qualified_name ( table_name )
@@ -353,10 +350,6 @@ def data_source_exists?(table_name)
353350 select_values ( sql , "SCHEMA" ) . any?
354351 end
355352
356- def views # :nodoc:
357- select_values ( "SHOW FULL TABLES WHERE table_type = 'VIEW'" , "SCHEMA" )
358- end
359-
360353 def view_exists? ( view_name ) # :nodoc:
361354 return false unless view_name . present?
362355
@@ -368,6 +361,10 @@ def view_exists?(view_name) # :nodoc:
368361 select_values ( sql , "SCHEMA" ) . any?
369362 end
370363
364+ def truncate ( table_name , name = nil )
365+ execute "TRUNCATE TABLE #{ quote_table_name ( table_name ) } " , name
366+ end
367+
371368 # Returns an array of indexes for the given table.
372369 def indexes ( table_name , name = nil ) #:nodoc:
373370 indexes = [ ]
0 commit comments