Sha256: 62b5257e37f50617ec5615d87262b317de409d4a59b1218dbcc38cf8a9830be9

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

#
# The OctopusSchemaTenant class relies upon Octopus [1], it uses the master
# database and simply switches the schema search path to allow for isolated
# data, but low overheads in terms of costs. Note: this means tenants will be
# sharing a single Postgres instance and therefore performance is shared.
#
# [1]: (https://github.com/thiagopradi/octopus)
#

require_relative './schema_tenant'
require 'octopus'

module Penthouse
  module Tenants
    class OctopusSchemaTenant < SchemaTenant

      # ensures we're on the master Octopus shard, just updates the schema name
      # with the tenant name
      # @param block [Block] The code to execute within the schema
      # @yield [SchemaTenant] The current tenant instance
      def call(&block)
        Octopus.using(:master) do
          super
        end
      end

      # creates the tenant schema within the master shard
      # @see Penthouse::Tenants::SchemaTenant#create
      def create(*)
        call { super }
      end

      # drops the tenant schema within the master shard
      # @see Penthouse::Tenants::SchemaTenant#delete
      def delete(*)
        call { super }
      end

      # returns whether or not the schema exists
      # @see Penthouse::Tenants::SchemaTenant#exists?
      def exists?(*)
        call { super }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
penthouse-0.3.0 lib/penthouse/tenants/octopus_schema_tenant.rb