Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def connect_to_read_db
- DatabaseConnector.connect_to_db('read')
- end
- def connect_to_write_db
- DatabaseConnector.connect_to_db('write')
- end
- class DatabaseConnector
- class << self
- def connect_to_db(function)
- if !(Rails.env.development? || Rails.env.test?)
- if ActiveRecord::Base.connection_config[:function] != function
- Rails.logger.debug "Gathering DB details"
- seed_file = Rails.root.join('config', 'database.yml')
- loaded_yml_file = YAML::load_file(seed_file)
- connection_name = "#{Rails.env}_#{function}"
- Rails.logger.debug "attempting connection to: #{connection_name}"
- db_details = loaded_yml_file[connection_name]
- Rails.logger.debug "database details:"
- db_details.each do |d|
- Rails.logger.debug(d)
- end
- ActiveRecord::Base.establish_connection(
- adapter: db_details['adapter'],
- port: db_details['port'],
- pool: db_details['pool'],
- timeout: db_details['timeout'],
- encoding: db_details['encoding'],
- host: db_details['host'],
- database: db_details['database'],
- username: db_details['username'],
- password: db_details['password']
- )
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement