加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-4 – 在Rails中使用Postgres多模式数据库

发布时间:2020-12-16 22:00:01 所属栏目:百科 来源:网络整理
导读:我在 this article之后开发一个多租户应用程序.问题是我第一次运行所有迁移时.在schema.rb文件中只是公共模式的表,但是其他模式发生了什么?并且如何创建具有不同结构的其他模式给公众,我不想使用宝石. 见下面的例子 要为公共模式创建的表 class CreatePersp
我在 this article之后开发一个多租户应用程序.问题是我第一次运行所有迁移时.在schema.rb文件中只是公共模式的表,但是其他模式发生了什么?并且如何创建具有不同结构的其他模式给公众,我不想使用宝石.

见下面的例子

要为公共模式创建的表

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

schema.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

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读