class Schema extends AbstractAsset (View source)

Object representation of a database schema.

Different vendors have very inconsistent naming with regard to the concept of a "schema". Doctrine understands a schema as the entity that conceptually wraps a set of database objects such as tables, sequences, indexes and foreign keys that belong to each other into a namespace. A Doctrine Schema has nothing to do with the "SCHEMA" defined as in PostgreSQL, it is more related to the concept of "DATABASE" that exists in MySQL and PostgreSQL.

Every asset in the doctrine schema has a name. A name consists of either a namespace.local name pair or just a local unqualified name.

The abstraction layer that covers a PostgreSQL schema is the namespace of an database object (asset). A schema can have a name, which will be used as default namespace for the unqualified database objects that are created in the schema.

In the case of MySQL where cross-database queries are allowed this leads to databases being "misinterpreted" as namespaces. This is intentional, however the CREATE/DROP SQL visitors will just filter this queries and do not execute them. Only the queries for the currently connected database are executed.

Properties

protected string $_name from AbstractAsset
protected string|null $_namespace Namespace of the asset. If none isset the default namespace is assumed. from AbstractAsset
protected bool $_quoted from AbstractAsset
protected Table[] $_tables
protected Sequence[] $_sequences
protected SchemaConfig $_schemaConfig

Methods

void
_setName(string $name)

Sets the name of this asset.

bool
isInDefaultNamespace(string $defaultNamespaceName)

Is this asset in the default namespace?

string|null
getNamespaceName()

Gets the namespace name of this asset.

string
getShortestName(string $defaultNamespaceName)

The shortest name is stripped of the default namespace. All other namespaced elements are returned as full-qualified names.

string
getFullQualifiedName(string $defaultNamespaceName)

The normalized name is full-qualified and lowerspaced. Lowerspacing is actually wrong, but we have to do it to keep our sanity. If you are using database objects that only differentiate in the casing (FOO vs Foo) then you will NOT be able to use Doctrine Schema abstraction.

bool
isQuoted()

Checks if this asset's name is quoted.

bool
isIdentifierQuoted(string $identifier)

Checks if this identifier is quoted.

string
trimQuotes(string $identifier)

Trim quotes from the identifier.

string
getName()

Returns the name of this schema asset.

string
getQuotedName(AbstractPlatform $platform)

Gets the quoted representation of this asset but only if it was defined with one. Otherwise return the plain unquoted value as inserted.

string
_generateIdentifierName(array $columnNames, string $prefix = '', int $maxSize = 30)

Generates an identifier from a list of column names obeying a certain string length.

__construct(array $tables = [], array $sequences = [], SchemaConfig $schemaConfig = null, array $namespaces = [])

No description

bool
hasExplicitForeignKeyIndexes()

No description

void
_addTable(Table $table)

No description

void
_addSequence(Sequence $sequence)

No description

array
getNamespaces()

Returns the namespaces of this schema.

Table[]
getTables()

Gets all tables of this schema.

getTable(string $tableName)

No description

bool
hasNamespace(string $namespaceName)

Does this schema have a namespace with the given name?

bool
hasTable(string $tableName)

Does this schema have a table with the given name?

array
getTableNames()

Gets all table names, prefixed with a schema name, even the default one if present.

bool
hasSequence(string $sequenceName)

No description

getSequence(string $sequenceName)

No description

getSequences()

No description

createNamespace(string $namespaceName)

Creates a new namespace.

createTable(string $tableName)

Creates a new table.

renameTable(string $oldTableName, string $newTableName)

Renames a table.

dropTable(string $tableName)

Drops a table from the schema.

createSequence(string $sequenceName, int $allocationSize = 1, int $initialValue = 1)

Creates a new sequence.

dropSequence(string $sequenceName)

No description

array
toSql(AbstractPlatform $platform)

Returns an array of necessary SQL queries to create the schema on the given platform.

array
toDropSql(AbstractPlatform $platform)

Return an array of necessary SQL queries to drop the schema on the given platform.

array
getMigrateToSql(Schema $toSchema, AbstractPlatform $platform)

No description

array
getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform)

No description

void
visit(Visitor $visitor)

No description

void
__clone()

Cloning a Schema triggers a deep clone of all related assets.

Details

protected void _setName(string $name)

Sets the name of this asset.

Parameters

string $name

Return Value

void

bool isInDefaultNamespace(string $defaultNamespaceName)

Is this asset in the default namespace?

Parameters

string $defaultNamespaceName

Return Value

bool

string|null getNamespaceName()

Gets the namespace name of this asset.

If NULL is returned this means the default namespace is used.

Return Value

string|null

string getShortestName(string $defaultNamespaceName)

The shortest name is stripped of the default namespace. All other namespaced elements are returned as full-qualified names.

Parameters

string $defaultNamespaceName

Return Value

string

string getFullQualifiedName(string $defaultNamespaceName)

The normalized name is full-qualified and lowerspaced. Lowerspacing is actually wrong, but we have to do it to keep our sanity. If you are using database objects that only differentiate in the casing (FOO vs Foo) then you will NOT be able to use Doctrine Schema abstraction.

Every non-namespaced element is prefixed with the default namespace name which is passed as argument to this method.

Parameters

string $defaultNamespaceName

Return Value

string

bool isQuoted()

Checks if this asset's name is quoted.

Return Value

bool

protected bool isIdentifierQuoted(string $identifier)

Checks if this identifier is quoted.

Parameters

string $identifier

Return Value

bool

protected string trimQuotes(string $identifier)

Trim quotes from the identifier.

Parameters

string $identifier

Return Value

string

string getName()

Returns the name of this schema asset.

Return Value

string

string getQuotedName(AbstractPlatform $platform)

Gets the quoted representation of this asset but only if it was defined with one. Otherwise return the plain unquoted value as inserted.

Parameters

AbstractPlatform $platform

Return Value

string

protected string _generateIdentifierName(array $columnNames, string $prefix = '', int $maxSize = 30)

Generates an identifier from a list of column names obeying a certain string length.

This is especially important for Oracle, since it does not allow identifiers larger than 30 chars, however building idents automatically for foreign keys, composite keys or such can easily create very long names.

Parameters

array $columnNames
string $prefix
int $maxSize

Return Value

string

__construct(array $tables = [], array $sequences = [], SchemaConfig $schemaConfig = null, array $namespaces = [])

Parameters

array $tables
array $sequences
SchemaConfig $schemaConfig
array $namespaces

bool hasExplicitForeignKeyIndexes()

Return Value

bool

protected void _addTable(Table $table)

Parameters

Table $table

Return Value

void

Exceptions

SchemaException

protected void _addSequence(Sequence $sequence)

Parameters

Sequence $sequence

Return Value

void

Exceptions

SchemaException

array getNamespaces()

Returns the namespaces of this schema.

Return Value

array A list of namespace names.

Table[] getTables()

Gets all tables of this schema.

Return Value

Table[]

Table getTable(string $tableName)

Parameters

string $tableName

Return Value

Table

Exceptions

SchemaException

bool hasNamespace(string $namespaceName)

Does this schema have a namespace with the given name?

Parameters

string $namespaceName

Return Value

bool

bool hasTable(string $tableName)

Does this schema have a table with the given name?

Parameters

string $tableName

Return Value

bool

array getTableNames()

Gets all table names, prefixed with a schema name, even the default one if present.

Return Value

array

bool hasSequence(string $sequenceName)

Parameters

string $sequenceName

Return Value

bool

Sequence getSequence(string $sequenceName)

Parameters

string $sequenceName

Return Value

Sequence

Exceptions

SchemaException

Sequence[] getSequences()

Return Value

Sequence[]

Schema createNamespace(string $namespaceName)

Creates a new namespace.

Parameters

string $namespaceName The name of the namespace to create.

Return Value

Schema This schema instance.

Exceptions

SchemaException

Table createTable(string $tableName)

Creates a new table.

Parameters

string $tableName

Return Value

Table

Schema renameTable(string $oldTableName, string $newTableName)

Renames a table.

Parameters

string $oldTableName
string $newTableName

Return Value

Schema

Schema dropTable(string $tableName)

Drops a table from the schema.

Parameters

string $tableName

Return Value

Schema

Sequence createSequence(string $sequenceName, int $allocationSize = 1, int $initialValue = 1)

Creates a new sequence.

Parameters

string $sequenceName
int $allocationSize
int $initialValue

Return Value

Sequence

Schema dropSequence(string $sequenceName)

Parameters

string $sequenceName

Return Value

Schema

array toSql(AbstractPlatform $platform)

Returns an array of necessary SQL queries to create the schema on the given platform.

Parameters

AbstractPlatform $platform

Return Value

array

array toDropSql(AbstractPlatform $platform)

Return an array of necessary SQL queries to drop the schema on the given platform.

Parameters

AbstractPlatform $platform

Return Value

array

array getMigrateToSql(Schema $toSchema, AbstractPlatform $platform)

Parameters

Schema $toSchema
AbstractPlatform $platform

Return Value

array

array getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform)

Parameters

Schema $fromSchema
AbstractPlatform $platform

Return Value

array

void visit(Visitor $visitor)

Parameters

Visitor $visitor

Return Value

void

void __clone()

Cloning a Schema triggers a deep clone of all related assets.

Return Value

void