Search code examples
ruby-on-rails-4multi-tenantapartment-gem

Apartment gem: How to rename tenant?


Can we able to rename the tenant in apartment-gem or we have to drop the tenant and create a new one to achieve this.

Please provide me some suggestions


Solution

  • I don't think this is available through the apartment gem, but it is fairly simple to do with a SQL query. It depends on your setup though.

    If you are using Postgresql with a schema for each tenant:

    ALTER SCHEMA old RENAME TO new;
    

    If you are using MySql, you should rename the table name prefixes for the tenant. This should work if the databases are on the same file system:

    RENAME TABLE current_tenant.table TO new_tenant.table;
    

    Disclaimer: not tested.