MultiTenantVisitor
in package
implements
Visitor
Converts a single tenant schema into a multi-tenant schema for SQL Azure Federations under the following assumptions:
- Every table is part of the multi-tenant application, only explicitly excluded tables are non-federated. The behavior of the tables being in global or federated database is undefined. It depends on you selecting a federation before DDL statements or not.
- Every Primary key of a federated table is extended by another column
'tenant_id' with a default value of the SQLAzure function
federation_filtering_value('tenant_id'). - You always have to work with
filtering=Onwhen using federations with this multi-tenant approach. - Primary keys are either using globally unique ids (GUID, Table Generator) or you explicitly add the tenent_id in every UPDATE or DELETE statement (otherwise they will affect the same-id rows from other tenents as well). SQLAzure throws errors when you try to create IDENTIY columns on federated tables.
Tags
Interfaces, Classes and Traits
- Visitor
- Schema Visitor used for Validation or Generation purposes.
Table of Contents
- $distributionName : string
- Name of the federation distribution, defaulting to the tenantColumnName if not specified.
- $excludedTables : array<string|int, mixed>
- $tenantColumnName : string
- $tenantColumnType : string
- __construct() : mixed
- acceptColumn() : void
- acceptForeignKey() : void
- acceptIndex() : void
- acceptSchema() : void
- acceptSequence() : void
- acceptTable() : void
- getClusteredIndex() : Index
Properties
$distributionName
Name of the federation distribution, defaulting to the tenantColumnName if not specified.
private
string
$distributionName
$excludedTables
private
array<string|int, mixed>
$excludedTables
= array()
$tenantColumnName
private
string
$tenantColumnName
$tenantColumnType
private
string
$tenantColumnType
= 'integer'
Methods
__construct()
public
__construct([array<string|int, mixed> $excludedTables = array() ][, string $tenantColumnName = 'tenant_id' ][, string|null $distributionName = null ]) : mixed
Parameters
- $excludedTables : array<string|int, mixed> = array()
- $tenantColumnName : string = 'tenant_id'
- $distributionName : string|null = null
Return values
mixed —acceptColumn()
public
acceptColumn(Table $table, Column $column) : void
Parameters
Return values
void —acceptForeignKey()
public
acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
Parameters
- $localTable : Table
- $fkConstraint : ForeignKeyConstraint
Return values
void —acceptIndex()
public
acceptIndex(Table $table, Index $index) : void
Parameters
Return values
void —acceptSchema()
public
acceptSchema(Schema $schema) : void
Parameters
- $schema : Schema
Return values
void —acceptSequence()
public
acceptSequence(Sequence $sequence) : void
Parameters
- $sequence : Sequence
Return values
void —acceptTable()
public
acceptTable(Table $table) : void
Parameters
- $table : Table
Return values
void —getClusteredIndex()
private
getClusteredIndex(Table $table) : Index
Parameters
- $table : Table