rubygems / gemstash

A RubyGems.org cache and private gem server
MIT License
753 stars 121 forks source link

Unable to connect to postgres #374

Open chris72205 opened 1 year ago

chris72205 commented 1 year ago

Unless I add the pg gem to my Gemfile, I am unable to connect to postgres due to the following error during setup:

...

Checking that the database is available
Error checking database: LoadError: cannot load such file -- pg
  <internal:/[...]/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
  <internal:/[...]/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
  /[...]/bundle/ruby/3.2.0/gems/sequel-5.73.0/lib/sequel/adapters/postgres.rb:6:in `<top (required)>'
  <internal:/[...]/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
  <internal:/[...]/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
  /[...]/bundle/ruby/3.2.0/gems/sequel-5.73.0/lib/sequel/database/connecting.rb:87:in `load_adapter'
  /[...]/bundle/ruby/3.2.0/gems/sequel-5.73.0/lib/sequel/database/connecting.rb:17:in `adapter_class'
  /[...]/bundle/ruby/3.2.0/gems/sequel-5.73.0/lib/sequel/database/connecting.rb:36:in `connect'
  /[...]/bundle/ruby/3.2.0/gems/sequel-5.73.0/lib/sequel/core.rb:124:in `connect'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/lib/gemstash/env.rb:146:in `db'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/lib/gemstash/cli/setup.rb:139:in `block in check_database'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/lib/gemstash/cli/setup.rb:188:in `with_new_config'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/lib/gemstash/cli/setup.rb:195:in `try'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/lib/gemstash/cli/setup.rb:139:in `check_database'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/lib/gemstash/cli/setup.rb:32:in `run'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/lib/gemstash/cli.rb:74:in `setup'
  /[...]/bundle/ruby/3.2.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
  /[...]/bundle/ruby/3.2.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
  /[...]/bundle/ruby/3.2.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
  /[...]/bundle/ruby/3.2.0/gems/thor-1.2.2/lib/thor/base.rb:485:in `start'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/lib/gemstash/cli.rb:34:in `start'
  /[...]/bundle/ruby/3.2.0/gems/gemstash-2.6.0/exe/gemstash:6:in `<top (required)>'
  /[...]/bundle/ruby/3.2.0/bin/gemstash:25:in `load'
  /[...]/bundle/ruby/3.2.0/bin/gemstash:25:in `<top (required)>'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:58:in `load'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:58:in `kernel_load'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:23:in `run'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:492:in `exec'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:34:in `dispatch'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:28:in `start'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/exe/bundle:45:in `block in <top (required)>'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
  /[...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/exe/bundle:33:in `<top (required)>'
  /[...]/.rbenv/versions/3.2.2/bin/bundle:25:in `load'
  /[...]/.rbenv/versions/3.2.2/bin/bundle:25:in `<main>'
The database is not available

I didn't see this mentioned as needed anywhere so I was wondering if it is and I've overlooked it or if it's a bug.

When developing directly from this repo, it fails unless I include the pg gem in the Gemfile. If this is a bug, I'm happy to submit a PR with the change.

olleolleolle commented 1 year ago

I think it's as it should be.

The gemspec lists a few commented-out database gems that you can offer to your setup, in your Gemfile, as well: https://github.com/rubygems/gemstash/blob/main/gemstash.gemspec#L47-L52

Hope this helps!

chris72205 commented 1 year ago

It's still a bit confusing. Perhaps a note under the database section in the docs would be helpful to others?

If you use the postgres :db_adapter, you'll need to include the gem pg in your Gemfile.

The docs for gemstash are really good, but I was surprised this isn't mentioned.