Creating a multi-tenant application using PostgreSQL's schemas and Rails

前端 未结 3 2058
攒了一身酷
攒了一身酷 2021-01-29 17:53

Stuff I\'ve already figured out

I\'m learning how to create a multi-tenant application in Rails that serves data from different schemas based on what domain or subdomai

3条回答
  •  醉话见心
    2021-01-29 18:51

    Is there a gem/plugin that has these things already?

    pg_power provides this functionality to create/drop PostgreSQL schemas in migration, like this:

    def change
      # Create schema
      create_schema 'demography'
    
      # Create new table in specific schema
      create_table "countries", :schema => "demography" do |t|
        # columns goes here
      end
    
      # Drop schema
      drop_schema 'politics'
    end
    

    Also it takes care about correctly dumping schemas into schema.rb file.

提交回复
热议问题