建表

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. NameNode重新格式化以后DataNode不能启动

    最近重新格式化NameNode以后,发现几个DataNode都不能启动了. 这是因为dfs.name.dir路径下面有一个current/VERSION文件,里面有一个clusterID,重新格式化以 ...

  2. python environ PYTHON_EGG_CACHE

    My first thought was "Wow, that's quite a long way of telling me to 'just quit.'" Not want ...

  3. eclipse mavenWeb项目真正实现热部署(修改java代码和页面文件不用重启tomcat)

            1.前言 首先,本文创作灵感源于博客园园作者signheart,特此鸣谢!原文链接见文末推荐: 百度都搜破了,全网讲的都是如何将maven项目部署到tomcat上,对于热部署的认知,真 ...

  4. HTML注释标签

      CreateTime--2016年11月4日08:46:25Author:Marydon参考链接--http://www.cnblogs.com/KeepMovingblog/archive/20 ...

  5. 基于py3和pymysql的数据库查询,查询某几列的数据

    #python3 #xiaodeng #基于py3和pymysql的数据库查询,查询某几列的数据 import pymysql conn=pymysql.connect(....) cur=conn. ...

  6. Ubuntu下,terminal经常使用快捷键

    # ctrl + l - 清屏 . cLear # ctrl + c - 终止命令. # ctrl + d - 退出 shell,好像也能够表示EOF. # ctrl + r - 从命令历史中找 . ...

  7. 初次使用Microsoft Azure

    一.介绍 在微博上偶然发现微软的Azure有免费申请试用的机会,于是赶快给微软发邮件申请,第二天就通过了. 早就听说过微软在云计算方面发力,但一直没机会试用,之前用过国产的BAE.SAE,用GoAge ...

  8. (原)linux下caffe模型转tensorflow模型

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/7419352.html 参考网址: https://github.com/ethereon/caffe- ...

  9. Virtualbox虚拟机克隆

    Vmware Workstation可以提供虚拟机的克隆,可以安装好虚拟机之后可以非常方便的复制一个虚拟机,这样在搭建多台虚拟机的环境下非常方便,无需一台台的安装系统,但是Virtualbox在图形界 ...

  10. 老男孩linux实战培训初级班第三次课课前考试题

    ################################################################ 本文内容摘录于老男孩linux实战运维培训中心考试题 如有转载,请务必 ...