My VPS has rbenv-vars installed, I've located .rbenv-vars file within config directory inside rails app. I pretend to load database password inside of it, but I'm doing something wrong, because rake db:create
gives me a no-password error. Rake works when I write the password as a string.
config/.rbenv-vars
DB_PASS=my_db_password
config/database.yml
password: $DB_PASS # Doesn't work
#password: <%= ENV['DB_PASS'] %> # Doesn't work
# password: my_db_password # Works
rbenv vars
ssh > rbenv vars
export DB_PASS='my_db_password'
via https://github.com/rails/rails/issues/19256#issuecomment-102980786
You may need to do a
spring stop
and then try it again. This worked for me.
I have the same problem. I know my variables are setup correctly
$ rbenv vars
# /Users/dave/code/project/.rbenv-vars
export SQL_SERVER_HOST='10.0.0.1'
export SQL_SERVER_PORT='1433'
export SQL_SERVER_USERNAME='project'
export SQL_SERVER_PASSWORD='password'
export SQL_SERVER_DATABASE='project-development'
$ cat config/database.yml
development:
adapter: sqlserver
host: <%= ENV['SQL_SERVER_HOST'] %>
port: <%= ENV['SQL_SERVER_PORT'] %>
username: <%= ENV['SQL_SERVER_USERNAME'] %>
password: <%= ENV['SQL_SERVER_PASSWORD'] %>
database: <%= ENV['SQL_SERVER_DATABASE'] %>
mode: dblib
Results in:
$ rails c
Inside TinyTds#initialize with {:dataserver=>nil, :host=>nil, :port=>nil, :username=>nil, :password=>nil, :database=>nil, :tds_version=>nil, :appname=>"project", :login_timeout=>nil, :timeout=>nil, :encoding=>nil, :azure=>nil}
/Users/dave/code/project/.gems/bundler/gems/tiny_tds-afef8218c3c0/lib/tiny_tds/client.rb:65:in `initialize': missing :host option if no :dataserver given (ArgumentError)
...
Maybe it's because rbenv-vars
hasn't loaded the variables into my session yet?
Interestingly, when I put explicit values into the config/database.yml
, it doesn't initialize tiny_tds
on rails server boot, but on loading the first model:
$ rails c
Loading development environment (Rails 4.2.2)
[1] pry(main)> # No TinyTds#initialize!!!
[2] pry(main)> User.first
Inside TinyTds#initialize with {:dataserver=>nil, :host=>"10.0.0.1", :port=>1433, :username=>"project", :password=>"password", :database=>"project-development", :tds_version=>nil, :appname=>"project", :login_timeout=>nil, :timeout=>nil, :encoding=>nil, :azure=>nil}
SQL (0.6ms) USE [project-development]
User Load (3.7ms) EXEC sp_executesql N'SELECT [users].* FROM [users] ORDER BY [users].[id] ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY'
=> #<User:0x007fb8a0929fe0
id: 1,
...
So rbenv-vars
seems to work fine once rails has been booted, but not during the boot?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With