pat/gutentag

Database does not exist

om-nishu-trantor opened this issue · 10 comments

When I run rails db:create || bundle exec rails db:create I get the stack trace given below.

~/apps/project/myapp$ bin/rails db:create
rails aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "myapp_development" does not exist
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:684:in `rescue in connect'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:680:in `connect'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:215:in `initialize'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:40:in `new'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:40:in `postgresql_connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:809:in `new_connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `checkout_new_connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:832:in `try_to_checkout_new_connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:793:in `acquire_connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:521:in `checkout'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:380:in `connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:1008:in `retrieve_connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/connection_handling.rb:90:in `connection'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/bundler/gems/rails-6d1dd1643dc8/activerecord/lib/active_record/model_schema.rb:324:in `table_exists?'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/gems/gutentag-2.0.0/lib/gutentag/tag_validations.rb:26:in `add_length_validation?'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/gems/gutentag-2.0.0/lib/gutentag/tag_validations.rb:34:in `validation_options'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/gems/gutentag-2.0.0/lib/gutentag/tag_validations.rb:18:in `call'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/gems/gutentag-2.0.0/lib/gutentag/tag_validations.rb:10:in `call'
/home/developer/.rvm/gems/ruby-2.4.1@myapp/gems/gutentag-2.0.0/lib/gutentag.rb:46:in `block in <top (required)>'

It is not allowing me to create a database.

http://take.ms/KND3Y happens when the database server isn't running.. it would be nice to handle that as well.

pat commented

@joevandyk: I've just pushed a fix for this in cce4bdf - if you could confirm it works fine for you, that'd be great:

gem "gutentag", "~> 2.2",
  :git    => "https://github.com/pat/gutentag.git",
  :branch => "master",
  :ref    => "cce4bdf2fa"
pat commented

@joevandyk: I've just published v2.3.0 which includes the fix :)

Great, thanks! I believe it works.

@pat actually, it only works if the mysql gem is included before gutentag (so the mysql constant is defined). What do you think about rescuing all errors? Like in joevandyk@33088d7

pat commented

I'm nervous about catching all exceptions, because it could hide other problems that should be raised.

Also, just to confirm, are you using the commit from earlier? Or the gem release? Because the gem release should only use the Mysql2 error if Mysql2 is defined - but if you're finding that's not actually happening, I'll need to debug further!

I’m using 2.3.0.

If MySQL isn’t defined when the gutentag gem is loaded, then it won’t add the MySQL2 Error to the list of catchable exceptions.

I have gems in the Gemfile alphabetically, so MySQL comes after gutentag. :)

pat commented

Ah, hadn't thought about load order - thanks for figuring that out. I've just pushed a fix: 8451465

pat commented

… and 2.3.1 has just been released with that fix 👍

🥇