tobento/app-migration

App migration support.

1.0.3 2024-02-20 17:34 UTC

This package is auto-updated.

Last update: 2024-04-20 18:03:19 UTC


README

App migration support.

Table of Contents

Getting Started

Add the latest version of the app migration project running this command.

composer require tobento/app-migration

Requirements

  • PHP 8.0 or greater

Documentation

App

Check out the App Skeleton if you are using the skeleton.

You may also check out the App to learn more about the app in general.

Migration Boot

The migration boot does the following:

  • definition of \Tobento\Service\Migration\MigratorInterface::class
  • definition of \Tobento\Service\Migration\MigrationResultsInterface::class
  • installs and loads migration config file
  • adds install and uninstall app macros
use Tobento\App\AppFactory;

// Create the app
$app = (new AppFactory())->createApp();

// Adding boots
$app->boot(\Tobento\App\Migration\Boot\Migration::class);

// Run the app
$app->run();

Install and Uninstall Migration

Once the Migration Boot has been booted you may install migrations by the following ways:

use Tobento\App\Boot;
use Tobento\App\Migration\Boot\Migration;

class AnyServiceBoot extends Boot
{
    public const BOOT = [
        // you may ensure the migration boot.
        Migration::class,
    ];
    
    public function boot(Migration $migration)
    {
        // Install migrations
        $migration->install(AnyMigration::class);
        
        // Uninstall migrations
        $migration->uninstall(AnyMigration::class);
        
        // Install migrations with app macro
        $this->app->install(AnyMigration::class);
        
        // Uninstall migrations with app macro
        $this->app->uninstall(AnyMigration::class);        
    }
}

Create Migration

Check out the Migration Service to learn more about creating migration classes.

Console

If you have installed the App Console you may run the following commands.

Migration List Command

The migration:list command provides an overview of all the migrations installed:

php ap migration:list

Migration Install Command

Install a migration by its class:

php ap migration:install --name=Namespace\Migration

Reinstalls all migrations:

php ap migration:install --all

Reinstalls specific migration(s) or/and action(s) by its ids. To get the ids, run migration:list command:

php ap migration:install --id=12|23

Reinstalls specific migration(s) or/and action(s) by its type.

php ap migration:install --type=database|views

Migration Uninstall Command

Uninstall a migration by its class:

php ap migration:uninstall --name=Namespace\Migration

Uninstalls all migrations:

php ap migration:uninstall --all

Uninstalls specific migration(s) by its ids. To get the ids, run migration:list command:

php ap migration:uninstall --id=12|23

Credits