20251004000003_create_member_table.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. use Phinx\Migration\AbstractMigration;
  4. final class CreateMemberTable 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. * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
  13. *
  14. * Remember to call "create()" or "update()" and NOT "save()" when working
  15. * with the Table class.
  16. */
  17. public function change(): void
  18. {
  19. $table = $this->table('mcard_member', ['id' => false, 'primary_key' => ['id'], 'comment' => '会员表']);
  20. $table->addColumn('id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'identity' => true, 'comment' => '主键ID'])
  21. ->addColumn('user_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'comment' => '用户ID'])
  22. ->addColumn('member_card_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'comment' => '会员卡ID'])
  23. ->addColumn('card_name', 'string', ['limit' => 100, 'null' => false, 'comment' => '会员卡名称'])
  24. ->addColumn('order_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'comment' => '订单ID'])
  25. ->addColumn('start_time', 'timestamp', ['null' => false, 'comment' => '生效开始时间'])
  26. ->addColumn('end_time', 'timestamp', ['null' => false, 'comment' => '生效结束时间'])
  27. ->addColumn('status', 'integer', ['limit' => 1, 'null' => false, 'default' => 1, 'comment' => '会员状态:0=过期,1=正常'])
  28. ->addColumn('create_time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
  29. ->addColumn('update_time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间'])
  30. ->addColumn('delete_time', 'timestamp', ['null' => true, 'comment' => '删除时间']);
  31. // 添加索引
  32. $table->addIndex(['user_id'])
  33. ->addIndex(['member_card_id'])
  34. ->addIndex(['order_id'])
  35. ->addIndex(['status'])
  36. ->addIndex(['start_time'])
  37. ->addIndex(['end_time'])
  38. ->addIndex(['create_time']);
  39. $table->create();
  40. }
  41. }