20250702075858_hello.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. use think\migration\Migrator;
  3. class Hello extends Migrator
  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. * renameColumn
  20. * addIndex
  21. * addForeignKey
  22. *
  23. * Remember to call "create()" or "update()" and NOT "save()" when working
  24. * with the Table class.
  25. */
  26. public function change()
  27. {
  28. $table = $this->table('extension_hello', [
  29. 'comment' => 'hello测试表',
  30. 'engine' => 'InnoDB',
  31. 'collation' => 'utf8mb4_general_ci',
  32. 'id' => false,
  33. 'primary_key' => 'id'
  34. ]);
  35. $table->addColumn('id', 'string', [
  36. 'limit' => 50,
  37. 'null' => false,
  38. 'comment' => '唯一标识符'
  39. ])->addColumn('name', 'string', [
  40. 'limit' => 100,
  41. 'null' => false,
  42. 'comment' => '名称'
  43. ])->addColumn('update_time', 'datetime', [
  44. 'null' => true,
  45. 'comment' => '更新时间'
  46. ])->addColumn('delete_time', 'datetime', [
  47. 'null' => true,
  48. 'comment' => '删除时间'
  49. ])->addIndex(['id'], [
  50. 'unique' => true,
  51. 'name' => 'uniq_id'
  52. ])->create();
  53. }
  54. }