Sha256: ec3485ac3f1c2c04ac85bac2dbbd8c4564ac75f2e8c2cae98123f50330957f21

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

#
# The OctopusShardTenant class relies upon Octopus [1], it switches to a
# different shard per tenant, allowing for each tenant to have their own
# database, 100% isolated from other tenants in terms of data and performance.
#
# [1]: (https://github.com/thiagopradi/octopus)
#

require_relative './octopus_schema_tenant'

module Penthouse
  module Tenants
    class OctopusShardTenant < OctopusSchemaTenant

      attr_accessor :shard
      private :shard=

      # @param identifier [String, Symbol] An identifier for the tenant
      # @param shard [String, Symbol] the configured Octopus shard to use for this tenant
      # @param tenant_schema [String] your tenant's schema name within the Postgres shard, typically just 'public' as the shard should be dedicated
      def initialize(identifer, shard:, tenant_schema: "public", **options)
        self.shard = shard
        super(identifier, tenant_schema: tenant_schema, **options)
      end

      # switches to the relevant Octopus shard, and processes the block
      # @param block [Block] The code to execute within the connection to the shard
      # @yield [ShardTenant] The current tenant instance
      # @return [void]
      def call(&block)
        super(shard: shard, &block)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
penthouse-0.7.5 lib/penthouse/tenants/octopus_shard_tenant.rb
penthouse-0.7.4 lib/penthouse/tenants/octopus_shard_tenant.rb
penthouse-0.7.3 lib/penthouse/tenants/octopus_shard_tenant.rb
penthouse-0.7.2 lib/penthouse/tenants/octopus_shard_tenant.rb
penthouse-0.7.1 lib/penthouse/tenants/octopus_shard_tenant.rb
penthouse-0.7.0 lib/penthouse/tenants/octopus_shard_tenant.rb
penthouse-0.6.0 lib/penthouse/tenants/octopus_shard_tenant.rb
penthouse-0.5.0 lib/penthouse/tenants/octopus_shard_tenant.rb