activerecord-trilogis-adapter 8.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d6986c4a92cdff8495b93cf837edbc946a9401c1a12a2b639bc7440c974d0d6
4
- data.tar.gz: b5663960d9aa5514a8c495d6603871c20acbdfdbdd534d78da2c70eb8f4e154d
3
+ metadata.gz: c50e53fc7f5c471c74e8f587e0c0bdab734181845cd438359537735cc1adbe19
4
+ data.tar.gz: 930f29abad6e57fbbbe3d6e922a191c21cbb75365ef99233633e728a4e4b8b0e
5
5
  SHA512:
6
- metadata.gz: 784de6dc127d3c4f584ed540d37391e1bbb88496ff1e05c9e0229686356b4bd69af33635910b7c81dd12844b649f9db9808458d4251734a4531b7261c2ee99bc
7
- data.tar.gz: 3e9e4ddea564f8e6843baa1f36104b83f5679b5ecb0ed46e8e0edb5c7f97f942534640f5a35d582dbae3a5c6332c59af828eb7a14b41c21b92f6f2637ae53123
6
+ metadata.gz: 8c504d937064d0ffbd6a57a4c6bb854db79436d1e6b9f933e138aeaf155e769316a54f77a37fe1ca1c704e3c30dd4f7a519559e355ca3159533b21fd3cd1c694
7
+ data.tar.gz: 2cafe377ca75657049c47678ad97eb41d74f1990b96aaa859820822aa4c7aa5d32c50fb555b0c7d0f6958e0a5d91ff0d9eaa9e9b6aec4f7dc9c8fe788ef7905c
@@ -9,7 +9,10 @@ module ActiveRecord
9
9
  def add_column_options!(sql, options)
10
10
  # Add SRID option for spatial columns in MySQL 8.0+
11
11
  # Format: /*!80003 SRID #{srid} */
12
- sql << " /*!80003 SRID #{options[:srid]} */" if options[:srid]
12
+ if options[:srid]
13
+ sql_result = "#{sql} /*!80003 SRID #{options[:srid]} */"
14
+ sql.replace(sql_result)
15
+ end
13
16
 
14
17
  super
15
18
  end
@@ -77,18 +77,20 @@ module ActiveRecord
77
77
  if spatial_type?(type.to_s)
78
78
  # Build ALTER TABLE statement for spatial column
79
79
  sql_type = spatial_sql_type(type, options[:type])
80
- sql = "ALTER TABLE #{quote_table_name(table_name)} ADD #{quote_column_name(column_name)} #{sql_type}"
80
+ base_sql = "ALTER TABLE #{quote_table_name(table_name)} " \
81
+ "ADD #{quote_column_name(column_name)} #{sql_type}"
82
+ sql_parts = [base_sql]
81
83
 
82
84
  # Add SRID if specified
83
- sql << " SRID #{options[:srid]}" if options[:srid] && options[:srid] != 0
85
+ sql_parts << " SRID #{options[:srid]}" if options[:srid] && options[:srid] != 0
84
86
 
85
87
  # Add NULL constraint
86
- sql << " NOT NULL" if options[:null] == false
88
+ sql_parts << " NOT NULL" if options[:null] == false
87
89
 
88
90
  # Add DEFAULT if specified (allow falsy values like 0/false)
89
- sql << " DEFAULT #{quote_default_expression(options[:default], nil)}" if options.key?(:default)
91
+ sql_parts << " DEFAULT #{quote_default_expression(options[:default], nil)}" if options.key?(:default)
90
92
 
91
- execute sql
93
+ execute sql_parts.join
92
94
 
93
95
  # Clear memoized spatial column info for this table
94
96
  clear_spatial_cache_for(table_name)
@@ -180,14 +182,14 @@ module ActiveRecord
180
182
  def visit_ColumnDefinition(o)
181
183
  if spatial_column?(o)
182
184
  sql_type = spatial_sql_type(o.sql_type, o.options[:type])
183
- column_sql = "#{quote_column_name(o.name)} #{sql_type}"
185
+ column_sql_parts = ["#{quote_column_name(o.name)} #{sql_type}"]
184
186
 
185
187
  # Add SRID if specified (MySQL 8.0+ syntax: COLUMN TYPE SRID value)
186
- column_sql << " SRID #{o.options[:srid]}" if o.options[:srid] && o.options[:srid] != 0
188
+ column_sql_parts << " SRID #{o.options[:srid]}" if o.options[:srid] && o.options[:srid] != 0
187
189
 
188
- column_sql << " NOT NULL" unless o.null
189
- column_sql << " DEFAULT #{quote_default_expression(o.default, o)}" unless o.default.nil?
190
- column_sql
190
+ column_sql_parts << " NOT NULL" unless o.null
191
+ column_sql_parts << " DEFAULT #{quote_default_expression(o.default, o)}" unless o.default.nil?
192
+ column_sql_parts.join
191
193
  else
192
194
  super
193
195
  end
@@ -13,7 +13,7 @@ module ActiveRecord
13
13
 
14
14
  module Trilogis
15
15
  class SpatialColumn < ActiveRecord::ConnectionAdapters::MySQL::Column
16
- attr_reader :geometric_type, :srid
16
+ attr_reader :geometric_type, :srid, :geo_type_name
17
17
 
18
18
  # Map SQL type strings to RGeo type classes
19
19
  GEOMETRIC_TYPES = {
@@ -27,24 +27,24 @@ module ActiveRecord
27
27
  "geometrycollection" => RGeo::Feature::GeometryCollection
28
28
  }.freeze
29
29
 
30
- def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil,
31
- comment: nil, spatial_info: nil, **)
30
+ def initialize(name, default, sql_type_metadata = nil, null = true,
31
+ default_function = nil, collation: nil, comment: nil, spatial_info: nil, **)
32
32
  super(name, default, sql_type_metadata, null, default_function, collation: collation, comment: comment)
33
33
 
34
34
  return unless spatial?
35
35
 
36
36
  if spatial_info
37
37
  # Use spatial info from INFORMATION_SCHEMA if available
38
- geo_type_str = spatial_info[:type].to_s.downcase
39
- @geometric_type = GEOMETRIC_TYPES[geo_type_str] || RGeo::Feature::Geometry
38
+ @geo_type_name = spatial_info[:type].to_s.downcase
39
+ @geometric_type = GEOMETRIC_TYPES[@geo_type_name] || RGeo::Feature::Geometry
40
40
  @srid = spatial_info[:srid] || 0
41
41
  @has_z = spatial_info[:has_z] || false
42
42
  @has_m = spatial_info[:has_m] || false
43
43
  else
44
44
  # Fallback to extracting from SQL type
45
- type_info = Type::Spatial.new(sql_type_metadata.sql_type)
46
- geo_type_str = type_info.geo_type.to_s.downcase
47
- @geometric_type = GEOMETRIC_TYPES[geo_type_str] || RGeo::Feature::Geometry
45
+ @geo_type_name = sql_type_metadata.sql_type.to_s.downcase
46
+ type_info = Type::Spatial.new(@geo_type_name)
47
+ @geometric_type = GEOMETRIC_TYPES[@geo_type_name] || RGeo::Feature::Geometry
48
48
  @srid = type_info.srid || 0
49
49
  @has_z = false
50
50
  @has_m = false
@@ -63,14 +63,25 @@ module ActiveRecord
63
63
  @has_m || false
64
64
  end
65
65
 
66
+ # Return Rails type for schema dumper
67
+ # Returns the actual geometric type (point, linestring, etc.) as symbol
68
+ # This allows schema dumper to generate t.point, t.linestring, etc.
69
+ def type
70
+ return super unless spatial?
71
+
72
+ # Return actual geometric type as symbol
73
+ # This matches PostGIS approach and enables proper schema dumping
74
+ @geo_type_name&.to_sym || :geometry
75
+ end
76
+
66
77
  # Return limit as hash with spatial metadata for schema dumper
78
+ # Only includes SRID (type is already in column type)
67
79
  def limit
68
80
  return super unless spatial?
69
81
 
70
- {
71
- type: sql_type_metadata.sql_type.downcase,
72
- srid: @srid
73
- }
82
+ # Only include SRID in limit
83
+ # Type information is in the type() method
84
+ { srid: @srid }.compact
74
85
  end
75
86
  end
76
87
  end
@@ -104,9 +104,6 @@ module ActiveRecord
104
104
  # Override the visitor for spatial support
105
105
  @visitor = Arel::Visitors::Trilogis.new(self)
106
106
 
107
- # Register spatial types
108
- register_spatial_types
109
-
110
107
  # Configure RGeo factory generator for SRID-based factory selection
111
108
  configure_rgeo_factory_generator
112
109
  end
@@ -138,6 +135,11 @@ module ActiveRecord
138
135
  Trilogis::SchemaCreation.new(self)
139
136
  end
140
137
 
138
+ # Override valid_type? to include spatial types
139
+ def valid_type?(type)
140
+ SPATIAL_COLUMN_TYPES.include?(type.to_s) || super
141
+ end
142
+
141
143
  def native_database_types
142
144
  super.merge(
143
145
  geometry: { name: "geometry" },
@@ -188,16 +190,6 @@ module ActiveRecord
188
190
 
189
191
  private
190
192
 
191
- def register_spatial_types
192
- SPATIAL_COLUMN_TYPES.each do |geo_type|
193
- ActiveRecord::Type.register(
194
- geo_type.to_sym,
195
- Type::Spatial.new(geo_type),
196
- adapter: :trilogis
197
- )
198
- end
199
- end
200
-
201
193
  def configure_rgeo_factory_generator
202
194
  # Register Geographic factories for geographic SRIDs in RGeo::ActiveRecord::SpatialFactoryStore
203
195
  # This ensures the correct factory (Geographic vs Cartesian) is used based on SRID
@@ -264,6 +256,15 @@ module ActiveRecord
264
256
  end
265
257
  end
266
258
 
259
+ # Register spatial types globally
260
+ ActiveRecord::ConnectionAdapters::TrilogisAdapter::SPATIAL_COLUMN_TYPES.each do |geo_type|
261
+ ActiveRecord::Type.register(
262
+ geo_type.to_sym,
263
+ ActiveRecord::Type::Spatial,
264
+ adapter: :trilogis
265
+ )
266
+ end
267
+
267
268
  # Register the adapter with ActiveRecord
268
269
  ActiveRecord::ConnectionAdapters.register(
269
270
  "trilogis",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-trilogis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0
4
+ version: 8.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ether Moon
@@ -13,22 +13,16 @@ dependencies:
13
13
  name: activerecord
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
18
  version: '8.0'
19
- - - "<"
20
- - !ruby/object:Gem::Version
21
- version: '9.0'
22
19
  type: :runtime
23
20
  prerelease: false
24
21
  version_requirements: !ruby/object:Gem::Requirement
25
22
  requirements:
26
- - - ">="
23
+ - - "~>"
27
24
  - !ruby/object:Gem::Version
28
25
  version: '8.0'
29
- - - "<"
30
- - !ruby/object:Gem::Version
31
- version: '9.0'
32
26
  - !ruby/object:Gem::Dependency
33
27
  name: rgeo
34
28
  requirement: !ruby/object:Gem::Requirement