建表

phinx\bin\phinx.bat migrate -e production

建设 phinx.yml文件

paths:
migrations: %%PHINX_CONFIG_DIR%%\database\migrations
seeds: %%PHINX_CONFIG_DIR%%\database\seeds environments:
default_migration_table: phinxlog
default_database: development
production:
adapter: mysql
host: localhost
name: jitamin2
user: root
pass: ''
port: 3306
charset: utf8 development:
adapter: mysql
host: localhost
name: development_db
user: root
pass: ''
port: 3306
charset: utf8 testing:
adapter: mysql
host: localhost
name: testing_db
user: root
pass: ''
port: 3306
charset: utf8
%%PHINX_CONFIG_DIR%%\database\migrations下面的文件示例20161222061456_create_users_table.php如下:
<?php

/*
* This file is part of Jitamin.
*
* Copyright (C) Jitamin Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/ use Phinx\Migration\AbstractMigration; class CreateUsersTable extends AbstractMigration
{
/**
* Change Method.
*/
public function change()
{
$table = $this->table('users');
$table->addColumn('username', 'string', ['limit'=>50])
->addColumn('password', 'string', ['null' => true])
->addColumn('is_ldap_user', 'boolean', ['null' => true, 'default' => false])
->addColumn('name', 'string', ['null' => true])
->addColumn('email', 'string')
->addColumn('google_id', 'string', ['null'=> true, 'limit' => 30])
->addColumn('github_id', 'string', ['null' => true, 'limit' => 30])
->addColumn('notifications_enabled', 'boolean', ['null' => true, 'default' => false])
->addColumn('timezone', 'string', ['null' => true, 'limit' => 50])
->addColumn('language', 'string', ['null' => true, 'limit' => 5])
->addColumn('disable_login_form', 'boolean', ['null' => true, 'default' => false])
->addColumn('twofactor_activated', 'boolean', ['null' => true, 'default' => false])
->addColumn('twofactor_secret', 'string', ['null' => true, 'limit' => 16])
->addColumn('token', 'string', ['null'=> true, 'default' => ''])
->addColumn('notifications_filter', 'integer', ['null' => true, 'default' => 4])
->addColumn('nb_failed_login', 'integer', ['null' => true, 'default' => 0])
->addColumn('lock_expiration_date', 'biginteger', ['null' => true])
->addColumn('gitlab_id', 'integer', ['null' => true])
->addColumn('role', 'string', ['limit' => 25, 'default' => 'app-user'])
->addColumn('is_active', 'boolean', ['null' => true, 'default' => true])
->addColumn('avatar_path', 'string', ['null' => true])
->addColumn('skin', 'string', ['null' => true, 'limit'=>15])
->addIndex(['username'], ['unique' => true])
->addIndex(['email'], ['unique' => true])
->create();
}
}

  

数据迁移命令如下:

phinx\bin\phinx.bat seed:run -e production
%%PHINX_CONFIG_DIR%%\database\seeds下面的文件示例CreateGroupsTable.php如下:
<?php

/*
* This file is part of Jitamin.
*
* Copyright (C) Jitamin Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/ use Jitamin\Foundation\Security\Role;
use Phinx\Seed\AbstractSeed; class UserSeeder extends AbstractSeed
{
/**
* Run Method.
*/
public function run()
{
$data = [
[
'username' => 'admin',
'password' => bcrypt('admin'),
'email' => 'admin@admin.com',
'role' => Role::APP_ADMIN,
],
]; $users = $this->table('users');
$users->insert($data)
->save();
}
}

  

如何在PHP项目中使用phinx进行数据迁移和建表的更多相关文章

  1. EF 中 Code First 的数据迁移以及创建视图

    写在前面: EF 中 Code First 的数据迁移网上有很多资料,我这份并没什么特别.Code First 创建视图网上也有很多资料,但好像很麻烦,而且亲测好像是无效的方法(可能是我太笨,没搞成功 ...

  2. [Laravel-Swagger]如何在 Laravel 项目中使用 Swagger

    如何在 Laravel 项目中使用 Swagger http://swagger.io/getting-started/ 安装依赖 swagger-php composer require zirco ...

  3. 如何在cocos2d项目中enable ARC

    如何在cocos2d项目中enable ARC 基本思想就是不支持ARC的代码用和支持ARC的分开,通过xcode中设置编译选项,让支持和不支持ARC的代码共存. cocos2d是ios app开发中 ...

  4. 如何在NodeJS项目中优雅的使用ES6

    如何在NodeJS项目中优雅的使用ES6 NodeJs最近的版本都开始支持ES6(ES2015)的新特性了,设置已经支持了async/await这样的更高级的特性.只是在使用的时候需要在node后面加 ...

  5. 如何在VUE项目中添加ESLint

    如何在VUE项目中添加ESLint 1. 首先在项目的根目录下 新建 .eslintrc.js文件,其配置规则可以如下:(自己小整理了一份),所有的代码如下: // https://eslint.or ...

  6. 如何在mvc项目中使用apiController

    文章地址:How do you route from an MVC project to an MVC ApiController in another project? 文章地址:How to Us ...

  7. 如何在Ionic2项目中使用第三方JavaScript库

    onic的官网放出一记大招Ionic and Typings,来介绍如何在Ionic2项目中使用第三方JavaScript库. 因为在前阵子正好想用一个非常有名的第三方JS库ChartJs来实现一些东 ...

  8. 如何在maven项目中使用spring

    今天开始在maven项目下加入spring. 边学习边截图. 在这个过程中我新建了一个hellospring的项目.于是乎从这个项目出发开始研究如何在maven项目中使用spring.鉴于网上的学习资 ...

  9. 如何在Vue-cli项目中使用JTopo

    1.前言 jTopo(Javascript Topology library)是一款完全基于HTML5 Canvas的关系.拓扑图形化界面开发工具包.其体积小,性能优异,由一群开发爱好者来维护.唯一感 ...

随机推荐

  1. SpringMVC+Spring+mybatis项目从零开始--分布式项目结构搭建

    转载出处: SpringMVC+Spring+mybatis+Redis项目从零开始--分布式项目结构搭建 /** 本文为博主原创文章,如转载请附链接. **/ SSM框架web项目从零开始--分布式 ...

  2. infobright系列一:源码安装infobright

    1:下载infobright http://www.infobright.org/downloads/ice/infobright-4.0.7-0-src-ice.tar.gz 2:查看环境 rpm ...

  3. system.DateTime ToDateTime(System.String)”,因此该方法无法转换为存储表达式-解决方法

    LINQ to Entities的lambda表达式中如果需要转换时间及各种时间格式请使用System.Data.Entity的类DbFunctions的各种方法 例如: IsOverdue = db ...

  4. iOS下Symbol not found: ___sincosf_stret错误

    在调试一个带第三方库的多媒体应用中,发如今iOS6.1.2的版本号上必定crash.显示Symbol not found: ___sincosf_stret错误,这个错误非常少见. watermark ...

  5. java 中文及特殊字符校验

      java 中文及特殊字符校验 CreateTime--2017年8月25日16:54:50 Author:Marydon 一.参考链接 http://blog.csdn.net/imduan/ar ...

  6. ntp时钟同步

    服务器时间的一致性,很关键的. 11. 基于ntp服务的形式 [root@server0 ~]# yum -y install chrony   //NTP客户端    centos7.x  cent ...

  7. FTP命令字和响应码解释

    FTP命令: 命令  描述  ABOR 中断数据连接程序 ACCT <account> 系统特权帐号 ALLO <bytes>  为服务器上的文件存储器分配字节 APPE &l ...

  8. std::string std::wstring 删除最后元素 得到最后元素

    std::string str = "abcdefg,"; std::cout << "last character:"<<str.ba ...

  9. java 结束程序进程 代码

    结束firefox的进程,一句代码就够了,如下: Runtime.getRuntime().exec("taskkill /F /IM firefox.exe"); 结束qq: R ...

  10. BAT面试的准备—iOS篇

    本文主要用于记录在准备BAT面试中关于iOS遇到的问题和做一些相关面试题的笔记 iOS网络层设计 1.网络层和业务层的对接设计 使用哪种交互模式来和业务层对接 : 使用Delegate为主,目的是为了 ...