M230525061728QimallGoodsAssociation.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M230525061728QimallGoodsAssociation
  6. */
  7. class M230525061728QimallGoodsAssociation extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. try {
  15. $table = 'qimall_goods_association';
  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_goods_association` (
  21. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  22. `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城id',
  23. `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品id',
  24. `extra1_goods_id` longtext COMMENT '关联配件商品id',
  25. `extra2_goods_id` longtext COMMENT '推荐商品商品id',
  26. `extra3_goods_id` longtext COMMENT '预留',
  27. `extra4_goods_id` longtext COMMENT '预留',
  28. `extra5_goods_id` longtext COMMENT '预留',
  29. `extra6_goods_id` longtext COMMENT '预留',
  30. `extra7_goods_id` longtext COMMENT '预留',
  31. `extra8_goods_id` longtext COMMENT '预留',
  32. `extra9_goods_id` longtext COMMENT '预留',
  33. `extra10_goods_id` longtext COMMENT '预留',
  34. `status` tinyint(4) DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  35. `created_at` bigint(20) NOT NULL DEFAULT '0',
  36. `updated_at` bigint(20) NOT NULL DEFAULT '0',
  37. PRIMARY KEY (`id`) USING BTREE,
  38. KEY `idx_goods_id` (`goods_id`) USING BTREE
  39. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='关联商品';
  40. ";
  41. $this->execute($sql);
  42. }catch (\Exception $e){
  43. }
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function safeDown()
  49. {
  50. echo "M230525061728QimallGoodsAssociation cannot be reverted.\n";
  51. return false;
  52. }
  53. /*
  54. // Use up()/down() to run migration code without a transaction.
  55. public function up()
  56. {
  57. }
  58. public function down()
  59. {
  60. echo "M230525061728QimallGoodsAssociation cannot be reverted.\n";
  61. return false;
  62. }
  63. */
  64. }