From 34f4c2d37969c7e9c31cedcd55a942c942db7e82 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 26 Nov 2024 10:24:14 +0700 Subject: [PATCH 01/16] Use new column builder --- src/AbstractMigrationBuilder.php | 229 ++++++++++-------- src/MigrationBuilder.php | 56 +++-- src/Migrator.php | 7 +- tests/Common/AbstractMigrationBuilderTest.php | 202 ++++----------- tests/Common/AbstractMigratorTest.php | 7 +- tests/Driver/Mssql/MigrationBuilderTest.php | 3 +- tests/Driver/Mysql/MigrationBuilderTest.php | 3 +- tests/Driver/Oracle/MigrationBuilderTest.php | 3 +- tests/Driver/Pgsql/MigrationBuilderTest.php | 3 +- 9 files changed, 222 insertions(+), 291 deletions(-) diff --git a/src/AbstractMigrationBuilder.php b/src/AbstractMigrationBuilder.php index f24b2c14..be2b5014 100644 --- a/src/AbstractMigrationBuilder.php +++ b/src/AbstractMigrationBuilder.php @@ -4,13 +4,12 @@ namespace Yiisoft\Db\Migration; -use Yiisoft\Db\Constant\ColumnType; -use Yiisoft\Db\Constant\PseudoType; -use Yiisoft\Db\Schema\Builder\ColumnInterface; +use Yiisoft\Db\Schema\Column\ColumnBuilder; +use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\SchemaInterface; /** - * AbstractMigrationBuilder contains shortcut methods to create instances of {@see ColumnInterface}. + * AbstractMigrationBuilder contains shortcut methods to create instances of {@see ColumnSchemaInterface}. * * These can be used in database migrations to define database schema types using a PHP interface. This is useful to * define a schema in a DBMS independent way so that the application may run on different DBMS the same way. @@ -21,19 +20,17 @@ * $this->createTable( * 'example_table', * [ - * 'id' => $this->primaryKey(), - * 'name' => $this->string(64)->notNull(), - * 'type' => $this->integer()->notNull()->defaultValue(10), - * 'description' => $this->text(), - * 'rule_name' => $this->string(64), - * 'data' => $this->text(), - * 'created_at' => $this->datetime()->notNull(), - * 'updated_at' => $this->datetime(), + * 'id' => ColumnBuilder::primaryKey(), + * 'name' => ColumnBuilder::string(64)->notNull(), + * 'type' => ColumnBuilder::integer()->notNull()->defaultValue(10), + * 'description' => ColumnBuilder::text(), + * 'rule_name' => ColumnBuilder::string(64), + * 'data' => ColumnBuilder::text(), + * 'created_at' => ColumnBuilder::datetime()->notNull(), + * 'updated_at' => ColumnBuilder::datetime(), * ], * ); * ``` - * - * @psalm-suppress DeprecatedMethod */ abstract class AbstractMigrationBuilder { @@ -48,11 +45,13 @@ public function __construct(private SchemaInterface $schema) * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::bigint()} instead. Will be removed in 2.0.0. */ - public function bigInteger(int $length = null): ColumnInterface + public function bigInteger(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::BIGINT, $length); + return ColumnBuilder::bigint($length); } /** @@ -62,11 +61,13 @@ public function bigInteger(int $length = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::bigPrimaryKey()} instead. Will be removed in 2.0.0. */ - public function bigPrimaryKey(int $length = null): ColumnInterface + public function bigPrimaryKey(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(PseudoType::BIGPK, $length); + return ColumnBuilder::bigPrimaryKey()->size($length); } /** @@ -74,11 +75,13 @@ public function bigPrimaryKey(int $length = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::uuidPrimaryKey()} instead. Will be removed in 2.0.0. */ - public function uuidPrimaryKey(): ColumnInterface + public function uuidPrimaryKey(): ColumnSchemaInterface { - return $this->schema->createColumn(PseudoType::UUID_PK); + return ColumnBuilder::uuidPrimaryKey(); } /** @@ -86,11 +89,13 @@ public function uuidPrimaryKey(): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::uuidPrimaryKey()} instead. Will be removed in 2.0.0. */ - public function uuidPrimaryKeySequenced(): ColumnInterface + public function uuidPrimaryKeySequenced(): ColumnSchemaInterface { - return $this->schema->createColumn(PseudoType::UUID_PK_SEQ); + return ColumnBuilder::uuidPrimaryKey(); } /** @@ -98,11 +103,13 @@ public function uuidPrimaryKeySequenced(): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::uuid()} instead. Will be removed in 2.0.0. */ - public function uuid(): ColumnInterface + public function uuid(): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::UUID); + return ColumnBuilder::uuid(); } /** @@ -112,21 +119,25 @@ public function uuid(): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::binary()} instead. Will be removed in 2.0.0. */ - public function binary(int $length = null): ColumnInterface + public function binary(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::BINARY, $length); + return ColumnBuilder::binary($length); } /** * Creates a boolean column. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::boolean()} instead. Will be removed in 2.0.0. */ - public function boolean(): ColumnInterface + public function boolean(): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::BOOLEAN); + return ColumnBuilder::boolean(); } /** @@ -136,21 +147,25 @@ public function boolean(): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::char()} instead. Will be removed in 2.0.0. */ - public function char(int $length = null): ColumnInterface + public function char(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::CHAR, $length); + return ColumnBuilder::char($length); } /** * Creates a date column. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::date()} instead. Will be removed in 2.0.0. */ - public function date(): ColumnInterface + public function date(): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::DATE); + return ColumnBuilder::date(); } /** @@ -161,11 +176,13 @@ public function date(): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::datetime()} instead. Will be removed in 2.0.0. */ - public function dateTime(int $precision = null): ColumnInterface + public function dateTime(int $precision = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::DATETIME, $precision); + return ColumnBuilder::datetime($precision); } /** @@ -180,21 +197,13 @@ public function dateTime(int $precision = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::decimal()} instead. Will be removed in 2.0.0. */ - public function decimal(int $precision = null, int $scale = null): ColumnInterface + public function decimal(int $precision = null, int $scale = null): ColumnSchemaInterface { - $length = []; - - if ($precision !== null) { - $length[] = $precision; - } - - if ($scale !== null) { - $length[] = $scale; - } - - return $this->schema->createColumn(ColumnType::DECIMAL, $length); + return ColumnBuilder::decimal($precision, $scale); } /** @@ -205,11 +214,13 @@ public function decimal(int $precision = null, int $scale = null): ColumnInterfa * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::double()} instead. Will be removed in 2.0.0. */ - public function double(int $precision = null): ColumnInterface + public function double(int $precision = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::DOUBLE, $precision); + return ColumnBuilder::double($precision); } /** @@ -220,11 +231,13 @@ public function double(int $precision = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::float()} instead. Will be removed in 2.0.0. */ - public function float(int $precision = null): ColumnInterface + public function float(int $precision = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::FLOAT, $precision); + return ColumnBuilder::float($precision); } /** @@ -234,21 +247,25 @@ public function float(int $precision = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::integer()} instead. Will be removed in 2.0.0. */ - public function integer(int $length = null): ColumnInterface + public function integer(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::INTEGER, $length); + return ColumnBuilder::integer($length); } /** * Creates a JSON column. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::json()} instead. Will be removed in 2.0.0. */ - public function json(): ColumnInterface + public function json(): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::JSON); + return ColumnBuilder::json(); } /** @@ -263,21 +280,13 @@ public function json(): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::money()} instead. Will be removed in 2.0.0. */ - public function money(int $precision = null, int $scale = null): ColumnInterface + public function money(int $precision = null, int $scale = null): ColumnSchemaInterface { - $length = []; - - if ($precision !== null) { - $length[] = $precision; - } - - if ($scale !== null) { - $length[] = $scale; - } - - return $this->schema->createColumn(ColumnType::MONEY, $length); + return ColumnBuilder::money($precision, $scale); } /** @@ -287,11 +296,13 @@ public function money(int $precision = null, int $scale = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::primaryKey()} instead. Will be removed in 2.0.0. */ - public function primaryKey(int $length = null): ColumnInterface + public function primaryKey(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(PseudoType::PK, $length); + return ColumnBuilder::primaryKey()->size($length); } /** @@ -301,11 +312,13 @@ public function primaryKey(int $length = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::smallint()} instead. Will be removed in 2.0.0. */ - public function smallInteger(int $length = null): ColumnInterface + public function smallInteger(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::SMALLINT, $length); + return ColumnBuilder::smallint($length); } /** @@ -315,21 +328,25 @@ public function smallInteger(int $length = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::string()} instead. Will be removed in 2.0.0. */ - public function string(int $length = null): ColumnInterface + public function string(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::STRING, $length); + return ColumnBuilder::string($length); } /** * Creates a text column. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::text()} instead. Will be removed in 2.0.0. */ - public function text(): ColumnInterface + public function text(): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::TEXT); + return ColumnBuilder::text(); } /** @@ -340,11 +357,13 @@ public function text(): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::time()} instead. Will be removed in 2.0.0. */ - public function time(int $precision = null): ColumnInterface + public function time(int $precision = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::TIME, $precision); + return ColumnBuilder::time($precision); } /** @@ -355,11 +374,13 @@ public function time(int $precision = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::timestamp()} instead. Will be removed in 2.0.0. */ - public function timestamp(int $precision = null): ColumnInterface + public function timestamp(int $precision = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::TIMESTAMP, $precision); + return ColumnBuilder::timestamp($precision); } /** @@ -369,10 +390,12 @@ public function timestamp(int $precision = null): ColumnInterface * * This parameter will be ignored if not supported by the DBMS. * - * @return ColumnInterface The column instance which can be further customized. + * @return ColumnSchemaInterface The column instance which can be further customized. + * + * @deprecated Use {@see ColumnBuilder::tinyint()} instead. Will be removed in 2.0.0. */ - public function tinyInteger(int $length = null): ColumnInterface + public function tinyInteger(int $length = null): ColumnSchemaInterface { - return $this->schema->createColumn(ColumnType::TINYINT, $length); + return ColumnBuilder::tinyint($length); } } diff --git a/src/MigrationBuilder.php b/src/MigrationBuilder.php index 69848e98..942120cb 100644 --- a/src/MigrationBuilder.php +++ b/src/MigrationBuilder.php @@ -6,12 +6,15 @@ use Exception; use Yiisoft\Db\Connection\ConnectionInterface; +use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Constraint\Constraint; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Migration\Informer\MigrationInformerInterface; +use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use function implode; use function ltrim; @@ -191,14 +194,14 @@ public function delete(string $table, array|string $condition = '', array $param * generated SQL. * * @param string $table The name of the table to be created. The name will be properly quoted by the method. - * @param array $columns The columns (name => definition) in the new table. + * @param (string|ColumnSchemaInterface)[] $columns The columns (name => definition) in the new table. * @param string|null $options Additional SQL fragment that will be appended to the generated SQL. * * @throws Exception * @throws InvalidConfigException * @throws NotSupportedException * - * @psalm-param array $columns + * @psalm-param array $columns */ public function createTable(string $table, array $columns, string|null $options = null): void { @@ -207,7 +210,7 @@ public function createTable(string $table, array $columns, string|null $options $this->db->createCommand()->createTable($table, $columns, $options)->execute(); foreach ($columns as $column => $type) { - if ($type instanceof ColumnInterface) { + if ($type instanceof ColumnInterface || $type instanceof ColumnSchemaInterface) { $comment = $type->getComment(); if ($comment !== null) { $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute(); @@ -265,24 +268,29 @@ public function truncateTable(string $table): void * @param string $table The table that the new column will be added to. * The table name will be properly quoted by the method. * @param string $column The name of the new column. The name will be properly quoted by the method. - * @param ColumnInterface|string $type The column type. The {@see QueryBuilder::getColumnType()} method - * will be invoked to convert an abstract column type (if any) into the physical one. Anything not - * recognized as an abstract type will be kept in the generated SQL. For example, 'string' will be turned - * into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'. + * @param ColumnSchemaInterface|string $type TThe column type. The {@see QueryBuilder::buildColumnDefinition()} + * method will convert the column type into the column definition. Any column type not recognized as a database type + * will be recognized as one of an {@see ColumnType abstract} or {@see PseudoType pseudo} type, or as a 'string' + * abstract type by default to generate column definition. For example, 'string' will be generated into + * 'varchar(255)', while 'string not null' will become 'varchar(255) not null'. */ - public function addColumn(string $table, string $column, ColumnInterface|string $type): void + public function addColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): void { - $comment = null; - if ($type instanceof ColumnInterface) { + if (is_string($type)) { + $comment = null; + } else { $comment = $type->getComment(); - $type = $type->asString(); } - $time = $this->beginCommand("add column $column $type to table $table"); + $typeAsString = $this->db->getQueryBuilder()->buildColumnDefinition($type); + + $time = $this->beginCommand("add column $column $typeAsString to table $table"); $this->db->createCommand()->addColumn($table, $column, $type)->execute(); + if ($comment !== null) { $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute(); } + $this->endCommand($time); } @@ -322,26 +330,26 @@ public function renameColumn(string $table, string $name, string $newName): void * * @param string $table The table whose column is to be changed. The method will properly quote the table name. * @param string $column The name of the column to be changed. The name will be properly quoted by the method. - * @param ColumnInterface|string $type The new column type. - * The {@see \Yiisoft\Db\Query\QueryBuilder::getColumnType()} method will be invoked to convert an abstract column - * type (if any) into the physical one. Anything not recognized as an abstract type will be kept in the - * generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become - * 'varchar(255) not null'. + * @param ColumnSchemaInterface|string $type TThe column type. The {@see QueryBuilder::buildColumnDefinition()} + * method will convert the column type into the column definition. Any column type not recognized as a database type + * will be recognized as one of an {@see ColumnType abstract} or {@see PseudoType pseudo} type, or as a 'string' + * abstract type by default to generate column definition. For example, 'string' will be generated into + * 'varchar(255)', while 'string not null' will become 'varchar(255) not null'. * * @throws Exception * @throws InvalidConfigException * @throws NotSupportedException */ - public function alterColumn(string $table, string $column, ColumnInterface|string $type): void + public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): void { - $comment = null; - $typeAsString = $type; - - if ($typeAsString instanceof ColumnInterface) { - $comment = $typeAsString->getComment(); - $typeAsString = $typeAsString->asString(); + if (is_string($type)) { + $comment = null; + } else { + $comment = $type->getComment(); } + $typeAsString = $this->db->getQueryBuilder()->buildColumnDefinition($type); + $time = $this->beginCommand("Alter column $column in table $table to $typeAsString"); $this->db->createCommand()->alterColumn($table, $column, $type)->execute(); diff --git a/src/Migrator.php b/src/Migrator.php index 936960bc..40848eee 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -9,6 +9,7 @@ use Yiisoft\Db\Query\Query; use Yiisoft\Db\Migration\Informer\MigrationInformerInterface; use Yiisoft\Db\Migration\Informer\NullMigrationInformer; +use Yiisoft\Db\Schema\Column\ColumnBuilder; final class Migrator { @@ -150,9 +151,9 @@ private function createMigrationHistoryTable(): void $b = $this->createBuilder(new NullMigrationInformer()); $b->createTable($this->historyTable, [ - 'id' => $b->primaryKey(), - 'name' => $b->string($this->migrationNameLimit)->notNull(), - 'apply_time' => $b->integer()->notNull(), + 'id' => ColumnBuilder::primaryKey(), + 'name' => ColumnBuilder::string($this->migrationNameLimit)->notNull(), + 'apply_time' => ColumnBuilder::integer()->notNull(), ]); $this->informer->endCreateHistoryTable('Done.'); diff --git a/tests/Common/AbstractMigrationBuilderTest.php b/tests/Common/AbstractMigrationBuilderTest.php index ee7bbd56..4f971b62 100644 --- a/tests/Common/AbstractMigrationBuilderTest.php +++ b/tests/Common/AbstractMigrationBuilderTest.php @@ -11,6 +11,7 @@ use Yiisoft\Db\Migration\MigrationBuilder; use Yiisoft\Db\Migration\Tests\Support\AssertTrait; use Yiisoft\Db\Migration\Tests\Support\Stub\StubMigrationInformer; +use Yiisoft\Db\Schema\Column\ColumnBuilder; abstract class AbstractMigrationBuilderTest extends TestCase { @@ -30,7 +31,7 @@ protected function setUp(): void public function testExecute(): void { - $this->builder->createTable('test', ['id' => $this->builder->integer()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::integer()]); $sql = 'DROP TABLE {{test}}'; $this->builder->execute($sql); @@ -43,7 +44,7 @@ public function testExecute(): void public function testInsert(): void { - $this->builder->createTable('test', ['id' => $this->builder->integer()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::integer()]); $this->builder->insert('test', ['id' => 1]); $this->assertEquals( @@ -57,7 +58,7 @@ public function testInsert(): void public function testBatchInsert(): void { - $this->builder->createTable('test', ['id' => $this->builder->integer()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::integer()]); $this->builder->batchInsert('test', ['id'], [['id' => 1], ['id' => 2]]); $this->assertEquals( @@ -71,7 +72,7 @@ public function testBatchInsert(): void public function testUpsertWithoutRow(): void { - $this->builder->createTable('test', ['id' => $this->builder->primaryKey(), 'name' => $this->builder->string()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::primaryKey(), 'name' => ColumnBuilder::string()]); $this->builder->insert('test', ['name' => 'Ivan']); $this->builder->upsert('test', ['name' => 'Petr'], false); @@ -89,7 +90,7 @@ public function testUpsertWithoutRow(): void public function testUpdate(): void { - $this->builder->createTable('test', ['id' => $this->builder->primaryKey(), 'name' => $this->builder->string()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::primaryKey(), 'name' => ColumnBuilder::string()]); $this->builder->insert('test', ['name' => 'Ivan']); $this->builder->update('test', ['name' => 'Petr'], '[[id]]=:id', ['id' => 1]); @@ -106,7 +107,7 @@ public function testUpdate(): void public function testDelete(): void { - $this->builder->createTable('test', ['id' => $this->builder->integer()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::integer()]); $this->builder->insert('test', ['id' => 1]); $this->builder->delete('test', '[[id]]=:id', ['id' => 1]); @@ -118,7 +119,7 @@ public function testDelete(): void public function testCreateTable(): void { - $this->builder->createTable('test', ['id' => $this->builder->primaryKey()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::primaryKey()]); $tableSchema = $this->db->getTableSchema('test'); $column = $tableSchema->getColumn('id'); @@ -197,17 +198,23 @@ public static function dataAddColumn(): array */ public function testAddColumn(string $type, string $expectedComment = null): void { - $expectedOutputString = ' > add column code string(4) to table test ... Done in'; + $expectedOutputString = match ($this->db->getDriverName()) { + 'sqlite' => ' > add column code varchar(4) to table test ... Done in', + 'pgsql' => ' > add column code varchar(4) to table test ... Done in', + 'mysql' => ' > add column code varchar(4) to table test ... Done in', + 'sqlsrv' => ' > add column code nvarchar(4) to table test ... Done in', + 'oci' => ' > add column code varchar2(4) to table test ... Done in', + }; if ($type === 'build-string(4)') { - $type = $this->builder->string(4); + $type = ColumnBuilder::string(4); } if ($type === 'build-string(4)-with-comment') { - $type = $this->builder->string(4)->comment('test comment'); + $type = ColumnBuilder::string(4)->comment('test comment'); if ($this->db->getDriverName() === 'mysql') { - $expectedOutputString = " > add column code string(4) COMMENT 'test comment' to table test ... Done in"; + $expectedOutputString = " > add column code varchar(4) COMMENT 'test comment' to table test ... Done in"; } } @@ -233,7 +240,7 @@ public function testAddColumn(string $type, string $expectedComment = null): voi public function testDropColumn(): void { - $this->builder->createTable('test', ['id' => $this->builder->primaryKey(), 'name' => $this->builder->string()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::primaryKey(), 'name' => ColumnBuilder::string()]); $this->builder->dropColumn('test', 'name'); $tableSchema = $this->db->getTableSchema('test'); @@ -246,7 +253,7 @@ public function testDropColumn(): void public function testRenameColumn(): void { - $this->builder->createTable('test', ['id' => $this->builder->integer()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::integer()]); $this->builder->renameColumn('test', 'id', 'id_new'); $tableSchema = $this->db->getTableSchema('test'); @@ -275,27 +282,35 @@ public function testAlterColumn(string $type, string|null $defaultValue = null, $expectedOutputString = ' > Alter column id in table test to string(4) ... Done in'; if ($type === 'build-string(4)') { - $type = $this->builder->string(4); + $type = ColumnBuilder::string(4); } if ($type === 'string(4)-defaultValue') { - $type = $this->builder->string(4)->defaultValue($defaultValue); + $type = ColumnBuilder::string(4)->defaultValue($defaultValue); $expectedOutputString = " > Alter column id in table test to string(4) DEFAULT '$defaultValue' ... Done in"; } if ($type === 'build-string(4)-with-comment') { - $type = $this->builder->string(4)->comment('test comment'); + $type = ColumnBuilder::string(4)->comment('test comment'); if ($this->db->getDriverName() === 'mysql') { $expectedOutputString = " > Alter column id in table test to string(4) COMMENT 'test comment' ... Done in"; } } + $expectedOutputString = match ($this->db->getDriverName()) { + 'sqlite' => str_replace('string(4)', 'varchar(4)', $expectedOutputString), + 'pgsql' => str_replace('string(4)', 'varchar(4)', $expectedOutputString), + 'mysql' => str_replace('string(4)', 'varchar(4)', $expectedOutputString), + 'sqlsrv' => str_replace('string(4)', 'nvarchar(4)', $expectedOutputString), + 'oci' => str_replace('string(4)', 'varchar2(4)', $expectedOutputString), + }; + if ($expectedComment === null && $this->db->getDriverName() === 'mysql') { $expectedComment = ''; } - $this->builder->createTable('test', ['id' => $this->builder->integer()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::integer()]); $this->builder->alterColumn('test', 'id', $type); $tableSchema = $this->db->getTableSchema('test'); @@ -318,10 +333,10 @@ public function testAlterColumn(string $type, string|null $defaultValue = null, public function testAddPrimaryKey(): void { - $fieldType = $this->builder->integer(); + $fieldType = ColumnBuilder::integer(); if ($this->db->getDriverName() === 'sqlsrv') { - $fieldType = $this->builder->integer()->notNull(); + $fieldType = ColumnBuilder::integer()->notNull(); } $this->builder->createTable('test', ['id' => $fieldType]); @@ -342,12 +357,12 @@ public function testDropPrimaryKey(): void if ($this->db->getDriverName() === 'sqlite') { $this->builder->createTable( 'test', - ['id' => 'int CONSTRAINT test_pk PRIMARY KEY', 'name' => $this->builder->string()], + ['id' => 'int CONSTRAINT test_pk PRIMARY KEY', 'name' => ColumnBuilder::string()], ); } else { $this->builder->createTable( 'test', - ['id' => $this->builder->integer()->notNull(), 'name' => $this->builder->string()], + ['id' => ColumnBuilder::integer()->notNull(), 'name' => ColumnBuilder::string()], ); $this->builder->addPrimaryKey('test', 'test_pk', 'id'); } @@ -369,7 +384,7 @@ public function testAddForeignKey(): void $this->builder->createTable('target_table', ['id' => 'int unique']); $this->builder->createTable( 'test_table', - ['id' => $this->builder->integer(), 'foreign_id' => $this->builder->integer()], + ['id' => ColumnBuilder::integer(), 'foreign_id' => ColumnBuilder::integer()], ); $update = 'CASCADE'; @@ -448,7 +463,7 @@ public function testCreateAndDropView(): void { $schema = $this->db->getSchema(); - $this->builder->createTable('test', ['id' => $this->builder->integer()]); + $this->builder->createTable('test', ['id' => ColumnBuilder::integer()]); $this->builder->createView('test_view', 'SELECT * FROM {{test}}'); $viewNames = $schema->getViewNames(refresh: true); @@ -468,7 +483,7 @@ public function testCreateAndDropView(): void public function testDropIndex(): void { - $this->builder->createTable('test_table', ['id' => $this->builder->integer()]); + $this->builder->createTable('test_table', ['id' => ColumnBuilder::integer()]); $this->builder->createIndex('test_table', 'test_index', 'id'); $this->builder->dropIndex('test_table', 'test_index'); @@ -482,7 +497,7 @@ public function testDropIndex(): void public function testDropIndexNoExist(): void { - $this->builder->createTable('test_table', ['id' => $this->builder->integer()]); + $this->builder->createTable('test_table', ['id' => ColumnBuilder::integer()]); $this->builder->dropIndex('test_table', 'test_index'); $indexes = $this->db->getSchema()->getTableIndexes('test_table'); @@ -495,7 +510,7 @@ public function testDropIndexNoExist(): void public function testDropIndexUnique(): void { - $this->builder->createTable('test_table', ['id' => $this->builder->integer()]); + $this->builder->createTable('test_table', ['id' => ColumnBuilder::integer()]); $this->builder->createIndex('test_table', 'test_index', 'id', 'UNIQUE'); $this->builder->dropIndex('test_table', 'test_index'); @@ -509,7 +524,7 @@ public function testDropIndexUnique(): void public function testAddCommentOnColumn(): void { - $this->builder->createTable('test_table', ['id' => $this->builder->integer()]); + $this->builder->createTable('test_table', ['id' => ColumnBuilder::integer()]); $this->builder->addCommentOnColumn('test_table', 'id', 'test comment'); $tableSchema = $this->db->getTableSchema('test_table'); @@ -523,7 +538,7 @@ public function testAddCommentOnColumn(): void public function testAddCommentOnTable(): void { - $this->builder->createTable('test_table', ['id' => $this->builder->integer()]); + $this->builder->createTable('test_table', ['id' => ColumnBuilder::integer()]); $this->builder->addCommentOnTable('test_table', 'test comment'); $tableSchema = $this->builder->getDb()->getTableSchema('test_table'); @@ -536,7 +551,7 @@ public function testAddCommentOnTable(): void public function testDropCommentFromColumn(): void { - $this->builder->createTable('test_table', ['id' => $this->builder->integer()]); + $this->builder->createTable('test_table', ['id' => ColumnBuilder::integer()]); $this->builder->addCommentOnColumn('test_table', 'id', 'comment'); $this->builder->dropCommentFromColumn('test_table', 'id'); @@ -544,7 +559,7 @@ public function testDropCommentFromColumn(): void $column = $tableSchema->getColumn('id'); match ($this->builder->getDb()->getDriverName()) { - 'mysql', 'oci', 'sqlsrv' => $this->assertEmpty($column->getComment()), + 'mysql' => $this->assertEmpty($column->getComment()), default => $this->assertNull($column->getComment()), }; @@ -555,7 +570,7 @@ public function testDropCommentFromColumn(): void public function testDropCommentFromTable(): void { - $this->builder->createTable('test_table', ['id' => $this->builder->integer()]); + $this->builder->createTable('test_table', ['id' => ColumnBuilder::integer()]); $this->builder->addCommentOnTable('test_table', 'comment'); $this->builder->dropCommentFromTable('test_table'); @@ -590,131 +605,6 @@ public function testMaxSqlOutputLength(): void $this->assertStringContainsString('Execute SQL: SELE [... hidden] ... Done', $this->informer->getOutput()); } - public function testBigInteger(): void - { - $this->assertSame('bigint', $this->builder->bigInteger()->asString()); - } - - public function testBigPrimaryKey(): void - { - $this->assertSame('bigpk', $this->builder->bigPrimaryKey()->asString()); - } - - public function testBinary(): void - { - $this->assertSame('binary', $this->builder->binary()->asString()); - } - - public function testBoolean(): void - { - $this->assertSame('boolean', $this->builder->boolean()->asString()); - } - - public function testChar(): void - { - $this->assertSame('char', $this->builder->char()->asString()); - } - - public function testDate(): void - { - $this->assertSame('date', $this->builder->date()->asString()); - } - - public function testDateTime(): void - { - $this->assertSame('datetime', $this->builder->dateTime()->asString()); - } - - public function testDecimal(): void - { - $this->assertSame('decimal', $this->builder->decimal()->asString()); - } - - public function testDecimalWithPrecisionAndScale(): void - { - $this->assertSame('decimal(10,2)', $this->builder->decimal(10, 2)->asString()); - } - - public function testDouble(): void - { - $this->assertSame('double', $this->builder->double()->asString()); - } - - public function testFloat(): void - { - $this->assertSame('float', $this->builder->float()->asString()); - } - - public function testInteger(): void - { - $this->assertSame('integer', $this->builder->integer()->asString()); - } - - public function testJson(): void - { - $this->assertSame('json', $this->builder->json()->asString()); - } - - public function testMoney(): void - { - $this->assertSame('money', $this->builder->money()->asString()); - } - - public function testMoneyWithPrecisionAndScale(): void - { - $this->assertSame('money(10,2)', $this->builder->money(10, 2)->asString()); - } - - public function testPrimaryKey(): void - { - $this->assertSame('pk', $this->builder->primaryKey()->asString()); - } - - public function testSmallInteger(): void - { - $this->assertSame('smallint', $this->builder->smallInteger()->asString()); - } - - public function testString(): void - { - $this->assertSame('string', $this->builder->string()->asString()); - } - - public function testText(): void - { - $this->assertSame('text', $this->builder->text()->asString()); - } - - public function testTime(): void - { - $this->assertSame('time', $this->builder->time()->asString()); - } - - public function testTimestamp(): void - { - $this->assertSame('timestamp', $this->builder->timestamp()->asString()); - } - - public function testTinyInteger(): void - { - $this->assertSame('tinyint', $this->builder->tinyInteger()->asString()); - } - - public function testUuid(): void - { - $this->assertSame('uuid', $this->builder->uuid()->asString()); - } - - public function testUuidPrimaryKey(): void - { - $this->assertSame('uuid_pk', $this->builder->uuidPrimaryKey()->asString()); - } - - public function testUuidPrimaryKeySequenced(): void - { - $this->assertSame('uuid_pk_seq', $this->builder->uuidPrimaryKeySequenced()->asString()); - } - public function testGetDb(): void { $this->assertSame($this->db, $this->builder->getDb()); diff --git a/tests/Common/AbstractMigratorTest.php b/tests/Common/AbstractMigratorTest.php index 195e8197..d7e11209 100644 --- a/tests/Common/AbstractMigratorTest.php +++ b/tests/Common/AbstractMigratorTest.php @@ -66,7 +66,12 @@ public function testGetMigrationNameLimitWithoutColumnSize(): void 'text' )->execute(); - $this->assertNull($migrator->getMigrationNameLimit()); + $limit = $migrator->getMigrationNameLimit(); + + match ($db->getDriverName()) { + 'sqlsrv' => $this->assertSame(2147483647, $limit), + default => $this->assertNull($limit), + }; } public function testGetMigrationNameLimitFromSchema(): void diff --git a/tests/Driver/Mssql/MigrationBuilderTest.php b/tests/Driver/Mssql/MigrationBuilderTest.php index 0e3080d4..eddd1794 100644 --- a/tests/Driver/Mssql/MigrationBuilderTest.php +++ b/tests/Driver/Mssql/MigrationBuilderTest.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Migration\Tests\Common\AbstractMigrationBuilderTest; use Yiisoft\Db\Migration\Tests\Support\Factory\MssqlFactory; +use Yiisoft\Db\Schema\Column\ColumnBuilder; /** * @group mssql @@ -33,7 +34,7 @@ public function testCreateTableAnotherSchema(): void $command->setSql('CREATE SCHEMA yii')->execute(); - $this->builder->createTable('yii.test', ['id' => $this->builder->primaryKey()]); + $this->builder->createTable('yii.test', ['id' => ColumnBuilder::primaryKey()]); $tableSchema = $db->getSchema()->getTableSchema('yii.test'); $column = $tableSchema->getColumn('id'); diff --git a/tests/Driver/Mysql/MigrationBuilderTest.php b/tests/Driver/Mysql/MigrationBuilderTest.php index cffef369..13856779 100644 --- a/tests/Driver/Mysql/MigrationBuilderTest.php +++ b/tests/Driver/Mysql/MigrationBuilderTest.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Migration\Tests\Common\AbstractMigrationBuilderTest; use Yiisoft\Db\Migration\Tests\Support\Factory\MysqlFactory; +use Yiisoft\Db\Schema\Column\ColumnBuilder; /** * @group mysql @@ -27,7 +28,7 @@ public function testCreateTableAnotherSchema(): void $command->setSql('CREATE SCHEMA yii')->execute(); - $this->builder->createTable('yii.test', ['id' => $this->builder->primaryKey()]); + $this->builder->createTable('yii.test', ['id' => ColumnBuilder::primaryKey()]); $tableSchema = $db->getSchema()->getTableSchema('yii.test'); $column = $tableSchema->getColumn('id'); diff --git a/tests/Driver/Oracle/MigrationBuilderTest.php b/tests/Driver/Oracle/MigrationBuilderTest.php index a6303ed3..0de0022b 100644 --- a/tests/Driver/Oracle/MigrationBuilderTest.php +++ b/tests/Driver/Oracle/MigrationBuilderTest.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Migration\Tests\Common\AbstractMigrationBuilderTest; use Yiisoft\Db\Migration\Tests\Support\Factory\OracleFactory; +use Yiisoft\Db\Schema\Column\ColumnBuilder; /** * @group oracle @@ -27,7 +28,7 @@ public function testCreateTableAnotherSchema(): void $command->setSql('CREATE USER yii IDENTIFIED BY yiiSCHEMA')->execute(); - $this->builder->createTable('YII.test', ['id' => $this->builder->primaryKey()]); + $this->builder->createTable('YII.test', ['id' => ColumnBuilder::primaryKey()]); $tableSchema = $db->getSchema()->getTableSchema('YII.test'); $column = $tableSchema->getColumn('id'); diff --git a/tests/Driver/Pgsql/MigrationBuilderTest.php b/tests/Driver/Pgsql/MigrationBuilderTest.php index 05f33607..4c243fea 100644 --- a/tests/Driver/Pgsql/MigrationBuilderTest.php +++ b/tests/Driver/Pgsql/MigrationBuilderTest.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Migration\Tests\Common\AbstractMigrationBuilderTest; use Yiisoft\Db\Migration\Tests\Support\Factory\PostgreSqlFactory; +use Yiisoft\Db\Schema\Column\ColumnBuilder; /** * @group pgsql @@ -27,7 +28,7 @@ public function testCreateTableAnotherSchema(): void $command->setSql('CREATE SCHEMA yii')->execute(); - $this->builder->createTable('yii.test', ['id' => $this->builder->primaryKey()]); + $this->builder->createTable('yii.test', ['id' => ColumnBuilder::primaryKey()]); $tableSchema = $db->getSchema()->getTableSchema('yii.test'); $column = $tableSchema->getColumn('id'); From 5e9354cf44621900647b1bb1900c9aac8fa311a6 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 1 Dec 2024 02:55:11 +0000 Subject: [PATCH 02/16] Apply fixes from StyleCI --- src/MigrationBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MigrationBuilder.php b/src/MigrationBuilder.php index 942120cb..49300d1d 100644 --- a/src/MigrationBuilder.php +++ b/src/MigrationBuilder.php @@ -194,7 +194,7 @@ public function delete(string $table, array|string $condition = '', array $param * generated SQL. * * @param string $table The name of the table to be created. The name will be properly quoted by the method. - * @param (string|ColumnSchemaInterface)[] $columns The columns (name => definition) in the new table. + * @param (ColumnSchemaInterface|string)[] $columns The columns (name => definition) in the new table. * @param string|null $options Additional SQL fragment that will be appended to the generated SQL. * * @throws Exception From 432e384013c7a3a8bbf18363ee80a3f1f1c6f6fe Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 2 Dec 2024 13:50:18 +0700 Subject: [PATCH 03/16] Update workflow --- .github/workflows/build.yml | 9 +++++++++ .github/workflows/mssql.yml | 9 +++++++++ .github/workflows/mutation.yml | 9 +++++++++ .github/workflows/mysql.yml | 9 +++++++++ .github/workflows/oracle.yml | 9 +++++++++ .github/workflows/pgsql.yml | 9 +++++++++ .github/workflows/sqlite.yml | 9 +++++++++ 7 files changed, 63 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe73189f..3eec4761 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -61,6 +61,15 @@ jobs: - name: Set environment variables pull request linux. uses: yiisoft/actions/db/environment-linux@master + - name: Install db. + uses: yiisoft/actions/db/subpackage-install@master + with: + BRANCH_NAME: ${{ env.BRANCH_NAME }} + COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} + CURRENT_PACKAGE: db + FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} + WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + - name: Install db-sqlite. uses: yiisoft/actions/db/subpackage-install@master with: diff --git a/.github/workflows/mssql.yml b/.github/workflows/mssql.yml index 9ca11cda..b595e828 100644 --- a/.github/workflows/mssql.yml +++ b/.github/workflows/mssql.yml @@ -78,6 +78,15 @@ jobs: - name: Set environment variables pull request linux. uses: yiisoft/actions/db/environment-linux@master + - name: Install db. + uses: yiisoft/actions/db/subpackage-install@master + with: + BRANCH_NAME: ${{ env.BRANCH_NAME }} + COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} + CURRENT_PACKAGE: db + FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} + WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + - name: Install db-mssql. uses: yiisoft/actions/db/subpackage-install@master with: diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index d0015053..738c7734 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -63,6 +63,15 @@ jobs: - name: Set environment variables pull request linux. uses: yiisoft/actions/db/environment-linux@master + - name: Install db. + uses: yiisoft/actions/db/subpackage-install@master + with: + BRANCH_NAME: ${{ env.BRANCH_NAME }} + COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} + CURRENT_PACKAGE: db + FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} + WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + - name: Install db-pgsql. uses: yiisoft/actions/db/subpackage-install@master with: diff --git a/.github/workflows/mysql.yml b/.github/workflows/mysql.yml index 89454945..78431f44 100644 --- a/.github/workflows/mysql.yml +++ b/.github/workflows/mysql.yml @@ -70,6 +70,15 @@ jobs: - name: Set environment variables pull request linux. uses: yiisoft/actions/db/environment-linux@master + - name: Install db. + uses: yiisoft/actions/db/subpackage-install@master + with: + BRANCH_NAME: ${{ env.BRANCH_NAME }} + COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} + CURRENT_PACKAGE: db + FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} + WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + - name: Install db-mysql. uses: yiisoft/actions/db/subpackage-install@master with: diff --git a/.github/workflows/oracle.yml b/.github/workflows/oracle.yml index 754ec1d3..3fd3e0a5 100644 --- a/.github/workflows/oracle.yml +++ b/.github/workflows/oracle.yml @@ -74,6 +74,15 @@ jobs: - name: Set environment variables pull request linux. uses: yiisoft/actions/db/environment-linux@master + - name: Install db. + uses: yiisoft/actions/db/subpackage-install@master + with: + BRANCH_NAME: ${{ env.BRANCH_NAME }} + COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} + CURRENT_PACKAGE: db + FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} + WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + - name: Install db-oracle. uses: yiisoft/actions/db/subpackage-install@master with: diff --git a/.github/workflows/pgsql.yml b/.github/workflows/pgsql.yml index efc9808d..8adb260f 100644 --- a/.github/workflows/pgsql.yml +++ b/.github/workflows/pgsql.yml @@ -70,6 +70,15 @@ jobs: - name: Set environment variables pull request linux. uses: yiisoft/actions/db/environment-linux@master + - name: Install db. + uses: yiisoft/actions/db/subpackage-install@master + with: + BRANCH_NAME: ${{ env.BRANCH_NAME }} + COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} + CURRENT_PACKAGE: db + FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} + WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + - name: Install db-pgsql. uses: yiisoft/actions/db/subpackage-install@master with: diff --git a/.github/workflows/sqlite.yml b/.github/workflows/sqlite.yml index da69d084..684d1ca6 100644 --- a/.github/workflows/sqlite.yml +++ b/.github/workflows/sqlite.yml @@ -68,6 +68,15 @@ jobs: if: matrix.os == 'windows-latest' uses: yiisoft/actions/db/environment-windows@master + - name: Install db. + uses: yiisoft/actions/db/subpackage-install@master + with: + BRANCH_NAME: ${{ env.BRANCH_NAME }} + COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} + CURRENT_PACKAGE: db + FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} + WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + - name: Install db-sqlite. uses: yiisoft/actions/db/subpackage-install@master with: From daf0bde1c597af9c31069696b923a6e8d3d2aff7 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 11 Dec 2024 18:49:24 +0700 Subject: [PATCH 04/16] Fix MSSQL tests --- tests/Support/Factory/MssqlFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Support/Factory/MssqlFactory.php b/tests/Support/Factory/MssqlFactory.php index 744af6c9..4724fddc 100644 --- a/tests/Support/Factory/MssqlFactory.php +++ b/tests/Support/Factory/MssqlFactory.php @@ -33,7 +33,7 @@ static function (string $id) use (&$container, $config): object { return match ($id) { ConnectionInterface::class => new MssqlConnection( new MssqlDriver( - 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest', + 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no', 'SA', 'YourStrong!Passw0rd', ), From c5f7c7f8aa69ec38d9d17845eca5b327fa5009ff Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 12 Dec 2024 11:02:03 +0700 Subject: [PATCH 05/16] Fix tests --- .github/workflows/build.yml | 2 +- .github/workflows/mssql.yml | 2 +- .github/workflows/mutation.yml | 3 ++- .github/workflows/mysql.yml | 2 +- .github/workflows/oracle.yml | 2 +- .github/workflows/pgsql.yml | 2 +- .github/workflows/sqlite.yml | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3eec4761..d1ed585d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,7 +62,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/db/subpackage-install@add-as-version with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/mssql.yml b/.github/workflows/mssql.yml index b595e828..f4f0da0e 100644 --- a/.github/workflows/mssql.yml +++ b/.github/workflows/mssql.yml @@ -79,7 +79,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/db/subpackage-install@add-as-version with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 738c7734..1b03bdac 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -25,6 +25,7 @@ jobs: name: PHP ${{ matrix.php }} env: + COMPOSER_ROOT_VERSION: dev-master extensions: pdo, pdo_pgsql, pdo_sqlite runs-on: ubuntu-latest @@ -64,7 +65,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/db/subpackage-install@add-as-version with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/mysql.yml b/.github/workflows/mysql.yml index 78431f44..65977ca4 100644 --- a/.github/workflows/mysql.yml +++ b/.github/workflows/mysql.yml @@ -71,7 +71,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/db/subpackage-install@add-as-version with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/oracle.yml b/.github/workflows/oracle.yml index 3fd3e0a5..38093a78 100644 --- a/.github/workflows/oracle.yml +++ b/.github/workflows/oracle.yml @@ -75,7 +75,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/db/subpackage-install@add-as-version with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/pgsql.yml b/.github/workflows/pgsql.yml index 8adb260f..dca0fcf9 100644 --- a/.github/workflows/pgsql.yml +++ b/.github/workflows/pgsql.yml @@ -71,7 +71,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/db/subpackage-install@add-as-version with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/sqlite.yml b/.github/workflows/sqlite.yml index 684d1ca6..9404bc5e 100644 --- a/.github/workflows/sqlite.yml +++ b/.github/workflows/sqlite.yml @@ -69,7 +69,7 @@ jobs: uses: yiisoft/actions/db/environment-windows@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/db/subpackage-install@add-as-version with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} From eef43a9fd7dda04c3b1754fd7afc702db5bd9755 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 12 Dec 2024 11:18:57 +0700 Subject: [PATCH 06/16] Fix psalm tests --- .github/workflows/static.yml | 50 +++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 20297a49..ac23ff1d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -20,9 +20,47 @@ name: static analysis jobs: psalm: - uses: yiisoft/actions/.github/workflows/psalm.yml@master - with: - os: >- - ['ubuntu-latest'] - php: >- - ['8.1', '8.2', '8.3'] + name: PHP ${{ matrix.php }} + + env: + COMPOSER_ROOT_VERSION: dev-master + extensions: pdo + + runs-on: ubuntu-latest + + strategy: + matrix: + php: + - 8.1 + - 8.2 + - 8.3 + + steps: + - name: Checkout. + uses: actions/checkout@v4 + + - name: Install PHP with extensions. + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + coverage: none + tools: cs2pr + + - name: Update composer. + run: composer self-update + + - name: Set environment variables pull request linux. + uses: yiisoft/actions/db/environment-linux@master + + - name: Install db. + uses: yiisoft/actions/db/subpackage-install@master + with: + BRANCH_NAME: ${{ env.BRANCH_NAME }} + COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} + CURRENT_PACKAGE: db + FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} + WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} + + - name: Static analysis. + run: vendor/bin/psalm --config=${{ inputs.psalm-config }} --shepherd --stats --output-format=github --php-version=${{ matrix.php }} From 3bdb1d53bf5119be40d4cfc70b8915ecf0fc9845 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 12 Dec 2024 11:20:12 +0700 Subject: [PATCH 07/16] Fix psalm tests --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index ac23ff1d..9376b0e1 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -54,7 +54,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@master + uses: yiisoft/actions/db/subpackage-install@add-as-version with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} From 56d517fb694213921841939c0ef800d33bbfde95 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 12 Dec 2024 18:07:38 +0700 Subject: [PATCH 08/16] Update tests --- .github/workflows/build.yml | 2 +- .github/workflows/mssql.yml | 2 +- .github/workflows/mutation.yml | 2 +- .github/workflows/mysql.yml | 2 +- .github/workflows/oracle.yml | 2 +- .github/workflows/pgsql.yml | 2 +- .github/workflows/sqlite.yml | 2 +- .github/workflows/static.yml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1ed585d..3eec4761 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,7 +62,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@add-as-version + uses: yiisoft/actions/db/subpackage-install@master with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/mssql.yml b/.github/workflows/mssql.yml index f4f0da0e..b595e828 100644 --- a/.github/workflows/mssql.yml +++ b/.github/workflows/mssql.yml @@ -79,7 +79,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@add-as-version + uses: yiisoft/actions/db/subpackage-install@master with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 1b03bdac..03508709 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -65,7 +65,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@add-as-version + uses: yiisoft/actions/db/subpackage-install@master with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/mysql.yml b/.github/workflows/mysql.yml index 65977ca4..78431f44 100644 --- a/.github/workflows/mysql.yml +++ b/.github/workflows/mysql.yml @@ -71,7 +71,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@add-as-version + uses: yiisoft/actions/db/subpackage-install@master with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/oracle.yml b/.github/workflows/oracle.yml index 38093a78..3fd3e0a5 100644 --- a/.github/workflows/oracle.yml +++ b/.github/workflows/oracle.yml @@ -75,7 +75,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@add-as-version + uses: yiisoft/actions/db/subpackage-install@master with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/pgsql.yml b/.github/workflows/pgsql.yml index dca0fcf9..8adb260f 100644 --- a/.github/workflows/pgsql.yml +++ b/.github/workflows/pgsql.yml @@ -71,7 +71,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@add-as-version + uses: yiisoft/actions/db/subpackage-install@master with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/sqlite.yml b/.github/workflows/sqlite.yml index 9404bc5e..684d1ca6 100644 --- a/.github/workflows/sqlite.yml +++ b/.github/workflows/sqlite.yml @@ -69,7 +69,7 @@ jobs: uses: yiisoft/actions/db/environment-windows@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@add-as-version + uses: yiisoft/actions/db/subpackage-install@master with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 9376b0e1..ac23ff1d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -54,7 +54,7 @@ jobs: uses: yiisoft/actions/db/environment-linux@master - name: Install db. - uses: yiisoft/actions/db/subpackage-install@add-as-version + uses: yiisoft/actions/db/subpackage-install@master with: BRANCH_NAME: ${{ env.BRANCH_NAME }} COMPOSER_ROOT_VERSION: ${{ env.COMPOSER_ROOT_VERSION }} From 9ffd67f87e57a14a9eef30eabeb7a8027b972ae5 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 13 Dec 2024 10:27:20 +0700 Subject: [PATCH 09/16] Update doc and add line to CHANGELOG.md --- CHANGELOG.md | 1 + src/MigrationBuilder.php | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad38596a..3682c79e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Enh #274: Refactor for compatibility with `yiisoft/db` package (@Tigrov) - Bug #277: Fix when there is a namespace but the directory does not exist (@Tigrov) +- Enh #279: Use `ColumnBuilder` class to create table column definitions (@Tigrov) ## 1.2.0 November 27, 2024 diff --git a/src/MigrationBuilder.php b/src/MigrationBuilder.php index 49300d1d..2803ddac 100644 --- a/src/MigrationBuilder.php +++ b/src/MigrationBuilder.php @@ -12,8 +12,10 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Query\QueryInterface; +use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Migration\Informer\MigrationInformerInterface; +use Yiisoft\Db\Schema\Column\ColumnBuilder; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use function implode; @@ -184,11 +186,32 @@ public function delete(string $table, array|string $condition = '', array $param * Builds and executes an SQL statement for creating a new DB table. * * The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name - * stands for a column name which will be properly quoted by the method, and definition stands for the column type - * which can contain an abstract DB type. - * - * The {@see \Yiisoft\Db\Query\QueryBuilder::getColumnType()} method will be invoked to convert any abstract type - * into a physical one. + * is the name of the column which will be properly quoted by the method, and definition is the type of the column + * which can contain a native database column type, {@see ColumnType abstract} or {@see PseudoType pseudo} type, + * or can be represented as instance of {@see ColumnSchemaInterface}. + * + * The {@see QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions + * into SQL representation. For example, it will convert `string not null` to `varchar(255) not null` + * and `pk` to `PRIMARY KEY AUTO_INCREMENT` (for MySQL). + * + * The preferred method is to use {@see ColumnBuilder} to generate column definitions as instances of + * {@see ColumnSchemaInterface}. + * + * ```php + * $this->createTable( + * 'example_table', + * [ + * 'id' => ColumnBuilder::primaryKey(), + * 'name' => ColumnBuilder::string(64)->notNull(), + * 'type' => ColumnBuilder::integer()->notNull()->defaultValue(10), + * 'description' => ColumnBuilder::text(), + * 'rule_name' => ColumnBuilder::string(64), + * 'data' => ColumnBuilder::text(), + * 'created_at' => ColumnBuilder::datetime()->notNull(), + * 'updated_at' => ColumnBuilder::datetime(), + * ], + * ); + * ``` * * If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly put into the * generated SQL. From 252c041a0b1aa605172d4dad049fa57719e4bb4e Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 13 Dec 2024 10:36:33 +0700 Subject: [PATCH 10/16] Update doc [skip ci] --- src/MigrationBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MigrationBuilder.php b/src/MigrationBuilder.php index 2803ddac..929cb1e0 100644 --- a/src/MigrationBuilder.php +++ b/src/MigrationBuilder.php @@ -192,7 +192,7 @@ public function delete(string $table, array|string $condition = '', array $param * * The {@see QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions * into SQL representation. For example, it will convert `string not null` to `varchar(255) not null` - * and `pk` to `PRIMARY KEY AUTO_INCREMENT` (for MySQL). + * and `pk` to `int PRIMARY KEY AUTO_INCREMENT` (for MySQL). * * The preferred method is to use {@see ColumnBuilder} to generate column definitions as instances of * {@see ColumnSchemaInterface}. From 238dafeaf3aba8ea33550c6b909409143deec444 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sat, 14 Dec 2024 10:59:59 +0700 Subject: [PATCH 11/16] Apply suggestions from code review Co-authored-by: Sergei Predvoditelev --- CHANGELOG.md | 2 +- src/Migrator.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3682c79e..207cb2c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Enh #274: Refactor for compatibility with `yiisoft/db` package (@Tigrov) - Bug #277: Fix when there is a namespace but the directory does not exist (@Tigrov) -- Enh #279: Use `ColumnBuilder` class to create table column definitions (@Tigrov) +- Chg #279: Use `ColumnBuilder` class to create table column definitions (@Tigrov) ## 1.2.0 November 27, 2024 diff --git a/src/Migrator.php b/src/Migrator.php index 40848eee..9787621c 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -148,8 +148,6 @@ private function createMigrationHistoryTable(): void $tableName = $this->db->getQuoter()->getRawTableName($this->historyTable); $this->informer->beginCreateHistoryTable('Creating migration history table "' . $tableName . '"...'); - $b = $this->createBuilder(new NullMigrationInformer()); - $b->createTable($this->historyTable, [ 'id' => ColumnBuilder::primaryKey(), 'name' => ColumnBuilder::string($this->migrationNameLimit)->notNull(), From eec186c6fe89d9e02de41be9bb78670f751421d7 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 14 Dec 2024 04:00:10 +0000 Subject: [PATCH 12/16] Apply fixes from StyleCI --- src/Migrator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Migrator.php b/src/Migrator.php index 9787621c..7460dc3c 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -8,7 +8,6 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Migration\Informer\MigrationInformerInterface; -use Yiisoft\Db\Migration\Informer\NullMigrationInformer; use Yiisoft\Db\Schema\Column\ColumnBuilder; final class Migrator From 7d7d91c1db810cd320333768a180940460719e51 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 14 Dec 2024 11:35:18 +0700 Subject: [PATCH 13/16] Revert changes --- src/Migrator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Migrator.php b/src/Migrator.php index 7460dc3c..89de074d 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -147,6 +147,8 @@ private function createMigrationHistoryTable(): void $tableName = $this->db->getQuoter()->getRawTableName($this->historyTable); $this->informer->beginCreateHistoryTable('Creating migration history table "' . $tableName . '"...'); + $b = $this->createBuilder(new NullMigrationInformer()); + $b->createTable($this->historyTable, [ 'id' => ColumnBuilder::primaryKey(), 'name' => ColumnBuilder::string($this->migrationNameLimit)->notNull(), From c659e09ab1f57250922ffb297ec1e3f2763bc1c6 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 14 Dec 2024 11:44:22 +0700 Subject: [PATCH 14/16] Revert changes --- src/Migrator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Migrator.php b/src/Migrator.php index 89de074d..40848eee 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -8,6 +8,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Migration\Informer\MigrationInformerInterface; +use Yiisoft\Db\Migration\Informer\NullMigrationInformer; use Yiisoft\Db\Schema\Column\ColumnBuilder; final class Migrator From fce3791b4863c425e677b43bd97db02afbc751ba Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 14 Dec 2024 13:12:49 +0700 Subject: [PATCH 15/16] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 207cb2c5..1c0a308d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Yii DB Migration Change Log -## 1.2.1 under development +## 2.0.0 under development - Enh #274: Refactor for compatibility with `yiisoft/db` package (@Tigrov) - Bug #277: Fix when there is a namespace but the directory does not exist (@Tigrov) From 588745dc817fdc83c3803fb8c7b752bd371df26a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 14 Dec 2024 13:19:45 +0700 Subject: [PATCH 16/16] Add UPGRADE.md --- UPGRADE.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 UPGRADE.md diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 00000000..3db75cdf --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,25 @@ +# Upgrading Instructions for Yii DB Migration + +This file contains the upgrade notes. These notes highlight changes that could break your +application when you upgrade the package from one version to another. + +> **Important!** The following upgrading instructions are cumulative. That is, if you want +> to upgrade from version A to version C and there is version B between A and C, you need +> to following the instructions for both A and B. + +## Upgrade from 1.x to 2.x + +Use `\Yiisoft\Db\Schema\Column\ColumnBuilder` to create table column definitions. + +```php +use Yiisoft\Db\Migration\MigrationBuilder; +use Yiisoft\Db\Schema\Column\ColumnBuilder; + +/** @var MigrationBuilder $b */ +$b->createTable('user', [ + 'id' => ColumnBuilder::primaryKey(), + 'name' => ColumnBuilder::string(64)->notNull(), + 'age' => ColumnBuilder::integer(), + 'created_at' => ColumnBuilder::timestamp(), +]); +```