10

我正在按照这篇文章开发一个多租户应用程序。问题是当我第一次运行所有迁移时。文件中schema.rb只有公共模式的表,但其他模式发生了什么?以及如何创建与public我不想使用 gem 的结构不同的其他模式。

请参阅下面的示例

为公共模式创建的表

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
end

架构.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
4

1 回答 1

2

你知道公寓宝石吗?https://github.com/influitive/apartment

我在今年的一个项目中使用了一个支持多模式的 postgresql。一切都记录在案且易于使用。您可以选择中间件模式。例如,当您访问域 customer.applicationdomain.com 时,应用程序可以为您选择正确的架构。顺便说一句,您也可以在 sidekiq 中使用后台作业。

于 2014-05-18T07:00:24.330 回答