-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Support for mysql schema with spatial types/indexes #27813
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kaspth (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
Cool! |
When was this added to MySQL? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a CHANGELOG entry?
@arthurnn I don't think we need to check the MySQL version. People needs to opt-in this feature and If people use a version that doesn't support it they will see when running the migration.
@arthurnn mysql added spatial extensions in 4.1, and as of 5.7.5 spatial indexing for InnoDB was added. Since we are supporting Mysql>=5.1.10 no additional checks are needed, except for index addition, but in this case one will get an error on migration. |
687fd5a
to
6e05b69
Compare
@rafaelfranca added changelog entry + rebased onto current master to resolve conflicts |
|
||
def multi_polygon(*args, **options) | ||
args.each { |name| column(name, :multi_polygon, options) } | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think it makes sense exposing those multi columns both via an option and a method, I'd go with the option across the board:
def point(*args, multi: false, **options)
type = multi ? :multi_point : :point
args.each { |name| column(name, type, options) }
end
Then the same for the other versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaspth I agree. Pushed changes
40f7e6d
to
e45bca8
Compare
@@ -396,7 +404,7 @@ def indexes(table_name, name = nil) #:nodoc: | |||
end | |||
|
|||
indexes.last.columns << row[:Column_name] | |||
indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part] | |||
indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part] && mysql_index_type != :spatial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremy can you vet this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mysql returns non-null Sub_part
for spatial index, but does not allow to set it, thus previous behaviour resulted in a schema dump that could not be loaded back.
https://dev.mysql.com/doc/refman/5.7/en/create-index.html :
Spatial indexes (created using SPATIAL INDEX) have these characteristics:
...
- Column prefix lengths are prohibited. The full width of each column is indexed.
How does this integrate with https://github.com/rgeo/rgeo or https://github.com/geokit/geokit-rails ? I notice that other spatial adapters use distinct "multi" types rather than making it an option on the singular type, e.g. |
@jeremy postgresql adapter provides similar types by adding geokit-rails does not use native spatial extensions, only mentions mysql2spatial adapter from rgeo as a synonym for regular mysql adapter for using mysql's math functions. Will look closer into implementation of rgeo adapter, it's master branch is incompatible with AR 5 ( rgeo/activerecord-mysql2spatial-adapter#19 ) at the moment. I doubt that all heavy-lifting of parsing binary WKB geo data should be brought into rails, so better is to provide an integration point. First thing coming to mind is monkey-patching |
Looks like this PR has been opened for more than a year now. Do you think it's worth rebasing this and pushing it forward to be included in 6.0? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Summary
This allows one to have spatial fields and indexes in database without switching to sql schema format.