From c03e064f44675f0bfd8bf16c1026db4046a16c8a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 18 Oct 2024 09:49:00 +0700 Subject: [PATCH 1/3] Load column properties via constructor --- src/Column/ColumnBuilder.php | 3 +-- src/Column/ColumnFactory.php | 11 +++++++---- src/Dsn.php | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Column/ColumnBuilder.php b/src/Column/ColumnBuilder.php index 945c43f9..ace70ca9 100644 --- a/src/Column/ColumnBuilder.php +++ b/src/Column/ColumnBuilder.php @@ -11,7 +11,6 @@ final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder { public static function binary(int|null $size = null): ColumnSchemaInterface { - return (new BinaryColumnSchema(ColumnType::BINARY)) - ->size($size); + return new BinaryColumnSchema(ColumnType::BINARY, size: $size); } } diff --git a/src/Column/ColumnFactory.php b/src/Column/ColumnFactory.php index a09b02a9..1fd0c97a 100644 --- a/src/Column/ColumnFactory.php +++ b/src/Column/ColumnFactory.php @@ -9,6 +9,7 @@ use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Schema\Column\AbstractColumnFactory; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; +use Yiisoft\Db\Schema\Column\StringColumnSchema; final class ColumnFactory extends AbstractColumnFactory { @@ -76,9 +77,11 @@ protected function getType(string $dbType, array $info = []): string public function fromPseudoType(string $pseudoType, array $info = []): ColumnSchemaInterface { if ($pseudoType === PseudoType::UUID_PK_SEQ) { - return ColumnBuilder::uuidPrimaryKey() - ->defaultValue(new Expression('newsequentialid()')) - ->load($info); + $info['primaryKey'] = true; + $info['autoIncrement'] = true; + $info['defaultValue'] = new Expression('newsequentialid()'); + + return new StringColumnSchema(ColumnType::UUID, ...$info); } return parent::fromPseudoType($pseudoType, $info); @@ -87,7 +90,7 @@ public function fromPseudoType(string $pseudoType, array $info = []): ColumnSche public function fromType(string $type, array $info = []): ColumnSchemaInterface { if ($type === ColumnType::BINARY) { - return (new BinaryColumnSchema($type))->load($info); + return new BinaryColumnSchema($type, ...$info); } return parent::fromType($type, $info); diff --git a/src/Dsn.php b/src/Dsn.php index 5050bc75..0330b872 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -18,7 +18,7 @@ final class Dsn extends AbstractDsn */ public function __construct( string $driver = 'sqlsrv', - string $host = 'localhost', + string $host = '127.0.0.1', string|null $databaseName = null, string|null $port = '1433', array $options = [] From 477b8bef779f94e6971fe6ff6a8bc748f12b1dd5 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 18 Oct 2024 15:35:50 +0700 Subject: [PATCH 2/3] Fix test and psalm --- src/Column/ColumnFactory.php | 2 ++ tests/CommandTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Column/ColumnFactory.php b/src/Column/ColumnFactory.php index 1fd0c97a..4e3b5a65 100644 --- a/src/Column/ColumnFactory.php +++ b/src/Column/ColumnFactory.php @@ -77,6 +77,7 @@ protected function getType(string $dbType, array $info = []): string public function fromPseudoType(string $pseudoType, array $info = []): ColumnSchemaInterface { if ($pseudoType === PseudoType::UUID_PK_SEQ) { + unset($info['type']); $info['primaryKey'] = true; $info['autoIncrement'] = true; $info['defaultValue'] = new Expression('newsequentialid()'); @@ -90,6 +91,7 @@ public function fromPseudoType(string $pseudoType, array $info = []): ColumnSche public function fromType(string $type, array $info = []): ColumnSchemaInterface { if ($type === ColumnType::BINARY) { + unset($info['type']); return new BinaryColumnSchema($type, ...$info); } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 560521e4..e3e50bfe 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -321,7 +321,7 @@ public function testShowDatabases(): void $command = $db->createCommand(); - $this->assertSame('sqlsrv:Server=localhost,1433;Encrypt=no', $db->getDriver()->getDsn()); + $this->assertSame('sqlsrv:Server=127.0.0.1,1433;Encrypt=no', $db->getDriver()->getDsn()); $this->assertSame(['yiitest'], $command->showDatabases()); } From b609698e21176b8ad14d31e45ce5a281775065f4 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 18 Oct 2024 18:04:44 +0700 Subject: [PATCH 3/3] Add line to CHANGELOG.md [skip ci] --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a99cb15e..a62bc393 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ - New #320: Realize `ColumnBuilder` class (@Tigrov) - Enh #321: Update according changes in `ColumnSchemaInterface` (@Tigrov) - New #322: Add `ColumnDefinitionBuilder` class (@Tigrov) +- Enh #323: Refactor `Dsn` class (@Tigrov) +- Enh #324: Use constructor to create columns and initialize properties (@Tigrov) ## 1.2.0 March 21, 2024