Can't see postgresql tables when using mongoid
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 456
- Forks
- 149
- Avg merge
- 9d 7h
- Merged PRs (30d)
- 3
Description
Hi! I'm using mongoid alongside postgresql in a rails 5 app.
My resque jobs work perfectly with the mongoid models, however, whenever I try to use one of my postgresql tables inside a job, I get the following error:
PG::UndefinedTable: ERROR: relation "admins" does not exist LINE 1: SELECT "admins".* FROM "admins" ^ : SELECT "admins".* FROM "admins"
This is my lib/tasks/resque.rake file
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
Resque.before_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
Resque.after_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
end
The postgres table mentioned does exist, and works perfectly with the rails app. It seems like, at least outside of the main rails app, ActiveRecord defaults to using mongoid, so none of my postgresql models are visible inside the worker.
Am I missing something?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/tasks/resque.rake and reproduce the failure in a Resque job that queries the PostgreSQL-backed Admin model alongside a Mongoid model. Trace how the worker initializes ActiveRecord and Mongoid connections; done means the PostgreSQL table can be queried successfully from the job without the PG::UndefinedTable error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, rails, ruby
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100