tobento/app-migration

应用迁移支持。

1.0.3 2024-02-20 17:34 UTC

This package is auto-updated.

Last update: 2024-09-20 18:59:23 UTC


README

应用迁移支持。

目录

入门

通过运行此命令添加正在运行的应用迁移项目的最新版本。

composer require tobento/app-migration

要求

  • PHP 8.0 或更高版本

文档

应用

如果您正在使用框架,请查看应用框架

您还可以查看应用以了解更多有关应用的一般信息。

迁移引导

迁移引导执行以下操作

  • \Tobento\Service\Migration\MigratorInterface::class的定义
  • \Tobento\Service\Migration\MigrationResultsInterface::class的定义
  • 安装和加载迁移配置文件
  • 添加安装和卸载应用宏
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();

安装和卸载迁移

一旦启动了迁移引导,您可以按照以下方式安装迁移:

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);        
    }
}

创建迁移

查看迁移服务以了解更多有关创建迁移类的信息。

控制台

如果您已安装应用控制台,可以运行以下命令。

迁移列表命令

migration:list命令提供了所有已安装迁移的概览

php ap migration:list

迁移安装命令

通过其类安装迁移

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

重新安装所有迁移

php ap migration:install --all

通过其ID重新安装特定的迁移或/和操作。要获取ID,请运行migration:list命令

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

通过其类型重新安装特定的迁移或/和操作。

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

迁移卸载命令

通过其类卸载迁移

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

卸载所有迁移

php ap migration:uninstall --all

通过其ID卸载特定的迁移。要获取ID,请运行migration:list命令

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

致谢