SchemaTool
in package
The SchemaTool is a tool to create/drop/update database schemas based on <tt>ClassMetadata</tt> class descriptors.
Tags
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
$em
private
EntityManagerInterface
$em
$platform
private
AbstractPlatform
$platform
$quoteStrategy
The quote strategy.
private
QuoteStrategy
$quoteStrategy
$schemaManager
private
AbstractSchemaManager
$schemaManager
Methods
__construct()
Initializes a new SchemaTool instance that uses the connection of the provided EntityManager.
public
__construct(EntityManagerInterface $em) : mixed
Parameters
- $em : EntityManagerInterface
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
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
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
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
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
Return values
SchemagetUpdateSchemaSql()
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
SchemagatherColumn()
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
gatherColumnOptions()
private
gatherColumnOptions(array<string|int, mixed> $mapping) : array<string|int, mixed>
Parameters
- $mapping : array<string|int, mixed>
Tags
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
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
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
Return values
array<string|int, mixed>|nullgetIndexColumns()
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
introspectSchema()
private
introspectSchema() : Schema
Return values
SchemaprocessingNotRequired()
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>