PHP code example of crazyfd / php-migrations

1. Go to this page and download the library: Download crazyfd/php-migrations 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/ */

    

crazyfd / php-migrations example snippets


return [
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            'driver'   => 'mysql',
            'host'     => '127.0.0.1',
            'port'     => '3306',
            'database' => 'demo',
            'username' => 'root',
            'password' => '',
            'charset'  => 'utf8mb4',
            'prefix'   => '',
        ],
        'pgsql'  => [ /* ... */ ],
        'sqlite' => [
            'driver'   => 'sqlite',
            'database' => '/path/to/database.sqlite',
            'prefix'   => '',
        ],
    ],
];



use Eloquent\Migrations\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};

$this->schema()->create('users', function (Blueprint $table) { /* ... */ });



namespace Database\Seeders;

use Eloquent\Migrations\Seeds\Seeder;

class UsersTableSeeder extends Seeder
{
    public function run(): void
    {
        $this->table('users')->insert([
            ['name' => 'alice', 'email' => '[email protected]'],
        ]);
    }
}


$capsule = new Illuminate\Database\Capsule\Manager();
$capsule->addConnection([
    'driver'   => 'mysql',
    'host'     => '127.0.0.1',
    'database' => 'demo',
    'username' => 'root',
    'password' => '',
    'prefix'   => '',
]);

return [
    'default_environment' => 'development',
    'paths' => [
        'migrations' => 'database/migrations',
        'seeds'      => 'database/seeders',
    ],
    'migration_table' => 'migrations',
    'db' => $capsule->getDatabaseManager(),
];
bash
composer 
bash
touch runtime/your_database.sqlite          # 手动创建
php webman create:database your_database.sqlite  # 或用本包命令自动创建