0

I am building a multitenant application using the Apartment gem. I have the core features that will be common across all tenants. But now I want to add a table the schema for TenantB that will not be in the schema for TenantA. If I do the following it adds the table to able tenants.

       class CreateStickies < ActiveRecord::Migration[5.0]

         def change
          if table_exists? :tenantb
           create_table :post do |t|
             t.text :body
             t.string :title

             t.timestamps
           end
          end
         end

       end

How can I add this Posts table to my tenant(s) of choice?

AntonioMarquis
  • 135
  • 1
  • 7

1 Answers1

0

As I understand Apartement does not support what you are asking.

If you are developing a Rails application using apartment, you may have a work around.

Loading tenant specific configurations (Shamelessly copied from wiki)

#config/initializers/country_specific.rb
COUNTRY_CONFIGS = YAML.load_file(Rails.root.join('config', 'country_specific' , 'config.yml'))

#config/country_specific/config.yml
da:
site_name: Boligsurf.dk
se:
site_name: Bostadssurf.se

#app/controllers/application_controller
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_country_config
......
def set_country_config
    $COUNTRY_CONFIG = COUNTRY_CONFIGS['da'] #As default as some strange domains also refer this site, we'll just catch em as danish
    $COUNTRY_CONFIG = COUNTRY_CONFIGS['se'] if request.host.include? 'bostadssurf'
end

#Somewhere in your code
puts "Welcome to #{$COUNTRY_CONFIG['site_name']}"

Probably you may explore the above feature to hide/expose the tenant specific areas of your applications based on the tenant.

fossil
  • 740
  • 6
  • 17