我正在开发一个遵循this article的多租户应用程序。问题是当我第一次运行所有迁移时。在schema.rb文件中,只有公共模式的表,但是其他模式会发生什么呢?以及如何创建与我不想使用的public不同结构的其他模式。
参见下面的示例
要为公共模式创建的表
class CreatePerspectives < ActiveRecord::Migration
include MultiSchema
def up
with_in_schemas :only => :public do
# Create table perspectives
end
end
def down
with_in_schemas :only => :public do
drop_table :prespectives
end
end
end为私有模式创建的表
class CreateObjectives < ActiveRecord::Migration
include MultiSchema
def change
with_in_schemas :except => :public do
# Create objectives table
end
end
endschema.rb
ActiveRecord::Schema.define(version: 20130810172443) do
create_table "perspectives", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
end发布于 2014-05-18 07:00:24
你知道公寓宝石吗?https://github.com/influitive/apartment
我在今年的一个项目中使用过,它支持postgresql的多模式。所有的东西都有文档记录,而且易于使用。您可以选择中间件模式。例如,当您访问域customer.applicationdomain.com时,应用程序可以为您选择正确的架构。顺便说一句,你也可以使用后台作业。
https://stackoverflow.com/questions/18186756
复制相似问题