Evan
Evan

Reputation: 121

Rails test database getting wrong column type on geographic columns

We have a rails app that uses postgis and activerecord-postgis-adapter for geographic information search. However, it doesn't work right in the test database. In development and production database, geographic columns get the type "geography(Point, 4236)". In test, those same columns have the type "geometry". This means that geographic searches don't do spherical geographic distance ... they just do plain cartesian geometry, which means the numbers are typically off by about 100,000. Boo.

Here's what it looks like in schema.rb:

create_table "buyers", :force => true do |t|
  # snip 
  t.spatial  "geocoded_coordinates",    :limit => {:srid=>4326, :type=>"point", :geographic=>true}
end

And in database.yml:

development: &development
  adapter: postgis
  database: lvs_dev
  username: postgres
  host:     "lrd-db"
  template: template_postgis

test:
  <<: *development
  database: lvs_test

The resulting columns in the database (via psql):

lvs_dev:

lvs_dev=# \d+ buyers
Table "public.buyers"
# snip
geocoded_coordinates    | geography(Point,4326)       |                                                      | main     |

lvs_test:

lvs_dev=# \d+ buyers
Table "public.buyers"
# snip
geocoded_coordinates    | geometry                    |                                                      | main     |

So ... what gives here? Any ideas why rails / rake is creating a different DB schema in development and test?

Upvotes: 2

Views: 495

Answers (1)

Josh
Josh

Reputation: 8586

Did you try dropping and recreating the test DB, then running the migrations again? Also, check to see if it's reloading the test DB from the schema somewhere instead of running the migrations.

Upvotes: 1

Related Questions