Class: Immigrate::Database
- Inherits:
-
Object
- Object
- Immigrate::Database
- Defined in:
- lib/immigrate/database.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #create_fdw_extension ⇒ Object
- #create_server_connection(server) ⇒ Object
- #create_user_mapping(server) ⇒ Object
- #current_user ⇒ Object
- #database_configuration ⇒ Object
- #drop_fdw_extension ⇒ Object
Instance Method Details
#connection ⇒ Object
38 39 40 |
# File 'lib/immigrate/database.rb', line 38 def connection ActiveRecord::Base.connection end |
#create_fdw_extension ⇒ Object
3 4 5 |
# File 'lib/immigrate/database.rb', line 3 def create_fdw_extension enable_extension :postgres_fdw end |
#create_server_connection(server) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/immigrate/database.rb', line 11 def create_server_connection server server_config = database_configuration[Rails.env][server.to_s] execute <<-SQL CREATE SERVER #{server} FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '#{server_config['host']}', port '#{server_config['port']}', dbname '#{server_config['dbname']}') SQL end |
#create_user_mapping(server) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/immigrate/database.rb', line 22 def create_user_mapping server server_config = database_configuration[Rails.env][server.to_s] execute <<-SQL CREATE USER MAPPING FOR #{current_user} SERVER #{server} OPTIONS (user '#{server_config['user']}', password '#{server_config['password']}') SQL end |
#current_user ⇒ Object
32 33 34 |
# File 'lib/immigrate/database.rb', line 32 def current_user execute("SELECT CURRENT_USER").first['current_user'] end |
#database_configuration ⇒ Object
42 43 44 45 |
# File 'lib/immigrate/database.rb', line 42 def database_configuration yaml = Pathname.new('config/immigrate.yml') YAML.load(ERB.new(yaml.read).result) end |
#drop_fdw_extension ⇒ Object
7 8 9 |
# File 'lib/immigrate/database.rb', line 7 def drop_fdw_extension disable_extension :postgres_fdw end |