rawphp / raw-migrator
RawMigrator 为 RawPHP 框架和其他应用程序提供数据库迁移服务。
dev-master / 0.x-dev
2014-09-24 02:06 UTC
Requires
- php: >=5.3.0
- rawphp/raw-base: 1.0.0-RC-1
- rawphp/raw-database: 0.*@dev
- rawphp/raw-yaml: 1.0.0-RC-2
Requires (Dev)
- phpdocumentor/phpdocumentor: dev-master
- phpunit/phpunit: 4.2.5
- rawphp/raw-code-standards: 1.*@dev
- satooshi/php-coveralls: dev-master
- squizlabs/php_codesniffer: dev-master
This package is auto-updated.
Last update: 2024-09-20 08:13:00 UTC
README
包功能
- 简单易用的迁移器
- 创建新的迁移类
- 迁移数据库上下文
- 支持迁移级别控制
安装
Composer
RawMigrator 通过 Composer/Packagist 提供。
将 "rawphp/raw-migrator": "0.*@dev"
添加到您的 composer.json 中的 require 块,然后运行 composer install
。
{ "require": { "rawphp/raw-migrator": "0.*@dev" } }
您还可以简单地从命令行运行以下命令
composer require rawphp/raw-migrator "0.*@dev"
压缩包
或者,只需将 RawMigrator 文件夹的内容复制到您的 PHP include_path
设置中。如果您不熟悉 git 或只想使用压缩包,请点击 GitHub 页面顶部的 'zip' 按钮。
基本用法
<?php use RawPHP\RawMigrator\Migrator; use RawPHP\RawDatabase\Database; // configuration $config = array( 'migration_path' => '/path/to/migrations/dir/', // path to migrations directory 'namespace' => 'RawPHP\\RawMigrator\\Migrations\\', // migrations namespace, leave empty if namespaces not used 'migration_table' => 'migrations', // migrations table name 'class_name_style' => Migrator::STYLE_CAMEL_CASE; // Migrator::STYLE_UNDERSCORE 'class_prefix' => 'M', // class prefix for creating new migrations 'overwrite' => FALSE, // Whether to overwrite existing migrations of the same name ); // get new migrator instance // the migrator expects an instance of RawPHP\RawDatabase\IDatabase class as its first parameter. // You can use your own database implementation as long as you implement the IDatabase interface. $database = new Database( ); $database->init( $dbConfig ); // create new instance $migrator = new Migrator( $database ); // initialise migrator $migrator->init( $config ); // create a new migration $migrator->migrationClass = 'CreateUsersTable'; $migrator->createMigration( ); // update database $migrator->migrateUp( ); // or to migrate up 1 level $migrator->levels = 1; $migrator->migrateUp( ); // migrate database down 1 level $migrator->levels = 1; $migrator->migrateDown( ); // NOTE: If using the RawConsole package to run these migrations, you need to // add 'RawPHP\\RawMigrator\\Commands\\' namespace to the console configuration file.
更多使用文档即将推出。
许可证
本软件包根据 MIT 许可证发布。请阅读 LICENSE 了解有关软件可用性和分发的信息。
贡献
请将错误报告、建议和拉取请求提交到 GitHub 问题跟踪器。
变更日志
22-09-2014
- 更新以支持 PHP 5.3。
- 添加了 'namespaces' 配置选项,用于列出迁移命名空间。
20-09-2014
- 将 'namespace' 更改为 'migration_namespace' 迁移器配置。
20-09-2014
- 添加了迁移命令。
- 将 php 数组配置替换为 yaml
- 修复了 MigrationException 命名空间。
18-09-2014
- 更新以与最新的 rawphp/rawbase 软件包兼容。
- 将 php 数组配置替换为 yaml
17-09-2014
- 添加了 DBTestCase 类,用于在测试数据库时与迁移器一起使用。
- 在迁移器选项中添加了类命名风格。选择 CamelCase 或下划线。
16-09-2014
- 在迁移器中为
migrateUp( )
和migrateDown( )
添加了可选的 $levels 参数。
13-09-2014
- 实现了钩子系统
- 将组件配置从构造函数移动到
init()
11-09-2014
- 初始代码提交