Abstract Class Yiisoft\Db\Schema\AbstractSchema
| Inheritance | Yiisoft\Db\Schema\AbstractSchema |
|---|---|
| Implements | Yiisoft\Db\Schema\SchemaInterface |
| Subclasses | Yiisoft\Db\Driver\Pdo\AbstractPdoSchema |
Provides a set of methods for working with database schemas such as creating, modifying, and inspecting tables, columns, and other database objects.
It's a powerful and flexible tool that allows you to perform a wide range of database operations in a database-agnostic way.
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $db | Yiisoft\Db\Connection\ConnectionInterface | Yiisoft\Db\Schema\AbstractSchema | |
| $defaultSchema | string | The default schema name used for the current session. | Yiisoft\Db\Schema\AbstractSchema |
| $resultColumns | (Yiisoft\Db\Schema\Column\ColumnInterface|null)[] | Saved columns from query results. | Yiisoft\Db\Schema\AbstractSchema |
| $viewNames | string[][] | Yiisoft\Db\Schema\AbstractSchema |
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| clearFullName() | Clears the full name. Removes the schema name if it is the default schema name, removes curly brackets from the name, and replaces the percentage character '%' with {@see ConnectionInterface::getTablePrefix()}. | Yiisoft\Db\Schema\AbstractSchema |
| findConstraints() | Find and initialize table constraints. | Yiisoft\Db\Schema\AbstractSchema |
| findSchemaNames() | Returns all schema names in the database, including the default one but not system schemas. | Yiisoft\Db\Schema\AbstractSchema |
| findTableNames() | Returns all table names in the database. | Yiisoft\Db\Schema\AbstractSchema |
| findViewNames() | Find the view names for the database. | Yiisoft\Db\Schema\AbstractSchema |
| getCacheKey() | Yiisoft\Db\Schema\AbstractSchema | |
| getCacheTag() | Yiisoft\Db\Schema\AbstractSchema | |
| getResultColumnCacheKey() | Returns the cache key for the column metadata received from the query result. | Yiisoft\Db\Schema\AbstractSchema |
| getSchemaMetadata() | Returns the metadata of the given type for all tables in the given schema. | Yiisoft\Db\Schema\AbstractSchema |
| getTableMetadata() | Returns the metadata of the given type for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| getTableTypeMetadata() | This method returns the desired metadata type for table name (with refresh if needed). | Yiisoft\Db\Schema\AbstractSchema |
| loadResultColumn() | Creates a new column instance according to the column metadata received from the query result. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableChecks() | Loads all check constraints for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableDefaultValues() | Loads all default value constraints for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableForeignKeys() | Loads all foreign keys for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableIndexes() | Loads all indexes for the given table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableSchema() | Loads the metadata for the specified table. | Yiisoft\Db\Schema\AbstractSchema |
| loadTableTypeMetadata() | This method returns the desired metadata type for the table name. | Yiisoft\Db\Schema\AbstractSchema |
| resolveFullName() | Resolves the full table name, considering the default schema name. Removes curly brackets from the names, and replaces the percentage character '%' with {@see ConnectionInterface::getTablePrefix()}. | Yiisoft\Db\Schema\AbstractSchema |
| setTableMetadata() | Sets the metadata of the given type for the given table. | Yiisoft\Db\Schema\AbstractSchema |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| CACHE_VERSION | 'cacheVersion' | Yiisoft\Db\Schema\AbstractSchema | |
| CHECKS | 'checks' | The metadata type for retrieving the check constraint. | Yiisoft\Db\Schema\SchemaInterface |
| DEFAULTS | 'defaults' | The metadata type for retrieving the default constraint. | Yiisoft\Db\Schema\SchemaInterface |
| DEFAULT_VALUES | 'defaultValues' | The metadata type for retrieving the default values constraint. | Yiisoft\Db\Schema\SchemaInterface |
| FOREIGN_KEYS | 'foreignKeys' | The metadata type for retrieving the foreign key constraints. | Yiisoft\Db\Schema\SchemaInterface |
| INDEXES | 'indexes' | The metadata type for retrieving the index constraints. | Yiisoft\Db\Schema\SchemaInterface |
| PRIMARY_KEY | 'primaryKey' | The metadata type for retrieving the primary key constraint. | Yiisoft\Db\Schema\SchemaInterface |
| SCHEMA | 'schema' | The metadata type for retrieving the table schema. | Yiisoft\Db\Schema\SchemaInterface |
| SCHEMA_CACHE_VERSION | 1 | Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes. | Yiisoft\Db\Schema\AbstractSchema |
| UNIQUES | 'uniques' | The metadata type for retrieving the unique constraints. | Yiisoft\Db\Schema\SchemaInterface |
Property Details
The default schema name used for the current session.
Saved columns from query results.
Method Details
| public mixed __construct ( Yiisoft\Db\Connection\ConnectionInterface $db, Yiisoft\Db\Cache\SchemaCache $schemaCache ) | ||
| $db | Yiisoft\Db\Connection\ConnectionInterface | |
| $schemaCache | Yiisoft\Db\Cache\SchemaCache | |
public function __construct(protected ConnectionInterface $db, private SchemaCache $schemaCache) {}
Clears the full name. Removes the schema name if it is the default schema name, removes curly brackets from the name, and replaces the percentage character '%' with {@see ConnectionInterface::getTablePrefix()}.
| protected string clearFullName ( string $fullName ) | ||
| $fullName | string | |
protected function clearFullName(string $fullName): string
{
return $this->resolveFullName(...$this->db->getQuoter()->getTableNameParts($fullName));
}
| public void enableCache ( boolean $value ) | ||
| $value | boolean | |
public function enableCache(bool $value): void
{
$this->schemaCache->setEnabled($value);
}
Find and initialize table constraints.
| protected void findConstraints ( Yiisoft\Db\Schema\TableSchemaInterface $table ) | ||
| $table | Yiisoft\Db\Schema\TableSchemaInterface |
The table metadata. |
protected function findConstraints(TableSchemaInterface $table): void
{
$tableName = $this->resolveFullName($table->getName(), $table->getSchemaName());
$table->checks(...$this->getTableMetadata($tableName, SchemaInterface::CHECKS));
$table->defaultValues(...$this->getTableMetadata($tableName, SchemaInterface::DEFAULT_VALUES));
$table->foreignKeys(...$this->getTableMetadata($tableName, SchemaInterface::FOREIGN_KEYS));
$table->indexes(...$this->getTableMetadata($tableName, SchemaInterface::INDEXES));
}
Returns all schema names in the database, including the default one but not system schemas.
This method should be overridden by child classes to support this feature because the default implementation simply throws an exception.
| protected string[] findSchemaNames ( ) | ||
| return | string[] |
All schemas name in the database, except system schemas. |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
If the DBMS doesn't support this method. |
protected function findSchemaNames(): array
{
throw new NotSupportedException(static::class . ' does not support fetching all schema names.');
}
Returns all table names in the database.
This method should be overridden by child classes to support this feature because the default implementation simply throws an exception.
| protected string[] findTableNames ( string $schema ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema. |
| return | string[] |
All tables name in the database. The names have NO schema name prefix. |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
If the DBMS doesn't support this method. |
protected function findTableNames(string $schema): array
{
throw new NotSupportedException(static::class . ' does not support fetching all table names.');
}
Find the view names for the database.
| protected string[] findViewNames ( string $schema = '' ) | ||
| $schema | string |
The schema of the views. Defaults to empty string, meaning the current or default schema. |
| return | string[] |
The names of all views in the database. |
|---|---|---|
protected function findViewNames(string $schema = ''): array
{
return [];
}
| protected abstract array getCacheKey ( string $name ) | ||
| $name | string |
The table name. |
| return | array |
The cache key for the specified table name. |
|---|---|---|
abstract protected function getCacheKey(string $name): array;
| protected abstract string getCacheTag ( ) | ||
| return | string |
The cache tag name. This allows {@see \Yiisoft\Db\Schema\refresh()} to invalidate all cached table schemas. |
|---|---|---|
abstract protected function getCacheTag(): string;
| public integer getDataType ( mixed $data ) | ||
| $data | mixed | |
public function getDataType(mixed $data): int
{
return match (gettype($data)) {
// php type => SQL data type
GettypeResult::BOOLEAN => DataType::BOOLEAN,
GettypeResult::INTEGER => DataType::INTEGER,
GettypeResult::RESOURCE => DataType::LOB,
GettypeResult::NULL => DataType::NULL,
default => DataType::STRING,
};
}
| public string getDefaultSchema ( ) |
public function getDefaultSchema(): string
{
return $this->defaultSchema;
}
| public Yiisoft\Db\Schema\Column\ColumnInterface|null getResultColumn ( array $metadata ) | ||
| $metadata | array | |
final public function getResultColumn(array $metadata): ?ColumnInterface
{
if (empty($metadata)) {
return null;
}
$cacheKey = $this->getResultColumnCacheKey($metadata);
if (array_key_exists($cacheKey, $this->resultColumns)) {
return $this->resultColumns[$cacheKey];
}
$isCacheEnabled = $this->schemaCache->isEnabled();
if ($isCacheEnabled) {
/** @var ColumnInterface */
$this->resultColumns[$cacheKey] = $this->schemaCache->get($cacheKey);
if (isset($this->resultColumns[$cacheKey])) {
return $this->resultColumns[$cacheKey];
}
}
$column = $this->loadResultColumn($metadata);
$this->resultColumns[$cacheKey] = $column;
if ($column !== null && $isCacheEnabled) {
$this->schemaCache->set($cacheKey, $column, $this->getCacheTag());
}
return $column;
}
Returns the cache key for the column metadata received from the query result.
| protected abstract string getResultColumnCacheKey ( array $metadata ) | ||
| $metadata | array |
The column metadata from the query result. |
abstract protected function getResultColumnCacheKey(array $metadata): string;
| public array getSchemaChecks ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaChecks(string $schema = '', bool $refresh = false): array
{
/** @var Check[] */
return $this->getSchemaMetadata($schema, SchemaInterface::CHECKS, $refresh);
}
| public array getSchemaDefaultValues ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaDefaultValues(string $schema = '', bool $refresh = false): array
{
/** @var DefaultValue[] */
return $this->getSchemaMetadata($schema, SchemaInterface::DEFAULT_VALUES, $refresh);
}
| public array getSchemaForeignKeys ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaForeignKeys(string $schema = '', bool $refresh = false): array
{
/** @var ForeignKey[] */
return $this->getSchemaMetadata($schema, SchemaInterface::FOREIGN_KEYS, $refresh);
}
| public array getSchemaIndexes ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaIndexes(string $schema = '', bool $refresh = false): array
{
/** @var Index[] */
return $this->getSchemaMetadata($schema, SchemaInterface::INDEXES, $refresh);
}
Returns the metadata of the given type for all tables in the given schema.
| protected Yiisoft\Db\Constraint\Check[][]|Yiisoft\Db\Constraint\DefaultValue[][]|Yiisoft\Db\Constraint\ForeignKey[][]|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Constraint\Index[][]|Yiisoft\Db\Schema\TableSchemaInterface[] getSchemaMetadata ( string $schema, string $type, boolean $refresh ) | ||
| $schema | string |
The schema of the metadata. Defaults to empty string, meaning the current or default schema name. |
| $type | string |
The metadata type. |
| $refresh | boolean |
Whether to fetch the latest available table metadata. If this is |
| return | Yiisoft\Db\Constraint\Check[][]|Yiisoft\Db\Constraint\DefaultValue[][]|Yiisoft\Db\Constraint\ForeignKey[][]|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Constraint\Index[][]|Yiisoft\Db\Schema\TableSchemaInterface[] |
The metadata of the given type for all tables in the given schema. |
|---|---|---|
protected function getSchemaMetadata(string $schema, string $type, bool $refresh): array
{
$metadata = [];
$quoter = $this->db->getQuoter();
$tableNames = $this->getTableNames($schema, $refresh);
foreach ($tableNames as $name) {
$name = $quoter->quoteSimpleTableName($name);
if ($schema !== '') {
$name = $schema . '.' . $name;
}
$tableMetadata = $this->getTableTypeMetadata($type, $name, $refresh);
if ($tableMetadata !== null) {
$metadata[] = $tableMetadata;
}
}
return $metadata;
}
| public array getSchemaNames ( boolean $refresh = false ) | ||
| $refresh | boolean | |
public function getSchemaNames(bool $refresh = false): array
{
if (empty($this->schemaNames) || $refresh) {
$this->schemaNames = $this->findSchemaNames();
}
return $this->schemaNames;
}
| public array getSchemaPrimaryKeys ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaPrimaryKeys(string $schema = '', bool $refresh = false): array
{
/** @var Index[] */
return $this->getSchemaMetadata($schema, SchemaInterface::PRIMARY_KEY, $refresh);
}
| public array getSchemaUniques ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getSchemaUniques(string $schema = '', bool $refresh = false): array
{
/** @var Index[] */
return $this->getSchemaMetadata($schema, SchemaInterface::UNIQUES, $refresh);
}
| public array getTableChecks ( string $name, boolean $refresh = false ) | ||
| $name | string | |
| $refresh | boolean | |
public function getTableChecks(string $name, bool $refresh = false): array
{
/** @var Check[] */
return $this->getTableMetadata($this->clearFullName($name), SchemaInterface::CHECKS, $refresh);
}
| public array getTableDefaultValues ( string $name, boolean $refresh = false ) | ||
| $name | string | |
| $refresh | boolean | |
public function getTableDefaultValues(string $name, bool $refresh = false): array
{
/** @var DefaultValue[] */
return $this->getTableMetadata($this->clearFullName($name), SchemaInterface::DEFAULT_VALUES, $refresh);
}
| public array getTableForeignKeys ( string $name, boolean $refresh = false ) | ||
| $name | string | |
| $refresh | boolean | |
public function getTableForeignKeys(string $name, bool $refresh = false): array
{
/** @var ForeignKey[] */
return $this->getTableMetadata($this->clearFullName($name), SchemaInterface::FOREIGN_KEYS, $refresh);
}
| public array getTableIndexes ( string $name, boolean $refresh = false ) | ||
| $name | string | |
| $refresh | boolean | |
public function getTableIndexes(string $name, bool $refresh = false): array
{
/** @var Index[] */
return $this->getTableMetadata($this->clearFullName($name), SchemaInterface::INDEXES, $refresh);
}
Returns the metadata of the given type for the given table.
| protected Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null getTableMetadata ( string $name, string $type, boolean $refresh = false ) | ||
| $name | string |
The table name. The table name may contain a schema name if any. Don't quote the table name. |
| $type | string |
The metadata type. |
| $refresh | boolean |
Whether to reload the table metadata even if it's found in the cache. |
| return | Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null |
The metadata of the given type for the given table. |
|---|---|---|
protected function getTableMetadata(
string $name,
string $type,
bool $refresh = false,
): array|Index|TableSchemaInterface|null {
if (!isset($this->tableMetadata[$name])) {
$this->loadTableMetadataFromCache($name);
}
if ($refresh || !isset($this->tableMetadata[$name][$type])) {
$this->tableMetadata[$name][$type] = $this->loadTableTypeMetadata($type, $name);
$this->saveTableMetadataToCache($name);
}
return $this->tableMetadata[$name][$type];
}
| public array getTableNames ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getTableNames(string $schema = '', bool $refresh = false): array
{
if (!isset($this->tableNames[$schema]) || $refresh) {
$this->tableNames[$schema] = $this->findTableNames($schema);
}
return $this->tableNames[$schema];
}
| public Yiisoft\Db\Constraint\Index|null getTablePrimaryKey ( string $name, boolean $refresh = false ) | ||
| $name | string | |
| $refresh | boolean | |
public function getTablePrimaryKey(string $name, bool $refresh = false): ?Index
{
foreach ($this->getTableIndexes($name, $refresh) as $index) {
if ($index->isPrimaryKey) {
return $index;
}
}
return null;
}
| public Yiisoft\Db\Schema\TableSchemaInterface|null getTableSchema ( string $name, boolean $refresh = false ) | ||
| $name | string | |
| $refresh | boolean | |
public function getTableSchema(string $name, bool $refresh = false): ?TableSchemaInterface
{
$rawName = $this->clearFullName($name);
if ($refresh) {
// Some constraints are loading and caching together.
// Reset the table constraint cache to load them without refreshing.
$this->tableMetadata[$rawName] = [];
if ($this->schemaCache->isEnabled()) {
$this->schemaCache->remove($this->getCacheKey($rawName));
}
}
/** @var TableSchemaInterface|null */
return $this->getTableMetadata($rawName, SchemaInterface::SCHEMA, $refresh);
}
| public array getTableSchemas ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getTableSchemas(string $schema = '', bool $refresh = false): array
{
/** @var TableSchemaInterface[] */
return $this->getSchemaMetadata($schema, SchemaInterface::SCHEMA, $refresh);
}
This method returns the desired metadata type for table name (with refresh if needed).
| protected Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null getTableTypeMetadata ( string $type, string $name, boolean $refresh = false ) | ||
| $type | string | |
| $name | string | |
| $refresh | boolean | |
protected function getTableTypeMetadata(
string $type,
string $name,
bool $refresh = false,
): array|Index|TableSchemaInterface|null {
return match ($type) {
SchemaInterface::SCHEMA => $this->getTableSchema($name, $refresh),
SchemaInterface::PRIMARY_KEY => $this->getTablePrimaryKey($name, $refresh),
SchemaInterface::UNIQUES => $this->getTableUniques($name, $refresh),
SchemaInterface::FOREIGN_KEYS => $this->getTableForeignKeys($name, $refresh),
SchemaInterface::INDEXES => $this->getTableIndexes($name, $refresh),
SchemaInterface::DEFAULT_VALUES => $this->getTableDefaultValues($name, $refresh),
SchemaInterface::CHECKS => $this->getTableChecks($name, $refresh),
default => null,
};
}
| public array getTableUniques ( string $name, boolean $refresh = false ) | ||
| $name | string | |
| $refresh | boolean | |
public function getTableUniques(string $name, bool $refresh = false): array
{
return array_filter(
$this->getTableIndexes($name, $refresh),
static fn(Index $index): bool => $index->isUnique,
);
}
| public array getViewNames ( string $schema = '', boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function getViewNames(string $schema = '', bool $refresh = false): array
{
if (!isset($this->viewNames[$schema]) || $refresh) {
$this->viewNames[$schema] = $this->findViewNames($schema);
}
return $this->viewNames[$schema];
}
| public boolean hasSchema ( string $schema, boolean $refresh = false ) | ||
| $schema | string | |
| $refresh | boolean | |
public function hasSchema(string $schema, bool $refresh = false): bool
{
$schemas = $this->getSchemaNames($refresh);
return in_array($schema, $schemas);
}
| public boolean hasTable ( string $tableName, string $schema = '', boolean $refresh = false ) | ||
| $tableName | string | |
| $schema | string | |
| $refresh | boolean | |
public function hasTable(string $tableName, string $schema = '', bool $refresh = false): bool
{
$tables = $this->getTableNames($schema, $refresh);
$rawTableName = $this->db->getQuoter()->getRawTableName($tableName);
return in_array($rawTableName, $tables);
}
| public boolean hasView ( string $viewName, string $schema = '', boolean $refresh = false ) | ||
| $viewName | string | |
| $schema | string | |
| $refresh | boolean | |
public function hasView(string $viewName, string $schema = '', bool $refresh = false): bool
{
$views = $this->getViewNames($schema, $refresh);
$rawViewName = $this->db->getQuoter()->getRawTableName($viewName);
return in_array($rawViewName, $views);
}
Creates a new column instance according to the column metadata received from the query result.
| protected abstract Yiisoft\Db\Schema\Column\ColumnInterface|null loadResultColumn ( array $metadata ) | ||
| $metadata | array |
The column metadata from the query result. |
abstract protected function loadResultColumn(array $metadata): ?ColumnInterface;
Loads all check constraints for the given table.
| protected abstract Yiisoft\Db\Constraint\Check[] loadTableChecks ( string $tableName ) | ||
| $tableName | string |
The table name. |
| return | Yiisoft\Db\Constraint\Check[] |
The check constraints for the given table. |
|---|---|---|
abstract protected function loadTableChecks(string $tableName): array;
Loads all default value constraints for the given table.
| protected abstract Yiisoft\Db\Constraint\DefaultValue[] loadTableDefaultValues ( string $tableName ) | ||
| $tableName | string |
The table name. |
| return | Yiisoft\Db\Constraint\DefaultValue[] |
The default value constraints for the given table. |
|---|---|---|
abstract protected function loadTableDefaultValues(string $tableName): array;
Loads all foreign keys for the given table.
| protected abstract Yiisoft\Db\Constraint\ForeignKey[] loadTableForeignKeys ( string $tableName ) | ||
| $tableName | string |
The table name. |
| return | Yiisoft\Db\Constraint\ForeignKey[] |
The foreign keys for the given table, indexed by constraint name. |
|---|---|---|
abstract protected function loadTableForeignKeys(string $tableName): array;
Loads all indexes for the given table.
| protected abstract Yiisoft\Db\Constraint\Index[] loadTableIndexes ( string $tableName ) | ||
| $tableName | string |
The table name. |
| return | Yiisoft\Db\Constraint\Index[] |
The indexes for the given table. |
|---|---|---|
abstract protected function loadTableIndexes(string $tableName): array;
Loads the metadata for the specified table.
| protected abstract Yiisoft\Db\Schema\TableSchemaInterface|null loadTableSchema ( string $name ) | ||
| $name | string |
The table name. |
| return | Yiisoft\Db\Schema\TableSchemaInterface|null |
DBMS-dependent table metadata, |
|---|---|---|
abstract protected function loadTableSchema(string $name): ?TableSchemaInterface;
This method returns the desired metadata type for the table name.
| protected Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null loadTableTypeMetadata ( string $type, string $name ) | ||
| $type | string | |
| $name | string | |
protected function loadTableTypeMetadata(string $type, string $name): array|TableSchemaInterface|null
{
return match ($type) {
SchemaInterface::SCHEMA => $this->loadTableSchema($name),
SchemaInterface::FOREIGN_KEYS => $this->loadTableForeignKeys($name),
SchemaInterface::INDEXES => $this->loadTableIndexes($name),
SchemaInterface::DEFAULT_VALUES => $this->loadTableDefaultValues($name),
SchemaInterface::CHECKS => $this->loadTableChecks($name),
default => null,
};
}
| public void refresh ( ) |
public function refresh(): void
{
if ($this->schemaCache->isEnabled()) {
$this->schemaCache->invalidate($this->getCacheTag());
}
$this->tableNames = [];
$this->tableMetadata = [];
$this->schemaNames = [];
$this->viewNames = [];
$this->resultColumns = [];
}
| public void refreshTableSchema ( string $name ) | ||
| $name | string | |
public function refreshTableSchema(string $name): void
{
$rawName = $this->clearFullName($name);
unset($this->tableMetadata[$rawName]);
$this->tableNames = [];
$this->viewNames = [];
if ($this->schemaCache->isEnabled()) {
$this->schemaCache->remove($this->getCacheKey($rawName));
}
}
Resolves the full table name, considering the default schema name. Removes curly brackets from the names, and replaces the percentage character '%' with {@see ConnectionInterface::getTablePrefix()}.
| protected string resolveFullName ( string $name, string $schemaName = '' ) | ||
| $name | string | |
| $schemaName | string | |
protected function resolveFullName(string $name, string $schemaName = ''): string
{
$quoter = $this->db->getQuoter();
$rawName = $quoter->getRawTableName($name);
return match ($schemaName) {
'', $this->defaultSchema => $rawName,
default => $quoter->getRawTableName($schemaName) . ".$rawName",
};
}
Sets the metadata of the given type for the given table.
| protected void setTableMetadata ( string $rawName, string $type, Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null $data ) | ||
| $rawName | string |
The raw table name. |
| $type | string |
The metadata type. |
| $data | Yiisoft\Db\Constraint\Check[]|Yiisoft\Db\Constraint\DefaultValue[]|Yiisoft\Db\Constraint\ForeignKey[]|Yiisoft\Db\Constraint\Index|Yiisoft\Db\Constraint\Index[]|Yiisoft\Db\Schema\TableSchemaInterface|null |
The metadata to set. |
protected function setTableMetadata(
string $rawName,
string $type,
array|Index|TableSchemaInterface|null $data,
): void {
$this->tableMetadata[$rawName][$type] = $data;
}
Signup or Login in order to comment.