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

Fix create_versions migration to support Ruby3 #1366

Merged
merged 2 commits into from
Mar 9, 2022

Conversation

joeytepp
Copy link
Contributor

@joeytepp joeytepp commented Jan 18, 2022

The create_versions migration created by doing bundle exec rails generate paper_trail:install is not compatible with Ruby3. This PR updates the migration so that it will be compatible

Check the following boxes:

  • Wrote good commit messages.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new
    code introduces user-observable changes.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.

@joeytepp joeytepp force-pushed the fix-migration-ruby-3 branch from 9660725 to 47f81bc Compare January 18, 2022 21:06
@batter
Copy link
Collaborator

batter commented Jan 24, 2022

Does this remove compatibility with Ruby 2 in any capacity?

@joeytepp
Copy link
Contributor Author

@batter No, keyword arguments were introduced in Ruby 2.0

@mathieujobin
Copy link
Contributor

I am curious why the tests were not failing on ruby 3 before?

@joeytepp
Copy link
Contributor Author

@mathieujobin they weren't failing because the migration still succeeds, however in the schema.rb file we end up with

    t.string "{:null=>false, :limit=>191}"

instead of

    t.string :item_type, null: false, limit: 191

This is due to the fact that Ruby 3 interprets the hash { null: false, limit: 191 } as a second argument instead of keyword arguments. So it needs to be explicitly passed as keyword arguments.

@jaredbeck
Copy link
Member

Thanks for the contribution. Please add an entry to the changelog under Unreleased -> Fixed.

@joeytepp
Copy link
Contributor Author

joeytepp commented Mar 9, 2022

@jaredbeck updated the changelog 👍

@jaredbeck jaredbeck merged commit 3b8f55b into paper-trail-gem:master Mar 9, 2022
@jaredbeck
Copy link
Member

Thanks, Joey

@joeytepp joeytepp deleted the fix-migration-ruby-3 branch March 10, 2022 14:16
@tinacious
Copy link

In existing projects, what do we need to do to get these changes applied retroactively? I've updated the gem to 12.3.0 but am still seeing the mangled schema.rb file after running migrations. bundle exec rails g paper_trail:install fails as there's already a version created, and --force doesn't do anything (this is expected as the table exists). I'm on Rails 6.1.0 and Ruby ruby 3.0.2. Any help would be appreciated, thanks! 🙏

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.

5 participants