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 add_column and generator behavior for missing type #49

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

michaelherold
Copy link
Owner

@michaelherold michaelherold commented Oct 21, 2023

When using add_column, the definition methods for ksuid and ksuid_binary are not used like when using table.ksuid since add_column creates the column directly.

This change makes it so any column definition can handle both ksuid and ksuid_binary correctly by monkey-patching the method that creates the column definitions.

It also makes it so rails generate model example:ksuid works as expected. I am unsure how fragile this test is. Ideally, we would have a test that runs the generator against a dummy app and asserts on the outcome, but I don't have the spoons to manage that right now.

Closes #48

Without this, ActiveRecord does not yet know which type of adapter to
use. This makes monkey patching the specific adapter class(es) that you
need impossible.

This mirrors what we do in the spec helper.
These were typos in the URLs for comparison links between versions. They
should now all work correctly.
When using `add_column`, the definition methods for `ksuid` and
`ksuid_binary` are not used like when using `table.ksuid` since
`add_column` creates the column directly.

This change makes it so any column definition can handle both `ksuid`
and `ksuid_binary` correctly by monkey-patching the method that creates
the column definitions.
@michaelherold
Copy link
Owner Author

@DataDaoDe, care to give this a whirl to see if it fixes the issue?

@DataDaoDe
Copy link

@michaelherold awesome. I'll check it out today.

@DataDaoDe
Copy link

This fixed the add_column error but I'm still getting the error when trying to run rails generate model Event my_field_name:ksuid, which is Could not generate field 'my_field_name' with unknown type 'ksuid'.

This change makes it so `rails generate model example:ksuid` works as
expected. I am unsure how fragile this test is. Ideally, we would have a
test that runs the generator against a dummy app and asserts on the
outcome, but I don't have the spoons to manage that right now.
@michaelherold michaelherold changed the title Fix add_column behavior for missing type Fix add_column and generator behavior for missing type Oct 24, 2023
@michaelherold
Copy link
Owner Author

Rats, I have a fix but it only works for 7.0+. I'd like to still support 6.1 so need to muddle some more. It's almost like monkey-patching Rails is a bad idea! 😅

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.

Cannot use the ksuid or ksuid_binary field types when adding a column
2 participants