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/ */
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'),
];
}