Schema
extends AbstractAsset
in package
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.
Table of Contents
Properties
- $_name : string
- $_namespace : string|null
- Namespace of the asset. If none isset the default namespace is assumed.
- $_quoted : bool
- $_schemaConfig : SchemaConfig
- $_sequences : array<string|int, Sequence>
- $_tables : array<string|int, Table>
- $namespaces : array<string|int, string>
- The namespaces in this schema.
Methods
- __clone() : void
- Cloning a Schema triggers a deep clone of all related assets.
- __construct() : mixed
- createNamespace() : Schema
- Creates a new namespace.
- createSequence() : Sequence
- Creates a new sequence.
- createTable() : Table
- Creates a new table.
- dropSequence() : Schema
- dropTable() : Schema
- Drops a table from the schema.
- getFullQualifiedName() : string
- The normalized name is full-qualified and lower-cased. Lower-casing 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.
- getMigrateFromSql() : array<string|int, string>
- getMigrateToSql() : array<string|int, string>
- getName() : string
- Returns the name of this schema asset.
- getNamespaceName() : string|null
- Gets the namespace name of this asset.
- getNamespaces() : array<string|int, string>
- Returns the namespaces of this schema.
- getQuotedName() : string
- Gets the quoted representation of this asset but only if it was defined with one. Otherwise return the plain unquoted value as inserted.
- getSequence() : Sequence
- getSequences() : array<string|int, Sequence>
- getShortestName() : string
- The shortest name is stripped of the default namespace. All other namespaced elements are returned as full-qualified names.
- getTable() : Table
- getTableNames() : array<string|int, string>
- Gets all table names, prefixed with a schema name, even the default one if present.
- getTables() : array<string|int, Table>
- Gets all tables of this schema.
- hasExplicitForeignKeyIndexes() : bool
- hasNamespace() : bool
- Does this schema have a namespace with the given name?
- hasSequence() : bool
- hasTable() : bool
- Does this schema have a table with the given name?
- isInDefaultNamespace() : bool
- Is this asset in the default namespace?
- isQuoted() : bool
- Checks if this asset's name is quoted.
- renameTable() : Schema
- Renames a table.
- toDropSql() : array<int, string>
- Return an array of necessary SQL queries to drop the schema on the given platform.
- toSql() : array<int, string>
- Returns an array of necessary SQL queries to create the schema on the given platform.
- visit() : void
- _addSequence() : void
- _addTable() : void
- _generateIdentifierName() : string
- Generates an identifier from a list of column names obeying a certain string length.
- _setName() : void
- Sets the name of this asset.
- isIdentifierQuoted() : bool
- Checks if this identifier is quoted.
- trimQuotes() : string
- Trim quotes from the identifier.
- getFullQualifiedAssetName() : string
- getUnquotedAssetName() : string
- Returns the unquoted representation of a given asset name.
- normalizeName() : string
Properties
$_name
protected
string
$_name
= ''
$_namespace
Namespace of the asset. If none isset the default namespace is assumed.
protected
string|null
$_namespace
$_quoted
protected
bool
$_quoted
= false
$_schemaConfig
protected
SchemaConfig
$_schemaConfig
$_sequences
protected
array<string|int, Sequence>
$_sequences
= []
$_tables
protected
array<string|int, Table>
$_tables
= []
$namespaces
The namespaces in this schema.
private
array<string|int, string>
$namespaces
= []
Methods
__clone()
Cloning a Schema triggers a deep clone of all related assets.
public
__clone() : void
__construct()
public
__construct([array<string|int, Table> $tables = [] ][, array<string|int, Sequence> $sequences = [] ][, SchemaConfig|null $schemaConfig = null ][, array<string|int, string> $namespaces = [] ]) : mixed
Parameters
- $tables : array<string|int, Table> = []
- $sequences : array<string|int, Sequence> = []
- $schemaConfig : SchemaConfig|null = null
- $namespaces : array<string|int, string> = []
Tags
createNamespace()
Creates a new namespace.
public
createNamespace(string $name) : Schema
Parameters
- $name : string
-
The name of the namespace to create.
Tags
Return values
Schema —This schema instance.
createSequence()
Creates a new sequence.
public
createSequence(string $name[, int $allocationSize = 1 ][, int $initialValue = 1 ]) : Sequence
Parameters
- $name : string
- $allocationSize : int = 1
- $initialValue : int = 1
Tags
Return values
SequencecreateTable()
Creates a new table.
public
createTable(string $name) : Table
Parameters
- $name : string
Tags
Return values
TabledropSequence()
public
dropSequence(string $name) : Schema
Parameters
- $name : string
Return values
SchemadropTable()
Drops a table from the schema.
public
dropTable(string $name) : Schema
Parameters
- $name : string
Tags
Return values
SchemagetFullQualifiedName()
The normalized name is full-qualified and lower-cased. Lower-casing 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.
public
getFullQualifiedName(string $defaultNamespaceName) : string
Every non-namespaced element is prefixed with the default namespace name which is passed as argument to this method.
Parameters
- $defaultNamespaceName : string
Tags
Return values
stringgetMigrateFromSql()
public
getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) : array<string|int, string>
Parameters
- $fromSchema : Schema
- $platform : AbstractPlatform
Tags
Return values
array<string|int, string>getMigrateToSql()
public
getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) : array<string|int, string>
Parameters
- $toSchema : Schema
- $platform : AbstractPlatform
Tags
Return values
array<string|int, string>getName()
Returns the name of this schema asset.
public
getName() : string
Return values
stringgetNamespaceName()
Gets the namespace name of this asset.
public
getNamespaceName() : string|null
If NULL is returned this means the default namespace is used.
Return values
string|nullgetNamespaces()
Returns the namespaces of this schema.
public
getNamespaces() : array<string|int, string>
Return values
array<string|int, string> —A list of namespace names.
getQuotedName()
Gets the quoted representation of this asset but only if it was defined with one. Otherwise return the plain unquoted value as inserted.
public
getQuotedName(AbstractPlatform $platform) : string
Parameters
- $platform : AbstractPlatform
Return values
stringgetSequence()
public
getSequence(string $name) : Sequence
Parameters
- $name : string
Tags
Return values
SequencegetSequences()
public
getSequences() : array<string|int, Sequence>
Return values
array<string|int, Sequence>getShortestName()
The shortest name is stripped of the default namespace. All other namespaced elements are returned as full-qualified names.
public
getShortestName(string|null $defaultNamespaceName) : string
Parameters
- $defaultNamespaceName : string|null
Return values
stringgetTable()
public
getTable(string $name) : Table
Parameters
- $name : string
Tags
Return values
TablegetTableNames()
Gets all table names, prefixed with a schema name, even the default one if present.
public
getTableNames() : array<string|int, string>
Tags
Return values
array<string|int, string>getTables()
Gets all tables of this schema.
public
getTables() : array<string|int, Table>
Return values
array<string|int, Table>hasExplicitForeignKeyIndexes()
public
hasExplicitForeignKeyIndexes() : bool
Tags
Return values
boolhasNamespace()
Does this schema have a namespace with the given name?
public
hasNamespace(string $name) : bool
Parameters
- $name : string
Return values
boolhasSequence()
public
hasSequence(string $name) : bool
Parameters
- $name : string
Return values
boolhasTable()
Does this schema have a table with the given name?
public
hasTable(string $name) : bool
Parameters
- $name : string
Return values
boolisInDefaultNamespace()
Is this asset in the default namespace?
public
isInDefaultNamespace(string $defaultNamespaceName) : bool
Parameters
- $defaultNamespaceName : string
Return values
boolisQuoted()
Checks if this asset's name is quoted.
public
isQuoted() : bool
Return values
boolrenameTable()
Renames a table.
public
renameTable(string $oldName, string $newName) : Schema
Parameters
- $oldName : string
- $newName : string
Tags
Return values
SchematoDropSql()
Return an array of necessary SQL queries to drop the schema on the given platform.
public
toDropSql(AbstractPlatform $platform) : array<int, string>
Parameters
- $platform : AbstractPlatform
Tags
Return values
array<int, string>toSql()
Returns an array of necessary SQL queries to create the schema on the given platform.
public
toSql(AbstractPlatform $platform) : array<int, string>
Parameters
- $platform : AbstractPlatform
Tags
Return values
array<int, string>visit()
public
visit(Visitor $visitor) : void
Parameters
- $visitor : Visitor
Tags
_addSequence()
protected
_addSequence(Sequence $sequence) : void
Parameters
- $sequence : Sequence
Tags
_addTable()
protected
_addTable(Table $table) : void
Parameters
- $table : Table
Tags
_generateIdentifierName()
Generates an identifier from a list of column names obeying a certain string length.
protected
_generateIdentifierName(array<string|int, string> $columnNames[, string $prefix = '' ][, int $maxSize = 30 ]) : string
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
- $columnNames : array<string|int, string>
- $prefix : string = ''
- $maxSize : int = 30
Return values
string_setName()
Sets the name of this asset.
protected
_setName(string $name) : void
Parameters
- $name : string
isIdentifierQuoted()
Checks if this identifier is quoted.
protected
isIdentifierQuoted(string $identifier) : bool
Parameters
- $identifier : string
Return values
booltrimQuotes()
Trim quotes from the identifier.
protected
trimQuotes(string $identifier) : string
Parameters
- $identifier : string
Return values
stringgetFullQualifiedAssetName()
private
getFullQualifiedAssetName(string $name) : string
Parameters
- $name : string
Return values
stringgetUnquotedAssetName()
Returns the unquoted representation of a given asset name.
private
getUnquotedAssetName(string $assetName) : string
Parameters
- $assetName : string
-
Quoted or unquoted representation of an asset name.
Return values
stringnormalizeName()
private
normalizeName(AbstractAsset $asset) : string
Parameters
- $asset : AbstractAsset