class PostgreSqlSchemaManager extends AbstractSchemaManager (View source)

PostgreSQL Schema Manager.

Properties

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

Methods

__construct(Connection $conn, AbstractPlatform $platform = null)

Constructor. Accepts the Connection instance to manage the schema for.

getDatabasePlatform()

Returns the associated platform.

mixed
tryMethod()

Tries 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()

Lists the available databases for this connection.

array
listNamespaceNames()

Returns a list of all namespaces in the current database.

listSequences(string|null $database = null)

Lists the available sequences for this connection.

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

Lists the columns for a given table.

Index[]
listTableIndexes(string $table)

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

boolean
tablesExist(array $tableNames)

Returns true if all the given tables exist.

array
listTableNames()

Returns a list of all tables in the current database.

array
filterAssetNames(array $assetNames)

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

string|null
Table[]
listTables()

Lists the tables for this connection.

listTableDetails(string $tableName)

No description

View[]
listViews()

Lists the views this connection has.

listTableForeignKeys(string $table, string|null $database = null)

Lists the foreign keys for the given table.

void
dropDatabase(string $database)

Drops a database.

void
dropTable(string $tableName)

Drops the given table.

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

Drops the index from the given table.

void
dropConstraint(Constraint $constraint, Table|string $table)

Drops the constraint from the given table.

void
dropForeignKey(ForeignKeyConstraint|string $foreignKey, Table|string $table)

Drops a foreign key from a table.

void
dropSequence(string $name)

Drops a sequence with a given name.

void
dropView(string $name)

Drops a view.

void
createDatabase(string $database)

Creates a new database.

void
createTable(Table $table)

Creates a new table.

void
createSequence(Sequence $sequence)

Creates a new sequence.

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

Creates a constraint on a table.

void
createIndex(Index $index, Table|string $table)

Creates a new index on a table.

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

Creates a new foreign key.

void
createView(View $view)

Creates a new view.

void
dropAndCreateConstraint(Constraint $constraint, Table|string $table)

Drops and creates a constraint.

void
dropAndCreateIndex(Index $index, Table|string $table)

Drops and creates a new index on a table.

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

Drops and creates a new foreign key.

void
dropAndCreateSequence(Sequence $sequence)

Drops and create a new sequence.

void
dropAndCreateTable(Table $table)

Drops and creates a new table.

void
dropAndCreateDatabase(string $database)

Drops and creates a new database.

void
dropAndCreateView(View $view)

Drops and creates a new view.

void
alterTable(TableDiff $tableDiff)

Alters an existing tables schema.

void
renameTable(string $name, string $newName)

Renames a given table to another name.

array
_getPortableDatabasesList(array $databases)

No description

array
getPortableNamespacesList(array $namespaces)

Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition.

mixed
_getPortableDatabaseDefinition(array $database)

No description

mixed
getPortableNamespaceDefinition(array $namespace)

Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition.

array
_getPortableFunctionsList(array $functions)

No description

mixed
_getPortableFunctionDefinition(array $function)

No description

array
_getPortableTriggersList(array $triggers)

No description

mixed
_getPortableTriggerDefinition(array $trigger)

No description

array
_getPortableSequencesList(array $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)

Gets Table Column Definition.

array
_getPortableTableIndexesList($tableIndexes, string|null $tableName = null)

Aggregates and groups the index results according to the required data result.

array
_getPortableTablesList(array $tables)

No description

array
_getPortableTableDefinition(array $table)

No description

array
_getPortableUsersList(array $users)

No description

mixed
_getPortableUserDefinition(array $user)

No description

array
_getPortableViewsList(array $views)

No description

mixed
_getPortableViewDefinition(array $view)

No description

array
_getPortableTableForeignKeysList(array $tableForeignKeys)

No description

mixed
_getPortableTableForeignKeyDefinition(array $tableForeignKey)

No description

void
_execSql(array|string $sql)

No description

createSchema()

Creates a schema instance for the current database.

createSchemaConfig()

Creates the configuration for this schema.

array
getSchemaSearchPaths()

Returns an array of schema search paths.

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.

string
removeDoctrineTypeFromComment(string $comment, string $type)

No description

array
getSchemaNames()

Gets all the existing schema names.

array
getExistingSchemaSearchPaths()

Gets names of all existing schemas in the current users search path.

void
determineExistingSchemaSearchPaths()

Sets or resets the order of the existing schemas in the current search path of the user.

Details

__construct(Connection $conn, AbstractPlatform $platform = null)

Constructor. Accepts the Connection instance to manage the schema for.

Parameters

Connection $conn
AbstractPlatform $platform

AbstractPlatform getDatabasePlatform()

Returns the associated platform.

Return Value

AbstractPlatform

mixed tryMethod()

Tries 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()

Lists the available databases for this connection.

Return Value

array

array listNamespaceNames()

Returns a list of all namespaces in the current database.

Return Value

array

Sequence[] listSequences(string|null $database = null)

Lists the available sequences for this connection.

Parameters

string|null $database

Return Value

Sequence[]

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

Lists 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|null $database

Return Value

Column[]

Index[] listTableIndexes(string $table)

Lists 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[]

boolean tablesExist(array $tableNames)

Returns true if all the given tables exist.

Parameters

array $tableNames

Return Value

boolean

array listTableNames()

Returns a list of all tables in the current database.

Return Value

array

protected array filterAssetNames(array $assetNames)

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

Parameters

array $assetNames

Return Value

array

protected string|null getFilterSchemaAssetsExpression()

Return Value

string|null

Table[] listTables()

Lists the tables for this connection.

Return Value

Table[]

Table listTableDetails(string $tableName)

Parameters

string $tableName

Return Value

Table

View[] listViews()

Lists the views this connection has.

Return Value

View[]

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

Lists the foreign keys for the given table.

Parameters

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

Return Value

ForeignKeyConstraint[]

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

Return Value

void

void dropTable(string $tableName)

Drops the given table.

Parameters

string $tableName The name of the table to drop.

Return Value

void

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

Drops the index from the given table.

Parameters

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

Return Value

void

void dropConstraint(Constraint $constraint, Table|string $table)

Drops the constraint from the given table.

Parameters

Constraint $constraint
Table|string $table The name of the table.

Return Value

void

void dropForeignKey(ForeignKeyConstraint|string $foreignKey, Table|string $table)

Drops a foreign key from a table.

Parameters

ForeignKeyConstraint|string $foreignKey The name of the foreign key.
Table|string $table The name of the table with the foreign key.

Return Value

void

void dropSequence(string $name)

Drops a sequence with a given name.

Parameters

string $name The name of the sequence to drop.

Return Value

void

void dropView(string $name)

Drops a view.

Parameters

string $name The name of the view.

Return Value

void

void createDatabase(string $database)

Creates a new database.

Parameters

string $database The name of the database to create.

Return Value

void

void createTable(Table $table)

Creates a new table.

Parameters

Table $table

Return Value

void

void createSequence(Sequence $sequence)

Creates a new sequence.

Parameters

Sequence $sequence

Return Value

void

Exceptions

ConnectionException If something fails at database level.

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

Creates a constraint on a table.

Parameters

Constraint $constraint
Table|string $table

Return Value

void

void createIndex(Index $index, Table|string $table)

Creates a new index on a table.

Parameters

Index $index
Table|string $table The name of the table on which the index is to be created.

Return Value

void

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

Creates a new foreign key.

Parameters

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

Return Value

void

void createView(View $view)

Creates a new view.

Parameters

View $view

Return Value

void

void dropAndCreateConstraint(Constraint $constraint, Table|string $table)

Drops and creates a constraint.

Parameters

Constraint $constraint
Table|string $table

Return Value

void

See also

dropConstraint()
createConstraint()

void dropAndCreateIndex(Index $index, Table|string $table)

Drops and creates a new index on a table.

Parameters

Index $index
Table|string $table The name of the table on which the index is to be created.

Return Value

void

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

Drops and creates a new foreign key.

Parameters

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

Return Value

void

void dropAndCreateSequence(Sequence $sequence)

Drops and create a new sequence.

Parameters

Sequence $sequence

Return Value

void

Exceptions

ConnectionException If something fails at database level.

void dropAndCreateTable(Table $table)

Drops and creates a new table.

Parameters

Table $table

Return Value

void

void dropAndCreateDatabase(string $database)

Drops and creates a new database.

Parameters

string $database The name of the database to create.

Return Value

void

void dropAndCreateView(View $view)

Drops and creates a new view.

Parameters

View $view

Return Value

void

void alterTable(TableDiff $tableDiff)

Alters an existing tables schema.

Parameters

TableDiff $tableDiff

Return Value

void

void renameTable(string $name, string $newName)

Renames a given table to another name.

Parameters

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

Return Value

void

protected array _getPortableDatabasesList(array $databases)

Parameters

array $databases

Return Value

array

protected array getPortableNamespacesList(array $namespaces)

Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition.

Parameters

array $namespaces The list of namespace names in the native DBMS data definition.

Return Value

array

protected mixed _getPortableDatabaseDefinition(array $database)

Parameters

array $database

Return Value

mixed

protected mixed getPortableNamespaceDefinition(array $namespace)

Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition.

Parameters

array $namespace The native DBMS namespace definition.

Return Value

mixed

protected array _getPortableFunctionsList(array $functions)

Parameters

array $functions

Return Value

array

protected mixed _getPortableFunctionDefinition(array $function)

Parameters

array $function

Return Value

mixed

protected array _getPortableTriggersList(array $triggers)

Parameters

array $triggers

Return Value

array

protected mixed _getPortableTriggerDefinition(array $trigger)

Parameters

array $trigger

Return Value

mixed

protected array _getPortableSequencesList(array $sequences)

Parameters

array $sequences

Return Value

array

protected Sequence _getPortableSequenceDefinition(array $sequence)

Parameters

array $sequence

Return Value

Sequence

Exceptions

DBALException

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

protected Column _getPortableTableColumnDefinition(array $tableColumn)

Gets Table Column Definition.

Parameters

array $tableColumn

Return Value

Column

protected array _getPortableTableIndexesList($tableIndexes, string|null $tableName = null)

Aggregates and groups the index results according to the required data result.

Parameters

$tableIndexes
string|null $tableName

Return Value

array

protected array _getPortableTablesList(array $tables)

Parameters

array $tables

Return Value

array

protected array _getPortableTableDefinition(array $table)

Parameters

array $table

Return Value

array

protected array _getPortableUsersList(array $users)

Parameters

array $users

Return Value

array

protected mixed _getPortableUserDefinition(array $user)

Parameters

array $user

Return Value

mixed

protected array _getPortableViewsList(array $views)

Parameters

array $views

Return Value

array

protected mixed _getPortableViewDefinition(array $view)

Parameters

array $view

Return Value

mixed

protected array _getPortableTableForeignKeysList(array $tableForeignKeys)

Parameters

array $tableForeignKeys

Return Value

array

protected mixed _getPortableTableForeignKeyDefinition(array $tableForeignKey)

Parameters

array $tableForeignKey

Return Value

mixed

protected void _execSql(array|string $sql)

Parameters

array|string $sql

Return Value

void

Schema createSchema()

Creates a schema instance for the current database.

Return Value

Schema

SchemaConfig createSchemaConfig()

Creates the configuration for this schema.

Return Value

SchemaConfig

array getSchemaSearchPaths()

Returns an array of schema search paths.

This is a PostgreSQL only function.

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

string removeDoctrineTypeFromComment(string $comment, string $type)

Parameters

string $comment
string $type

Return Value

string

array getSchemaNames()

Gets all the existing schema names.

Return Value

array

array getExistingSchemaSearchPaths()

Gets names of all existing schemas in the current users search path.

This is a PostgreSQL only function.

Return Value

array

void determineExistingSchemaSearchPaths()

Sets or resets the order of the existing schemas in the current search path of the user.

This is a PostgreSQL only function.

Return Value

void