ConnectionMigrator
Handling schema migrations per connection.
Table of Contents
Properties
- $connection : Connection
- $connectionName : string
- $deletedPrefix : string
- $tables : array<string|int, Table>
Methods
- __construct() : mixed
- create() : ConnectionMigrator
- getSchemaDiff() : SchemaDiff
- Return the raw Doctrine SchemaDiff object for the current connection.
- getUpdateSuggestions() : array<string|int, mixed>
- Compare current and expected schema definitions and provide updates suggestions in the form of SQL statements.
- install() : array<string|int, mixed>
- 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() : array<string|int, string>
- Replace the array keys with a md5 sum of the actual SQL statement
- getChangedFieldUpdateSuggestions() : array<string|int, mixed>
- Extract update suggestions (SQL statements) for changed fields from the complete schema diff.
- getChangedTableOptions() : array<string|int, mixed>
- 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<string|int, mixed>
- Extract update suggestions (SQL statements) for fields that can be removed from the complete schema diff.
- getDropTableUpdateSuggestions() : array<string|int, mixed>
- Extract update suggestions (SQL statements) for tables that can be removed from the complete schema diff.
- getNewFieldUpdateSuggestions() : array<string|int, mixed>
- Extract the update suggestions (SQL statements) for newly added fields from the complete schema diff.
- getNewTableUpdateSuggestions() : array<string|int, mixed>
- Extract the update suggestions (SQL statements) for newly added tables from the complete schema diff.
- getTableOptions() : array<string|int, array<string|int, mixed>>
- 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<string|int, mixed>
- Extract update suggestions (SQL statements) for fields that are no longer present in the expected schema from the schema diff.
- getUnusedTableUpdateSuggestions() : array<string|int, mixed>
- 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<string|int, mixed>
- removeUnrelatedTables() : array<string|int, TableDiff>
- Helper for buildSchemaDiff to filter an array of TableDiffs against a list of valid table names.
- transformTablesForDatabasePlatform() : array<string|int, 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
$connection
protected
Connection
$connection
$connectionName
protected
string
$connectionName
$deletedPrefix
protected
string
$deletedPrefix
= 'zzz_deleted_'
Prefix of deleted tables
$tables
protected
array<string|int, Table>
$tables
Methods
__construct()
public
__construct(string $connectionName, array<string|int, Table> $tables) : mixed
Parameters
- $connectionName : string
- $tables : array<string|int, Table>
create()
public
static create(string $connectionName, array<string|int, Table> $tables) : ConnectionMigrator
Parameters
- $connectionName : string
- $tables : array<string|int, Table>
Return values
ConnectionMigratorgetSchemaDiff()
Return the raw Doctrine SchemaDiff object for the current connection.
public
getSchemaDiff() : SchemaDiff
This diff contains all changes without any pre-processing.
Return values
SchemaDiffgetUpdateSuggestions()
Compare current and expected schema definitions and provide updates suggestions in the form of SQL statements.
public
getUpdateSuggestions([bool $remove = false ]) : array<string|int, mixed>
Parameters
- $remove : bool = false
Return values
array<string|int, mixed>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<string|int, mixed>
Parameters
- $createOnly : bool = false
Return values
array<string|int, mixed>buildExpectedSchemaDefinitions()
Build the expected schema definitions from raw SQL statements.
protected
buildExpectedSchemaDefinitions(string $connectionName) : Schema
Parameters
- $connectionName : string
Tags
Return values
SchemabuildQuotedColumn()
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
ColumnbuildQuotedForeignKey()
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
ForeignKeyConstraintbuildQuotedIndex()
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
IndexbuildQuotedTable()
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
TablebuildSchemaDiff()
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
Return values
SchemaDiffcalculateUpdateSuggestionsHashes()
Replace the array keys with a md5 sum of the actual SQL statement
protected
calculateUpdateSuggestionsHashes(array<string|int, string> $statements) : array<string|int, string>
Parameters
- $statements : array<string|int, string>
Return values
array<string|int, string>getChangedFieldUpdateSuggestions()
Extract update suggestions (SQL statements) for changed fields from the complete schema diff.
protected
getChangedFieldUpdateSuggestions(SchemaDiff $schemaDiff) : array<string|int, mixed>
Parameters
- $schemaDiff : SchemaDiff
Tags
Return values
array<string|int, mixed>getChangedTableOptions()
Extract update suggestions (SQL statements) for changed options (like ENGINE) from the complete schema diff.
protected
getChangedTableOptions(SchemaDiff $schemaDiff) : array<string|int, mixed>
Parameters
- $schemaDiff : SchemaDiff
Tags
Return values
array<string|int, mixed>getConnectionNameForTable()
Determine the connection name for a table
protected
getConnectionNameForTable(string $tableName) : string
Parameters
- $tableName : string
Tags
Return values
stringgetDatabasePlatform()
protected
getDatabasePlatform(string $tableName) : string
Parameters
- $tableName : string
Return values
stringgetDropFieldUpdateSuggestions()
Extract update suggestions (SQL statements) for fields that can be removed from the complete schema diff.
protected
getDropFieldUpdateSuggestions(SchemaDiff $schemaDiff) : array<string|int, mixed>
Fields that can be removed have been prefixed in a previous run of the schema migration.
Parameters
- $schemaDiff : SchemaDiff
Tags
Return values
array<string|int, mixed>getDropTableUpdateSuggestions()
Extract update suggestions (SQL statements) for tables that can be removed from the complete schema diff.
protected
getDropTableUpdateSuggestions(SchemaDiff $schemaDiff) : array<string|int, mixed>
Tables that can be removed have been prefixed in a previous run of the schema migration.
Parameters
- $schemaDiff : SchemaDiff
Tags
Return values
array<string|int, mixed>getNewFieldUpdateSuggestions()
Extract the update suggestions (SQL statements) for newly added fields from the complete schema diff.
protected
getNewFieldUpdateSuggestions(SchemaDiff $schemaDiff) : array<string|int, mixed>
Parameters
- $schemaDiff : SchemaDiff
Tags
Return values
array<string|int, mixed>getNewTableUpdateSuggestions()
Extract the update suggestions (SQL statements) for newly added tables from the complete schema diff.
protected
getNewTableUpdateSuggestions(SchemaDiff $schemaDiff) : array<string|int, mixed>
Parameters
- $schemaDiff : SchemaDiff
Tags
Return values
array<string|int, mixed>getTableOptions()
Get COLLATION, ROW_FORMAT, COMMENT and ENGINE table options on MySQL connections.
protected
getTableOptions(array<string|int, string> $tableNames) : array<string|int, array<string|int, mixed>>
Parameters
- $tableNames : array<string|int, string>
Tags
Return values
array<string|int, array<string|int, mixed>>getTableRecordCount()
Return the amount of records in the given table.
protected
getTableRecordCount(string $tableName) : int
Parameters
- $tableName : string
Tags
Return values
intgetUnusedFieldUpdateSuggestions()
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<string|int, mixed>
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
Return values
array<string|int, mixed>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<string|int, mixed>
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
Return values
array<string|int, mixed>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
Return values
SchemaDiffmigrateUnprefixedRemovedFieldsToRenames()
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
Return values
SchemaDiffmigrateUnprefixedRemovedTablesToRenames()
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
Return values
SchemaDiffprepareColumnOptions()
protected
prepareColumnOptions(Column $column) : array<string|int, mixed>
Parameters
- $column : Column
Return values
array<string|int, mixed>removeUnrelatedTables()
Helper for buildSchemaDiff to filter an array of TableDiffs against a list of valid table names.
protected
removeUnrelatedTables(array<string|int, TableDiff>|array<string|int, Table> $tableDiffs, array<string|int, string> $validTableNames) : array<string|int, TableDiff>
Parameters
- $tableDiffs : array<string|int, TableDiff>|array<string|int, Table>
- $validTableNames : array<string|int, string>
Tags
Return values
array<string|int, 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(array<string|int, Table> $tables, Connection $connection) : array<string|int, Table>
Parameters
- $tables : array<string|int, Table>
- $connection : Connection