m220227_143427_common_log.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use yii\db\Migration;
  3. class m220227_143427_common_log extends Migration
  4. {
  5. public function up()
  6. {
  7. /* 取消外键约束 */
  8. $this->execute('SET foreign_key_checks = 0');
  9. /* 创建表 */
  10. $this->createTable('{{%common_log}}', [
  11. 'id' => "int(11) NOT NULL AUTO_INCREMENT",
  12. 'app_id' => "varchar(50) NULL DEFAULT '' COMMENT '应用id'",
  13. 'merchant_id' => "int(10) unsigned NULL DEFAULT '0' COMMENT '商户id'",
  14. 'store_id' => "int(10) unsigned NULL DEFAULT '0' COMMENT '店铺ID'",
  15. 'member_id' => "int(11) NULL DEFAULT '0' COMMENT '用户id'",
  16. 'member_name' => "varchar(100) NULL DEFAULT '' COMMENT '用户名称'",
  17. 'method' => "varchar(20) NULL DEFAULT '' COMMENT '提交类型'",
  18. 'module' => "varchar(50) NULL DEFAULT '' COMMENT '模块'",
  19. 'controller' => "varchar(100) NULL DEFAULT '' COMMENT '控制器'",
  20. 'action' => "varchar(50) NULL DEFAULT '' COMMENT '方法'",
  21. 'url' => "varchar(1000) NULL DEFAULT '' COMMENT '提交url'",
  22. 'get_data' => "json NULL COMMENT 'get数据'",
  23. 'post_data' => "json NULL COMMENT 'post数据'",
  24. 'header_data' => "json NULL COMMENT 'header数据'",
  25. 'ip' => "varchar(50) NULL DEFAULT '' COMMENT 'ip地址'",
  26. 'error_code' => "int(10) NULL DEFAULT '0' COMMENT '报错code'",
  27. 'error_msg' => "varchar(1000) NULL DEFAULT '' COMMENT '报错信息'",
  28. 'error_data' => "json NULL COMMENT '报错日志'",
  29. 'is_addon' => "tinyint(4) unsigned NULL DEFAULT '0' COMMENT '是否插件'",
  30. 'addon_name' => "varchar(200) NULL DEFAULT '' COMMENT '插件名称'",
  31. 'req_id' => "varchar(50) NULL DEFAULT '' COMMENT '对外id'",
  32. 'device' => "varchar(200) NULL DEFAULT '' COMMENT '设备信息'",
  33. 'status' => "tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态(-1:已删除,0:禁用,1:正常)'",
  34. 'created_at' => "int(10) NULL DEFAULT '0' COMMENT '创建时间'",
  35. 'updated_at' => "int(10) unsigned NULL DEFAULT '0' COMMENT '修改时间'",
  36. 'PRIMARY KEY (`id`)'
  37. ], "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='公用_日志'");
  38. /* 索引设置 */
  39. $this->createIndex('error_code','{{%common_log}}','error_code',0);
  40. $this->createIndex('req_id','{{%common_log}}','req_id',0);
  41. $this->createIndex('ip','{{%common_log}}','ip',0);
  42. $this->createIndex('created_at','{{%common_log}}','created_at',0);
  43. $this->createIndex('status','{{%common_log}}','status, created_at',0);
  44. /* 表数据 */
  45. /* 设置外键约束 */
  46. $this->execute('SET foreign_key_checks = 1;');
  47. }
  48. public function down()
  49. {
  50. $this->execute('SET foreign_key_checks = 0');
  51. /* 删除表 */
  52. $this->dropTable('{{%common_log}}');
  53. $this->execute('SET foreign_key_checks = 1;');
  54. }
  55. }
粤ICP备19079148号