-
Notifications
You must be signed in to change notification settings - Fork 8
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 for property tables to live on a separate db #106
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HeyNonster
force-pushed
the
nony--configure-superclass
branch
15 times, most recently
from
November 7, 2023 12:54
abad7cb
to
48a5f4e
Compare
HeyNonster
force-pushed
the
nony--configure-superclass
branch
from
November 7, 2023 13:03
48a5f4e
to
6a948f0
Compare
Thomascountz
reviewed
Nov 7, 2023
Thomascountz
reviewed
Nov 7, 2023
Thomascountz
reviewed
Nov 7, 2023
This commit adds `attr_accessor` (to the class level) of `ActiveRecord::Base` that allows you to set a specific connection class for the property sets tables. This is useful if you want to have the tables for your model live on one database, but all of the property sets tables live on a separate database. Usage: ```ruby class Account < MainConnectionClass # Ensure you set this _before_ configuring the property sets. self.property_sets_connection_class = SeparateDatabase property_set :settings do property :foo end end ``` Co-authored-by: Thomas Countz <[email protected]>
Thomascountz
approved these changes
Nov 7, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Small nit. Shit it!
This commit re-organizes the spec support files: - Has `Account` inherit from a new abstract model `MainDatabase`. (this effectively changes nothing, but we'll use it later) - Moves all of the models into one file - Moves the database configurations into a `database_config.rb` file - Moves the migrations from `database` => `database_migrations.rb`
HeyNonster
force-pushed
the
nony--configure-superclass
branch
2 times, most recently
from
November 7, 2023 15:11
6388cac
to
519ad23
Compare
bquorning
approved these changes
Nov 7, 2023
This commit creates two separate databases `test` and `test_alt_database` and abstract `ActiveRecord` models (MainDatabase, AltDatabase) that connect to each of those, respectively. The existing models all inherit from the `MainDatabase` and thus their behavior is unchanged. This creates a new model called `Parent::AccountAltDb` which is just a copy of `Parent::Account` but instead we call `self.property_sets_connection_class = AltDatabase` on it to instruct `property_sets` to use the connection (and database) from the `AltDatabase` class when creating and looking for the property_sets tables. We also run the same migrations we ran for `Account` but now for `AccountAltDb` and on the `AltDatabase` connection. We then run the property_sets specs twice: once with `Parent::Account` and again with `Parent::AccountAltDb` to ensure that they pass, no matter which database the property tables live on: ```ruby describe Parent::Account do it_behaves_like "different account models", Parent::Account end describe Parent::AccountAltDb do it_behaves_like "different account models", Parent::AccountAltDb end ```
This tests the gem with `legacy_connection_handling = true` and `legacy_connection_handling = false` to test the new connection handling logic which was added in Rails 6.1. When `false` we now use the new `connects_to` syntax to configure the models.
HeyNonster
force-pushed
the
nony--configure-superclass
branch
from
November 8, 2023 08:22
519ad23
to
33edd9b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the ability for the property tables of a model to live on a separate database to the model itself.
It does so by adding
attr_accessor
(to the class level) ofActiveRecord::Base
that allows you to set a specific connection classfor the property sets tables.
This is useful if you want to have the tables for your model live on one
database, but all of the property sets tables live on a separate database.
Usage: