Module: PgMultitenantSchemas
- Defined in:
- lib/pg_multitenant_schemas.rb,
lib/pg_multitenant_schemas/ui.rb,
lib/pg_multitenant_schemas/errors.rb,
lib/pg_multitenant_schemas/context.rb,
lib/pg_multitenant_schemas/version.rb,
lib/pg_multitenant_schemas/migrator.rb,
lib/pg_multitenant_schemas/ui/engine.rb,
lib/pg_multitenant_schemas/configuration.rb,
lib/pg_multitenant_schemas/rails/railtie.rb,
lib/pg_multitenant_schemas/schema_switcher.rb,
lib/pg_multitenant_schemas/tenant_resolver.rb,
lib/pg_multitenant_schemas/migration_executor.rb,
lib/pg_multitenant_schemas/rails/model_concern.rb,
lib/pg_multitenant_schemas/rails/controller_concern.rb,
lib/pg_multitenant_schemas/migration_status_reporter.rb,
lib/pg_multitenant_schemas/migration_display_reporter.rb,
lib/pg_multitenant_schemas/migration_schema_operations.rb,
lib/pg_multitenant_schemas/rails/generators/install_generator.rb,
lib/pg_multitenant_schemas/rails/generators/tenant_migration_generator.rb,
lib/pg_multitenant_schemas/ui/app/controllers/pg_multitenant_schemas/ui/tenants_controller.rb,
sig/pg_multitenant_schemas.rbs
Overview
PgMultitenantSchemas provides PostgreSQL schema-based multitenancy functionality.
Defined Under Namespace
Modules: Generators, MigrationDisplayReporter, MigrationExecutor, MigrationSchemaOperations, MigrationStatusReporter, Rails, UI Classes: Configuration, ConfigurationError, ConnectionError, Context, Error, Migrator, SchemaExists, SchemaNotFound, SchemaSwitcher, TenantNotFound, TenantResolver
Constant Summary collapse
- VERSION =
"0.3.6"
Class Attribute Summary collapse
-
.current_schema ⇒ String
Get the current tenant schema name.
-
.current_tenant ⇒ Object?
Get the current tenant object.
Class Method Summary collapse
-
.configuration ⇒ Configuration
Get the current configuration.
-
.configure { ... } ⇒ Object
Configure the gem.
-
.create_tenant_schema(tenant_or_schema) ⇒ void
Create a new tenant schema.
-
.drop_tenant_schema(tenant_or_schema, cascade: true) ⇒ void
Drop a tenant schema.
-
.extract_subdomain(hostname) ⇒ String?
Extract tenant subdomain from a hostname.
-
.find_tenant_by_subdomain(subdomain) ⇒ Object?
Find a tenant by subdomain.
-
.reset! ⇒ void
Reset the current tenant context.
-
.resolve_tenant_from_request(request) ⇒ Object?
Resolve tenant from Rails request.
-
.switch_to_schema(schema_name) ⇒ void
Switch to a specific schema.
-
.switch_to_tenant(tenant) ⇒ void
Switch to a specific tenant's schema.
-
.with_tenant(tenant_or_schema) { ... } ⇒ Object
Execute a block within a tenant context.
Class Attribute Details
.current_schema ⇒ String
Get the current tenant schema name
56 57 58 |
# File 'lib/pg_multitenant_schemas.rb', line 56 def current_schema @current_schema end |
.current_tenant ⇒ Object?
Get the current tenant object
45 46 47 |
# File 'lib/pg_multitenant_schemas.rb', line 45 def current_tenant @current_tenant end |
Class Method Details
.configuration ⇒ Configuration
Get the current configuration
149 150 151 |
# File 'lib/pg_multitenant_schemas.rb', line 149 def self.configuration @configuration ||= Configuration.new end |
.configure { ... } ⇒ Object
Configure the gem
161 162 163 |
# File 'lib/pg_multitenant_schemas.rb', line 161 def self.configure yield(configuration) if block_given? end |
.create_tenant_schema(tenant_or_schema) ⇒ void
This method returns an undefined value.
Create a new tenant schema
104 105 106 |
# File 'lib/pg_multitenant_schemas.rb', line 104 def create_tenant_schema(tenant_or_schema) Context.create_tenant_schema(tenant_or_schema) end |
.drop_tenant_schema(tenant_or_schema, cascade: true) ⇒ void
This method returns an undefined value.
Drop a tenant schema
114 115 116 |
# File 'lib/pg_multitenant_schemas.rb', line 114 def drop_tenant_schema(tenant_or_schema, cascade: true) Context.drop_tenant_schema(tenant_or_schema, cascade: cascade) end |
.extract_subdomain(hostname) ⇒ String?
Extract tenant subdomain from a hostname
123 124 125 |
# File 'lib/pg_multitenant_schemas.rb', line 123 def extract_subdomain(hostname) TenantResolver.extract_subdomain(hostname) end |
.find_tenant_by_subdomain(subdomain) ⇒ Object?
Find a tenant by subdomain
132 133 134 |
# File 'lib/pg_multitenant_schemas.rb', line 132 def find_tenant_by_subdomain(subdomain) TenantResolver.find_tenant_by_subdomain(subdomain) end |
.reset! ⇒ void
This method returns an undefined value.
Reset the current tenant context
67 68 69 |
# File 'lib/pg_multitenant_schemas.rb', line 67 def reset! Context.reset! end |
.resolve_tenant_from_request(request) ⇒ Object?
Resolve tenant from Rails request
141 142 143 |
# File 'lib/pg_multitenant_schemas.rb', line 141 def resolve_tenant_from_request(request) TenantResolver.resolve_tenant_from_request(request) end |
.switch_to_schema(schema_name) ⇒ void
This method returns an undefined value.
Switch to a specific schema
76 77 78 |
# File 'lib/pg_multitenant_schemas.rb', line 76 def switch_to_schema(schema_name) Context.switch_to_schema(schema_name) end |
.switch_to_tenant(tenant) ⇒ void
This method returns an undefined value.
Switch to a specific tenant's schema
85 86 87 |
# File 'lib/pg_multitenant_schemas.rb', line 85 def switch_to_tenant(tenant) Context.switch_to_tenant(tenant) end |
.with_tenant(tenant_or_schema) { ... } ⇒ Object
Execute a block within a tenant context
95 96 97 |
# File 'lib/pg_multitenant_schemas.rb', line 95 def with_tenant(tenant_or_schema, &) Context.with_tenant(tenant_or_schema, &) end |