是否可以在Rails ActiveRecord迁移中指定SQL Server模式名称?

Bri*_*van 3 sql-server activerecord ruby-on-rails

我工作的当前约定是使用SQL Server模式,如命名空间(例如,Company.Employees,Company.Branches等)是否有可能使ActiveRecord迁移使用SQL Server中默认的"dbo"模式以外的任何其他模式?

Har*_*tty 7

在迁移中,为create_table和drop_table调用提供具有模式前缀的表名.

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

在模型中,使用覆盖默认表名set_table_name.

class Employees < ActiveRecord::Base
  set_table_name "Company.Employees"
end
Run Code Online (Sandbox Code Playgroud)

另一方面

如果rails应用程序中使用的所有表都属于同一模式,则可以将该模式指定为database.yml文件中指定的DB用户的缺省模式.