Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Database Support? #22

Closed
joegaudet opened this issue Jun 25, 2021 · 1 comment · Fixed by #32
Closed

Multiple Database Support? #22

joegaudet opened this issue Jun 25, 2021 · 1 comment · Fixed by #32

Comments

@joegaudet
Copy link

Looking to add triggers to multiple db, any guidance there?

@tjwp
Copy link
Contributor

tjwp commented Jun 25, 2021

I have not yet worked with multiple databases in Rails.

To try this, I would do the following:

  1. Run the generator from this gem with a --database argument as described here: https://guides.rubyonrails.org/active_record_multiple_databases.html#generators-and-migrations. If the migration is not generated in the correct directory for the database then move it there.
  2. For the model that is triggering notifications, make sure that it inherits from an abstract record class that specifies the connection you want to use.
  3. Finally when you are running the listener in application code wrap it within a block that specifies the connection to use:
ActiveRecord::Base.connected_to(...) do
  ActiveRecord::PostgresPubSub::Listener.listen(...) { }
end

Within the Listener, ActiveRecord::Base is used to get a connection (https://github.com/ezcater/activerecord-postgres_pub_sub/blob/master/lib/activerecord/postgres_pub_sub/listener.rb#L57) so I'm guessing at how to switch it.

There are likely things that the gem could make easier in supporting multiple databases, such as accepting which database to use as an arg in the listen call, but if you get a chance to try this out please report back!

agrobbin added a commit to agrobbin/activerecord-postgres_pub_sub that referenced this issue Mar 19, 2024
agrobbin added a commit to agrobbin/activerecord-postgres_pub_sub that referenced this issue Mar 21, 2024
jmpage pushed a commit that referenced this issue Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants