cycle / migrations
数据库迁移,迁移脚手架
v4.2.3
2024-01-25 10:49 UTC
Requires
- php: >=8.1
- cycle/database: ^2.7.0
- spiral/core: ^3.0
- spiral/files: ^3.0
- spiral/reactor: ^3.0
- spiral/tokenizer: ^3.0
Requires (Dev)
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5
- vimeo/psalm: dev-master
This package is auto-updated.
Last update: 2024-08-25 12:08:53 UTC
README
迁移是一种方便的、结构化和组织化的方式,用于更改您的数据库。此包添加了版本控制数据库模式的功能,并可以轻松部署更改。这是一个非常易于使用且功能强大的工具。
安装
composer require cycle/migrations ^4.0
配置
use Cycle\Migrations; use Cycle\Database; use Cycle\Database\Config; $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, ), ] ])); $config = new Migrations\Config\MigrationConfig([ 'directory' => __DIR__ . '/../migrations/', // where to store migrations 'vendorDirectories' => [ // Where to look for vendor package migrations __DIR__ . '/../vendor/vendorName/packageName/migrations/' ], 'table' => 'migrations' // database table to store migration status 'safe' => true // When set to true no confirmation will be requested on migration run. ]); $migrator = new Migrations\Migrator( $config, $dbal, new Migrations\FileRepository($config) ); // Init migration table $migrator->configure();
运行
while (($migration = $migrator->run()) !== null) { echo 'Migrate ' . $migration->getState()->getName(); }
生成迁移
在架构编译过程中,您可以自动生成一系列迁移文件。在这种情况下,在运行之前,您可以手动更改这些迁移。要实现这一点,您必须安装架构迁移生成器扩展。
许可
MIT 许可证 (MIT)。有关更多信息,请参阅LICENSE
。由 Spiral Scout 维护。