20250702075858_hello.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. use Phinx\Migration\AbstractMigration;
  4. class Hello extends AbstractMigration
  5. {
  6. /**
  7. * Change Method.
  8. *
  9. * Write your reversible migrations using this method.
  10. *
  11. * More information on writing migrations is available here:
  12. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  13. *
  14. * The following commands can be used in this method and Phinx will
  15. * automatically reverse them when rolling back:
  16. *
  17. * createTable
  18. * renameTable
  19. * addColumn
  20. * renameColumn
  21. * addIndex
  22. * addForeignKey
  23. *
  24. * Remember to call "create()" or "update()" and NOT "save()" when working
  25. * with the Table class.
  26. */
  27. public function change()
  28. {
  29. $table = $this->table('extension_hello', [
  30. 'comment' => 'hello测试表',
  31. 'engine' => 'InnoDB',
  32. 'collation' => 'utf8mb4_general_ci',
  33. 'id' => false,
  34. 'primary_key' => 'id'
  35. ]);
  36. $table->addColumn('id', 'string', [
  37. 'limit' => 50,
  38. 'null' => false,
  39. 'comment' => '唯一标识符'
  40. ])->addColumn('name', 'string', [
  41. 'limit' => 100,
  42. 'null' => false,
  43. 'comment' => '名称'
  44. ])->addColumn('update_time', 'datetime', [
  45. 'null' => true,
  46. 'comment' => '更新时间'
  47. ])->addColumn('delete_time', 'datetime', [
  48. 'null' => true,
  49. 'comment' => '删除时间'
  50. ])->addIndex(['id'], [
  51. 'unique' => true,
  52. 'name' => 'uniq_id'
  53. ])->create();
  54. }
  55. }