rafaelmiano/phpspa-migrate
最新稳定版本:v1.1.0
Composer 安装命令:
composer require rafaelmiano/phpspa-migrate
包简介
A simple and elegant database migration system for PHP applications
README 文档
README
A simple and elegant database migration system for PHP applications.
Installation
composer require rafaelmiano/phpspa-migrate
Configuration
Create a .env file in your project root with database configuration:
DB_HOST=localhost DB_DATABASE=your_database DB_USERNAME=root DB_PASSWORD=
Usage
You can use the migration tool through vendor/bin:
php vendor/bin/migrate create users_table
Creating Migrations
This will create a new migration file in database/migrations with a timestamp prefix.
Example:
php vendor/bin/migrate create users_table
This will create a new migration file in database/migrations with a timestamp prefix.
Writing Migrations
<?php use RafaelMiano\PhpSpaMigrate\Migration\Migration; return new class($connection) extends Migration { public function up() { $this->createTable('users', function($table) { $table->id(); $table->string('username')->unique(); $table->string('email'); $table->string('password'); $table->timestamps(); }); } public function down() { $this->dropTable('users'); } };
Available Schema Methods
id()- Add auto-incrementing IDstring(name, length = 255)- Add VARCHAR columninteger(name)- Add INT columntext(name)- Add TEXT columntimestamp(name)- Add TIMESTAMP columntimestamps()- Add created_at and updated_at columnsunique()- Make column uniquenullable()- Make column nullableforeignKey(column)- Add foreign keyreferences(table.column)- Reference a foreign key
Running Migrations
php vendor/bin/migrate run # Run pending migrations php vendor/bin/migrate fresh # Drop all tables and run migrations
Rolling Back Migrations
php vendor/bin/migrate rollback # Rollback last batch of migrations
Other Commands
php vendor/bin/migrate help # Show all available commands php vendor/bin/migrate status # Show migration status
Fresh Migrations
The fresh command provides a clean slate by dropping all tables and running migrations again:
php vendor/bin/migrate fresh
This will:
- Show a confirmation prompt
- Drop all existing tables
- Recreate the migrations table
- Run all migrations from scratch
Features
- Interactive database creation
- Batch-based migrations
- Simple and intuitive schema builder
- Environment configuration support
- Rollback capability
- Pretty console output
- Error handling and user feedback
Contributing
Feel free to submit pull requests or create issues for bugs and feature requests.
License
This package is open-source software licensed under the MIT license.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-10