Dorp

The term "Dorp" is the word in Dutch/Afrikaans that mean 'village', symbolizing the gem's capacity for managing multiple distinct 'tenants' in a single application.

Key Features:

  • Supports the essential CRUD operations for multi-tenant data isolation
  • Middleware support for subdomain or domain-based tenant scoping
  • Compatibility with Ruby on Rails 6.1+

The goal of the gem is to leverage to the maximum rails multi db feature.

Installation

To install the Dorp gem, add this line to your project's Gemfile:

gem 'dorp'

Usage

Configuration

To start, you need to cha

To migrate the the the database yaml from from a single database to multiple databases, you can use the following command:

Before:

development:
    adapter: postgresql
    database: myapp_development
    ....

After:

development:
  main:
    adapter: postgresql
    database: myapp_development
    primary: true
    ....

  hamlets:
    adapter: postgresql
    database:  myapp_tenants_development
    migrations_paths: db/tenants_migrate ## Those are the migrations that will be run for each tenant

Creating a new tenant

To create a new tenant, you can use the following command:

Dorp::Tenant.create(name: 'my_tenant', subdomain: 'my_tenant')

Creating a new model

Before starting, an abstract model must be created. This model will be used as a base for all the models that will be created for each tenant.

class TenantRecord < ApplicationRecord
  self.abstract_class = true
  include Dorp::TenantRecord
end

Then, you can create a new model that will be used for each tenant:


## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/seuros/dorp.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).