class SchemaTool (View source)

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

Methods

__construct(EntityManagerInterface $em)

Initializes a new SchemaTool instance that uses the connection of the provided EntityManager.

createSchema(array $classes)

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

string[]
getCreateSchemaSql(array $classes)

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

Schema
getSchemaFromMetadata(array $classes)

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

dropSchema(array $classes)

Drops the database schema for the given classes.

dropDatabase()

Drops all elements in the database of the current connection.

string[]
getDropDatabaseSQL()

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

string[]
getDropSchemaSQL(array $classes)

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

updateSchema(array $classes, bool $saveMode = false)

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

string[]
getUpdateSchemaSql(array $classes, bool $saveMode = false)

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.

Details

__construct(EntityManagerInterface $em)

Initializes a new SchemaTool instance that uses the connection of the provided EntityManager.

Parameters

EntityManagerInterface $em

createSchema(array $classes)

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

Parameters

array $classes

Exceptions

ToolsException

string[] getCreateSchemaSql(array $classes)

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

Parameters

array $classes

Return Value

string[] The SQL statements needed to create the schema for the classes.

Schema getSchemaFromMetadata(array $classes)

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

Parameters

array $classes

Return Value

Schema

Exceptions

ORMException

dropSchema(array $classes)

Drops the database schema for the given classes.

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

array $classes

dropDatabase()

Drops all elements in the database of the current connection.

string[] getDropDatabaseSQL()

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

Return Value

string[]

string[] getDropSchemaSQL(array $classes)

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

Parameters

array $classes

Return Value

string[]

updateSchema(array $classes, bool $saveMode = false)

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

Parameters

array $classes
bool $saveMode If TRUE, only performs a partial update without dropping assets which are scheduled for deletion.

string[] getUpdateSchemaSql(array $classes, bool $saveMode = false)

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.

Parameters

array $classes The classes to consider.
bool $saveMode If TRUE, only generates SQL for a partial update that does not include SQL for dropping assets which are scheduled for deletion.

Return Value

string[] The sequence of SQL statements.