Skip to content

Possible syntax improvements #316

@samdark

Description

@samdark

Proposed new feature or change

Why

It should be as easy as possible to write and read migrations. Current syntax could be optimized.

Current syntax

<?php

declare(strict_types=1);

namespace App\Migration;

use Yiisoft\Db\Migration\MigrationBuilder;
use Yiisoft\Db\Migration\RevertibleMigrationInterface;

final class M251225221906CreateNewsTable implements RevertibleMigrationInterface
{
    public function up(MigrationBuilder $b): void
    {
        $cb = $b->columnBuilder();

        $b->createTable('news', [
            'id' => $cb::uuidPrimaryKey(),
            'title' => $cb::string()->notNull(),
            'content' => $cb::text(),
        ]);
    }

    public function down(MigrationBuilder $b): void
    {
        $b->dropTable('news');
    }
}

Proposal

  1. Pass column builder as argument so there's no need to call $cb = $b->columnBuilder();
  2. Better naming.
<?php

declare(strict_types=1);

namespace App\Migration;

use Yiisoft\Db\Migration\MigrationBuilder;
use Yiisoft\Db\Migration\RevertibleMigrationInterface;

final class M251225221906CreateNewsTable implements RevertibleMigrationInterface
{
    public function up(MigrationBuilder $build, string $type): void
    {
        $build->createTable('news', [
            'id' => $type::uuidPrimaryKey(),
            'title' => $type::string()->notNull(),
            'content' => $type::text(),
        ]);
    }

    public function down(MigrationBuilder $build): void
    {
        $build->dropTable('news');
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions