Reputation: 6189
Assuming all databases of a rails 7.0.3 application are on the same server (be they replicas or not)
app_development
) has a table shop
appusers_development
) has a table role
applocal_development
) that will need to
connect as well.If a migration is created in the secondary database, where
t.references :shop, index: true, null: false, foreign_key: true
t.references :role, index: true, null: false, foreign_key: true
this migration will not pass, as postgresql has no knowledge of the connection to the other database: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "shops" does not exist
Different users exist for main database deploy_root
and replicas deploy_readonly
.
It does not appear that this is set out in rails functionalities, thus how can it be accomplished with postgresql
Upvotes: 1
Views: 231
Reputation: 27961
There's no way to have a foreign key constraint (or any constraint) between databases (not in postgresql, and not in any engine AFAIK). The whole idea of a relational database is that the relations are contained within a (single) database. Anything outside of that (arguably other than something like a read replica) needs to be handled outside of that.
Upvotes: 1