odan/phinx-migrations-generator
Composer 安装命令:
composer require odan/phinx-migrations-generator
包简介
Migration generator for Phinx
README 文档
README
Generates Phinx migrations by comparing your current database with your schema information.
Requirements
- PHP 8.1 - 8.5
Features
- Framework independent
- DBMS: MySQL 5.7+, MySQL 8, MariaDB (partially supported)
- Initial schema
- Schema difference
- Database: character set, collation
- Tables: create, update, remove, engine, comment, character set, collation
- Columns: create, update, remove
- Indexes: create, remove
- Foreign keys: create, remove, constraint name
Install
Via Composer
composer require odan/phinx-migrations-generator --dev
Usage
Generating migrations
The first run generates an initial schema and a migration class.
The file schema.php contains the previous database schema and is compared with the current schema.
Based on the difference, a Phinx migration class is generated.
vendor/bin/phinx-migrations generate
When the generate command is executed again, only the difference to the last schema is generated.
Parameters
| Parameter | Values | Default | Description |
|---|---|---|---|
| --name | string | The class name. | |
| --overwrite | bool | Overwrite schema.php file. | |
| --path | string | (from phinx) | Specify the path in which to generate this migration. |
| --environment or -e | string | (from phinx) | The target environment. |
| --configuration or -c | string | (from phinx) | The configuration file e.g. config/phinx.php |
Running migrations
The Phinx migrate command runs all the available migrations.
vendor/bin/phinx migrate
Configuration
The phinx-migrations-generator uses the configuration of phinx.
Migration configuration
| Parameter | Values | Default | Description |
|---|---|---|---|
| foreign_keys | bool | false | Enable or disable foreign key migrations. |
| default_migration_prefix | string | null | If specified, in the absence of the name parameter, the default migration name will be offered with this prefix and a random hash at the end. |
| generate_migration_name | bool | false | If enabled, a random migration name will be generated. The user will not be prompted for a migration name anymore. The parameter default_migration_prefix must be specified. The --name parameter can overwrite this setting. |
| mark_generated_migration | bool | true | Enable or disable marking the migration as applied after creation. |
| migration_base_class | string | \Phinx\Migration\AbstractMigration |
Sets up base class of created migration. |
| schema_file | string | %%PHINX_CONFIG_DIR%%/db/ migrations/schema.php |
Specifies the location for saving the schema file. |
Example configuration
Filename: phinx.php (in your project root directory)
<?php // Framework bootstrap code here require_once __DIR__ . '/config/bootstrap.php'; // Get PDO object $pdo = new PDO( 'mysql:host=127.0.0.1;dbname=test;charset=utf8mb4', 'root', '', array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => false, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci', ) ); return [ 'paths' => [ 'migrations' => __DIR__ . '/../resources/migrations', ], 'schema_file' => __DIR__ . '/../resources/schema/schema.php', 'foreign_keys' => false, 'default_migration_prefix' => '', 'mark_generated_migration' => true, 'environments' => [ 'default_environment' => 'local', 'local' => [ // Database name 'name' => $pdo->query('select database()')->fetchColumn(), 'connection' => $pdo, ] ] ];
Testing
Create a local database: phinx_test
composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
License
The MIT License (MIT). Please see License File for more information.
odan/phinx-migrations-generator 适用场景与选型建议
odan/phinx-migrations-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 920.89k 次下载、GitHub Stars 达 233, 最近一次更新时间为 2016 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「migrations」 「generator」 「mysql」 「migration」 「phinx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 odan/phinx-migrations-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 odan/phinx-migrations-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 odan/phinx-migrations-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
统计信息
- 总下载量: 920.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 234
- 点击次数: 29
- 依赖项目数: 22
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-09