Can't parse `database.yml` with environment variables and ERB
tannakartikey opened this issue · 10 comments
Hello,
I installed it with apt-get on Ubuntu 16.04
development restore-from staging
gives me the following error:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 27247 100 27247 0 0 3109 0 0:00:08 0:00:08 --:--:-- 7992
sh: 1: Syntax error: "&&" unexpected
sh: 1: cannot open %=: No such file
Is there any way I can debug it or check out logs to know what is the error exactly for?
I use rbenv. I tried it with Ruby 2.1.1p76, 2.2.2p95
@tannakartikey do you have your database defined with an ERB file and a dynamic value?
@geoffharcourt sorry did not get you about ERB file.
I have used Figaro for ENV variables. Variables are used in the config/database.yml. Please find it below:
default: &default
adapter: postgresql
pool: 5
timeout: 5000
production:
<<: *default
database: db/production.sqlite3
development:
adapter: postgresql
host: 127.0.0.1
database: <%= ENV["CURRENTS_DB_NAME"] %>
username: <%= ENV["CURRENTS_PSQL_USERNAME"] %>
password: <%= ENV["CURRENTS_PSQL_PASSWORD"] %>
test:
adapter: postgresql
host: 127.0.0.1
database: <%= ENV["CURRENTS_DB_NAME"] %>
username: <%= ENV["CURRENTS_PSQL_USERNAME"] %>
password: <%= ENV["CURRENTS_PSQL_PASSWORD"] %>
Hi @tannakartikey we don't currently support dynamic database names via environment variables (your database config is using ERB-style variables).
Ok. Thank you.
Can I contribute that feature? What are the ups/downs for having the feature?
You are very welcome to make a PR!
The requirements for this to work in acceptance is that whatever solution for bundling the ERB-parsing (you'll need that to parse the database.yml
file since that's not valid YAML until the ERB is processed) and the environment variable-loading needs to work when the gem gets repackaged for distribution with Homebrew and APT. We experimented with ERB support previously but had to remove it when we ran into issues with packaging.
Closing this out, but open to PRs that are distributable via package managers.
@geoffharcourt we're interested in this as well. Do you happen to remember any details about what went wrong with the package managers so we have an idea of where to start if we come around to offering a PR for this?
@bbugh Traveling Ruby is no longer supported and has a version of Bundler that causes permissions issues when installed through Homebrew. If you want to try tackling a PR that includes ERB, I would enthusiastically support this.
Any solution we implement would have to work through a Homebrew install (and likely apt), so keep those in mind if you decide to take this on.
Got it, thanks for the fast reply. We made a local patch that has resolved the issue for now, but I imagine it's not portable. We'll see if this works or if we can submit a PR for this project.
--- backup.rb 2018-02-08 09:23:48.000000000 -0600
+++ backup.rb 2018-02-08 09:23:55.000000000 -0600
@@ -1,4 +1,6 @@
require "etc"
+require 'erb'
+require 'rails'
module Parity
class Backup
@@ -104,7 +106,7 @@
end
def database_yaml_file
- IO.read(DATABASE_YML_RELATIVE_PATH)
+ ERB.new(IO.read(DATABASE_YML_RELATIVE_PATH)).result(binding)
end
end
end
@bbugh possibly relevant: https://github.com/thoughtbot/homebrew-formulae/blob/master/Formula/parity.rb
I went through a couple iterations of this before giving up. I'd be pretty excited to see this make it back into the utility.