eril/migraw
Composer 安装命令:
composer require eril/migraw
包简介
Simple SQL-first migrations for PHP.
README 文档
README
SQL-first migrations for PHP.
Write SQL. Not magic.
Migraw is a lightweight migration tool that embraces SQL instead of hiding it.
Write raw SQL when you need complete control, generate smart SQL templates to get started quickly, or use the optional schema builder for common table operations.
Features
- SQL-first migrations
- Raw SQL support
- Lightweight schema builder
- Smart migration templates
- MySQL, MariaDB, PostgreSQL and SQLite support
- Driver-aware schema helpers
- Migration batches
- Rollback support
- Dry-run mode
- Interactive CLI
- PDO or callable connection
- Framework agnostic
- Zero runtime dependencies
Installation
composer require eril/migraw
Getting Started
Generate the default configuration:
php vendor/bin/migraw init
or choose a specific driver:
php vendor/bin/migraw init:mysql php vendor/bin/migraw init:pgsql php vendor/bin/migraw init:sqlite
This creates:
migraw.php
database/
└── migrations/
Configuration
Using a connection array:
<?php return [ 'path' => 'database/migrations', 'connection' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'example', 'username' => 'root', 'password' => '', 'charset' => 'utf8mb4', ], ];
Or provide a PDO instance:
return [ 'path' => 'database/migrations', 'connection' => new PDO(...), ];
Or a callable:
return [ 'path' => 'database/migrations', 'connection' => static fn (): PDO => Database::connection(), ];
Creating a Migration
Create a migration:
php vendor/bin/migraw make my_migration_name
Migraw will generate a smart SQL template when the migration name matches a known pattern.
Example:
database/migrations/
└── 20260627143000_my_migration_name.php
Raw SQL
<?php use Eril\Migraw\Migration; return new class extends Migration { public function up(): string { return <<<SQL -- Write your UP SQL here SQL; } public function down(): string { return <<<SQL -- Write your DOWN SQL here SQL; } };
Smart Templates
Migraw recognizes common migration names and generates an appropriate SQL template.
| Migration name | Generated SQL |
|---|---|
create_users_table |
CREATE TABLE users (...) |
create_roles |
CREATE TABLE roles (...) |
drop_users_table |
DROP TABLE users |
rename_users_to_members |
RENAME TABLE users TO members |
add_email_to_users |
ALTER TABLE users ADD COLUMN email ... |
remove_email_from_users |
ALTER TABLE users DROP COLUMN email |
create_users_email_index |
CREATE INDEX idx_users_email ON users(email) |
drop_users_email_index |
DROP INDEX idx_users_email |
create_unique_users_email |
ALTER TABLE users ADD CONSTRAINT uq_users_email UNIQUE(email) |
drop_unique_users_email |
ALTER TABLE users DROP CONSTRAINT uq_users_email |
If no known pattern matches, Migraw generates a blank SQL migration instead.
Use --blank or -b to force an empty raw SQL stub.
return $this->raw(<<<SQL -- Write here your sql SQL);
SQL Helpers
<?php 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 { return $this->drop('users') ->ifExists(); } };
Multiple Statements
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'), ]; }
Running Migrations
Run pending migrations:
php vendor/bin/migraw migrate php vendor/bin/migraw up
Rollback the last batch:
php vendor/bin/migraw rollback php vendor/bin/migraw down
Rollback every executed migration:
php vendor/bin/migraw reset
Rollback everything and migrate again:
php vendor/bin/migraw fresh
Show migration status:
php vendor/bin/migraw status
Validate migration files:
php vendor/bin/migraw validate
Check configuration and environment:
php vendor/bin/migraw doctor
Remove missing migration records:
php vendor/bin/migraw repair
Dry Run
Preview SQL without executing it:
php vendor/bin/migraw migrate --dry-run
or
php vendor/bin/migraw migrate --pretend
Migration Philosophy
Treat migrations as immutable.
Instead of editing an existing migration:
20260601_create_users_table.php
create a new one:
20260601_create_users_table.php
20260610_add_phone_to_users.php
20260612_create_roles_table.php
This keeps every environment synchronized and preserves migration history.
Philosophy
Migraw is built around a simple idea:
SQL is already a schema language.
Instead of replacing SQL with a complex abstraction, Migraw keeps SQL visible and explicit.
You choose the level of abstraction that best fits your project:
- Raw SQL
- Smart SQL templates
- Lightweight SQL helpers
Nothing more.
Requirements
- PHP 8.1+
- PDO extension
Supported databases:
- MySQL
- MariaDB
- PostgreSQL
- SQLite
Testing
composer test
License
MIT License
Copyright (c) 2026 Eril TS Carvalho
eril/migraw 适用场景与选型建议
eril/migraw 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「migrations」 「sql」 「cli」 「mysql」 「schema」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eril/migraw 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eril/migraw 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eril/migraw 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Query filtering in your frontend
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 48
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-29