PHP code example of eril / migraw

1. Go to this page and download the library: Download eril/migraw library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eril / migraw example snippets




return [

    'path' => 'database/migrations',

    'connection' => [

        'driver' => 'mysql',

        'host' => '127.0.0.1',
        'port' => '3306',
        'database' => 'example',

        'username' => 'root',
        'password' => '',

        'charset' => 'utf8mb4',

    ],

];

return [

    'path' => 'database/migrations',

    'connection' => new PDO(...),

];

return [

    'path' => 'database/migrations',

    'connection' => static fn (): PDO => Database::connection(),

];



use Eril\Migraw\Migration;

return new class extends Migration
{
    public function up(): string
    {
        return <<<SQL
        CREATE TABLE users (
            id INT AUTO_INCREMENT PRIMARY KEY,
            name VARCHAR(255) NOT NULL
        );
        SQL;
    }

    public function down(): string
    {
        return <<<SQL
        DROP TABLE users;
        SQL;
    }
};



use Eril\Migraw\Migration;
use Eril\Migraw\Sql\SqlStatement;

return new class extends Migration
{
    public function up(): SqlStatement
    {
        return $this->create('users')
            ->id()
            ->column('name VARCHAR(255) NOT NULL')
            ->column('email VARCHAR(180) NOT NULL UNIQUE')
            ->column('password_hash VARCHAR(255) NOT NULL')
            ->timestamps();
    }

    public function down(): SqlStatement
    {
        $this->drop('users')
            ->ifExists();
    }
};

public function up(): array
{
    return [

        $this->create('roles')
            ->id()
            ->column('name VARCHAR(80) NOT NULL UNIQUE'),

        $this->create('users')
            ->id()
            ->column('role_id INT NOT NULL')
            ->foreign('role_id', 'roles'),

    ];
}
bash
php vendor/bin/migraw init
bash
php vendor/bin/migraw init:mysql
php vendor/bin/migraw init:pgsql
php vendor/bin/migraw init:sqlite
text
migraw.php

database/
└── migrations/
bash
php vendor/bin/migraw make create_users_table
text
database/migrations/
└── 20260627143000_create_users_table.php
bash
php vendor/bin/migraw make create_users_table -t
bash
php vendor/bin/migraw
bash
php vendor/bin/migraw migrate
php vendor/bin/migraw up
bash
php vendor/bin/migraw rollback
php vendor/bin/migraw down
bash
php vendor/bin/migraw reset
bash
php vendor/bin/migraw fresh
bash
php vendor/bin/migraw status
bash
php vendor/bin/migraw migrate --dry-run
bash
php vendor/bin/migraw migrate --pretend
text
20260601_create_users_table.php
text
20260601_create_users_table.php
20260610_add_phone_to_users.php
20260612_create_roles_table.php