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

Allow a list of schemas when switching using schemas #568

Open
wants to merge 315 commits into
base: development
Choose a base branch
from

Conversation

ryanbrunner
Copy link
Contributor

This PR adds the ability to switch to a list of tenants rather than a single tenant.

The reason you may want to do this is to support a partial schema. If you create a schema that contains some of the tables present in a customer schema, you can use Apartment to prefer the partial schema when retrieving or modifying data, but falling back to the "main" customer schema when a table isn't present.

For example, if Schema A contained the following tables:

foo
bar

and Schema B contained the following tables:

foo
bar
baz

then calls to Foo and Bar would access Schema A, while calls to Baz would access Schema B:

Apartment::Tenant.switch(['foo', 'bar']) do
  Foo.all # from Schema A
  Bar.all # from Schema A
  Baz.all # from Schema B
end

We use this to create a "context" where some tables can be updated while other tables continue to utilize the main tables. This can simulate the effect of a transaction by allowing a table to be populated in a staging schema prior to it being committed to the main schema.

@ryanbrunner ryanbrunner force-pushed the feature/multiple_schemas branch 4 times, most recently from 65ec5c1 to 99cb83e Compare October 5, 2018 19:07
rpbaltazar and others added 29 commits December 17, 2020 17:09
Update readme example for `active_record_log`
Prepare Release - 2.8.1

**Implemented enhancements:**

**Fixed bugs:**

- New version raises an error with ActiveSupport::LogSubscriber [influitive#128](rails-on-services/apartment#128)
- Weird logs when tenant fails to create [influitive#127](<rails-on-services/apartment#127>)

**Closed issues:**

- Removed travis and slim configured circleci [influitive#130](rails-on-services/apartment#130)
Prepare Release - 2.9.0

**Implemented enhancements:**

- Add config for handling tenant creation on db:migrate - influitive#140

**Fixed bugs:**

**Closed issues:**

- Tenant exists errors on migrate task on 2.8.0 [influitive#136](rails-on-services/apartment#136)
- Add Rails 6.1 to build matrix influitive#144
@marksiemers marksiemers force-pushed the feature/multiple_schemas branch from 390bede to 19770a1 Compare April 13, 2021 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.