开发者

Is it possible to specify a SQL Server schema name in a Rails ActiveRecord migration?

The current convention where I work is to us开发者_如何转开发e 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜