Browse Source

增加mysql过滤,修改角色id长度 模板长度修改为size模式

QM303176530 4 years ago
parent
commit
ad4d738924

+ 1 - 1
server/initialize/mysql.go

@@ -13,7 +13,7 @@ func Mysql() {
 	admin := global.GVA_CONFIG.Mysql
 	mysqlConfig := mysql.Config{
 		DSN:                       admin.Username + ":" + admin.Password + "@(" + admin.Path + ")/" + admin.Dbname + "?" + admin.Config, // DSN data source name
-		DefaultStringSize:         256,                                                                                                  // string 类型字段的默认长度
+		DefaultStringSize:         191,                                                                                                  // string 类型字段的默认长度
 		DisableDatetimePrecision:  true,                                                                                                 // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
 		DontSupportRenameIndex:    true,                                                                                                 // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
 		DontSupportRenameColumn:   true,                                                                                                 // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列

+ 1 - 1
server/model/sys_authority.go

@@ -8,7 +8,7 @@ type SysAuthority struct {
 	CreatedAt       time.Time
 	UpdatedAt       time.Time
 	DeletedAt       *time.Time     `sql:"index"`
-	AuthorityId     string         `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;type:varchar(100)"`
+	AuthorityId     string         `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"`
 	AuthorityName   string         `json:"authorityName" gorm:"comment:'角色名'"`
 	ParentId        string         `json:"parentId" gorm:"comment:'父角色ID'"`
 	DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"`

+ 2 - 2
server/resource/template/te/model.go.tpl

@@ -9,9 +9,9 @@ import (
 type {{.StructName}} struct {
       gorm.Model {{- range .Fields}}
             {{- if eq .FieldType "bool" }}
-      {{.FieldName}}  *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}}"`
+      {{.FieldName}}  *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:{{.DataType}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
             {{- else }}
-      {{.FieldName}}  {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}}"`
+      {{.FieldName}}  {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:{{.DataType}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
             {{- end }}  {{- end }} 
 }