20190526165318_my_new_migration2.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. use Phinx\Migration\AbstractMigration;
  3. class MyNewMigration2 extends AbstractMigration
  4. {
  5. /**
  6. * Change Method.
  7. *
  8. * Write your reversible migrations using this method.
  9. *
  10. * More information on writing migrations is available here:
  11. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  12. *
  13. * The following commands can be used in this method and Phinx will
  14. * automatically reverse them when rolling back:
  15. *
  16. * createTable
  17. * renameTable
  18. * addColumn
  19. * addCustomColumn
  20. * renameColumn
  21. * addIndex
  22. * addForeignKey
  23. *
  24. * Any other destructive changes will result in an error when trying to
  25. * rollback the migration.
  26. *
  27. * Remember to call "create()" or "update()" and NOT "save()" when working
  28. * with the Table class.
  29. */
  30. // public function change()
  31. // {
  32. //
  33. // }
  34. public function up() {
  35. $users = $this->table('users',['engine' => 'Innodb','id' => 'user_id','comment' => '用户表']);
  36. $users
  37. ->addColumn('username', 'string', ['limit' => 20,'comment' => '用户名'])
  38. ->addColumn('password', 'string', ['limit' => 40,'comment' => '密码'])
  39. ->addColumn('password_salt', 'string', ['limit' => 40,'comment'=> '盐值'])
  40. ->addColumn('email', 'string', ['limit' => 100])
  41. ->addColumn('first_name', 'string', ['limit' => 30])
  42. ->addColumn('remark', 'text', [])
  43. ->addColumn('created', 'timestamp',['default' => 'CURRENT_TIMESTAMP'])
  44. ->addColumn('updated', 'timestamp', ['null' => true,'default' => 'CURRENT_TIMESTAMP'])
  45. ->addIndex(['username', 'email'], ['unique' => true,'name' => 'idx_user_name_email'])
  46. ->save();
  47. }
  48. }