wijoc / mi-grator
A stand alone database migration for PHP and Wordpress.
Requires
- php: ^7.4 || ^8.0 || ^8.1 || ^8.2
- symfony/console: ^6.0
- vlucas/phpdotenv: ^5.5
Suggests
- wp-cli/wp-cli: Install WP-CLI globally if you want WP-CLI support
This package is not auto-updated.
Last update: 2025-08-08 04:44:30 UTC
README
Extra Package PHP Database Migration that is compatible with procedural PHP and WordPress. This project provides a database migration specifically for WordPress projects. Heavily influenced by Laravel and/or Symfony migration and inspired by CakePHP/Phinx cakephp/phinx, this project originated from a personal need and is still in beta development. All inputs are highly appreciated.
📦 Features
- Create, Migrate and rollback migration
- PHP CLI support (
vendor/bin/mi-grator
) - Native WordPress CLI (
wp mi-grator
) support - Supported commands to make migration, migrate new migration, and/or reset migration
🧩 Dependencies
- PHP 7.4+ or 8.x
- Composer (for autoloading)
- Symfony Consolesymfony/console (for cli command)
- PHP dotenvvlucas/phpdotenv (for loading .env file)
- WP-CLI (for WordPress command-line integration)
- WordPress (optional, only for WP CLI support)
Autoloading and command registration are handled automatically via Composer.
📁 Project Directory Structure (after installation directories)
your-project
├── migrations/
│ ├── 2025_08_07_000000_create_user_table.php
│ └── 2025_08_07_000000_create_user_detail_table.php
├── vendor/
│ ├── wijoc/mi-grator
│ │ ├── Commands
│ │ └── Migrations
| ├── Kernel.php
│ └── QueryBuilder.php
🧰 Requirements
- WordPress 6.2+
- PHP 8.0+
🚧 Installation
- You can install the library via Composer:
composer require wijoc/mi-grator
or copy from this repository and move it to your project directory
git clone git@github.com:wijoc/validify-mi.git mv wijoc/mi-grator /project-dir
- Set env or constant for migration table name and migration path
DB_HOST={your_databe_host} DB_USER={your_databe_username} DB_PASSWORD={your_databe_password} DB_NAME={your_databe_name} MIGRATION_TABLE={your_migration_table_name} # By default this will set to 'migration' MIGRATION_FILE_PATH={your_migration_table_name} # By default this will set to directory ./migrations
Usage
💻 In Plain PHP (non-WordPress)
Use the CLI binary provided:
./vendor/bin/mygrator make:migration create_users_table --table=users ./vendor/bin/mygrator migrate ./vendor/bin/mygrator migrate:fresh ./vendor/bin/mygrator migrate:rollback ./vendor/bin/mygrator migrate:reset
You can include these in your deployment scripts, CI/CD pipelines, or setup scripts.
🧩 In WordPress (via WP-CLI)
If you're using WordPress and WP-CLI, and your theme/plugin loads vendor/autoload.php, you're ready to go:
wp mi-grator make:migration create_users_table --table=users wp mi-grator migrate wp mi-grator migrate:rollback
⚠️ Ensure your theme or plugin loads Composer autoloader:
require_once **DIR** . '/vendor/autoload.php';
You can also use a must-use plugin (mu-plugin) to include the autoloader automatically if you're building a distributable plugin.
📃 License
MIT License
🤝 Contributions
Pull requests are welcome! If you find a bug or have a feature request, feel free to open an issue.