views:

59

answers:

1

The current convention where I work is to use SQL Server schemas like namespaces (e.g. Company.Employees, Company.Branches, etc.) Is it possible to get an ActiveRecord migration to use anything other than the default "dbo" schema in SQL Server?

+1  A: 

In your migration, supply table names with schema prefix to create_table and drop_table calls.

create_table("Company.Employees") do |t|
  t.column :name, :string, :limit => 60
  # Other fields here
end

In the model, override the default table name using set_table_name.

class Employees < ActiveRecord::Base
  set_table_name "Company.Employees"
end

On the other hand

If all the tables used in your rails application belong to the same schema, then you can assign that schema as the default schema for the DB user specified in the database.yml file.

KandadaBoggu