Documentation

SchemaTool
in package

The SchemaTool is a tool to create/drop/update database schemas based on <tt>ClassMetadata</tt> class descriptors.

Tags
link
www.doctrine-project.org
psalm-import-type

AssociationMapping from ClassMetadata

psalm-import-type

DiscriminatorColumnMapping from ClassMetadata

psalm-import-type

FieldMapping from ClassMetadata

psalm-import-type

JoinColumnData from ClassMetadata

Table of Contents

Constants

KNOWN_COLUMN_OPTIONS  = ['comment', 'unsigned', 'fixed', 'default']

Properties

$em  : EntityManagerInterface
$platform  : AbstractPlatform
$quoteStrategy  : QuoteStrategy
The quote strategy.
$schemaManager  : AbstractSchemaManager

Methods

__construct()  : mixed
Initializes a new SchemaTool instance that uses the connection of the provided EntityManager.
createSchema()  : void
Creates the database schema for the given array of ClassMetadata instances.
dropDatabase()  : void
Drops all elements in the database of the current connection.
dropSchema()  : void
Drops the database schema for the given classes.
getCreateSchemaSql()  : array<int, string>
Gets the list of DDL statements that are required to create the database schema for the given list of ClassMetadata instances.
getDropDatabaseSQL()  : array<int, string>
Gets the SQL needed to drop the database schema for the connections database.
getDropSchemaSQL()  : array<int, string>
Gets SQL to drop the tables defined by the passed classes.
getSchemaFromMetadata()  : Schema
Creates a Schema instance from a given set of metadata classes.
getUpdateSchemaSql()  : array<int, string>
Gets the sequence of SQL statements that need to be performed in order to bring the given class mappings in-synch with the relational schema.
updateSchema()  : void
Updates the database schema of the given classes by comparing the ClassMetadata instances to the current database schema that is inspected.
addDiscriminatorColumnDefinition()  : void
Gets a portable column definition as required by the DBAL for the discriminator column of a class.
createSchemaForComparison()  : Schema
Creates the schema from the database, ensuring tables from the target schema are whitelisted for comparison.
gatherColumn()  : void
Creates a column definition as required by the DBAL from an ORM field mapping definition.
gatherColumnOptions()  : array<string|int, mixed>
gatherColumns()  : void
Gathers the column definitions as required by the DBAL of all field mappings found in the given class.
gatherRelationJoinColumns()  : void
Gathers columns and fk constraints that are required for one part of relationship.
gatherRelationsSql()  : void
Gathers the SQL for properly setting up the relations of the given class.
getDefiningClass()  : array<string|int, mixed>|null
Gets the class metadata that is responsible for the definition of the referenced column name.
getIndexColumns()  : array<int, string>
Resolves fields in index mapping to column names
introspectSchema()  : Schema
processingNotRequired()  : bool
Detects instances of ClassMetadata that don't need to be processed in the SchemaTool context.

Constants

KNOWN_COLUMN_OPTIONS

private mixed KNOWN_COLUMN_OPTIONS = ['comment', 'unsigned', 'fixed', 'default']

Properties

Methods

createSchema()

Creates the database schema for the given array of ClassMetadata instances.

public createSchema(array<string|int, mixed> $classes) : void
Parameters
$classes : array<string|int, mixed>
Tags
psalm-param

list<ClassMetadata> $classes

throws
ToolsException

dropDatabase()

Drops all elements in the database of the current connection.

public dropDatabase() : void

dropSchema()

Drops the database schema for the given classes.

public dropSchema(array<string|int, mixed> $classes) : void

In any way when an exception is thrown it is suppressed since drop was issued for all classes of the schema and some probably just don't exist.

Parameters
$classes : array<string|int, mixed>
Tags
psalm-param

list<ClassMetadata> $classes

getCreateSchemaSql()

Gets the list of DDL statements that are required to create the database schema for the given list of ClassMetadata instances.

public getCreateSchemaSql(array<string|int, mixed> $classes) : array<int, string>
Parameters
$classes : array<string|int, mixed>
Tags
psalm-param

list<ClassMetadata> $classes

Return values
array<int, string>

The SQL statements needed to create the schema for the classes.

getDropDatabaseSQL()

Gets the SQL needed to drop the database schema for the connections database.

public getDropDatabaseSQL() : array<int, string>
Return values
array<int, string>

getDropSchemaSQL()

Gets SQL to drop the tables defined by the passed classes.

public getDropSchemaSQL(array<string|int, mixed> $classes) : array<int, string>
Parameters
$classes : array<string|int, mixed>
Tags
psalm-param

list<ClassMetadata> $classes

Return values
array<int, string>

getSchemaFromMetadata()

Creates a Schema instance from a given set of metadata classes.

public getSchemaFromMetadata(array<string|int, mixed> $classes) : Schema
Parameters
$classes : array<string|int, mixed>
Tags
psalm-param

list<ClassMetadata> $classes

throws
NotSupported
Return values
Schema

getUpdateSchemaSql()

Gets the sequence of SQL statements that need to be performed in order to bring the given class mappings in-synch with the relational schema.

public getUpdateSchemaSql(array<int, ClassMetadata$classes[, bool $saveMode = false ]) : array<int, string>
Parameters
$classes : array<int, ClassMetadata>

The classes to consider.

$saveMode : bool = false

If TRUE, only generates SQL for a partial update that does not include SQL for dropping assets which are scheduled for deletion.

Return values
array<int, string>

The sequence of SQL statements.

updateSchema()

Updates the database schema of the given classes by comparing the ClassMetadata instances to the current database schema that is inspected.

public updateSchema(array<string|int, mixed> $classes[, bool $saveMode = false ]) : void
Parameters
$classes : array<string|int, mixed>
$saveMode : bool = false

If TRUE, only performs a partial update without dropping assets which are scheduled for deletion.

addDiscriminatorColumnDefinition()

Gets a portable column definition as required by the DBAL for the discriminator column of a class.

private addDiscriminatorColumnDefinition(ClassMetadata $class, Table $table) : void
Parameters
$class : ClassMetadata
$table : Table

createSchemaForComparison()

Creates the schema from the database, ensuring tables from the target schema are whitelisted for comparison.

private createSchemaForComparison(Schema $toSchema) : Schema
Parameters
$toSchema : Schema
Return values
Schema

gatherColumn()

Creates a column definition as required by the DBAL from an ORM field mapping definition.

private gatherColumn(ClassMetadata $class, array<string|int, mixed> $mapping, Table $table) : void
Parameters
$class : ClassMetadata

The class that owns the field mapping.

$mapping : array<string|int, mixed>
$table : Table
Tags
psalm-param

FieldMapping $mapping The field mapping.

gatherColumnOptions()

private gatherColumnOptions(array<string|int, mixed> $mapping) : array<string|int, mixed>
Parameters
$mapping : array<string|int, mixed>
Tags
psalm-param

JoinColumnData|FieldMapping|DiscriminatorColumnMapping $mapping

Return values
array<string|int, mixed>

gatherColumns()

Gathers the column definitions as required by the DBAL of all field mappings found in the given class.

private gatherColumns(ClassMetadata $class, Table $table) : void
Parameters
$class : ClassMetadata
$table : Table

gatherRelationJoinColumns()

Gathers columns and fk constraints that are required for one part of relationship.

private gatherRelationJoinColumns(array<string|int, mixed> $joinColumns, Table $theJoinTable, ClassMetadata $class, array<string|int, mixed> $mapping, array<string|int, mixed> &$primaryKeyColumns, array<string|int, mixed> &$addedFks, array<string|int, mixed> &$blacklistedFks) : void
Parameters
$joinColumns : array<string|int, mixed>
$theJoinTable : Table
$class : ClassMetadata
$mapping : array<string|int, mixed>
$primaryKeyColumns : array<string|int, mixed>
$addedFks : array<string|int, mixed>
$blacklistedFks : array<string|int, mixed>
Tags
psalm-param

array<string, JoinColumnData> $joinColumns

psalm-param

AssociationMapping $mapping

psalm-param

list $primaryKeyColumns

psalm-param

array<string, array{ foreignTableName: string, foreignColumns: list }> $addedFks

psalm-param

array<string,bool> $blacklistedFks

throws
MissingColumnException

gatherRelationsSql()

Gathers the SQL for properly setting up the relations of the given class.

private gatherRelationsSql(ClassMetadata $class, Table $table, Schema $schema, array<string|int, mixed> &$addedFks, array<string|int, mixed> &$blacklistedFks) : void

This includes the SQL for foreign key constraints and join tables.

Parameters
$class : ClassMetadata
$table : Table
$schema : Schema
$addedFks : array<string|int, mixed>
$blacklistedFks : array<string|int, mixed>
Tags
psalm-param

array<string, array{ foreignTableName: string, foreignColumns: list }> $addedFks

psalm-param

array<string, bool> $blacklistedFks

throws
NotSupported

getDefiningClass()

Gets the class metadata that is responsible for the definition of the referenced column name.

private getDefiningClass(ClassMetadata $class, string $referencedColumnName) : array<string|int, mixed>|null

Previously this was a simple task, but with DDC-117 this problem is actually recursive. If its not a simple field, go through all identifier field names that are associations recursively and find that referenced column name.

TODO: Is there any way to make this code more pleasing?

Parameters
$class : ClassMetadata
$referencedColumnName : string
Tags
psalm-return

array{ClassMetadata, string}|null

Return values
array<string|int, mixed>|null

getIndexColumns()

Resolves fields in index mapping to column names

private getIndexColumns(ClassMetadata $class, array<string|int, mixed> $indexData) : array<int, string>
Parameters
$class : ClassMetadata
$indexData : array<string|int, mixed>

index or unique constraint data

Return values
array<int, string>

Column names from combined fields and columns mappings

processingNotRequired()

Detects instances of ClassMetadata that don't need to be processed in the SchemaTool context.

private processingNotRequired(ClassMetadata $class, array<string|int, mixed> $processedClasses) : bool
Parameters
$class : ClassMetadata
$processedClasses : array<string|int, mixed>
Tags
psalm-param

array<string, bool> $processedClasses

Return values
bool

        
On this page

Search results