yiisoft / yiisoft/db-migration

Possible syntax improvements

Open
#316 15 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type:enhancement
Dominant language
PHP
Stars
32
Forks
18
Avg merge
22h 18m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the current and proposed migration examples, then trace MigrationBuilder, columnBuilder(), and RevertibleMigrationInterface. Clarify the intended parameter and naming changes, inspect existing migration-related tests, and consider the work done when the revised syntax is consistently supported for both up() and down() migrations.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.