Project

penthouse

0.01
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Multi-tenancy framework. Out of the box, supports Postgres schemas and per-tenant databases
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.2.6
~> 0.8.6
~> 1.11
>= 0
>= 0
~> 1.6.4
~> 10.0
~> 3.4.0
~> 0.38
~> 0.11.2
~> 0.8.7.6

Runtime

~> 1.11
 Project Readme

Penthouse

Codeship Status Code Climate RubyDocs

Penthouse is an alternative to the excellent Apartment gem – however Penthouse is more of a framework for multi-tenancy than a library, in that it provides less out-of-the-box functionality, but should make for easier customisation.

  • Penthouse
    • Installation
    • Basic Usage
    • Octopus (shard) Usage
    • ActiveJob
    • Sidekiq
    • Dictionary
    • Contributing
    • Testing
      • CI/Local
      • Without Circle

Installation

Add this line to your application's Gemfile:

gem 'penthouse'

Basic Usage

If you're using Rails, you just need to configure an initializer at config/initializers/penthouse.rb

require 'penthouse'
# include the standard Rack app
require 'penthouse/app'
# require the relevant router/runner you wish to use
require 'penthouse/routers/subdomain_router'
require 'penthouse/runners/schema_runner'

Penthouse.configure do |config|
  config.router = Penthouse::Routers::SubdomainRouter
  config.runner = Penthouse::Runners::SchemaRunner
  # enhance migrations to migrate all tenants
  config.migrate_tenants = true
  # setup a proc which will return the tenants
  config.tenants = Proc.new do
    Account.each_with_object({}) do |account, result|
      result.merge!(account.slug => account)
    end
  end
end

Rails.application.config.middleware.use Penthouse::App

It's advised that if you want to customise these classes, you do so by sub-classing Penthouse::App, Penthouse::Routers::BaseRouter and/or Penthouse::Runners::BaseRunner within this initializer.

Octopus (shard) Usage

If you want to have multiple databases on isolated hardware, you'll need to use the Octopus tenant types. In addition to the above initializer you'll need to configure Octopus:

require 'octopus'

Octopus.setup do |config|
  config.environments = [Rails.env]
end

ActiveJob

If you are using ActiveJob, you'll need to create an active_job.rb initializer:

require 'penthouse/active_job'

class ActiveJob::Base
  include Penthouse::ActiveJob
end

Sidekiq

If you are using Sidekiq, you simply need to include the Penthouse module, this can be done in the penthouse.rb initializer:

require 'penthouse/sidekiq'

Dictionary

  • Router – this class receives a Rack request object and returns an identifier (just a string or symbol) for the tenant.
  • Runner – this class receives the identifier (either from the router or manually switching), then looks up the tenant instance and runs the code within it.

Contributing

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

Testing

CI/Local

We use circle,a dn it can be used locally with docker. See:

echo <circle-api-token> | circleci setup
circleci local execute

Without Circle

Docker is used for isolated testing. To test all supported versions run:

make test

For specific versions see the Makefile.

Alternatively you can tets any version locally with:

export RUBY_VERSION=2.5.0
rbenv local $RUBY_VERSION

RUBY_VERSION=$RUBY_VERSION RAILS_VERSION=4.2.11.1 PG_VERSION=0.21.0 bundle install
RUBY_VERSION=$RUBY_VERSION RAILS_VERSION=4.2.11.1 PG_VERSION=0.21.0 bundle exec rsepc