roolith / migration
php simple migration
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/roolith/migration
Requires
- php: >=8.0
- fakerphp/faker: ^1.24
- roolith/database: 1.4.0
README
Simple migration and seeding tool for PHP applications.
Installation
You can install roolith-migration using Composer:
composer require roolith/migration
Usage
Create a PHP file migration.php and add the following code:
use Roolith\Migration\Migration; require __DIR__ . "/../vendor/autoload.php"; $migration = new Migration(); $migration ->settings([ "folder" => __DIR__ . "/migrations", "database" => [ "host" => "localhost", "name" => "db_name", "user" => "user", "pass" => "pass", ], ]) ->run($argv);
Command
Assuming your filename is migration.php, you can run the migration command as follows:
php migration.php migration:create migration_name
php migration.php migration:run # it will run all pending migrations
php migration.php migration:run migration_name
php migration.php migration:rollback migration_name
php migration.php migration:status
For seeding data, you can use the following command:
php migration.php seed:create seed_name
php migration.php seed:run # it will run all pending seeds
php migration.php seed:run seed_name
Notes
- it will create migrations table if not exists
- it will create migrations folder if not exists
- You can change the name of the folder by passing settings
Example of migration file
php migration.php migration:create create_users_table
<?php use Roolith\Store\Interfaces\DatabaseInterface; use Roolith\Migration\Interfaces\MigrationInterface; class CreateUsersTable implements MigrationInterface { public function up(DatabaseInterface $db): void {} public function down(DatabaseInterface $db): void {} }
Example of seed file
php migration.php seed:create add_users
<?php use Roolith\Migration\Interfaces\SeederInterface; use Roolith\Store\Interfaces\DatabaseInterface; class AddUsers implements SeederInterface { public function run(DatabaseInterface $db): void {} }