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

Adds support for horizontally sharded database projects #1079

Merged
merged 12 commits into from
Apr 29, 2022
Merged

Adds support for horizontally sharded database projects #1079

merged 12 commits into from
Apr 29, 2022

Conversation

donquxiote
Copy link
Contributor

@donquxiote donquxiote commented Feb 28, 2022

In our project we're using a horizontally sharded database in Rails 6.1. As part of that we have to define what shards our different models can connect to through ApplicationRecord. As the gem is currently, the taggings and tags tables we use from the gem would not have access to the right connection information since they inherited from ActiveRecord::Base. It seemed like this might help more than just my project.

This PR makes the class ActsAsTaggableOn::Tags and ActsAsTaggableOn::Tagging inherit from a configurable base_class variable on ActsAsTaggableOn. A rake task acts_as_taggable_on:sharded_db:install_initializer is provided that will add an example initializer to a project.

The class passed to base_class is checked to be a Class object, otherwise an error is raised.

Tests verify that ActsAsTaggableOn::Tags and ActsAsTaggableOn::Tagging inherit from ActiveRecord::Base by default or the passed class if present.

@seuros
Copy link
Collaborator

seuros commented Apr 26, 2022

can you rebase this PR ?

@seuros seuros self-requested a review April 26, 2022 09:29
@donquxiote
Copy link
Contributor Author

@seuros more than happy to.

@seuros seuros merged commit b4eed9b into mbleigh:master Apr 29, 2022
f1sherman added a commit to f1sherman/acts-as-taggable-on that referenced this pull request Aug 29, 2022
Rails [Zeitwerk](https://github.com/fxn/zeitwerk) autoloader is a lot
more strict about when constants are loaded than the old autoloader.
I noticed that in
mbleigh#1079 `base_class` is
being set to the actual class in an initializer, which results in an
`unintialized constant` error when the autoloader is set to Zeitwerk.
This fixes the setting to work in Zeitwerk by allowing it to be set to
a `String` which gets constantized later, after initializers have run.

I also fixed the initializer example to call the `setup` method, which
I believe is the recommended way to do that.
seuros pushed a commit that referenced this pull request Jan 18, 2023
Rails [Zeitwerk](https://github.com/fxn/zeitwerk) autoloader is a lot
more strict about when constants are loaded than the old autoloader.
I noticed that in
#1079 `base_class` is
being set to the actual class in an initializer, which results in an
`unintialized constant` error when the autoloader is set to Zeitwerk.
This fixes the setting to work in Zeitwerk by allowing it to be set to
a `String` which gets constantized later, after initializers have run.

I also fixed the initializer example to call the `setup` method, which
I believe is the recommended way to do that.
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.

2 participants