Set database host dynamically with ecto

Looking at migrating an application over to Elixir

Having an Issue of setting database dynamically, the only variabe that changes is the host(different_ip)
so…

 username: "CONSTANT",
 password: "CONSTANT",
 database: "CONSTANT",
 hostname: "dynamically_SET",...

With ActiveRecord, in a.rb << ActiveRecord… file, I’ve got

 def self.set_database(ip_address)
  establish_connection({:adapter => "postgresql", :database => "db_name", :host => ip_address,
                      :username => "username", :password => "password" })
end
self.abstract_class = true

and b.rb << a

def self.set_database(ip_address)
  a.set_database(ip_address)
end
self.table_name = 'cdrs_primary'

elsewhere, i have

def set_db
b.set_database(actual_ip)
end

called in a before_filter.

What might be the best approach in achieving this with Ecto?

1 Like

Does the IP always change or you have a limited number of IPs?

1 Like

The IPs change and can be in the thousands

1 Like

Use a dynamic dns service. There are a ton of free ones.

1 Like

Please how would this fit in this scenario?

1 Like

This scenario is not supported in Ecto right now but we are working to support it.

4 Likes

Thank you Jose.

1 Like