Comments (17)
Thank you! This is a known issue. We use Rails' standard hooks to initialize Figaro before Rails initializes. Unfortunately, this hook apparently occurs after database.yml
is read. Trying to circumvent the standard hooks and tie into Rails' initialization elsewhere introduces a host of new problems and makes it very difficult to account for every situation in which the Rails environment is loaded.
I'm afraid this falls into the "won't fix" bucket until Rails provides a better (and supported) hook that Figaro can tie into. In my apps, I Git-ignore database.yml
like I ignore application.yml
. Not ideal, but it seems like the best we can do for now. Please feel free to investigate possible solutions yourself, as I'd love for Figaro to work as you expected. In the meantime, I'll close this issue. Thank you for the report! 👏
from figaro.
Uhm I see.
I love Figaro, it should even be merged to Rails project I think.
Thanks for this great job! :)
But this issue is very important and deserves to be mentioned in README I guess. I'd encourage you to add it.
from figaro.
I'm a bit confused by this issue.
I have exactly the same setup (database user/passwords in application.yml, inserted into database.yml using erb) and it's working fine so far. The server is working, rake db:migrate is working, tests are still working (running rspec
).
from figaro.
@ideasasylum: Interesting! Would you be willing to put up a small Git repo to step through how you build/configure a Rails app so I could take a look?
from figaro.
Oh really? How? :/
from figaro.
Hmm... I'm not sure if a small app would really capture how this app is setup. It's not massive but it is slightly unusual.
Here's some items of interest: I'm using Rails 3.2.13 with postgres. Fairly normal. I'm using Unicorn (in dev and production) with preload_app true
. This means that in my after_fork handler I'm calling ActiveRecord::Base.establish_connection
. Could this really be reloading the database.yml? I'd be surprised.
Additionally, I'm using the Apartment gem to switch postgres schemas based on the subdomain, which would also be changing the AR connection.
Do you know where in Rails database.yml gets loaded?
from figaro.
ok, probably nothing to do with Unicorn etc.
I can put <% binding.pry %>
into my database.yml
file, run rails c
and in the pry console I'll be able to see all my Figaro env variables in ENV
Obviously, the question is why but I also needed to convince myself that I wasn't going mad!
from figaro.
I've done some digging around this but I still can't figure out why it works in my case but not @scaryguy's
Figaro hooks into config.before_configuration
but, I'm wondering, could Figaro be an initializer instead? Then you can specify that it should load before "active_record.initialize_database"?
So, I did it: ideasasylum@1eeb7a9
You can try this fork with gem "figaro", git: 'https://github.com/ideasasylum/figaro.git'
. And if works then it can be pulled in.
And if you want to explore the Rails/Figaro/database initialisation process… Here's a gist of a pry session I used to verify that the Figaro initializer was being loaded before the activerecord database initialization
from figaro.
Could you try my PR #69 which fixed the Rails 4.1 issue by hooking into first initializer. This would then solve all the issues 🎉
from figaro.
@mrfoto yeah, it looks like we both took the same approach of using initializer
. I think that definitely the way forward. The only difference is when it happens (and I don't mind, just as long as it's before database initialisation and is compatible with Rails 3.2+)
from figaro.
Judging by your gist, the load_environment_hook
is included in your initializers list so it should play nicely
from figaro.
I face the same problem.
Alternatively can be used ENV["DATABASE_URL"] instead of database.yml config. If both are present, DATABASE_URL silently wins (database.yml just ignored).
from figaro.
@laserlemon Any update on this? I think we have a few solutions that could be merged in
from figaro.
@ideasasylum Before I change the hook, I'll need to be able to add a failing test. I need a case where database.yml
is loaded before application.yml
. Please feel free to add a test to a branch of off master
if you can!
from figaro.
I just pushed a test that I think might cover this for all versions of Rails 3-4. Please take a look: afc6699
from figaro.
That commit works for me on Rails 3.2.11 using Unicorn.
from figaro.
Eventhough I set me environment, it overrides with the other environment. What would be the problem behind it?
from figaro.
Related Issues (20)
- Dynamically load development or test default values HOT 2
- Can't push application.yml keys to heroku
- figaro heroku:set => “Could not find command heroku:set” HOT 1
- Using with docker and ENV.fetch HOT 1
- ar
- Override contents of generated `application.yml`
- Figaro 2 HOT 3
- Options for Figaro on Elastic BeanStalk HOT 2
- Not working HOT 1
- Environment variables in config/keycloak.yml files, not supported?
- Herarchical structure
- Project status? HOT 15
- Remove escape characters when loading environment values
- Rails and heroku failing tests
- Any npm packages that could use the same secrets? HOT 4
- Starting Rails app through `foreman` doesn't load ENV vars on `config/puma.rb` file
- What do you think about HashiCorp Vault integration?
- `visit_Psych_Nodes_Alias': Unknown alias: shared (Psych::BadAlias) error with ruby 3.1 HOT 3
- Project status (2022) HOT 2
- Undefined method exists? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from figaro.