Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • T torque-postgresql
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 6
    • Issues 6
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Carlos
  • torque-postgresql
  • Wiki
  • Multiple Schemas

Multiple Schemas · Changes

Page history
Created Multiple Schemas (markdown) authored Dec 25, 2022 by Carlos's avatar Carlos
Hide whitespace changes
Inline Side-by-side
Multiple-Schemas.md 0 → 100644
View page @ 3797a442
Add smooth support to managing and utilizing multiple schemas in your application. It works incredibly nicely with [Inherited Tables](https://github.com/crashtech/torque-postgresql/wiki/Inherited-Tables) and it's part of a larger feature for a better multi-tenancy application. [PostgreSQL Docs](https://www.postgresql.org/docs/current/ddl-schemas.html)
# How it works
### Configuration
This feature works with a [whitelist](https://github.com/crashtech/torque-postgresql/wiki/Configuring#schemas.whitelist)/[blacklist](https://github.com/crashtech/torque-postgresql/wiki/Configuring#schemas.blacklist) set of schemas, that filters, in a LIKE manner, the ones that will be present in the schema. These lists are extremely important so that not only can work properly, but also interact with other features from this gem.
```yaml
default: &default
adapter: postgresql
encoding: unicode
schemas:
whitelist: ['internal']
blacklist: ['external']
# OR a list of items, that also demonstrates the LIKE behavior
default: &default
schemas:
whitelist:
- internal_%
```
This can also be configured exclusively for Torque, in your `application.rb` or similar place.
```ruby
Torque::PostgreSQL.configure do |c|
c.schemas.whitelist << 'internal'
c.schemas.blacklist += %w[external other]
end
```
### Migration
Once you stipulated which schemas will be supported in the configuration, you can now create a migration that creates it.
```ruby
create_schema :internal
```
### Models
There are 2 ways to set a model's schema. You can define it directly or use the model as the reference for all its models' schemas.
```ruby
# Directly on the model
module Internal
class User < ActiveRecord::Base
self.schema = 'internal'
end
end
# Indirect using the module
module Internal
def self.schema
'internal'
end
class User < ActiveRecord::Base
end
end
```
\ No newline at end of file
Clone repository
  • Wiki
  • Configuring

Data types

  • Box
  • Circle
  • Date/Time Range
  • Enum
  • EnumSet
  • Interval
  • Line
  • Segment

Querying

  • Arel
  • Auxiliary Statements
  • Belongs to Many
  • Distinct On
  • Dynamic Attributes
  • Has Many
  • Inherited Tables
  • Insert All
  • Multiple Schemas