是否有可能在Rails的ActiveRecord迁移指定SQL Server架构的名字吗? [英] Is it possible to specify a SQL Server schema name in a Rails ActiveRecord migration?

查看:104
本文介绍了是否有可能在Rails的ActiveRecord迁移指定SQL Server架构的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我工作的地方目前的惯例是使用类似的命名空间的SQL Server架构(如Company.Employees,Company.Branches等)是否有可能得到一个ActiveRecord迁移到使用任何比默认的DBO模式等SQL Server的?

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?

推荐答案

在您的迁移,用模式preFIX供给表名CREATE_TABLE和drop_table电话。

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

在模型中,利用覆盖缺省的表名 set_table_name

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

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

在另一方面

如果在你的Rails应用程序中使用的表属于同一模式,那么你可以分配方案为在database.yml文件中指定的数据库用户的默认架构。

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.

这篇关于是否有可能在Rails的ActiveRecord迁移指定SQL Server架构的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆