M230218073419CreateQimallScoreLogRelation.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M230218073419CreateQimallScoreLogRelation
  6. */
  7. class M230218073419CreateQimallScoreLogRelation extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. try {
  15. $table = 'qimall_score_log_relation';
  16. $sql="select * from information_schema.TABLES where TABLE_NAME = '{$table}';";
  17. $res = $this->db->createCommand($sql)->execute();
  18. if(!empty($res)) return '';
  19. $sql="
  20. CREATE TABLE `qimall_score_log_relation` (
  21. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  22. `log_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'score的id/score_frozen的id',
  23. `source_type` varchar(255) NOT NULL DEFAULT '' COMMENT 'score/score_frozen',
  24. `describe` varchar(1000) NOT NULL DEFAULT '' COMMENT '自定义的描述',
  25. `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
  26. PRIMARY KEY (`id`) USING BTREE,
  27. KEY `idx_source_type_log_id` (`source_type`,`log_id`) USING BTREE
  28. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='积分记录关联表表';";
  29. $this->execute($sql);
  30. }catch (\Exception $e){
  31. }
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function safeDown()
  37. {
  38. echo "M230218073419CreateQimallScoreLogRelation cannot be reverted.\n";
  39. return false;
  40. }
  41. /*
  42. // Use up()/down() to run migration code without a transaction.
  43. public function up()
  44. {
  45. }
  46. public function down()
  47. {
  48. echo "M230218073419CreateQimallScoreLogRelation cannot be reverted.\n";
  49. return false;
  50. }
  51. */
  52. }