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.

void
createSchema(array $classes)

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

array
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.

void
dropSchema(array $classes)

Drops the database schema for the given classes.

void
dropDatabase()

Drops all elements in the database of the current connection.

array
getDropDatabaseSQL()

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

array
getDropSchemaSQL(array $classes)

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

void
updateSchema(array $classes, boolean $saveMode = false)

Updates the database schema of the given classes by comparing the ClassMetadata instances to the current database schema that is inspected. If $saveMode is set to true the command is executed in the Database, else SQL is returned.

array
getUpdateSchemaSql(array $classes, boolean $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

void createSchema(array $classes)

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

Parameters

array $classes

Return Value

void

Exceptions

ToolsException

array 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

array 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

void 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

Return Value

void

void dropDatabase()

Drops all elements in the database of the current connection.

Return Value

void

array getDropDatabaseSQL()

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

Return Value

array

array getDropSchemaSQL(array $classes)

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

Parameters

array $classes

Return Value

array

void updateSchema(array $classes, boolean $saveMode = false)

Updates the database schema of the given classes by comparing the ClassMetadata instances to the current database schema that is inspected. If $saveMode is set to true the command is executed in the Database, else SQL is returned.

Parameters

array $classes
boolean $saveMode

Return Value

void

array getUpdateSchemaSql(array $classes, boolean $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.

If $saveMode is set to true the command is executed in the Database, else SQL is returned.

Parameters

array $classes The classes to consider.
boolean $saveMode True for writing to DB, false for SQL string.

Return Value

array The sequence of SQL statements.