whirlwind-framework/migration-core
最新稳定版本:v0.0.3
Composer 安装命令:
composer require whirlwind-framework/migration-core
包简介
Whirlwind framework migration tool interface
README 文档
README
Common interface for implementing Whirlwind framework database migrations.
Implementation notes
- Create implementation of
MigrationTableGatewayInterface. MethodqueryOrCreateCollectionmust create migration collection if it not exists.
class DummyMigrationTableGateway extends MongoTableGateway implements MigrationTableGatewayInterface { protected string $collectionName = 'migrations'; public function queryOrCreateCollection(array $conditions = [], int $limit = 0, array $order = []): array { $collection = $this->connection->listCollections(['name' => $this->collectionName]); if (!$collection) { $this->createCollection($this->collectionName); } return $this->queryAll($conditions, $order, $limit) } }
- Create your database implementation for
BlueprintInterfaceandBlueprintFactoryInterface. All operation such as creating, modifying, dropping and others will be handled there.
class DummyBlueprint implements \Whirlwind\MigrationCore\BlueprintInterface { protected string $collectionName; protected Query $current; // your database query builder implementation protected array $queries = []; public function __construct(string $collectionName) { $this->collectionName = $collectionName; } public function build(ConnectionInterface $connection): void { foreach ($queries as $query) { $query->execute($connection); } } public function create(callable $callback): void { $this->current = new Query(); $callback($this); $this->queries[] = $this->current; } public function drop(): void { $this->queries[] = (new Query())->dropCollection($this->collectionName); } public function dropIfExists(): void { $this->queries[] = (new Query())->dropCollectionIfExists($this->collectionName); } public function createIfNotExists(callable $callback) { $this->create($callback); } }
- Create ServiceProvider for your migration tool implementation. Bind your implementations with interfaces.
Also, you need to configure your module by adding
Configdependency. For example
class MyDatabaseServiceProvider extends \League\Container\ServiceProvider\AbstractServiceProvider { public function register(): void { $container->add( \Whirlwind\MigrationCore\Config\MigrationPaths::class, fn() => new \Whirlwind\MigrationCore\Config\MigrationPaths([ new \Whirlwind\MigrationCore\Config\MigrationPath( 'path/to/your/migrations', 'Your\\Migration\\Namespace' ), new \Whirlwind\MigrationCore\Config\MigrationPath( 'path/to/your/another/migrations', 'Your\\Another\\Migration\\Namespace' ), ]) ); $container->add( \Whirlwind\MigrationCore\Config\Config::class, fn () => new \Whirlwind\MigrationCore\Config\Config( $container->get(\Whirlwind\MigrationCore\Config\MigrationPaths::class), '/path/to/your/template' // by default using template from core package ) ); } }
- Add console commands routes.
/** * @var \Whirlwind\App\Console\Application $app */ $app->addCommand('migrate:create', \Whirlwind\MigrationCore\Command\Migration\CreateCommand::class); $app->addCommand('migrate:install', \Whirlwind\MigrationCore\Command\Migration\InstallCommand::class); $app->addCommand('migrate:rollback', \Whirlwind\MigrationCore\Command\Migration\RollbackCommand::class); $app->addCommand('migrate:status', \Whirlwind\MigrationCore\Command\Migration\StatusCommand::class);
统计信息
- 总下载量: 292
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-05-23