masom / lhm
为 phinx 设计的大型强子迁移器
0.5.1
2017-05-11 19:55 UTC
Requires
- php: ^5.6.0 || ^7.0.0
- psr/log: ^1.0.0
- symfony/console: ~2
- symfony/event-dispatcher: ~2
- symfony/monolog-bridge: ~2
Requires (Dev)
- monolog/monolog: ~1.0
- phpunit/phpunit: ^5.7.0 || ^6.1.0
- robmorgan/phinx: ~0.8.0
Suggests
- monolog/monolog: Allows more advanced logging of the application flow
- robmorgan/phinx: Advanced database migration tool
README
大型强子迁移器
这是 https://github.com/soundcloud/lhm 的 PHP 版本。lhm_php 支持除 id 之外的其他主键名称。
版本 0.4.0 被认为是“生产就绪”。它在 PopKey.co 中用于迁移数百万条记录。
待办事项
- [SqlHelper] 支持列重命名
- [LHM] 支持清理
- [Chunker] 数据限制/过滤
- [Chunker] 限制
- [Switchers] 锁定开关
- 添加索引/删除索引
使用方法
<?php use Phinx\Migration\AbstractMigration; class DropLargeColumns extends AbstractMigration { /** * Migrate Up. */ public function up() { /** * Uncomment this to see logs. * $logger = new Monolog\Logger('test', [new \Monolog\Handler\StreamHandler('php://stdout')]); * \Lhm\Lhm::setLogger($logger); */ \Lhm\Lhm::setAdapter($this->getAdapter()); \Lhm\Lhm::changeTable('characters', function (Phinx\Db\Table $table) { $table ->removeColumn('alternate_name') ->removeColumn('alternate_bio') ->removeColumn('alternate_storyline') ->save(); }); } /** * Migrate Down. */ public function down() { \Lhm\Lhm::setAdapter($this->getAdapter()); \Lhm\Lhm::changeTable('characters', function (Phinx\Db\Table $table) { $table ->addColumn('alternate_name', 'string', ['limit' => 255, 'null' => true, 'default' => null]) ->addColumn('alternate_bio', 'string', ['limit' => 255, 'null' => true, 'default' => null]) ->addColumn('alternate_storyline', 'string', ['limit' => 255, 'null' => true, 'default' => null]) ->save(); }); } }
清理
如果在运行 LHM 时出现错误,一些触发器和表可能仍留在数据库中。
bin/lhm 命令可让您清理数据库。
除非指定了 --run 选项,否则将执行 dry-run。
Large Hadron Migrator version 0.4.0
Usage:
cleanup [-c|--configuration="..."] [-p|--parser="..."] [-e|--environment="..."] [-r|--run] [-u|--until="..."]
Options:
--configuration (-c) The configuration file to load
--parser (-p) Parser used to read the config file. Defaults to YAML
--environment (-e) The target environment
--run (-r) Apply the cleanup operations.
--until (-u) Drop archive tables older than the specified date at UTC (YYYY-MM-DD_hh:mm:ss).
--help (-h) Display this help message
--quiet (-q) Do not output any message
Help:
Cleanup LHM tables, old archives and triggers. Defaults to a dry-run unless --run is specified.
AWS 考虑因素
Amazon RDS 默认禁用 log_bin_trust_function_creators。
参见 soundcloud/lhm#76 和 soundcloud/lhm#65
如果您的数据库实例正在运行自定义参数组
- 打开 RDS 网络控制台。
- 打开“参数组”选项卡。
- 创建一个新的参数组。在对话框中,选择与您的 MySQL 数据库版本兼容的 MySQL 系列,为其命名并确认。
- 选择刚刚创建的参数组并执行“编辑参数”。
- 查找参数“log_bin_trust_function_creators”并将其值设置为“1”。
- 保存更改。
参数组的更改将立即生效。
如果您的数据库实例正在运行默认参数组
- 打开 RDS 网络控制台。
- 打开“参数组”选项卡。
- 创建一个新的参数组。在对话框中,选择与您的 MySQL 数据库版本兼容的 MySQL 系列,为其命名并确认。
- 选择刚刚创建的参数组并执行“编辑参数”。
- 查找参数“log_bin_trust_function_creators”并将其值设置为“1”。
- 保存更改。
- 打开“实例”选项卡。展开您的 MySQL 实例并执行名为“实例操作”的操作。
- 选择刚刚创建的参数组并启用“立即应用”。
- 点击“继续”并确认更改。
- 打开“实例”选项卡。展开您的 MySQL 实例并执行名为“重新启动”的实例操作。
来源: https://techtavern.wordpress.com/2013/06/17/mysql-triggers-and-amazon-rds/