3
我工作的当前约定是使用SQL Server架构(如名称空间)(例如Company.Employees,Company.Branches等)是否有可能获得ActiveRecord迁移,以便在SQL中使用除缺省“dbo”架构以外的任何其他服务器?是否可以在Rails ActiveRecord迁移中指定SQL Server模式名称?
我工作的当前约定是使用SQL Server架构(如名称空间)(例如Company.Employees,Company.Branches等)是否有可能获得ActiveRecord迁移,以便在SQL中使用除缺省“dbo”架构以外的任何其他服务器?是否可以在Rails ActiveRecord迁移中指定SQL Server模式名称?
在您的迁移过程中,为具有create_table和drop_table调用的模式前缀提供表名称。
create_table("Company.Employees") do |t|
t.column :name, :string, :limit => 60
# Other fields here
end
在该模型中,使用set_table_name
覆盖缺省表名称。
class Employees < ActiveRecord::Base
set_table_name "Company.Employees"
end
在另一方面
如果你的Rails应用程序中使用的所有表属于同一个模式,那么你可以分配方案为在数据库中指定数据库用户的默认架构.yml文件。
根据我的发现,这可以在Rails 3.x中使用,但不能使用Rails 2.x(我在2.3.2中测试)。有没有人有相反的经验?还是另一种解决方案 – 2011-05-12 20:14:12