简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM