abstract class AbstractSchemaManager (View source)

Base class for schema managers. Schema managers are used to inspect and/or modify the database schema/structure.

Properties

protected Connection $_conn Holds instance of the Doctrine connection for this schema manager
protected AbstractPlatform $_platform Holds instance of the database platform used for this schema manager

Methods

__construct(Connection $conn)

Constructor. Accepts the Connection instance to manage the schema for

AbstractPlatform
getDatabasePlatform()

Return associated platform.

mixed
tryMethod()

Try any method on the schema manager. Normally a method throws an exception when your DBMS doesn't support it or if an error occurs.

array
listDatabases()

List the available databases for this connection

listSequences($database = null)

List the available sequences for this connection

Column[]
listTableColumns(string $table, string $database = null)

List the columns for a given table.

Index[]
listTableIndexes(string $table)

List the indexes for a given table returning an array of Index instances.

bool
tablesExist(array $tableNames)

Return true if all the given tables exist.

array
listTableNames()

Return a list of all tables in the current database

array
filterAssetNames(array $assetNames)

Filter asset names if they are configured to return only a subset of all the found elements.

Table[]
listTables()

List the tables for this connection

listTableDetails(string $tableName)

No description

View[]
listViews()

List the views this connection has

listTableForeignKeys($table, $database = null)

List the foreign keys for the given table

dropDatabase(string $database)

Drops a database.

dropTable(string $table)

Drop the given table

dropIndex(Index|string $index, string|Table $table)

Drop the index from the given table

dropConstraint(Constraint $constraint, string $table)

Drop the constraint from the given table

boolean
dropForeignKey($foreignKey, $table)

Drops a foreign key from a table.

dropSequence(string $name)

Drops a sequence with a given name.

boolean
dropView(string $name)

Drop a view

createDatabase(string $database)

Creates a new database.

createTable(Table $table)

Create a new table.

createSequence(Sequence $sequence)

Create a new sequence

createConstraint(Constraint $constraint, string|Table $table)

Create a constraint on a table

createIndex(Index $index, string $table)

Create a new index on a table

createForeignKey(ForeignKeyConstraint $foreignKey, string|Table $table)

Create a new foreign key

createView(View $view)

Create a new view

dropAndCreateConstraint(Constraint $constraint, string $table)

Drop and create a constraint

dropAndCreateIndex(Index $index, $table)

Drop and create a new index on a table

dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, string|Table $table)

Drop and create a new foreign key

dropAndCreateSequence(Sequence $sequence)

Drop and create a new sequence

dropAndCreateTable(Table $table)

Drop and create a new table.

dropAndCreateDatabase(string $database)

Drop and creates a new database.

dropAndCreateView(View $view)

Drop and create a new view

alterTable(TableDiff $tableDiff)

Alter an existing tables schema

renameTable(string $name, string $newName)

Rename a given table to another name

_getPortableDatabasesList($databases)

Methods for filtering return values of list*() methods to convert the native DBMS data definition to a portable Doctrine definition

_getPortableDatabaseDefinition($database)

No description

_getPortableFunctionsList($functions)

No description

_getPortableFunctionDefinition($function)

No description

_getPortableTriggersList($triggers)

No description

_getPortableTriggerDefinition($trigger)

No description

_getPortableSequencesList($sequences)

No description

_getPortableSequenceDefinition(array $sequence)

No description

array
_getPortableTableColumnList(string $table, string $database, array $tableColumns)

Independent of the database the keys of the column list result are lowercased.

_getPortableTableColumnDefinition(array $tableColumn)

Get Table Column Definition

array
_getPortableTableIndexesList(array $tableIndexRows, string $tableName = null)

Aggregate and group the index results according to the required data result.

_getPortableTablesList($tables)

No description

_getPortableTableDefinition($table)

No description

_getPortableUsersList($users)

No description

_getPortableUserDefinition($user)

No description

_getPortableViewsList($views)

No description

_getPortableViewDefinition($view)

No description

_getPortableTableForeignKeysList($tableForeignKeys)

No description

_getPortableTableForeignKeyDefinition($tableForeignKey)

No description

_execSql($sql)

No description

createSchema()

Create a schema instance for the current database.

createSchemaConfig()

Create the configuration for this schema.

array
getSchemaSearchPaths()

The search path for namespaces in the currently connected database.

string
extractDoctrineTypeFromComment(string $comment, string $currentType)

Given a table comment this method tries to extract a typehint for Doctrine Type, or returns the type given as default.

removeDoctrineTypeFromComment($comment, $type)

No description

Details

__construct(Connection $conn)

Constructor. Accepts the Connection instance to manage the schema for

Parameters

Connection $conn

AbstractPlatform getDatabasePlatform()

Return associated platform.

Return Value

AbstractPlatform

mixed tryMethod()

Try any method on the schema manager. Normally a method throws an exception when your DBMS doesn't support it or if an error occurs.

This method allows you to try and method on your SchemaManager instance and will return false if it does not work or is not supported.

$result = $sm->tryMethod('dropView', 'view_name');

Return Value

mixed

array listDatabases()

List the available databases for this connection

Return Value

array $databases

Sequence[] listSequences($database = null)

List the available sequences for this connection

Parameters

$database

Return Value

Sequence[]

Column[] listTableColumns(string $table, string $database = null)

List the columns for a given table.

In contrast to other libraries and to the old version of Doctrine, this column definition does try to contain the 'primary' field for the reason that it is not portable accross different RDBMS. Use {see listTableIndexes($tableName)} to retrieve the primary key of a table. We're a RDBMS specifies more details these are held in the platformDetails array.

Parameters

string $table The name of the table.
string $database

Return Value

Column[]

Index[] listTableIndexes(string $table)

List the indexes for a given table returning an array of Index instances.

Keys of the portable indexes list are all lower-cased.

Parameters

string $table The name of the table

Return Value

Index[] $tableIndexes

bool tablesExist(array $tableNames)

Return true if all the given tables exist.

Parameters

array $tableNames

Return Value

bool

array listTableNames()

Return a list of all tables in the current database

Return Value

array

protected array filterAssetNames(array $assetNames)

Filter asset names if they are configured to return only a subset of all the found elements.

Parameters

array $assetNames

Return Value

array

protected getFilterSchemaAssetsExpression()

Table[] listTables()

List the tables for this connection

Return Value

Table[]

Table listTableDetails(string $tableName)

Parameters

string $tableName

Return Value

Table

View[] listViews()

List the views this connection has

Return Value

View[]

ForeignKeyConstraint[] listTableForeignKeys($table, $database = null)

List the foreign keys for the given table

Parameters

$table
$database

Return Value

ForeignKeyConstraint[]

dropDatabase(string $database)

Drops a database.

NOTE: You can not drop the database this SchemaManager is currently connected to.

Parameters

string $database The name of the database to drop

dropTable(string $table)

Drop the given table

Parameters

string $table The name of the table to drop

dropIndex(Index|string $index, string|Table $table)

Drop the index from the given table

Parameters

Index|string $index The name of the index
string|Table $table The name of the table

dropConstraint(Constraint $constraint, string $table)

Drop the constraint from the given table

Parameters

Constraint $constraint
string $table The name of the table

boolean dropForeignKey($foreignKey, $table)

Drops a foreign key from a table.

Parameters

$foreignKey
$table

Return Value

boolean $result

dropSequence(string $name)

Drops a sequence with a given name.

Parameters

string $name The name of the sequence to drop.

boolean dropView(string $name)

Drop a view

Parameters

string $name The name of the view

Return Value

boolean $result

createDatabase(string $database)

Creates a new database.

Parameters

string $database The name of the database to create.

createTable(Table $table)

Create a new table.

Parameters

Table $table

createSequence(Sequence $sequence)

Create a new sequence

Parameters

Sequence $sequence

Exceptions

ConnectionException if something fails at database level

createConstraint(Constraint $constraint, string|Table $table)

Create a constraint on a table

Parameters

Constraint $constraint
string|Table $table

createIndex(Index $index, string $table)

Create a new index on a table

Parameters

Index $index
string $table name of the table on which the index is to be created

createForeignKey(ForeignKeyConstraint $foreignKey, string|Table $table)

Create a new foreign key

Parameters

ForeignKeyConstraint $foreignKey ForeignKey instance
string|Table $table name of the table on which the foreign key is to be created

createView(View $view)

Create a new view

Parameters

View $view

dropAndCreateConstraint(Constraint $constraint, string $table)

Drop and create a constraint

Parameters

Constraint $constraint
string $table

See also

dropConstraint()
createConstraint()

dropAndCreateIndex(Index $index, $table)

Drop and create a new index on a table

Parameters

Index $index
$table

dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, string|Table $table)

Drop and create a new foreign key

Parameters

ForeignKeyConstraint $foreignKey associative array that defines properties of the foreign key to be created.
string|Table $table name of the table on which the foreign key is to be created

dropAndCreateSequence(Sequence $sequence)

Drop and create a new sequence

Parameters

Sequence $sequence

Exceptions

ConnectionException if something fails at database level

dropAndCreateTable(Table $table)

Drop and create a new table.

Parameters

Table $table

dropAndCreateDatabase(string $database)

Drop and creates a new database.

Parameters

string $database The name of the database to create.

dropAndCreateView(View $view)

Drop and create a new view

Parameters

View $view

alterTable(TableDiff $tableDiff)

Alter an existing tables schema

Parameters

TableDiff $tableDiff

renameTable(string $name, string $newName)

Rename a given table to another name

Parameters

string $name The current name of the table
string $newName The new name of the table

protected _getPortableDatabasesList($databases)

Methods for filtering return values of list*() methods to convert the native DBMS data definition to a portable Doctrine definition

Parameters

$databases

protected _getPortableDatabaseDefinition($database)

Parameters

$database

protected _getPortableFunctionsList($functions)

Parameters

$functions

protected _getPortableFunctionDefinition($function)

Parameters

$function

protected _getPortableTriggersList($triggers)

Parameters

$triggers

protected _getPortableTriggerDefinition($trigger)

Parameters

$trigger

protected _getPortableSequencesList($sequences)

Parameters

$sequences

protected Sequence _getPortableSequenceDefinition(array $sequence)

Parameters

array $sequence

Return Value

Sequence

protected array _getPortableTableColumnList(string $table, string $database, array $tableColumns)

Independent of the database the keys of the column list result are lowercased.

The name of the created column instance however is kept in its case.

Parameters

string $table The name of the table.
string $database
array $tableColumns

Return Value

array

abstract protected Column _getPortableTableColumnDefinition(array $tableColumn)

Get Table Column Definition

Parameters

array $tableColumn

Return Value

Column

protected array _getPortableTableIndexesList(array $tableIndexRows, string $tableName = null)

Aggregate and group the index results according to the required data result.

Parameters

array $tableIndexRows
string $tableName

Return Value

array

protected _getPortableTablesList($tables)

Parameters

$tables

protected _getPortableTableDefinition($table)

Parameters

$table

protected _getPortableUsersList($users)

Parameters

$users

protected _getPortableUserDefinition($user)

Parameters

$user

protected _getPortableViewsList($views)

Parameters

$views

protected _getPortableViewDefinition($view)

Parameters

$view

protected _getPortableTableForeignKeysList($tableForeignKeys)

Parameters

$tableForeignKeys

protected _getPortableTableForeignKeyDefinition($tableForeignKey)

Parameters

$tableForeignKey

protected _execSql($sql)

Parameters

$sql

Schema createSchema()

Create a schema instance for the current database.

Return Value

Schema

SchemaConfig createSchemaConfig()

Create the configuration for this schema.

Return Value

SchemaConfig

array getSchemaSearchPaths()

The search path for namespaces in the currently connected database.

The first entry is usually the default namespace in the Schema. All further namespaces contain tables/sequences which can also be addressed with a short, not full-qualified name.

For databases that don't support subschema/namespaces this method returns the name of the currently connected database.

Return Value

array

string extractDoctrineTypeFromComment(string $comment, string $currentType)

Given a table comment this method tries to extract a typehint for Doctrine Type, or returns the type given as default.

Parameters

string $comment
string $currentType

Return Value

string

removeDoctrineTypeFromComment($comment, $type)

Parameters

$comment
$type