M240826203048createQimallAddonsStoretrack.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace addons\Store\console\migrations;
  3. use addons\Store\common\models\StoreAdmin;
  4. use yii\db\Migration;
  5. /**
  6. * Class M240826203048CreateQimallAddonsStoretrack
  7. */
  8. class M240826203048CreateQimallAddonsStoretrack extends Migration
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function safeUp()
  14. {
  15. $table = 'qimall_addons_store_tracking';
  16. $sql="select * from information_schema.TABLES where TABLE_NAME = '{$table}';";
  17. $res = $this->db->createCommand($sql)->execute();
  18. if(!empty($res)) return '';
  19. $this->execute("CREATE TABLE `qimall_addons_store_tracking` (
  20. `id` int(11) NOT NULL AUTO_INCREMENT,
  21. `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
  22. `store_id` int(11) NOT NULL DEFAULT '0' COMMENT '门店id',
  23. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
  24. `browse_num` int(11) NOT NULL DEFAULT '0' COMMENT '浏览次数',
  25. `track_date` int(11) NOT NULL DEFAULT '0' COMMENT '日期,格式ymd[20240826]',
  26. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[0禁用 1启用 -1删除]',
  27. `created_at` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
  28. `updated_at` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
  29. PRIMARY KEY (`id`),
  30. KEY `mall_id` (`mall_id`) USING BTREE,
  31. KEY `store_id` (`store_id`) USING BTREE,
  32. KEY `user_id` (`user_id`) USING BTREE
  33. ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='商城埋点表';");
  34. // $this->createTable($table, [
  35. // 'id' => $this->primaryKey(),
  36. // 'mall_id' => $this->integer()->notNull()->defaultValue(0)->comment('商城id'),
  37. // 'store_id' => $this->integer()->notNull()->defaultValue(0)->comment('门店id'),
  38. // 'user_id' => $this->integer()->notNull()->defaultValue(0)->comment('用户id'),
  39. // 'browse_num' => $this->integer()->notNull()->defaultValue(0)->comment('浏览次数'),
  40. // 'track_date' => $this->integer()->notNull()->defaultValue(0)->comment('日期,格式ymd[20240826]'),
  41. // 'status' => $this->integer()->notNull()->defaultValue(1)->comment('[0禁用 1启用 -1删除]'),
  42. // 'created_at' => $this->integer()->notNull()->defaultValue(0)->comment('创建时间'),
  43. // 'updated_at' => $this->integer()->notNull()->defaultValue(0)->comment('修改时间'),
  44. // ]);
  45. // // 添加索引
  46. // // 创建复合索引
  47. // $this->createIndex(
  48. // 'idx_mall_store_user', // 索引名称
  49. // $table, // 表名
  50. // ['mall_id', 'store_id', 'user_id'] // 要索引的列
  51. // );
  52. //
  53. // // 创建单列索引
  54. // $this->createIndex(
  55. // 'idx_user_id', // 索引名称
  56. // $table, // 表名
  57. // 'user_id' // 要索引的列
  58. // );
  59. // $this->addCommentOnTable($table,'商城埋点表');
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function safeDown()
  65. {
  66. echo "M240826203048CreateQimallAddonsStoretrack cannot be reverted.\n";
  67. return false;
  68. }
  69. /*
  70. // Use up()/down() to run migration code without a transaction.
  71. public function up()
  72. {
  73. }
  74. public function down()
  75. {
  76. echo "M240716083948AlterQimallAddonsStoreAdmin cannot be reverted.\n";
  77. return false;
  78. }
  79. */
  80. }