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

Define column methods on the ColumnMethods module #51730

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ccutrer
Copy link
Contributor

@ccutrer ccutrer commented May 3, 2024

Motivation / Background

I was writing some code that parses our migrations and extracts information about newly added columns. It was missing some columns because they were of a less column datatype that we weren't explicitly handling. I went to see if I could just list the methods on a module to find the valid column method aliases, and was happy to see such a module exists. Except that due to how it's structured, none of the column method aliases actually exist on that module.

Detail

The way they were being defined inside the included hook meant they ended up being defined directly on TableDefinition, contrary to the documentation:
https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/PostgreSQL/ColumnMethods.html. By extending ClassMethods onto ColumnMethods, the module can call the macro directly, and end up with the methods defined on the ColumnMethods module, instead of deferring their creation until they're included, and defining them on the including class.

Additional information

I left define_column_methods as a class method that gets extended onto TableDefinition, since there's at least one gem that relies on being able to call it there to define their own column types

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

The way they were being defined inside the `included` hook meant
they ended up being defined directly on TableDefinition, contrary
to the documentation:
https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/PostgreSQL/ColumnMethods.html

I left `define_column_methods` as a class method that gets extended
onto TableDefinition, since there's at least one gem that relies
on being able to call it there to define their own column types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant