| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- declare(strict_types=1);
- use Phinx\Migration\AbstractMigration;
- final class CreateMemberTable extends AbstractMigration
- {
- /**
- * Change Method.
- *
- * Write your reversible migrations using this method.
- *
- * More information on writing migrations is available here:
- * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
- *
- * Remember to call "create()" or "update()" and NOT "save()" when working
- * with the Table class.
- */
- public function change(): void
- {
- $table = $this->table('mcard_member', ['id' => false, 'primary_key' => ['id'], 'comment' => '会员表']);
-
- $table->addColumn('id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'identity' => true, 'comment' => '主键ID'])
- ->addColumn('user_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'comment' => '用户ID'])
- ->addColumn('member_card_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'comment' => '会员卡ID'])
- ->addColumn('card_name', 'string', ['limit' => 100, 'null' => false, 'comment' => '会员卡名称'])
- ->addColumn('order_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'comment' => '订单ID'])
- ->addColumn('start_time', 'timestamp', ['null' => false, 'comment' => '生效开始时间'])
- ->addColumn('end_time', 'timestamp', ['null' => false, 'comment' => '生效结束时间'])
- ->addColumn('status', 'integer', ['limit' => 1, 'null' => false, 'default' => 1, 'comment' => '会员状态:0=过期,1=正常'])
- ->addColumn('create_time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
- ->addColumn('update_time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间'])
- ->addColumn('delete_time', 'timestamp', ['null' => true, 'comment' => '删除时间']);
- // 添加索引
- $table->addIndex(['user_id'])
- ->addIndex(['member_card_id'])
- ->addIndex(['order_id'])
- ->addIndex(['status'])
- ->addIndex(['start_time'])
- ->addIndex(['end_time'])
- ->addIndex(['create_time']);
- $table->create();
- }
- }
|