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




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

return new class extends Migration
{
public function up(): string|array|SqlStatement
    {
        return $this->raw(<<<'SQL'
        CREATE TABLE users (
            id INT NOT NULL AUTO_INCREMENT,
            name VARCHAR(255) NOT NULL,
            email VARCHAR(180) NOT NULL,
            PRIMARY KEY (id)
        );
        SQL);
    }

    public function down(): string|array|SqlStatement
    {
        return $this->raw(<<<'SQL'
        DROP TABLE IF EXISTS users;
        SQL);
    }
};

public function up(): SqlStatement
{
    return $this->create('users')
        ->id()
        ->column('name VARCHAR(255) NOT NULL')
        ->column('email VARCHAR(180) NOT NULL')
        ->unique('uq_users_email', 'email')
        ->timestamps();
}

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

'template' => 'raw', // raw | fluent
bash
php vendor/bin/migraw init
bash
php vendor/bin/migraw make create_users_table
bash
php vendor/bin/migraw migrate
bash
php vendor/bin/migraw status
bash
php vendor/bin/migraw rollback
bash
php vendor/bin/migraw make populate_roles --populate
bash
php vendor/bin/migraw squash
bash
php vendor/bin/migraw unsquash
bash
php vendor/bin/migraw help