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

Feature: Support models with specific table_name during migration generation #46

Merged
merged 6 commits into from
Sep 13, 2024

Conversation

buntine
Copy link
Contributor

@buntine buntine commented Sep 13, 2024

Context

In our app we have all models namespaced via sub-domain. The current Hoardable generator assumes the table name by doing some string manipulation on the passed in model.

So, in our case (using a fictional example):

bin/rails g hoardable:migration Domain::SubDomain::ModelName  # --> assumes domain_subdomain_model_names table

This causes the migration to die when we run it. If we pass in the explicit table name instead of the model, the migration still dies because it cannot resolve back to the model when it tries to work out the primary key type (we use uuid).

It's perhaps nicer to actually consult the model itself to work out what the correct table name is. That's what this PR does.

Happy to discuss it further if you have some other ideas!

@waymondo
Copy link
Owner

thanks again. i agree it would be best to try and consult the model's table_name first.

regarding the implementation, i think using constantize is fine in this case and falling back to super on any StandardError is simple and fine with me.

@waymondo waymondo merged commit 2624617 into waymondo:main Sep 13, 2024
8 checks passed
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