activerecord-trilogis-adapter 8.0.0 → 8.0.2

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: c62868490c8dbbca1486797b7f451fe16da47e250d97d9578bc28bd405f88979
4
+ data.tar.gz: 53635558156147dadcf07913b4faeec937b0c8d1fd09548a82ac8168d10c3c45
5
5
  SHA512:
6
- metadata.gz: 784de6dc127d3c4f584ed540d37391e1bbb88496ff1e05c9e0229686356b4bd69af33635910b7c81dd12844b649f9db9808458d4251734a4531b7261c2ee99bc
7
- data.tar.gz: 3e9e4ddea564f8e6843baa1f36104b83f5679b5ecb0ed46e8e0edb5c7f97f942534640f5a35d582dbae3a5c6332c59af828eb7a14b41c21b92f6f2637ae53123
6
+ metadata.gz: 12824854fd79269b2f00231712267db378e642579ea462a2aee7c1e377961ee65a0f03d2d47227484b9bfaa1800549fa2b207c7e8c5e29d9b1059b7deafed4bd
7
+ data.tar.gz: 1bb9c83957682886cb09eb343fe82ef2e9e9c2a4eb6998f01ecfe0d5c3c8a52659bfccd7344433260e1de3c66d15f8579ed2132286471fe9b9f235b042ef2b1e
@@ -9,7 +9,15 @@ 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
+
16
+ # MySQL does not support DEFAULT values for spatial columns
17
+ # Remove :default option before calling super to prevent SQL errors
18
+ options = options.dup
19
+ options.delete(:default)
20
+ end
13
21
 
14
22
  super
15
23
  end
@@ -77,18 +77,21 @@ 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
- # Add DEFAULT if specified (allow falsy values like 0/false)
89
- sql << " DEFAULT #{quote_default_expression(options[:default], nil)}" if options.key?(:default)
90
+ # MySQL does not support DEFAULT values for spatial/geometry columns
91
+ # Silently ignore :default option to prevent SQL syntax errors
92
+ # Users should handle defaults at application level instead
90
93
 
91
- execute sql
94
+ execute sql_parts.join
92
95
 
93
96
  # Clear memoized spatial column info for this table
94
97
  clear_spatial_cache_for(table_name)
@@ -163,10 +166,10 @@ module ActiveRecord
163
166
 
164
167
  SpatialColumn.new(
165
168
  field_name,
166
- extract_field_value(field, :Default, :default),
169
+ nil, # MySQL spatial columns cannot have DEFAULT values
167
170
  type_metadata,
168
171
  extract_field_value(field, :Null, :null) == "YES",
169
- extract_field_value(field, :Extra, :extra),
172
+ nil, # MySQL spatial columns cannot have DEFAULT functions
170
173
  collation: extract_field_value(field, :Collation, :collation),
171
174
  comment: extract_field_value(field, :Comment, :comment).presence,
172
175
  spatial_info: spatial_info
@@ -180,14 +183,17 @@ module ActiveRecord
180
183
  def visit_ColumnDefinition(o)
181
184
  if spatial_column?(o)
182
185
  sql_type = spatial_sql_type(o.sql_type, o.options[:type])
183
- column_sql = "#{quote_column_name(o.name)} #{sql_type}"
186
+ column_sql_parts = ["#{quote_column_name(o.name)} #{sql_type}"]
184
187
 
185
188
  # 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
189
+ column_sql_parts << " SRID #{o.options[:srid]}" if o.options[:srid] && o.options[:srid] != 0
187
190
 
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
191
+ column_sql_parts << " NOT NULL" unless o.null
192
+
193
+ # MySQL does not support DEFAULT values for spatial/geometry columns
194
+ # Silently ignore default to prevent SQL syntax errors
195
+
196
+ column_sql_parts.join
191
197
  else
192
198
  super
193
199
  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,45 @@ 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
85
+ end
86
+
87
+ # Override default to always return nil for spatial columns
88
+ # MySQL does not support DEFAULT values for spatial/geometry columns
89
+ def default
90
+ return super unless spatial?
91
+
92
+ # Always return nil for spatial columns to prevent schema dumper
93
+ # from generating invalid DEFAULT clauses
94
+ nil
95
+ end
96
+
97
+ # Override default_function to always return nil for spatial columns
98
+ # MySQL does not support DEFAULT values for spatial/geometry columns
99
+ def default_function
100
+ return super unless spatial?
101
+
102
+ # Always return nil for spatial columns to prevent schema dumper
103
+ # from generating invalid DEFAULT clauses
104
+ nil
74
105
  end
75
106
  end
76
107
  end
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  module Trilogis
6
- VERSION = "8.0.0"
6
+ VERSION = "8.0.2"
7
7
  end
8
8
  end
9
9
  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.2
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