-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Connect to database if not connected #309
Conversation
Thanks for the PR! This is partially reverting a recent commit--let's make sure we're addressing everyone's use cases before merging (see #305) |
Hi! As I was suspecting it breaks when the DB don't exist, for example during tests on a real app : ✔ 03 nicolas@localhost 8.502s
04 ~/.rvm/bin/rvm 2.5.1 do bundle exec rake db:create
04 Unable to connect to a database. Globalize skipped ignoring columns of translated attributes.
04 Unable to connect to a database. Globalize skipped ignoring columns of translated attributes.
04 rake aborted!
04 PG::ConnectionBad: FATAL: la base de données « concerto » n'existe pas
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/pg-1.0.0/lib/pg.rb:56:in `initialize'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/pg-1.0.0/lib/pg.rb:56:in `new'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/pg-1.0.0/lib/pg.rb:56:in `connect'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:684:in `connect'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:215:in `initialize'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:40:in `new'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:40:in `postgresql_connection'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:809:in `new_connection'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `checkout_new_connection'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:832:in `try_to_checkout_new_connection'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:793:in `acquire_connection'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:521:in `checkout'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:380:in `connection'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:1008:in `retrieve_connection'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
04 /home/nicolas/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_handling.rb:90:in `connection'
04 /home/nicolas/PROJECTS/CONCERTO/concerto/vendor/gems/closure_tree/lib/closure_tree/support_flags.rb:22:in `order_is_numeric?'
04 /home/nicolas/PROJECTS/CONCERTO/concerto/vendor/gems/closure_tree/lib/closure_tree/support.rb:28:in `initialize'
04 /home/nicolas/PROJECTS/CONCERTO/concerto/vendor/gems/closure_tree/lib/closure_tree/has_closure_tree.rb:16:in `new'
04 /home/nicolas/PROJECTS/CONCERTO/concerto/vendor/gems/closure_tree/lib/closure_tree/has_closure_tree.rb:16:in `has_closure_tree'
04 /home/nicolas/PROJECTS/CONCERTO/concerto/app/models/page.rb:45:in `<class:Page>'
04 /home/nicolas/PROJECTS/CONCERTO/concerto/app/models/page.rb:24:in `<main>' As you can notice, Globalize gem has the same chicken and egg issue : 04 Unable to connect to a database. Globalize skipped ignoring columns of translated attributes.
04 Unable to connect to a database. Globalize skipped ignoring columns of translated attributes. It's here : https://github.com/globalize/globalize/blob/master/lib/globalize/active_record/act_macro.rb#L44 |
@n-rodriguez thanks a bunch for taking the time to research that. Can you think of a way to write a breaking test so this can be automated? |
Well... this one is a bit complicated : Ruby module inclusion depends on the return value of
|
The method is evaluated only once (I think) : at boot time. |
So the patch I've made is wrong because it will always return false and thus the module won't be included. |
In fact I don't why this part should be dynamic... |
We make a DB query to check if the DB field is an integer... Well... (us) the developer should know in advance the field type and pass it as an option to |
By reading the doc (https://github.com/ClosureTree/closure_tree#deterministic-ordering) it seems legit to get the info from the DB... but sometimes a good duplication is better than a bad abstraction ^^ |
This one should fix it for good :) #311 |
Hello! I think this issue can be closed as it's fixed by #311 |
👍 |
Fix for this issue #308 (comment)