建表

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. https 简介学习

    https://program-think.blogspot.com/2014/11/https-ssl-tls-1.html https://program-think.blogspot.com/2 ...

  2. php与redis使用经验分享 (转载)

    一.安装 1.redis的下载及安装: 引用 mkdir /usr/local/redis cd /usr/local/redis wget http://redis.googlecode.com/f ...

  3. 转:OGRE 渲染通路(Pass)

    一个渲染通路就是几何问题里的一次渲染:一个带有一整套渲染属性的渲染API的一次调用.一个技术可以包含有1到16个渲染通路,当然,渲染通路用得越多,技术在渲染的时候开销越大. 为了清楚识别使用的到底是哪 ...

  4. 基于springboot的多数据源配置

    发布时间:2018-12-11   技术:springboot1.5.1 + maven3.0.1+ mybatis-plus-boot-starter2.3.1 + dynamic-datasour ...

  5. js截取相应的域名----正则匹配法 和校验Url 正则表达式

    js截取相应的域名----正则匹配法 和校验Url 正则表达式 用javascript截取相应的域名方法两种,供大家参考 1.方法1: [javascript] view plain copy fun ...

  6. \u Unicode和汉字转化

    介绍 \uxxxx这种格式是Unicode写法,表示一个字符,其中xxxx表示一个16进制数字,范围所0-65535. Unicode十六进制数只能包含数字0-9.大写字母A-F或者小写字母A-F.需 ...

  7. WordPress固定链接修改后访问文章页面404

    如题, 修改固定链接为自定义结构后, 访问文章页面出现404的nginx错误. 解决:修改nginx.conf配置文件(/usr/local/nginx/conf/nginx.conf). 在serv ...

  8. struts2基本配置详解2

    接上篇struts2基本配置详解,还有一些配置没有讲到,下面将继续. struts.xml <package name="com.amos.web.action" names ...

  9. C语言学习笔记 (007) - 数组指针和通过指针引用数组元素的方法总结

    1.数组指针:即指向数组的指针 那么, 如何声明一个数组指针呢? ]; /*括号是必须写的,不然就是指针数组:10是数组的大小*/ 拓展:有指针类型元素的数组称为指针数组. 2.通过指针引用数组元素的 ...

  10. XML 特殊字符处理

    在XML中,有一些符号作为XML 的标记符号,一些特定情况下,属性值必须带有这些特殊符号. 下面主要是讲解一些常用的特殊符号的处理 例一: 双引号的使用. 双引号作为XML 属性值的开始结束符号,因此 ...