ConnectionMigrator

class \TYPO3\CMS\Core\Database\Schema\ConnectionMigrator

Handling schema migrations per connection.

Table of Contents

Properties

$connection  : Connection
$connectionName  : string
$deletedPrefix  : string
$tables  : Table[]

Methods

__construct()  : mixed
create()  : ConnectionMigrator
getSchemaDiff()  : SchemaDiff
Return the raw Doctrine SchemaDiff object for the current connection.
getUpdateSuggestions()  : array
Compare current and expected schema definitions and provide updates suggestions in the form of SQL statements.
install()  : array
Perform add/change/create operations on tables and fields in an optimized, non-interactive, mode using the original doctrine SchemaManager ->toSaveSql() method.
buildExpectedSchemaDefinitions()  : Schema
Build the expected schema definitions from raw SQL statements.
buildQuotedColumn()  : Column
Helper function to build a column object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.
buildQuotedForeignKey()  : ForeignKeyConstraint
Helper function to build a foreign key constraint object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.
buildQuotedIndex()  : Index
Helper function to build an index object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.
buildQuotedTable()  : Table
Helper function to build a table object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original table object.
buildSchemaDiff()  : SchemaDiff
If the schema is not for the Default connection remove all tables from the schema that have no mapping in the TYPO3 configuration. This avoids update suggestions for tables that are in the database but have no direct relation to the TYPO3 instance.
calculateUpdateSuggestionsHashes()  : string[]
Replace the array keys with a md5 sum of the actual SQL statement
getChangedFieldUpdateSuggestions()  : array
Extract update suggestions (SQL statements) for changed fields from the complete schema diff.
getChangedTableOptions()  : array
Extract update suggestions (SQL statements) for changed options (like ENGINE) from the complete schema diff.
getConnectionNameForTable()  : string
Determine the connection name for a table
getDatabasePlatform()  : string
getDropFieldUpdateSuggestions()  : array
Extract update suggestions (SQL statements) for fields that can be removed from the complete schema diff.
getDropTableUpdateSuggestions()  : array
Extract update suggestions (SQL statements) for tables that can be removed from the complete schema diff.
getNewFieldUpdateSuggestions()  : array
Extract the update suggestions (SQL statements) for newly added fields from the complete schema diff.
getNewTableUpdateSuggestions()  : array
Extract the update suggestions (SQL statements) for newly added tables from the complete schema diff.
getTableOptions()  : array[]
Get COLLATION, ROW_FORMAT, COMMENT and ENGINE table options on MySQL connections.
getTableRecordCount()  : int
Return the amount of records in the given table.
getUnusedFieldUpdateSuggestions()  : array
Extract update suggestions (SQL statements) for fields that are no longer present in the expected schema from the schema diff.
getUnusedTableUpdateSuggestions()  : array
Extract update suggestions (SQL statements) for tables that are no longer present in the expected schema from the schema diff.
migrateColumnRenamesToDistinctActions()  : SchemaDiff
Revert the automatic rename optimization that Doctrine performs when it detects a column being added and a column being dropped that only differ by name.
migrateUnprefixedRemovedFieldsToRenames()  : SchemaDiff
Scan the list of changed tables for fields that are going to be dropped. If the name of the field does not start with the deleted prefix mark the column for a rename instead of a drop operation.
migrateUnprefixedRemovedTablesToRenames()  : SchemaDiff
Move tables to be removed that are not prefixed with the deleted prefix to the list of changed tables and set a new prefixed name.
prepareColumnOptions()  : array
removeUnrelatedTables()  : TableDiff[]
Helper for buildSchemaDiff to filter an array of TableDiffs against a list of valid table names.
transformTablesForDatabasePlatform()  : Table[]
Transform the table information to conform to specific requirements of different database platforms like removing the index substring length for Non-MySQL Platforms.

Properties

$connectionName

protected string $connectionName

$deletedPrefix

protected string $deletedPrefix = 'zzz_deleted_'

Prefix of deleted tables

Methods

__construct()

public __construct(string $connectionName, Table[] $tables) : mixed

Parameters

$connectionName : string
$tables : Table[]

getSchemaDiff()

Return the raw Doctrine SchemaDiff object for the current connection.

public getSchemaDiff() : SchemaDiff

This diff contains all changes without any pre-processing.

Return values

SchemaDiff

getUpdateSuggestions()

Compare current and expected schema definitions and provide updates suggestions in the form of SQL statements.

public getUpdateSuggestions([bool $remove = false ]) : array

Parameters

$remove : bool = false

Return values

array

install()

Perform add/change/create operations on tables and fields in an optimized, non-interactive, mode using the original doctrine SchemaManager ->toSaveSql() method.

public install([bool $createOnly = false ]) : array

Parameters

$createOnly : bool = false

Return values

array

buildExpectedSchemaDefinitions()

Build the expected schema definitions from raw SQL statements.

protected buildExpectedSchemaDefinitions(string $connectionName) : Schema

Parameters

$connectionName : string

Tags

throws
Exception
throws
InvalidArgumentException

Return values

Schema

buildQuotedColumn()

Helper function to build a column object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.

protected buildQuotedColumn(Column $column) : Column

Parameters

$column : Column

Return values

Column

buildQuotedForeignKey()

Helper function to build a foreign key constraint object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.

protected buildQuotedForeignKey(ForeignKeyConstraint $index) : ForeignKeyConstraint

Parameters

$index : ForeignKeyConstraint

Return values

ForeignKeyConstraint

buildQuotedIndex()

Helper function to build an index object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original column object.

protected buildQuotedIndex(Index $index) : Index

Parameters

$index : Index

Return values

Index

buildQuotedTable()

Helper function to build a table object that has the _quoted attribute set so that the SchemaManager will use quoted identifiers when creating the final SQL statements. This is needed as Doctrine doesn't provide a method to set the flag after the object has been instantiated and there's no possibility to hook into the createSchema() method early enough to influence the original table object.

protected buildQuotedTable(Table $table) : Table

Parameters

$table : Table

Return values

Table

buildSchemaDiff()

If the schema is not for the Default connection remove all tables from the schema that have no mapping in the TYPO3 configuration. This avoids update suggestions for tables that are in the database but have no direct relation to the TYPO3 instance.

protected buildSchemaDiff([bool $renameUnused = true ]) : SchemaDiff

Parameters

$renameUnused : bool = true

Tags

throws
Exception
throws
SchemaException
throws
InvalidArgumentException

Return values

SchemaDiff

calculateUpdateSuggestionsHashes()

Replace the array keys with a md5 sum of the actual SQL statement

protected calculateUpdateSuggestionsHashes(string[] $statements) : string[]

Parameters

$statements : string[]

Return values

string[]

getChangedFieldUpdateSuggestions()

Extract update suggestions (SQL statements) for changed fields from the complete schema diff.

protected getChangedFieldUpdateSuggestions(SchemaDiff $schemaDiff) : array

Parameters

$schemaDiff : SchemaDiff

Tags

throws
SchemaException
throws
InvalidArgumentException

Return values

array

getChangedTableOptions()

Extract update suggestions (SQL statements) for changed options (like ENGINE) from the complete schema diff.

protected getChangedTableOptions(SchemaDiff $schemaDiff) : array

Parameters

$schemaDiff : SchemaDiff

Tags

throws
SchemaException
throws
InvalidArgumentException

Return values

array

getConnectionNameForTable()

Determine the connection name for a table

protected getConnectionNameForTable(string $tableName) : string

Parameters

$tableName : string

Tags

throws
InvalidArgumentException

Return values

string

getDatabasePlatform()

protected getDatabasePlatform(string $tableName) : string

Parameters

$tableName : string

Return values

string

getDropFieldUpdateSuggestions()

Extract update suggestions (SQL statements) for fields that can be removed from the complete schema diff.

protected getDropFieldUpdateSuggestions(SchemaDiff $schemaDiff) : array

Fields that can be removed have been prefixed in a previous run of the schema migration.

Parameters

$schemaDiff : SchemaDiff

Tags

throws
SchemaException
throws
InvalidArgumentException

Return values

array

getDropTableUpdateSuggestions()

Extract update suggestions (SQL statements) for tables that can be removed from the complete schema diff.

protected getDropTableUpdateSuggestions(SchemaDiff $schemaDiff) : array

Tables that can be removed have been prefixed in a previous run of the schema migration.

Parameters

$schemaDiff : SchemaDiff

Tags

throws
SchemaException
throws
InvalidArgumentException

Return values

array

getNewFieldUpdateSuggestions()

Extract the update suggestions (SQL statements) for newly added fields from the complete schema diff.

protected getNewFieldUpdateSuggestions(SchemaDiff $schemaDiff) : array

Parameters

$schemaDiff : SchemaDiff

Tags

throws
SchemaException
throws
InvalidArgumentException

Return values

array

getNewTableUpdateSuggestions()

Extract the update suggestions (SQL statements) for newly added tables from the complete schema diff.

protected getNewTableUpdateSuggestions(SchemaDiff $schemaDiff) : array

Parameters

$schemaDiff : SchemaDiff

Tags

throws
InvalidArgumentException

Return values

array

getTableOptions()

Get COLLATION, ROW_FORMAT, COMMENT and ENGINE table options on MySQL connections.

protected getTableOptions(string[] $tableNames) : array[]

Parameters

$tableNames : string[]

Tags

throws
InvalidArgumentException

Return values

array[]

getTableRecordCount()

Return the amount of records in the given table.

protected getTableRecordCount(string $tableName) : int

Parameters

$tableName : string

Tags

throws
InvalidArgumentException

Return values

int

getUnusedFieldUpdateSuggestions()

Extract update suggestions (SQL statements) for fields that are no longer present in the expected schema from the schema diff.

protected getUnusedFieldUpdateSuggestions(SchemaDiff $schemaDiff) : array

In this case the update suggestions are renames of the fields with a prefix to mark them for deletion in a second sweep.

Parameters

$schemaDiff : SchemaDiff

Tags

throws
SchemaException
throws
InvalidArgumentException

Return values

array

getUnusedTableUpdateSuggestions()

Extract update suggestions (SQL statements) for tables that are no longer present in the expected schema from the schema diff.

protected getUnusedTableUpdateSuggestions(SchemaDiff $schemaDiff) : array

In this case the update suggestions are renames of the tables with a prefix to mark them for deletion in a second sweep.

Parameters

$schemaDiff : SchemaDiff

Tags

throws
SchemaException
throws
InvalidArgumentException

Return values

array

migrateColumnRenamesToDistinctActions()

Revert the automatic rename optimization that Doctrine performs when it detects a column being added and a column being dropped that only differ by name.

protected migrateColumnRenamesToDistinctActions(SchemaDiff $schemaDiff) : SchemaDiff

Parameters

$schemaDiff : SchemaDiff

Tags

throws
SchemaException
throws
InvalidArgumentException

Return values

SchemaDiff

migrateUnprefixedRemovedFieldsToRenames()

Scan the list of changed tables for fields that are going to be dropped. If the name of the field does not start with the deleted prefix mark the column for a rename instead of a drop operation.

protected migrateUnprefixedRemovedFieldsToRenames(SchemaDiff $schemaDiff) : SchemaDiff

Parameters

$schemaDiff : SchemaDiff

Tags

throws
InvalidArgumentException

Return values

SchemaDiff

migrateUnprefixedRemovedTablesToRenames()

Move tables to be removed that are not prefixed with the deleted prefix to the list of changed tables and set a new prefixed name.

protected migrateUnprefixedRemovedTablesToRenames(SchemaDiff $schemaDiff) : SchemaDiff

Without this help the Doctrine SchemaDiff has no idea if a table has been renamed and performs a drop of the old table and creates a new table, which leads to all data in the old table being lost.

Parameters

$schemaDiff : SchemaDiff

Tags

throws
InvalidArgumentException

Return values

SchemaDiff

prepareColumnOptions()

protected prepareColumnOptions(Column $column) : array

Parameters

$column : Column

Return values

array

removeUnrelatedTables()

Helper for buildSchemaDiff to filter an array of TableDiffs against a list of valid table names.

protected removeUnrelatedTables(TableDiff[]|Table[] $tableDiffs, string[] $validTableNames) : TableDiff[]

Parameters

$tableDiffs : TableDiff[]|Table[]
$validTableNames : string[]

Tags

throws
InvalidArgumentException

Return values

TableDiff[]

transformTablesForDatabasePlatform()

Transform the table information to conform to specific requirements of different database platforms like removing the index substring length for Non-MySQL Platforms.

protected transformTablesForDatabasePlatform(Table[] $tables, Connection $connection) : Table[]

Parameters

$tables : Table[]
$connection : Connection

Tags

throws
InvalidArgumentException

Return values

Table[]
On this page