The bellow code returns array of all tables present in particular database connection mentioned in the database.yml.
ActiveRecord::Base.establish_connection(Rails.configuration.database_configuration["#{other_connection_name}"]).connection.tables
Where other_connection_name is the name of connection to DB mentioned in database.yml.
For example database.yml
development:
adapter: mysql2
encoding: utf8
collation: utf8_bin
reconnect: true
database: dev_schema
pool: 5
username: xxx
password: xxxx
host: localhost
otherconnection:
adapter: mysql2
encoding: utf8
collation: utf8_bin
reconnect: true
database: gbl_schema
pool: 5
username: xxx
password: xxx
host: localhost
For above database.yml we use bellow code to retrieve all tables present in dev_schema and gbl_schema respectively
ActiveRecord::Base.establish_connection(Rails.configuration.database_configuration["development"]).connection.tables
ActiveRecord::Base.establish_connection(Rails.configuration.database_configuration["otherconnection"]).connection.tables