dconco / schema-migrator
A beautiful command-line database migration tool for any PHP project. Laravel-style migrations without the framework.
Requires
- php: ^8.1
- illuminate/database: ^11.0|^12.0
- illuminate/events: ^11.0|^12.0
- symfony/console: ^6.0|^7.0
- symfony/yaml: ^6.0|^7.0
README
A beautiful command-line database migration tool for any PHP project. Laravel-style migrations without the framework complexity.
Features
✨ Beautiful CLI Interface - Powered by Symfony Console with colored output and interactive commands
🚀 Global Installation - Install once, use anywhere in any PHP project
🔧 Zero Dependencies - No need to install Laravel or any framework in your projects
📁 Project-Based Config - Each project maintains its own configuration and migrations
🗄️ Multi-Database Support - MySQL, PostgreSQL, SQLite, and SQL Server
⚡ Laravel-Compatible - Uses Laravel's proven migration syntax and features
Global Installation
Install Schema Migrator globally via Composer:
composer global require dconco/schema-migrator
Make sure your global Composer bin directory is in your PATH:
# Add to your ~/.bashrc or ~/.zshrc export PATH="$PATH:$HOME/.composer/vendor/bin"
Quick Start
1. Initialize in Your Project
Navigate to your PHP project and initialize Schema Migrator:
cd /path/to/your/project
schema-migrator init
This will:
- Create a
schema-migrator.yml
configuration file - Create a
database/migrations
directory - Prompt you for database connection details
2. Create Your First Migration
schema-migrator make:migration CreateUsersTable
3. Edit the Migration
Edit the generated file in database/migrations/
:
<?php 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'); } };
4. Run Migrations
schema-migrator migrate
Commands
Initialize Project
schema-migrator init
Creates configuration and migrations directory in current project.
Create Migration
schema-migrator make:migration CreatePostsTable schema-migrator make:migration AddEmailToUsersTable
Creates a new migration file with timestamp.
Run Migrations
schema-migrator migrate
Executes all pending migrations.
Check Status
schema-migrator migrate:status
Shows which migrations have been executed and which are pending.
Rollback Migrations
schema-migrator migrate:rollback schema-migrator migrate:rollback --steps=3
Rolls back the last batch of migrations (or specified number of batches).
Configuration
The schema-migrator.yml
file contains your project's configuration:
database: driver: mysql # mysql, pgsql, sqlite, sqlsrv host: 127.0.0.1 port: 3306 database: your_database username: your_username password: your_password charset: utf8mb4 collation: utf8mb4_unicode_ci prefix: '' migrations: table: migrations path: database/migrations
Usage Examples
Project Structure
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
Migration Examples
Create a table:
Capsule::schema()->create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('content'); $table->foreignId('user_id')->constrained(); $table->timestamps(); });
Add columns:
Capsule::schema()->table('users', function (Blueprint $table) { $table->string('phone')->nullable(); $table->boolean('is_active')->default(true); });
Create indexes:
Capsule::schema()->table('posts', function (Blueprint $table) { $table->index('title'); $table->index(['user_id', 'created_at']); });
Multiple Projects
Schema Migrator works per-project. You can use it in multiple projects simultaneously:
cd /project-a schema-migrator init # Configure for project A schema-migrator migrate cd /project-b schema-migrator init # Configure for project B schema-migrator migrate
Each project maintains its own configuration and migration state.
Requirements
- PHP 8.1 or higher
- PDO extension for your database
- Composer (for global installation)
License
The MIT License (MIT). Please see License File for more information.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Now you have Laravel-style migrations in any PHP project! 🎉