SchemaMigrator

readonly class \TYPO3\CMS\Core\Database\Schema\SchemaMigrator

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

Attributes

#[Autoconfigure]
$public: true

Table of Contents

Methods

__construct()  : mixed
getSchemaDiffs()  : array<string, SchemaDiff>
Return the raw Doctrine SchemaDiff objects for each connection. This diff contains all changes without any pre-processing.
getUpdateSuggestions()  : array<string, array>
Compare current and expected schema definitions and provide updates suggestions in the form of SQL statements.
importStaticData()  : array
Import static data (INSERT statements)
install()  : array<string, string>
Perform add/change/create operations on tables and fields in an optimized, non-interactive, mode.
migrate()  : array
This method executes statements from the update suggestions, or a subset of them filtered by the statements hashes, one by one.
enrichTablesFromDefaultTCASchema()  : array<non-empty-string, Table>
ensureDefaultTCAFieldsAreOrdered()  : array<non-empty-string, Table>
Ensure the default TCA fields are ordered.
ensureTableDefinitionForAllTCAManagedTables()  : Table[]
Ensure we have a table definition for all tables within TCA, add missing ones as "empty" tables without columns. This is needed for DefaultTcaSchema: It goes through TCA to add columns automatically, but needs a table definition of all TCA tables. We're not doing this in DefaultTcaSchema to not introduce a dependency to the Parser class in there, which we have here so conveniently already.
flushDatabaseSchemaCache()  : void
getPrioritizedFieldNames()  : string[]
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.
parseCreateTableStatements()  : array<non-empty-string, Table>
Parse CREATE TABLE statements into Doctrine Table objects.
prepareTablesFromStatements()  : Table[]

Methods

getSchemaDiffs()

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

public getSchemaDiffs(array $statements) : array<string, SchemaDiff>

Parameters

$statements : array

Tags

throws
Exception
throws
SchemaException
throws
InvalidArgumentException
throws
RuntimeException
throws
StatementException

Return values

array<string, SchemaDiff>

getUpdateSuggestions()

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

public getUpdateSuggestions(string[] $statements[, bool $remove = false ]) : array<string, array>

Parameters

$statements : string[]

The CREATE TABLE statements

$remove : bool = false

TRUE for RENAME/DROP table and column suggestions, FALSE for ADD/CHANGE suggestions

Tags

throws
Exception
throws
SchemaException
throws
InvalidArgumentException
throws
RuntimeException
throws
StatementException

Return values

array<string, array> —

SQL statements to migrate the database to the expected schema, indexed by performed operation

importStaticData()

Import static data (INSERT statements)

public importStaticData(array $statements[, bool $truncate = false ]) : array

Parameters

$statements : array
$truncate : bool = false

Return values

array

install()

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

public install(string[] $statements[, bool $createOnly = false ]) : array<string, string>

Parameters

$statements : string[]

The CREATE TABLE statements

$createOnly : bool = false

Only perform changes that add fields or create tables

Tags

throws
Exception
throws
SchemaException
throws
InvalidArgumentException
throws
RuntimeException
throws
StatementException

Return values

array<string, string> —

Error messages for statements that occurred during the installation procedure.

migrate()

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

public migrate(string[] $statements, array<string|int, mixed> $selectedStatements) : array

Parameters

$statements : string[]

The CREATE TABLE statements

$selectedStatements : array<string|int, mixed>

Hashes as keys

Tags

throws
Exception
throws
SchemaException
throws
InvalidArgumentException
throws
StatementException
throws
RuntimeException

Return values

array

enrichTablesFromDefaultTCASchema()

protected enrichTablesFromDefaultTCASchema(array<non-empty-string, Table> $tables) : array<non-empty-string, Table>

Parameters

$tables : array<non-empty-string, Table>

Return values

array<non-empty-string, Table>

ensureDefaultTCAFieldsAreOrdered()

Ensure the default TCA fields are ordered.

protected ensureDefaultTCAFieldsAreOrdered(array<non-empty-string, Table> $tables) : array<non-empty-string, Table>

Parameters

$tables : array<non-empty-string, Table>

Return values

array<non-empty-string, Table>

ensureTableDefinitionForAllTCAManagedTables()

Ensure we have a table definition for all tables within TCA, add missing ones as "empty" tables without columns. This is needed for DefaultTcaSchema: It goes through TCA to add columns automatically, but needs a table definition of all TCA tables. We're not doing this in DefaultTcaSchema to not introduce a dependency to the Parser class in there, which we have here so conveniently already.

protected ensureTableDefinitionForAllTCAManagedTables(Table[] $tables) : Table[]

Parameters

$tables : Table[]

Tags

throws
SchemaException
throws
StatementException

Return values

Table[]

flushDatabaseSchemaCache()

protected flushDatabaseSchemaCache() : void

getPrioritizedFieldNames()

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.

protected getPrioritizedFieldNames(string $tableName) : string[]

Parameters

$tableName : string

Return values

string[]

parseCreateTableStatements()

Parse CREATE TABLE statements into Doctrine Table objects.

protected parseCreateTableStatements(string[] $statements) : array<non-empty-string, Table>

Parameters

$statements : string[]

The SQL CREATE TABLE statements

Tags

throws
SchemaException
throws
InvalidArgumentException
throws
RuntimeException
throws
StatementException

Return values

array<non-empty-string, Table>

prepareTablesFromStatements()

protected prepareTablesFromStatements(string[] $statements) : Table[]

Parameters

$statements : string[]

Tags

throws
SchemaException
throws
StatementException

Return values

Table[]
On this page