cycle/schema-migrations-generator

Cycle ORM 迁移生成

2.2.0 2023-11-02 09:24 UTC

This package is auto-updated.

Last update: 2024-08-31 00:31:36 UTC


README

Latest Stable Version Build Status Scrutinizer Code Quality Codecov

通过迁移生成器包,您可以在模式编译期间自动生成一组迁移文件用于 Cycle ORM。在这种情况下,您可以在运行之前手动修改这些迁移。

安装

composer require cycle/schema-migrations-generator

配置

use Cycle\Migrations;
use Cycle\Schema\Registry;
use Cycle\Schema\Definition\Entity;
use Cycle\Database;
use Cycle\Database\Config;
use Cycle\Schema\Generator\Migrations\GenerateMigrations;

$dbal = new Database\DatabaseManager(new Config\DatabaseConfig([
    'default' => 'default',
    'databases' => [
        'default' => [
            'connection' => 'sqlite'
        ]
    ],
    'connections' => [
        'sqlite' => new Config\SQLiteDriverConfig(
            connection: new Config\SQLite\MemoryConnectionConfig(),
            queryCache: true,
        ),
    ]
]));

$migrator = new Migrations\Migrator(
    $config, 
    $dbal, 
    new Migrations\FileRepository($config)
);

$registry = new Registry($dbal);
$registry->register(....);

$generator = new GenerateMigrations(
    $migrator->getRepository(), 
    $migrator->getConfig()
);

运行

迁移生成器创建一组所需的迁移,以同步数据库模式与期望的状态。每个数据库将接收自己的迁移。

$generator->run($registry);

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅LICENSE。由 Spiral Scout 维护。