pckg/
使数据库和配置迁移变得简单
dev-master
2022-04-10 14:05 UTC
Requires
- pckg/database: dev-master
- symfony/console: >=3
Requires (Dev)
- pckg-app/frontend-dev: dev-master
- pckg/framework: dev-master
- pckg/htmlbuilder: dev-master
- pckg/manager: dev-master
This package is auto-updated.
Last update: 2024-09-15 20:05:19 UTC
README
使用方法
在您的应用程序中注册 Pckg\Migration\Provider\Migration
提供者。如果您不使用 Pckg\Framework\Provider\Framework
,则需要这样做。
...
use Pckg\Migration\Provider\Migration;
...
public function providers()
{
return [
Migration::class,
];
}
控制台
所有命令都是应用程序范围内的,并且需要使用 php console $appName
前缀。
migrator:install
- 从环境安装迁移
--only=SomeMigration
- 仅安装列出的迁移--fields
- 仅安装字段(不包含索引/键)--indexes
- 仅安装索引/键(不包含字段)--yes
- 对所有问题回答“是”--clear
- 在前后清除缓存--retry=1
- 重试迭代次数--repository=default
- 仅安装仓库
创建迁移
<?php
namespace Foo\Migration;
use Foo\Migration\SomeMigration;
class SomeMigration extends \Pckg\Framework\Provider
{
public function up()
{
$clients = $this->table('clients');
$clients->deletable();
$clients->varchar('name');
$clients->json('props');
$projects = $this->table('projects');
$projects->timeable();
$projects->deletable();
$projects->integer('client_id')->references('clients');
$projects->varchar('name');
$this->save();
}
}
应用迁移
在 ./config/migrations.php
或 ./app/$app/config/migrations.php
中列出您的迁移。
<?php
use Foo\Migration\SomeMigration;
return [
SomeMigration::class,
];
或将您的迁移添加到 Provider
。
<?php
namespace Foo\Provider;
use Pckg\Framework\Provider;
use Foo\Migration\SomeMigration;
class Feature extends Provider
{
public function migrations()
{
return [
SomeMigration::class,
];
}
}
然后执行迁移
# php console $appName migrator:install