With your setup, you have databases – and Anvil instances – that are physically distinct, and physically isolated from each other. One might do this for load-balancing, security, or both.
Are you looking for a way for one running Anvil instance to access the database of another running Anvil instance, as if that database was its own? I’d be very surprised if there was an easy, built-in way.
If you’re looking for an easy way to move a user (individual) from one customer (company) to another, without them manually logging out of one and into the other, that sounds more feasible. It’s not built in, but there are ways to automate log-outs and log-ins so that it appears somewhat seamless.
If you clarified the distinction between “user” and “customer”, that would probably help us understand what you want to achieve.
From the user’s perspective, what would the series of steps look like?
I should add, Anvil offers other approaches, that could give you some or all of what you want.
In Anvil, the original way to handle this uses the following approach:
- A single, shared App and database
- Each table has an “owner” column
- Each row has an “owner” entry
- Users don’t see the entire table. They only see the subset of rows that they own, courtesy of Anvil’s Views.
Because Views are constructed at run-time, and can be filtered on any column(s) you choose, you could use the same mechanism to give users the appearance of switching databases, programmatically, at run-time.
The second way this effect is handled is by giving a single App multiple Deployment Environments. Each run-time Environment can have its own branch of the App, and its own Database, within the same Anvil+PG instance. You’d typically assign one Environment to each user or user-organization.
If an Environment needs to switch databases, that can be done manually. I don’t know of any programmatic way to do it.
And I think you’d want to have every user of that Environment logged off, at the time of the switch. But then that probably applies to any such switch, programmatic or otherwise.