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

Rails 7 support #25

Closed
jasonfb opened this issue Oct 7, 2021 · 10 comments
Closed

Rails 7 support #25

jasonfb opened this issue Oct 7, 2021 · 10 comments

Comments

@jasonfb
Copy link

jasonfb commented Oct 7, 2021

[PGEnum] Current ActiveRecord version unsupported! Falling back to: 6.1

@alassek
Copy link
Owner

alassek commented Dec 16, 2021

Native enums are supported by 7, so I'll probably do one more release to officially deprecate this library so people can migrate their schemas.

@soffes
Copy link

soffes commented Dec 16, 2021

@alassek I have really enjoyed using your gem. Thanks so much for all of your work! ❤️

@soffes
Copy link

soffes commented Dec 16, 2021

@alassek if you have the time, it would really appreciate a guide for how to adopt the Rails 7 things. I was able to figure out the model changes, but I'm having trouble finding how to update the migrations other using using plain SQL.


For others, this is what I in my models:

KINDS = %w[foo bar]

# Before
include PGEnum(kind: KINDS, _suffix: true)

# After
enum :kind, KINDS.index_by(&:to_sym), suffix: true

Also the Rails 7 docs say _suffix: but it's actually suffix:.

@alassek
Copy link
Owner

alassek commented Dec 17, 2021

@soffes thank you, I glad that it was useful! Lately I've been much happier working with ROM, so it's just as well that Rails is obsoleting this gem.

The major difference is that my syntax was t.enum :column_name, as: "sql_type" and rails is t.enum :column_name, enum_type: "sql_type". I think mine reads better but whatever.

As for the module builder, my recommendation is to just copy-paste the code into your project. It's a very small part of the gem, not really worth the dependency on its own.

@jasonfb
Copy link
Author

jasonfb commented Jan 11, 2022

Nevermind, this is now in Rails 7.

When upgrading to Rails 7, you will remove this gem and:

replace the model enum defs

PGEnum()

with the default rails

enum thing: {..}

and in the rails migration as on the setting for the enum field becomes enum_type
https://jfb.teachable.com/courses/hot-glue-in-depth-tutorial/lectures/36600895
otherwise, Rails 7 seems to

covered recently in my Hot Glue tutorial
https://jfb.teachable.com/courses/hot-glue-in-depth-tutorial/lectures/36600895

@rayfaddis
Copy link

Rails 7 added better enum model support for PG enums though only added the create_enum migration command so this gem still offers\offered some nice and additional things.

See my Rails 7 PR that adds all of the migration commands to Rails 7 rails/rails#44898

@alassek
Copy link
Owner

alassek commented Jul 15, 2022

@rayfaddis That's a fair point. I will release a new version with only the additional stuff.

@alassek alassek reopened this Jul 15, 2022
@alassek
Copy link
Owner

alassek commented Jul 17, 2022

Version 2.0 has been released for Rails 7, there are a couple breaking interface changes. See CHANGELOG for more info

@alassek alassek closed this as completed Jul 17, 2022
@jasonfb
Copy link
Author

jasonfb commented Jul 18, 2022

@alassek - can you explain what advantage this gem has over the native Rails 7 tools?

@alassek
Copy link
Owner

alassek commented Jul 23, 2022

@jasonfb Everything that Rails 7 has implemented has been dropped from 2.0 but there were some additional migration helpers that they didn't implement:

  • drop_enum
  • rename_enum
  • add_enum_value
  • rename_enum_value

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

No branches or pull requests

4 participants