matheusbiagini/biagini-migration

本包的最新版本(v1.0.1)没有可用的许可证信息。

使用pdo、schema和queryBuilder实现dbal do doctrine的php数据迁移机制

v1.0.1 2022-05-11 19:06 UTC

This package is auto-updated.

Last update: 2024-09-12 00:24:25 UTC


README

Minimum PHP Version

一个用于处理从数据库迁移数据的库。它使用并提供 doctrine dbal 实例的迁移,给开发者提供更大的灵活性。它使用 symfony 控制台,使得帮助更加友好和迭代。

设置。

  1. 在您的个人项目中创建一个文件,取您喜欢的任何名称

例如:example.php

<?php

declare(strict_types=1);

use AliceMigration\Management\Configuration\Configuration;
use AliceMigration\Migration\Migration;

#Path where your migration classes will be created
$pathMigrations = "/path/";

#Namespace that your migration classes meet, use the path namespace that you previously defined.
$namespace = 'PathNamespace';

#Here it can be customized because the configuration class expects an instance of the PDO
$pdo = new PDO('mysql:host=your_hostname;dbname=your_db;charset=UTF-8', $user, $pass);

#Creating the migration command console
$migration = new Migration(new Configuration($pdo, $pathMigrations, $namespace));
$migration->run();
  1. 现在您新创建的文件已经成为中央数据迁移命令,要访问终端,请输入
php example.php

创建数据迁移。

这个迁移命令提供了使用 doctrine Dbal 添加命令和 sql 语句的可能性。要生成数据迁移类,您必须在终端中输入以下命令

php example.php migrate:create

运行命令后,将在您在设置中定义的路径中创建一个类。现在编辑创建的类,并添加您需要的迁移指令。

运行创建的迁移。

要运行您的迁移类,您需要在终端中运行以下命令

php example.php migrate:run

有关此命令可选参数的更多信息,请在终端上运行带有 --help 结尾的命令。例如

php example.php migrate:run --help

回滚迁移。

要回滚迁移或运行您设置的回滚,请在终端上运行以下命令

php example.php migrate:revert <filename>
  • filename 是您数据迁移类的名称。

例如

php example.php migrate:revert MigrateVersion1546978382.php

有关此命令可选参数的更多信息,请在终端上运行带有 --help 结尾的命令。例如

php example.php migrate:revert --help

作者

享受它 :)