20230115090200_add_user_coupon.php 1.1 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. declare(strict_types=1);
  3. use Phinx\Migration\AbstractMigration;
  4. final class AddUserCoupon extends AbstractMigration
  5. {
  6. public function up(): void
  7. {
  8. if (! $this->hasTable('user_coupon')) {
  9. $this->table('user_coupon', [ 'id' => false, 'primary_key' => [ 'id' ]])
  10. ->addColumn('id', 'integer', [ 'comment' => '优惠码ID', 'identity' => true ])
  11. ->addColumn('code', 'string', [ 'comment' => '优惠码' ])
  12. ->addColumn('content', 'json', [ 'comment' => '优惠码内容' ])
  13. ->addColumn('limit', 'json', [ 'comment' => '优惠码限制' ])
  14. ->addColumn('create_time', 'integer', [ 'comment' => '创建时间' ])
  15. ->addColumn('expire_time', 'integer', [ 'comment' => '过期时间' ])
  16. ->addIndex([ 'id' ])
  17. ->addIndex([ 'code' ])
  18. ->addIndex([ 'expire_time' ])
  19. ->create();
  20. }
  21. }
  22. public function down(): void
  23. {
  24. $this->table('user_coupon')->drop()->update();
  25. }
  26. }