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

Refactor the typecasting behavior of ActiveRecord columns #15134

Closed
wants to merge 5 commits into from

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented May 16, 2014

This removes all cases from Column where behavior was determined soley
based on the SQL type string. Instead, we push this decision up to the
Column's creation, and inject the object with knowledge of the type
casting behavior of it.

The API exposed was intended to be close to the PostgreSQL
implementation for OID lookups. There's additional refactoring that
could be done on this, especially in the PostgreSQL adapter and MySQL
adapter, but this felt like a good place to cut it off, as the pull
request was getting quite large.

This removes all cases from `Column` where behavior was determined soley
based on the SQL type string. Instead, we push this decision up to the
Column's creation, and inject the object with knowledge of the type
casting behavior of it.

The API exposed was intended to be close to the PostgreSQL
implementation for OID lookups. There's additional refactoring that
could be done on this, especially in the PostgreSQL adapter and MySQL
adapter, but this felt like a good place to cut it off, as the pull
request was getting quite large.
@rafaelfranca
Copy link
Member

Cool! Thank you for working on this.

@senny since you are working on this area could you take a look on it?

@sgrif
Copy link
Contributor Author

sgrif commented May 16, 2014

Just a few notes on the reasoning here:

I went with the mapping structure that's used in order to make it easiest to extend in subclasses, and bring the API of the AbstractAdapter somewhat in line with the API of the PostgreSQLAdapter when possible. Additional changes I'd like to make in the future (but this pull request was large enough):

  • Inline all of the methods in postgresql/cast.rb to their appropriate type classes
  • Move the classes in postgresql/oid.rb to separate files
  • Remove the separate type mappings from MysqlAdapter and PostgreSQLAdapter

@senny
Copy link
Member

senny commented May 16, 2014

@sgrif please don't add more stuff to this PR. It's already very big and will take a long time to review. I was working on the same code and sadly we now have a lot of duplicated work (my branch is not yet pushed). I try to look into this and hopefully apply the PR in separate parts and not in one go.

@senny
Copy link
Member

senny commented May 16, 2014

@sgrif Thanks for moving this forward. It will clarify a lot ❤️

@sgrif
Copy link
Contributor Author

sgrif commented May 16, 2014

Not a problem, I don't plan to add any more, I had just spotted a minor issue. I apologize for the size, it would have been nice to break it up a bit more.

@sgrif
Copy link
Contributor Author

sgrif commented May 16, 2014

@senny Let me know if there's any way I can help. I'd be happy to pair if it might help reduce the duplicated work. :)

@senny
Copy link
Member

senny commented May 16, 2014

@sgrif actually I was thinking about that. Might be a good approach to keep the ball going. Can I reach you over GTalk/Hangout? If so, let me know over mail (found on my profile page).

@sgrif
Copy link
Contributor Author

sgrif commented May 16, 2014

Sent you my contact info, you can reach me on hangouts from that address.

@@ -644,6 +626,15 @@ def valid_type?(type)

protected

def initialize_type_map(mapping)
super
mapping.alias_type(/tinyint\(1\)/i, 'boolean') if emulate_booleans
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping code block-indented here but not in abstract adapter. should be consistent one way or another

@sgrif
Copy link
Contributor Author

sgrif commented May 17, 2014

@rafaelfranca @senny There's definitely parts of this that can be easily split into smaller PRs. I'm going to start doing that, now that there's context on what I'm working towards.

@rafaelfranca
Copy link
Member

👍

@senny
Copy link
Member

senny commented May 17, 2014

@sgrif 👍 thanks for splitting stuff up. Let's keep this PR open for reference but review the smaller pieces instead.

sgrif added a commit to sgrif/rails that referenced this pull request May 17, 2014
Part of rails#15134. In order to perform typecasting polymorphically, we need
to add another argument to the constructor. The order was chosen to
match the `oid_type` on `PostgreSQLColumn`.
@sgrif
Copy link
Contributor Author

sgrif commented May 21, 2014

This has been merged.

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

4 participants