Documentation
¶
Overview ¶
Package migration contains tenant schema migration planning APIs.
Index ¶
- Constants
- Variables
- func DetectDeletePolicy(columns []string, softDeleteField string) string
- type Dialect
- type Migrator
- type Planner
- func (planner Planner) AddTenantColumn(table string, tenantField string, fieldType string) (string, error)
- func (planner Planner) CreateHardDeleteUniqueIndex(table string, indexName string, tenantField string, businessFields []string) (string, error)
- func (planner Planner) CreateMySQLSoftDeleteUniqueIndex(table string, indexName string, tenantField string, businessFields []string, ...) (string, error)
- func (planner Planner) CreateSoftDeleteUniqueIndex(table string, indexName string, tenantField string, businessFields []string, ...) (string, error)
- func (planner Planner) SeedTenants(table string, tenants []types.Tenant) ([]Statement, error)
- type Statement
Constants ¶
View Source
const ( DefaultTenantField = "tenant_id" DefaultTenantFieldType = "VARCHAR(64)" DefaultSoftDeleteField = "deleted_at" DefaultDeleteMarker = "deleted_flag" )
Variables ¶
View Source
var ( // ErrInvalidIdentifier reports an unsafe SQL identifier. ErrInvalidIdentifier = errors.New("gotenancy/migration: invalid identifier") // ErrInvalidMigration reports incomplete migration input. ErrInvalidMigration = errors.New("gotenancy/migration: invalid migration") // ErrUnsupportedDialect reports a dialect not supported by the planner. ErrUnsupportedDialect = errors.New("gotenancy/migration: unsupported dialect") )
Functions ¶
func DetectDeletePolicy ¶
DetectDeletePolicy returns "soft" when softDeleteField exists, otherwise "hard".
Types ¶
type Migrator ¶
type Migrator interface {
AddTenantColumn(table string, tenantField string, fieldType string) (string, error)
CreateSoftDeleteUniqueIndex(table string, indexName string, tenantField string, businessFields []string, softDeleteField string) (string, error)
CreateHardDeleteUniqueIndex(table string, indexName string, tenantField string, businessFields []string) (string, error)
SeedTenants(table string, tenants []types.Tenant) ([]Statement, error)
}
Migrator defines tenant-schema migration planning operations.
type Planner ¶
type Planner struct {
Dialect Dialect
}
Planner generates migration SQL without executing it.
func (Planner) AddTenantColumn ¶
func (planner Planner) AddTenantColumn(table string, tenantField string, fieldType string) (string, error)
AddTenantColumn returns SQL to add a tenant_id column.
func (Planner) CreateHardDeleteUniqueIndex ¶
func (planner Planner) CreateHardDeleteUniqueIndex(table string, indexName string, tenantField string, businessFields []string) (string, error)
CreateHardDeleteUniqueIndex returns SQL for a hard-delete table unique index.
func (Planner) CreateMySQLSoftDeleteUniqueIndex ¶
func (planner Planner) CreateMySQLSoftDeleteUniqueIndex(table string, indexName string, tenantField string, businessFields []string, markerField string) (string, error)
CreateMySQLSoftDeleteUniqueIndex returns SQL using a non-nullable delete marker.
Click to show internal directories.
Click to hide internal directories.