Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
appraise "ar80" do
gem "activerecord", "~> 8.0.0"
end

appraise "ar81" do
gem "activerecord", "~> 8.1.0"
gem "rgeo-activerecord", "~> 8.1.0"
end
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@ Gemfile:
gem 'activerecord-mysql2rgeo-adapter'
```

#### Version 8.1

Requirements:

```
ActiveRecord 8.1
Ruby 3.1+ (no JRuby support yet)
MySQL 8.0+
```

#### Version 8.0

Requirements:

```
ActiveRecord 7.2
ActiveRecord 8.0
Ruby 3.1+ (no JRuby support yet)
MySQL 8.0+
```
Expand Down
4 changes: 2 additions & 2 deletions activerecord-mysql2rgeo-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.7.0"

spec.add_dependency "activerecord", "~> 8.0.0"
spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
spec.add_dependency "activerecord", ">= 8.1", "< 9"
spec.add_dependency "rgeo-activerecord", ">= 7.0", "< 9"
spec.add_dependency "rgeo", "~> 3.0"

spec.add_development_dependency "rake", "~> 12.0"
Expand Down
12 changes: 12 additions & 0 deletions gemfiles/ar81.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "mysql2", "~> 0.5.2", platform: :ruby
gem "jdbc-mysql", platform: :jruby
gem "activerecord-jdbc-adapter", "~> 5.0", platform: :jruby
gem "ffi-geos", platform: :jruby
gem "activerecord", "~> 8.1.0"
gem "rgeo-activerecord", "~> 8.1.0"

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def new_column_from_field(table_name, field, _definitions)

SpatialColumn.new(
field["Field"],
lookup_cast_type(type_metadata.sql_type),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

API change in ActiveRecord 8.1

default,
type_metadata,
field["Null"] == "YES",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ActiveRecord # :nodoc:
module ConnectionAdapters # :nodoc:
module Mysql2Rgeo # :nodoc:
class SpatialColumn < ConnectionAdapters::MySQL::Column # :nodoc:
def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, spatial: nil, **)
def initialize(name, cast_type, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, spatial: nil, **)
@sql_type_metadata = sql_type_metadata
if spatial
# This case comes from an entry in the geometry_columns table
Expand All @@ -14,10 +14,9 @@ def initialize(name, default, sql_type_metadata = nil, null = true, default_func
build_from_sql_type(sql_type_metadata.sql_type)
elsif sql_type_metadata.sql_type =~ /geometry|point|linestring|polygon/i
# A geometry column with no geometry_columns entry.
# @geometric_type = geo_type_from_sql_type(sql_type)
build_from_sql_type(sql_type_metadata.sql_type)
end
super(name, default, sql_type_metadata, null, default_function, collation: collation, comment: comment)
super(name, cast_type, default, sql_type_metadata, null, default_function, collation: collation, comment: comment)
if spatial?
if @srid
@limit = { type: geometric_type.type_name.underscore, srid: @srid }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ActiveRecord
module ConnectionAdapters
module Mysql2Rgeo
VERSION = "8.0.0"
VERSION = "8.1.0"
end
end
end
27 changes: 12 additions & 15 deletions lib/active_record/type/spatial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ def self.parse_sql_type(sql_type)
[geo_type, srid]
end

def spatial_factory
@spatial_factories ||= {}

@spatial_factories[@srid] ||=
RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
geo_type: @geo_type,
sql_type: @sql_type,
srid: @srid
def spatial_factory(srid = @srid)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ActiveRecord 8.1 adds memoization for the various types so we can't use an instance variable anymore.

RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
geo_type: @geo_type,
sql_type: @sql_type,
srid: srid
)
end

Expand Down Expand Up @@ -87,15 +84,15 @@ def cast_value(value)
def parse_wkt(string)
marker = string[4, 1]
if ["\x00", "\x01"].include?(marker)
@srid = string[0, 4].unpack1(marker == "\x01" ? "V" : "N")
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid).parse(string[4..-1])
srid = string[0, 4].unpack1(marker == "\x01" ? "V" : "N")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Due to added memoization of types in AR 8.1 we have to stop using an instance variable.

RGeo::WKRep::WKBParser.new(spatial_factory(srid), support_ewkb: true, default_srid: srid).parse(string[4..-1])
elsif string[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
@srid = string[0, 8].to_i(16)
@srid = [@srid].pack("V").unpack("N").first if string[9, 1] == "1"
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(string[8..-1])
srid = string[0, 8].to_i(16)
srid = [srid].pack("V").unpack("N").first if string[9, 1] == "1"
RGeo::WKRep::WKBParser.new(spatial_factory(srid), support_ewkb: true, default_srid: srid).parse(string[8..-1])
else
string, @srid = Arel::Visitors::Mysql2Rgeo.parse_node(string)
RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(string)
string, srid = Arel::Visitors::Mysql2Rgeo.parse_node(string)
RGeo::WKRep::WKTParser.new(spatial_factory(srid), support_ewkt: true, default_srid: srid).parse(string)
end
rescue RGeo::Error::ParseError, RGeo::Error::InvalidGeometry
nil
Expand Down
Loading