20200430170235_MigrationToolsTokens.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. use Migrations\AbstractMigration;
  3. class MigrationToolsTokens extends AbstractMigration {
  4. /**
  5. * Change Method.
  6. *
  7. * More information on this method is available here:
  8. * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
  9. *
  10. * @return void
  11. */
  12. public function change() {
  13. if ($this->table('tokens')->exists()) {
  14. $this->table('tokens')
  15. ->renameColumn('key', 'token_key')
  16. ->update();
  17. return;
  18. }
  19. $this->table('tokens')
  20. ->addColumn('user_id', 'integer', [
  21. 'limit' => null,
  22. 'null' => true,
  23. ])
  24. ->addColumn('type', 'string', [
  25. 'comment' => 'e.g.:activate,reactivate',
  26. 'default' => null,
  27. 'limit' => 20,
  28. 'null' => false,
  29. ])
  30. ->addColumn('token_key', 'string', [
  31. 'default' => null,
  32. 'limit' => 60,
  33. 'null' => false,
  34. ])
  35. ->addColumn('content', 'string', [
  36. 'comment' => 'can transport some information',
  37. 'default' => null,
  38. 'limit' => 255,
  39. 'null' => true,
  40. ])
  41. ->addColumn('used', 'integer', [
  42. 'default' => 0,
  43. 'limit' => null,
  44. 'null' => false,
  45. ])
  46. ->addColumn('created', 'datetime', [
  47. 'default' => null,
  48. 'limit' => null,
  49. 'null' => true,
  50. ])
  51. ->addColumn('modified', 'datetime', [
  52. 'default' => null,
  53. 'limit' => null,
  54. 'null' => true,
  55. ])
  56. ->addIndex(['user_id'])
  57. ->addIndex(['token_key'], ['unique' => true])
  58. ->create();
  59. }
  60. }