Search code examples
sql-serverruby-on-railsruby-on-rails-pluginsforeigner

Ruby on Rails Foreigner plugin not working for SQL Server


Well, now that I've finally got my stupid ODBC stuff configured, I took a schema.rb file that I dumped from a Postgres database and did a db:schema:load on it in a Rails project configured for SQL Server.

Well, it sets up all the schema in the SQL Server database except for a minor detail: No foreign keys are created.

The rake command doesn't show any errors and does say it is adding foreign keys. But they don't actually get added. This is the last bit from the command:

-- add_foreign_key("workhistoryform", "form", {:name=>"workhistoryform_form_rid_fkey", :column=>"form_rid", :primary_key=>"form_rid"})
   -> 0.0002s
-- initialize_schema_migrations_table()
   -> 0.0092s
-- assume_migrated_upto_version(0)
   -> 0.0942s
[earlz@earlzarch avp_msql_migrations]$

So what is the problem? Does the Foreigner plugin not work in SQL Server? If it didn't I'd expect to see an error or something...


Solution

  • Ok, I fixed it. Well, hacked it anyway. Foreigner doesn't actually have built in support for SQL Server, but it is close enough to SQL_2003 that it works (minus removing Foreign Keys and detecting the Schema)

    I made a post about it on my blog which basically boiled down to adding a to the list of adapters and creating a very simple new adapter for SQL Server(use the PostgreSQL adapter as a template). (modifying the Foreigner gem)