activerecord-sqlserver-adapter icon indicating copy to clipboard operation
activerecord-sqlserver-adapter copied to clipboard

Support Geography datatype and spatial index

Open ttilberg opened this issue 8 months ago • 2 comments

There is a datatype called geography that is a binary representation of spatial data. I found that when I tried leveraging this in Rails, it was mapped to string in the schema dump. This will cause inconsistency with schema loading in tasks like db:prepare.

Additionally, Spatial Indexes allow performance querying against the geography datatype by organizing the information into quadrants. They are handled separately from traditional data indexes.

We can create them using the type: option with

add_index :zip_codes, :geography_point, type: :spatial

But they do not get listed in the schema dump, and they cannot be found for reversal without specifying by name.

ttilberg avatar Jun 23 '25 20:06 ttilberg

Updated the issue to reflect that spatial index creation is already available using the type option, i.e.

add_index :zip_codes, :geography_point, type: :spatial

ttilberg avatar Jun 23 '25 20:06 ttilberg

But, the spatial index isn't added to schema.rb, and remove_index does not work without specifying :name. It seems to be related to the fact that spatial indices are not included in the #indexes method, which uses sp_helpindex sproc.

So, if this gets picked up, we should be sure to check for index reversal for type: :spatial.

ttilberg avatar Jun 23 '25 20:06 ttilberg