Documentation
¶
Index ¶
- func CreateSchemaForTenant(db *gorm.DB, schemaName string) error
- func DropSchemaForTenant(db *gorm.DB, schemaName string) error
- func MigratePublicSchema(db *gorm.DB) error
- func New(config Config, models ...interface{}) gorm.Dialector
- func Open(dsn string, models ...interface{}) gorm.Dialector
- func RegisterModels(db *gorm.DB, models ...interface{})
- type Config
- type Dialector
- type Migrator
- type MultitenancyMigrator
- type TenantModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateSchemaForTenant ¶
CreateSchemaForTenant creates the schema for the tenant, and migrates the private tables
func DropSchemaForTenant ¶
DropSchemaForTenant drops the schema for the tenant (CASCADING tables)
func MigratePublicSchema ¶
MigratePublicSchema migrates the public tables
func RegisterModels ¶
RegisterModels registers the models for multitenancy
Types ¶
type Migrator ¶
Migrator is the struct that implements the Migratorer interface
func (Migrator) AutoMigrate ¶
AutoMigrate migrates the tables based on the migration options.
func (*Migrator) CreateSchemaForTenant ¶
CreateSchemaForTenant creates the schema for the tenant and migrates the private tables
func (*Migrator) DropSchemaForTenant ¶
DropSchemaForTenant drops the schema for the tenant (CASCADING tables)
func (*Migrator) MigratePublicSchema ¶
MigratePublicSchema migrates the public tables
type MultitenancyMigrator ¶
type MultitenancyMigrator interface {
multitenancy.Migrator
// CreateSchemaForTenant creates the schema for the tenant, and migrates the private tables
//
// Parameters:
// - tenant: the tenant's schema name
//
// Returns:
// - error: the error if any
CreateSchemaForTenant(tenant string) error
// DropSchemaForTenant drops the schema for the tenant (CASCADING tables)
//
// Parameters:
// - tenant: the tenant's schema name
//
// Returns:
// - error: the error if any
DropSchemaForTenant(tenant string) error
// MigratePublicSchema migrates the public tables
MigratePublicSchema() error
}
MultitenancyMigrator is the interface for the postgres migrator with multitenancy support
type TenantModel ¶
type TenantModel struct {
// DomainURL is the domain URL of the tenant
DomainURL string `gorm:"column:domain_url;uniqueIndex;size:128" json:"domainURL"`
// SchemaName is the schema name of the tenant.
//
// Field-level permissions are restricted to read and create.
//
// The following constraints are applied:
// - unique index
// - size: 63
// - check: schema_name ~ '^[_a-zA-Z][_a-zA-Z0-9]{2,}$' AND schema_name !~ '^pg_' (to prevent invalid schema names)
SchemaName string `` /* 152-byte string literal not displayed */
}
TenantModel a basic GoLang struct which includes the following fields: DomainURL, SchemaName. It's intended to be embedded into any public postgresql model that needs to be scoped to a tenant. It may be embedded into your model or you may build your own model without it.
For example:
type Tenant struct {
postgres.TenantModel
}