20251004000001_create_member_card_table.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. use Phinx\Migration\AbstractMigration;
  4. final class CreateMemberCardTable 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_card', ['id' => false, 'primary_key' => ['id'], 'comment' => '会员卡定义表']);
  20. $table->addColumn('id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'identity' => true, 'comment' => '主键ID'])
  21. ->addColumn('name', 'string', ['limit' => 100, 'null' => false, 'comment' => '会员卡名称'])
  22. ->addColumn('description', 'text', ['null' => true, 'comment' => '会员卡描述'])
  23. ->addColumn('price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => false, 'comment' => '会员卡价格'])
  24. ->addColumn('validity_period', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'comment' => '有效期(天)'])
  25. ->addColumn('sort', 'integer', ['limit' => 11, 'null' => false, 'default' => 0, 'comment' => '排序'])
  26. ->addColumn('status', 'integer', ['limit' => 1, 'null' => false, 'default' => 1, 'comment' => '状态:0=禁用,1=启用'])
  27. ->addColumn('create_time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
  28. ->addColumn('update_time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间'])
  29. ->addColumn('delete_time', 'timestamp', ['null' => true, 'comment' => '删除时间']);
  30. // 添加索引
  31. $table->addIndex(['status'])
  32. ->addIndex(['sort'])
  33. ->addIndex(['create_time']);
  34. $table->create();
  35. }
  36. }