com\setasign\SetaFramework\Database\Manager

TableSchemaBuilder Class TableSchemaBuilder

File: /SetaFramework/src/Database/Manager/TableSchemaBuilder.php

Class hierarchy

Implements

  • \Psr\Log\LoggerAwareInterface

Summary

Properties

$dbManager

$eventManager

$initialized

protected bool TableSchemaBuilder::$initialized = false

$knownCollations

protected array TableSchemaBuilder::$knownCollations = array()

Memoize the already checked collations.

$logger

protected ?\Psr\Log\LoggerInterface TableSchemaBuilder::$logger

$runningBuild

protected ?string TableSchemaBuilder::$runningBuild

Methods

__construct()

TableSchemaBuilder constructor.

Parameters
$dbManager : AbstractManager
 
$eventManager : ?\com\setasign\SetaFramework\EventManager\EventManager
 

__sleep()

public TableSchemaBuilder::__sleep (
void
): void

build()

public TableSchemaBuilder::build (
TableSchema $expectedTableSchema
): bool

Creates/Updates a table by $expectedColumns.

This method will not delete any column instead it will add an underscore (or multiple if necessary) to the column, remove all indexes for the column, set allow_null = true and set default to null.

If the type of one column will change the method will set mysql to non-strict mode and mysql will try to soft type change the columns.

Be careful when you call this method. Changes to tables can't be in transactions and can't roll back. You have to ensure yourself that only one php process use this method on the same table at the same time.

Parameters
$expectedTableSchema : TableSchema

Autosync must be off!

Exceptions

Throws TableSchemaBuilderException

checkAutoIncrementValues()

protected TableSchemaBuilder::checkAutoIncrementValues (
string $tableName,
string $columnName
): void
Parameters
$tableName : string
 
$columnName : string
 
Exceptions

Throws TableSchemaBuilderException

checkSchemaCollation()

protected TableSchemaBuilder::checkSchemaCollation (
TableSchema $tableSchema
): void

Check if the collation exists for the used database.

We check this to prevent infinite change loops in the table schema when setting a collation which is an alias.

Parameters
$tableSchema : TableSchema
 

copyAlterColumns()

protected TableSchemaBuilder::copyAlterColumns (
TableSchema $actualSchema,
array $alterColumns,
Column\AbstractColumn[] $expectedColumns,
bool $simulationMode
): void
Parameters
$actualSchema : TableSchema
 
$alterColumns : array
 
$expectedColumns : Column\AbstractColumn[]
 
$simulationMode : bool
 

findChanges()

Parameters
$actualSchema : TableSchema
 
$expectedSchema : TableSchema
 
Exceptions

Throws TableSchemaBuilderException

init()

protected TableSchemaBuilder::init (
void
): void

markColumnAsDeleted()

Will not really be deleted, just set allowNull = true and default = null and all indexes will be deleted

Parameters
$column : Column\AbstractColumn
 

reoderColumns()

protected TableSchemaBuilder::reoderColumns (
TableSchema $actualSchema,
Column\AbstractColumn[] $expectedColumns
): void
Parameters
$actualSchema : TableSchema
 
$expectedColumns : Column\AbstractColumn[]
 

runBuild()

protected TableSchemaBuilder::runBuild (
TableSchema $actualSchema,
TableSchema $expectedSchema,
?TableSchema $originalSchema,
TableSchemaBuilderChangeData $changes
): bool
Parameters
$actualSchema : TableSchema
 
$expectedSchema : TableSchema
 
$originalSchema : ?TableSchema

If is null we are in simulation mode no query will be executed and all queries are added as down-queries.

$changes : TableSchemaBuilderChangeData
 
Exceptions

Throws TableSchemaBuilderException

searchNewColumnName()

protected TableSchemaBuilder::searchNewColumnName (
Column\AbstractColumn[] $expectedColumns,
string $columnName
): ?string
Parameters
$expectedColumns : Column\AbstractColumn[]
 
$columnName : string
 

setIndexes()

protected TableSchemaBuilder::setIndexes (
TableSchema $actualSchema,
array<string, Column\AbstractColumn> $expectedColumns,
bool $simulationMode
): void
Parameters
$actualSchema : TableSchema
 
$expectedColumns : array<string, Column\AbstractColumn>
 
$simulationMode : bool
 

setLogger()

public TableSchemaBuilder::setLogger (
\Psr\Log\LoggerInterface $logger
): void
Parameters
$logger : \Psr\Log\LoggerInterface
 

updateTableSchema()

protected TableSchemaBuilder::updateTableSchema (
TableSchema $actualSchema,
TableSchemaBuilderChangeData $changes,
Column\AbstractColumn[] $expectedColumns
): bool
Parameters
$actualSchema : TableSchema
 
$changes : TableSchemaBuilderChangeData
 
$expectedColumns : Column\AbstractColumn[]
 
Return Values

Whether something was changed.

Exceptions

Throws \com\setasign\SetaFramework\Exception