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

Remove NonNilColumnDefault exception from ranked-model.rb #181

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vanboom
Copy link

@vanboom vanboom commented Oct 10, 2021

For your consideration...

Raising the NonNilColumnDefault exception causes the Rails app to not even boot. Allow users to react to this requirement without crashing their application after adding the gem.

Raising the NonNilColumnDefault exception causes the Rails app to not even boot.  Allow users to react to this requirement without crashing their application after adding the gem.
@vanboom vanboom changed the title Update ranked-model.rb #180 Remove NonNilColumnDefault exception from ranked-model.rb Oct 10, 2021
@brendon
Copy link
Owner

brendon commented Oct 10, 2021

Hi @vanboom, what does .fatal do in this situation. Does it prevent the app from running until the problem is fixed. If it just logs out and carries on then I'm not a huge fan. This is something that needs to be fixed right from the start.

Perhaps we could improve the error raised?

@vanboom
Copy link
Author

vanboom commented Oct 10, 2021

The logger message simply prints out the requirement but does not cause an exception. Thanks for considering this change. The reason we suggested it was that we added ranked-model to our Gemfile, then the app crashed with the exception because our rank column had a default value. We are adding ranked-model to an existing model with code in place to manage the position value. The exception causes an issue with deployment to production.

The NonNilColumnDefault exception requires that the database migration be released to production (to correct the default value requirement) prior to the gem being added to the application (because adding the gem renders rake impossible). This would cause the production application to break in the interim.

So our suggestion would be to print a warning similar to the way gems print deprecation warnings without raising a formal exception. That would allow developers to recognize the warning message, develop on a branch that includes the migration, then make one merge to main of 100% working code vs. releasing breaking code to production. Thanks for your consideration - this is a brilliant gem!

@brendon
Copy link
Owner

brendon commented Oct 12, 2021

Thanks @vanboom. Good points. Let's continue the discussion on the issue thread for now until we come to an agreement :)

@brendon
Copy link
Owner

brendon commented Jun 4, 2024

Closing this since we couldn't come to an agreement. I don't think it's too unreasonable to expect the database conditions to be correct when the ranking is declared on boot. Perhaps the workaround would have been to create a new column for the ranking and then rebuild the list based on the old gem's ordering, then remove that column. There were just a lot of issues where users were setting a default on the column, so this avoided all that pain for me.

@brendon brendon closed this Jun 4, 2024
@vanboom
Copy link
Author

vanboom commented Jun 4, 2024

Thanks for reviewing this. Imho, having the exception block the rake migration step which would allow the dev to correct the database condition is too aggressive. The warning method would allow devs to correct the migration without the extra steps of removing and re-adding the gem. Rake should be allowed to run. Thanks again for your consideration.

@brendon brendon reopened this Jun 4, 2024
@brendon
Copy link
Owner

brendon commented Jun 4, 2024

Fair enough. We just need to figure out how to detect the CLI environment vs a running app. I definitely don't want the app to boot if there's a default column value.

@brendon
Copy link
Owner

brendon commented Jun 4, 2024

Turns out the check is in a middleware: ActiveRecord::Migration::CheckPending. Not sure if it's gross to add a middleware for our purposes?

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.

None yet

2 participants