Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
- Bug #1109: Fix column definition parsing in cases with brackets and escaped quotes (@vjik)
- New #1107: Add abstract enumeration column type (@vjik)
- Bug #1115: Do not reset `$retryHandler` property on `AbstractCommand::reset()` method call (@Tigrov)
- New #1124: Add source of column information (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
30 changes: 30 additions & 0 deletions src/Constant/ColumnInfoSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Yiisoft\Db\Constant;

use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;

/**
* Defines the possible sources of column information.
*
* It can be used in `ColumnFactoryInterface` instances when creating column objects.
*
* @see ColumnFactoryInterface
*/
final class ColumnInfoSource
{
/**
* @var string Used to indicate that column information is taken from the column definition.
*/
public const DEFINITION = 'definition';

/**
* @var string Used to indicate that column information is taken from the database table schema.
*/
public const TABLE_SCHEMA = 'table_schema';

/**
* @var string Used to indicate that column information is taken from the query result.
*/
public const QUERY_RESULT = 'query_result';
}
2 changes: 2 additions & 0 deletions src/Schema/Column/AbstractColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Db\Schema\Column;

use Closure;
use Yiisoft\Db\Constant\ColumnInfoSource;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\PseudoType;
use Yiisoft\Db\Expression\Expression;
Expand Down Expand Up @@ -142,6 +143,7 @@ public function fromDefinition(string $definition, array $info = []): ColumnInte
unset($definitionInfo['type']);

$info = array_merge($info, $definitionInfo);
$info['source'] ??= ColumnInfoSource::DEFINITION;

if ($this->isDbType($type)) {
return $this->fromDbType($type, $info);
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Column/ColumnFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Db\Schema\Column;

use Yiisoft\Db\Constant\ColumnInfoSource;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\PseudoType;
use Yiisoft\Db\Constraint\ForeignKey;
Expand All @@ -26,14 +27,14 @@
* defaultValueRaw?: string|null,
* dimension?: positive-int,
* extra?: string|null,
* fromResult?: bool,
* primaryKey?: bool,
* name?: string|null,
* notNull?: bool,
* reference?: ForeignKey|null,
* scale?: int|null,
* schema?: string|null,
* size?: int|null,
* source?: ColumnInfoSource::*,
* table?: string|null,
* type?: ColumnType::*,
* unique?: bool,
Expand Down
Loading