作者 陈志颖

feat:增加pg自动建表

正在显示 31 个修改的文件 包含 258 行增加5 行删除
  1 +swagger: "2.0"
  2 +info:
  3 + title: ""
  4 + description: 合伙人后管平台
  5 + contact:
  6 + name: SteveChan
  7 + email: steve.d.chan@qq.com
  8 + home: ""
  9 + version: 0.0.1
  10 +consumes:
  11 +- application/json
  12 +- application/xml
  13 +produces:
  14 +- application/json
  15 +- application/xml
  16 +paths:
  17 + /column-settings:
  18 + get:
  19 + tags:
  20 + - column_setting
  21 + summary: 返回栏目设置增删改查列表
  22 + description: 返回栏目设置增删改查列表
  23 + operationId: column_setting#listColumnSetting
  24 + parameters:
  25 + - name: offset
  26 + in: query
  27 + description: 查询偏离量
  28 + required: false
  29 + type: integer
  30 + - name: limit
  31 + in: query
  32 + description: 查询限制
  33 + required: false
  34 + type: integer
  35 + responses:
  36 + "200":
  37 + description: OK response.
  38 + schema:
  39 + $ref: '#/definitions/ColumnSettingListColumnSettingResponseBody'
  40 + schemes:
  41 + - http
  42 + post:
  43 + tags:
  44 + - column_setting
  45 + summary: 重置栏目设置
  46 + description: 重置栏目设置
  47 + operationId: column_setting#resetColumn
  48 + responses:
  49 + "200":
  50 + description: OK response.
  51 + schema:
  52 + $ref: '#/definitions/ColumnSettingResetColumnResponseBody'
  53 + schemes:
  54 + - http
  55 + /column-settings/{columnSettingId}:
  56 + get:
  57 + tags:
  58 + - column_setting
  59 + summary: 返回栏目设置增删改查
  60 + description: 返回栏目设置增删改查
  61 + operationId: column_setting#getColumnSetting
  62 + parameters:
  63 + - name: columnSettingId
  64 + in: path
  65 + description: 栏目设置id
  66 + required: true
  67 + type: integer
  68 + responses:
  69 + "200":
  70 + description: OK response.
  71 + schema:
  72 + $ref: '#/definitions/ColumnSettingGetColumnSettingResponseBody'
  73 + schemes:
  74 + - http
  75 + put:
  76 + tags:
  77 + - column_setting
  78 + summary: 更新栏目设置增删改查
  79 + description: 更新栏目设置增删改查
  80 + operationId: column_setting#updateColumnSetting
  81 + parameters:
  82 + - name: columnSettingId
  83 + in: path
  84 + description: 栏目设置id
  85 + required: true
  86 + type: integer
  87 + responses:
  88 + "200":
  89 + description: OK response.
  90 + schema:
  91 + $ref: '#/definitions/ColumnSettingUpdateColumnSettingResponseBody'
  92 + schemes:
  93 + - http
  94 + delete:
  95 + tags:
  96 + - column_setting
  97 + summary: 移除栏目设置增删改查
  98 + description: 移除栏目设置增删改查
  99 + operationId: column_setting#removeColumnSetting
  100 + parameters:
  101 + - name: columnSettingId
  102 + in: path
  103 + description: 栏目设置id
  104 + required: true
  105 + type: integer
  106 + responses:
  107 + "200":
  108 + description: OK response.
  109 + schema:
  110 + $ref: '#/definitions/ColumnSettingRemoveColumnSettingResponseBody'
  111 + schemes:
  112 + - http
  113 +definitions:
  114 + ColumnSettingCreateColumnSettingRequestBody:
  115 + title: ColumnSettingCreateColumnSettingRequestBody
  116 + type: object
  117 + properties:
  118 + description:
  119 + type: string
  120 + description: 栏目设置描述
  121 + required:
  122 + - description
  123 + userName:
  124 + type: string
  125 + description: 栏目设置关联用户名称
  126 + required:
  127 + - userName
  128 + ColumnSettingCreateColumnSettingResponseBody:
  129 + title: 'Mediatype identifier: ColumnSettingCreateColumnSettingResponseBody'
  130 + type: object
  131 + properties:
  132 + column_setting:
  133 + $ref: '#/definitions/column_settingResponseBody'
  134 + ColumnSettingGetColumnSettingResponseBody:
  135 + title: 'Mediatype identifier: ColumnSettingGetColumnSettingResponseBody'
  136 + type: object
  137 + properties:
  138 + column_setting:
  139 + $ref: '#/definitions/column_settingResponseBody'
  140 + ColumnSettingListColumnSettingResponseBody:
  141 + title: 'Mediatype identifier: ColumnSettingListColumnSettingResponseBody'
  142 + type: object
  143 + properties:
  144 + column_setting:
  145 + $ref: '#/definitions/column_settingResponseBody'
  146 + count:
  147 + type: integer
  148 + description: 匹配数目
  149 + required:
  150 + - count
  151 + ColumnSettingRemoveColumnSettingResponseBody:
  152 + title: 'Mediatype identifier: ColumnSettingRemoveColumnSettingResponseBody'
  153 + type: object
  154 + properties:
  155 + column_setting:
  156 + $ref: '#/definitions/column_settingResponseBody'
  157 + ColumnSettingResetColumnResponseBody:
  158 + title: 'Mediatype identifier: ColumnSettingResetColumnResponseBody'
  159 + type: object
  160 + properties:
  161 + column_setting:
  162 + $ref: '#/definitions/column_settingResponseBody'
  163 + ColumnSettingUpdateColumnSettingResponseBody:
  164 + title: 'Mediatype identifier: ColumnSettingUpdateColumnSettingResponseBody'
  165 + type: object
  166 + properties:
  167 + column_setting:
  168 + $ref: '#/definitions/column_settingResponseBody'
  169 + column_settingResponseBody:
  170 + title: column_settingResponseBody
  171 + type: object
  172 + properties:
  173 + columnSettingId:
  174 + type: integer
  175 + description: 栏目设置id
  176 + required:
  177 + - columnSettingId
  178 + companyId:
  179 + type: integer
  180 + description: 栏目设置关联用户公司id
  181 + required:
  182 + - companyId
  183 + createdAt:
  184 + type: string
  185 + description: 栏目设置创建时间
  186 + required:
  187 + - createdAt
  188 + description:
  189 + type: string
  190 + description: 栏目设置描述
  191 + required:
  192 + - description
  193 + key:
  194 + type: string
  195 + description: 栏目设置模块名称
  196 + required:
  197 + - key
  198 + uid:
  199 + type: integer
  200 + description: 栏目设置关联用户uid
  201 + required:
  202 + - uid
  203 + updatedAt:
  204 + type: string
  205 + description: 栏目设置更新时间
  206 + required:
  207 + - updatedAt
  208 + userName:
  209 + type: string
  210 + description: 栏目设置关联用户名称
  211 + required:
  212 + - userName
  213 + value:
  214 + type: array
  215 + items:
  216 + $ref: '#/definitions/columnResponseBody'
  217 + description: 栏目数组
  218 + description: 栏目设置
  219 + columnResponseBody:
  220 + title: columnResponseBody
  221 + type: object
  222 + properties:
  223 + columnId:
  224 + type: string
  225 + description: 列标记
  226 + required:
  227 + - columnId
  228 + paramCn:
  229 + type: string
  230 + description: 列标记中文
  231 + required:
  232 + - paramCn
  233 + paramFix:
  234 + type: integer
  235 + description: 列标记是否固定,1:固定,2:不固定
  236 + required:
  237 + - paramFix
  238 + description: 栏目项
@@ -7,7 +7,7 @@ var POSTGRESQL_USER = "postgres" @@ -7,7 +7,7 @@ var POSTGRESQL_USER = "postgres"
7 var POSTGRESQL_PASSWORD = "1993618jack" // eagle1010 7 var POSTGRESQL_PASSWORD = "1993618jack" // eagle1010
8 var POSTGRESQL_HOST = "127.0.0.1" // 114.55.200.59 8 var POSTGRESQL_HOST = "127.0.0.1" // 114.55.200.59
9 var POSTGRESQL_PORT = "5432" // 31543 9 var POSTGRESQL_PORT = "5432" // 31543
10 -var DISABLE_CREATE_TABLE = true 10 +var DISABLE_CREATE_TABLE = false
11 var DISABLE_SQL_GENERATE_PRINT = false 11 var DISABLE_SQL_GENERATE_PRINT = false
12 12
13 func init() { 13 func init() {
@@ -21,7 +21,7 @@ type ColumnSetting struct { @@ -21,7 +21,7 @@ type ColumnSetting struct {
21 // 栏目设置关联用户名称 21 // 栏目设置关联用户名称
22 UserName string `json:"userName"` 22 UserName string `json:"userName"`
23 // 栏目数组 23 // 栏目数组
24 - Value []*Column `json:"valuea"` 24 + Value []Column `json:"value"`
25 } 25 }
26 26
27 type ColumnSettingRepository interface { 27 type ColumnSettingRepository interface {
@@ -64,7 +64,7 @@ func (columnSetting *ColumnSetting) Update(data map[string]interface{}) error { @@ -64,7 +64,7 @@ func (columnSetting *ColumnSetting) Update(data map[string]interface{}) error {
64 columnSetting.UserName = userName.(string) 64 columnSetting.UserName = userName.(string)
65 } 65 }
66 if value, ok := data["value"]; ok { 66 if value, ok := data["value"]; ok {
67 - columnSetting.Value = value.([]*Column) 67 + columnSetting.Value = value.([]Column)
68 } 68 }
69 return nil 69 return nil
70 } 70 }
@@ -5,7 +5,9 @@ import ( @@ -5,7 +5,9 @@ import (
5 "fmt" 5 "fmt"
6 6
7 "github.com/go-pg/pg/v10" 7 "github.com/go-pg/pg/v10"
  8 + "github.com/go-pg/pg/v10/orm"
8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" 9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/log" 11 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/log"
10 ) 12 )
11 13
@@ -21,6 +23,20 @@ func init() { @@ -21,6 +23,20 @@ func init() {
21 if !constant.DISABLE_SQL_GENERATE_PRINT { 23 if !constant.DISABLE_SQL_GENERATE_PRINT {
22 DB.AddQueryHook(SqlGeneratePrintHook{}) 24 DB.AddQueryHook(SqlGeneratePrintHook{})
23 } 25 }
  26 + if !constant.DISABLE_CREATE_TABLE {
  27 + for _, model := range []interface{}{
  28 + &models.ColumnSetting{},
  29 + } {
  30 + err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
  31 + Temp: false,
  32 + IfNotExists: true,
  33 + FKConstraints: true,
  34 + })
  35 + if err != nil {
  36 + panic(err)
  37 + }
  38 + }
  39 + }
24 } 40 }
25 41
26 type SqlGeneratePrintHook struct{} 42 type SqlGeneratePrintHook struct{}
@@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
6 ) 6 )
7 7
8 type ColumnSetting struct { 8 type ColumnSetting struct {
9 - TableName string `pg:"column_settings,alias:column_setting"`  
10 // 栏目设置id 9 // 栏目设置id
11 Id int64 10 Id int64
12 // 栏目设置关联用户公司id 11 // 栏目设置关联用户公司id
@@ -24,5 +23,5 @@ type ColumnSetting struct { @@ -24,5 +23,5 @@ type ColumnSetting struct {
24 // 栏目设置关联用户名称 23 // 栏目设置关联用户名称
25 UserName string 24 UserName string
26 // 栏目数组 25 // 栏目数组
27 - Value []*domain.Column `pg:",array"` 26 + Value []domain.Column `pg:",array"`
28 } 27 }