PHP code example of dconco / schema-migrator

1. Go to this page and download the library: Download dconco/schema-migrator 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/ */

    

dconco / schema-migrator example snippets




use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Capsule\Manager as Capsule;

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

    public function down(): void
    {
        Capsule::schema()->dropIfExists('users');
    }
};

Capsule::schema()->create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->text('content');
    $table->foreignId('user_id')->constrained();
    $table->timestamps();
});

Capsule::schema()->table('users', function (Blueprint $table) {
    $table->string('phone')->nullable();
    $table->boolean('is_active')->default(true);
});

Capsule::schema()->table('posts', function (Blueprint $table) {
    $table->index('title');
    $table->index(['user_id', 'created_at']);
});

your-project/
├── schema-migrator.yml
├── database/
│   └── migrations/
│       ├── 2025_01_01_000000_create_users.php
│       ├── 2025_01_01_000001_create_posts.php
│       └── 2025_01_01_000002_add_category_to_posts.php
├── src/
└── composer.json