M230216065345AddQimallServiceAgreement.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M230216065345AddQimallServiceAgreement
  6. */
  7. class M230216065345AddQimallServiceAgreement extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. try {
  15. $table = 'qimall_service_agreement';
  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_service_agreement` (
  21. `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键',
  22. `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城id',
  23. `name` varchar(255) DEFAULT '' COMMENT '协议名称',
  24. `remark` varchar(1000) NOT NULL DEFAULT '' COMMENT '备注',
  25. `sort` int(10) NOT NULL DEFAULT '0' COMMENT '排序',
  26. `content` longtext COMMENT '内容',
  27. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  28. `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
  29. `updated_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '修改时间',
  30. PRIMARY KEY (`id`) USING BTREE
  31. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='服务协议表';
  32. ";
  33. $this->execute($sql);
  34. } catch (\Exception $e) {
  35. }
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function safeDown()
  41. {
  42. echo "M230216065345AddQimallServiceAgreement cannot be reverted.\n";
  43. return false;
  44. }
  45. /*
  46. // Use up()/down() to run migration code without a transaction.
  47. public function up()
  48. {
  49. }
  50. public function down()
  51. {
  52. echo "M230216065345AddQimallServiceAgreement cannot be reverted.\n";
  53. return false;
  54. }
  55. */
  56. }