‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Database\Schema\SchemaMigrator Class Reference

Public Member Functions

 __construct (private readonly ConnectionPool $connectionPool, private readonly Parser $parser, private readonly DefaultTcaSchema $defaultTcaSchema,)
 
array< string, getUpdateSuggestions(array $statements, bool $remove=false):array { $tables=$this-> parseCreateTableStatements ($statements)
 
array< string, getSchemaDiffs(array $statements):array { $tables=$this-> parseCreateTableStatements ($statements)
 
 migrate (array $statements, array $selectedStatements)
 
array< string, install(array $statements, bool $createOnly=false):array { $tables=$this-> parseCreateTableStatements ($statements)
 
 importStaticData (array $statements, bool $truncate=false)
 

Public Attributes

 $updateSuggestions = []
 
foreach($this->connectionPool->getConnectionNames() as $connectionName) return $updateSuggestions
 
 $schemaDiffs = []
 
foreach($this->connectionPool->getConnectionNames() as $connectionName) return $schemaDiffs
 
 $result = []
 
return $result
 
if(!array_key_exists($tableName, $return)) $currentTableDefinition = $return[$tableName]
 
 $return [$tableName]
 
return $return
 

Protected Member Functions

Table[] parseCreateTableStatements (array $statements)
 
string[] getPrioritizedFieldNames (string $tableName)
 

Private Member Functions

array< non-empty-string, mergeTableDefinitions(array $tables):array { $return=[];foreach( $tables as $table) { $tableName=$this-> trimIdentifierQuotes ($table->getName())
 
Column[] mergeColumns (Column ... $columns)
 
Index[] mergeIndexes (Index ... $indexes)
 
 trimIdentifierQuotes (string $identifier)
 

Detailed Description

Helper methods to handle SQL files and transform them into individual statements for further processing.

not part of public core API.

Definition at line 37 of file SchemaMigrator.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::__construct ( private readonly ConnectionPool  $connectionPool,
private readonly Parser  $parser,
private readonly DefaultTcaSchema  $defaultTcaSchema 
)

Definition at line 39 of file SchemaMigrator.php.

Member Function Documentation

◆ getPrioritizedFieldNames()

string [] TYPO3\CMS\Core\Database\Schema\SchemaMigrator::getPrioritizedFieldNames ( string  $tableName)
protected

Have fields triggered by 'ctrl' settings first in the list. This is done for cosmetic reasons to improve readability of db schema when opening tables in a database browser.

Returns
‪string[]

Definition at line 292 of file SchemaMigrator.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Database\Schema\SchemaMigrator\parseCreateTableStatements().

◆ importStaticData()

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::importStaticData ( array  $statements,
bool  $truncate = false 
)

Import static data (INSERT statements)

Definition at line 165 of file SchemaMigrator.php.

References TYPO3\CMS\Core\Database\Schema\SchemaMigrator\$result.

◆ mergeColumns()

Column [] TYPO3\CMS\Core\Database\Schema\SchemaMigrator::mergeColumns ( Column ...  $columns)
private
Parameters
Column‪...$columns
Returns
‪Column[]

Definition at line 400 of file SchemaMigrator.php.

◆ mergeIndexes()

Index [] TYPO3\CMS\Core\Database\Schema\SchemaMigrator::mergeIndexes ( Index ...  $indexes)
private
Parameters
Index‪...$indexes
Returns
‪Index[]

Definition at line 413 of file SchemaMigrator.php.

◆ migrate()

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::migrate ( array  $statements,
array  $selectedStatements 
)

This method executes statements from the update suggestions, or a subset of them filtered by the statements hashes, one by one.

Parameters
string[]$statements‪The CREATE TABLE statements
string[]$selectedStatements‪The hashes of the update suggestions to execute
Exceptions
DBALException
SchemaException

Definition at line 105 of file SchemaMigrator.php.

References TYPO3\CMS\Core\Database\Schema\SchemaMigrator\$result, TYPO3\CMS\Core\Database\Schema\SchemaMigrator\$updateSuggestions, and TYPO3\CMS\Core\Core\Bootstrap\createCache().

◆ parseCreateTableStatements() [1/4]

array<string, getUpdateSuggestions(array $statements, bool $remove = false): array { $tables = $this-> TYPO3\CMS\Core\Database\Schema\SchemaMigrator::parseCreateTableStatements (   $statements)

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

Parameters
string[]$statements‪The CREATE TABLE statements
bool$remove‪TRUE for RENAME/DROP table and column suggestions, FALSE for ADD/CHANGE suggestions
Returns
‪array<string, array> SQL statements to migrate the database to the expected schema, indexed by performed operation
Exceptions
DBALException
SchemaException

◆ parseCreateTableStatements() [2/4]

array<string, getSchemaDiffs(array $statements): array { $tables = $this-> TYPO3\CMS\Core\Database\Schema\SchemaMigrator::parseCreateTableStatements (   $statements)

Return the raw Doctrine SchemaDiff objects for each connection. This diff contains all changes without any pre-processing.

Returns
‪array<string, SchemaDiff>
Exceptions
DBALException
SchemaException

◆ parseCreateTableStatements() [3/4]

array<string, install(array $statements, bool $createOnly = false): array { $tables = $this-> TYPO3\CMS\Core\Database\Schema\SchemaMigrator::parseCreateTableStatements (   $statements)

Perform add/change/create operations on tables and fields in an optimized, non-interactive, mode.

Parameters
string[]$statements‪The CREATE TABLE statements
bool$createOnly‪Only perform changes that add fields or create tables
Returns
‪array<string, string> Error messages for statements that occurred during the installation procedure.
Exceptions
DBALException
SchemaException

◆ parseCreateTableStatements() [4/4]

Table [] TYPO3\CMS\Core\Database\Schema\SchemaMigrator::parseCreateTableStatements ( array  $statements)
protected

Parse CREATE TABLE statements into Doctrine Table objects.

Parameters
string[]$statements‪The SQL CREATE TABLE statements
Returns
‪Table[]
Exceptions
SchemaException

Definition at line 213 of file SchemaMigrator.php.

References $GLOBALS, and TYPO3\CMS\Core\Database\Schema\SchemaMigrator\getPrioritizedFieldNames().

◆ trimIdentifierQuotes() [1/2]

array<non-empty-string, mergeTableDefinitions(array $tables): array { $return = []; foreach ($tables as $table) { $tableName = $this-> TYPO3\CMS\Core\Database\Schema\SchemaMigrator::trimIdentifierQuotes (   $table->())
private

To give extensions the ability to extend or modify the database schema for core or other extension tables, a collection of DDL statement parts are parsed into partial table classes. This method merges the table definition parts to end up with a single table representation to ease further handling.

Parameters
Table[]$tables
Returns
‪array<non-empty-string, Table>

◆ trimIdentifierQuotes() [2/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::trimIdentifierQuotes ( string  $identifier)
private

Trim all possible identifier quotes from identifier. This method has been cloned from Doctrine DBAL.

See also
‪\Doctrine\DBAL\Schema\AbstractAsset::trimQuotes()

Definition at line 427 of file SchemaMigrator.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

Member Data Documentation

◆ $currentTableDefinition

if (!array_key_exists( $tableName, $return)) TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$currentTableDefinition = $return[$tableName]

Definition at line 382 of file SchemaMigrator.php.

◆ $result [1/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$result = []

◆ $result [2/2]

return TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$result

Definition at line 159 of file SchemaMigrator.php.

◆ $return [1/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$return[ $tableName]
Initial value:
= new Table(
$tableName,
$this->‪mergeColumns(...‪$currentTableDefinition->getColumns(), ...$table->getColumns()),
$this->mergeIndexes(...$currentTableDefinition->getIndexes(), ...$table->getIndexes()),
[],
array_merge(‪$currentTableDefinition->getForeignKeys(), $table->getForeignKeys()),
array_merge(‪$currentTableDefinition->getOptions(), $table->getOptions())
)

Definition at line 383 of file SchemaMigrator.php.

◆ $return [2/2]

return TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$return

Definition at line 393 of file SchemaMigrator.php.

◆ $schemaDiffs [1/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$schemaDiffs = []

Definition at line 84 of file SchemaMigrator.php.

◆ $schemaDiffs [2/2]

foreach ( $this->connectionPool->getConnectionNames() as $connectionName) return TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$schemaDiffs

Definition at line 90 of file SchemaMigrator.php.

◆ $updateSuggestions [1/2]

TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$updateSuggestions = []

◆ $updateSuggestions [2/2]

foreach ( $this->connectionPool->getConnectionNames() as $connectionName) return TYPO3\CMS\Core\Database\Schema\SchemaMigrator::$updateSuggestions

Definition at line 67 of file SchemaMigrator.php.

‪TYPO3\CMS\Core\Database\Schema\SchemaMigrator\mergeColumns
‪Column[] mergeColumns(Column ... $columns)
Definition: SchemaMigrator.php:400
‪TYPO3\CMS\Core\Database\Schema\SchemaMigrator\$currentTableDefinition
‪if(!array_key_exists($tableName, $return)) $currentTableDefinition
Definition: SchemaMigrator.php:382