0 follower

Abstract Class Yiisoft\Db\Driver\Pdo\AbstractPdoSchema

InheritanceYiisoft\Db\Driver\Pdo\AbstractPdoSchema » Yiisoft\Db\Schema\AbstractSchema
ImplementsYiisoft\Db\Schema\SchemaInterface

Represents a schema for a PDO (PHP Data Object) connection.

Protected Methods

Hide inherited 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
generateCacheKey() Generates the cache key for the current connection. Yiisoft\Db\Driver\Pdo\AbstractPdoSchema
getCacheKey() Yiisoft\Db\Driver\Pdo\AbstractPdoSchema
getCacheTag() Yiisoft\Db\Driver\Pdo\AbstractPdoSchema
getResultColumnCacheKey() Yiisoft\Db\Driver\Pdo\AbstractPdoSchema
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

Hide inherited 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

Method Details

Hide inherited methods

__construct() public method
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) {}

            
clearFullName() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::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()}.

protected string clearFullName ( string $fullName )
$fullName string

                protected function clearFullName(string $fullName): string
{
    return $this->resolveFullName(...$this->db->getQuoter()->getTableNameParts($fullName));
}

            
enableCache() public method
public void enableCache ( boolean $value )
$value boolean

                public function enableCache(bool $value): void
{
    $this->schemaCache->setEnabled($value);
}

            
findConstraints() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::findConstraints()

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));
}

            
findSchemaNames() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::findSchemaNames()

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.');
}

            
findTableNames() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::findTableNames()

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.');
}

            
findViewNames() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::findViewNames()

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 [];
}

            
generateCacheKey() protected method

Generates the cache key for the current connection.

protected array generateCacheKey ( )
return array

The cache key.

throws Yiisoft\Db\Exception\NotSupportedException

If the connection is not a PDO connection.

                protected function generateCacheKey(): array
{
    if ($this->db instanceof PdoConnectionInterface) {
        $cacheKey = [$this->db->getDriver()->getDsn(), $this->db->getDriver()->getUsername()];
    } else {
        throw new NotSupportedException('Only PDO connections are supported.');
    }
    return $cacheKey;
}

            
getCacheKey() protected method

protected array getCacheKey ( string $name )
$name string

                protected function getCacheKey(string $name): array
{
    return [static::class, ...$this->generateCacheKey(), $name];
}

            
getCacheTag() protected method

protected string getCacheTag ( )

                protected function getCacheTag(): string
{
    return md5(serialize([static::class, ...$this->generateCacheKey()]));
}

            
getDataType() public method
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,
    };
}

            
getDefaultSchema() public method
public string getDefaultSchema ( )

                public function getDefaultSchema(): string
{
    return $this->defaultSchema;
}

            
getResultColumn() public method
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;
}

            
getResultColumnCacheKey() protected method

protected string getResultColumnCacheKey ( array $metadata )
$metadata array

                protected function getResultColumnCacheKey(array $metadata): string
{
    return md5(serialize([static::class . '::getResultColumn', ...$this->generateCacheKey(), ...$metadata]));
}

            
getSchemaChecks() public method
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);
}

            
getSchemaDefaultValues() public method
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);
}

            
getSchemaForeignKeys() public method
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);
}

            
getSchemaIndexes() public method
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);
}

            
getSchemaMetadata() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::getSchemaMetadata()

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 false, cached data may be returned if available.

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;
}

            
getSchemaNames() public method
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;
}

            
getSchemaPrimaryKeys() public method
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);
}

            
getSchemaUniques() public method
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);
}

            
getTableChecks() public method
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);
}

            
getTableDefaultValues() public method
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);
}

            
getTableForeignKeys() public method
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);
}

            
getTableIndexes() public method
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);
}

            
getTableMetadata() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::getTableMetadata()

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];
}

            
getTableNames() public method
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];
}

            
getTablePrimaryKey() public method
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;
}

            
getTableSchema() public method
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);
}

            
getTableSchemas() public method
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);
}

            
getTableTypeMetadata() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::getTableTypeMetadata()

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,
    };
}

            
getTableUniques() public method
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,
    );
}

            
getViewNames() public method
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];
}

            
hasSchema() public method
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);
}

            
hasTable() public method
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);
}

            
hasView() public method
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);
}

            
loadResultColumn() protected abstract method

Defined in: Yiisoft\Db\Schema\AbstractSchema::loadResultColumn()

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;

            
loadTableChecks() protected abstract method

Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableChecks()

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;

            
loadTableDefaultValues() protected abstract method

Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableDefaultValues()

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;

            
loadTableForeignKeys() protected abstract method

Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableForeignKeys()

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;

            
loadTableIndexes() protected abstract method

Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableIndexes()

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;

            
loadTableSchema() protected abstract method

Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableSchema()

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, null if the table doesn't exist.

                abstract protected function loadTableSchema(string $name): ?TableSchemaInterface;

            
loadTableTypeMetadata() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::loadTableTypeMetadata()

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,
    };
}

            
refresh() public method
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 = [];
}

            
refreshTableSchema() public method
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));
    }
}

            
resolveFullName() protected method

Defined in: 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()}.

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",
    };
}

            
setTableMetadata() protected method

Defined in: Yiisoft\Db\Schema\AbstractSchema::setTableMetadata()

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;
}