From 9186c6ce04f1dc3095b0aae71fa6b040b8a5b33b Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Fri, 19 Feb 2021 10:48:27 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/models/datascope.go | 5 +- .../migration/version/1599190683659_tables.go | 4 +- .../version/1600089797118_migrate.go | 2 +- .../version/1613638159444_migrate.go | 50 +++++++++++++++++++ common/models/by.go | 13 ++--- 5 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 cmd/migrate/migration/version/1613638159444_migrate.go diff --git a/app/admin/models/datascope.go b/app/admin/models/datascope.go index 83702fb8..6e9ad60e 100644 --- a/app/admin/models/datascope.go +++ b/app/admin/models/datascope.go @@ -2,10 +2,9 @@ package models import ( "errors" - "fmt" - "gorm.io/gorm" + "go-admin/common/log" "go-admin/tools" "go-admin/tools/config" ) @@ -21,7 +20,7 @@ func (e *DataPermission) GetDataScope(tbname string, table *gorm.DB) (*gorm.DB, if !config.ApplicationConfig.EnableDP { usageStr := `数据权限已经为您` + tools.Green(`关闭`) + `,如需开启请参考配置文件字段说明` - fmt.Printf("%s\n", usageStr) + log.Debug("%s\n", usageStr) return table, nil } SysUser := new(SysUser) diff --git a/cmd/migrate/migration/version/1599190683659_tables.go b/cmd/migrate/migration/version/1599190683659_tables.go index 1306553f..d7f18976 100644 --- a/cmd/migrate/migration/version/1599190683659_tables.go +++ b/cmd/migrate/migration/version/1599190683659_tables.go @@ -24,13 +24,13 @@ func _1599190683659Tables(db *gorm.DB, version string) error { new(system.SysConfig), new(tools.SysTables), new(tools.SysColumns), - new(models.Menu), + new(models.SysMenu), new(system.SysLoginLog), new(system.SysOperaLog), new(models.RoleMenu), new(models.SysRoleDept), new(models.SysUser), - new(models.SysRole), + new(system.SysRole), new(models.Post), new(models.DictData), new(models.DictType), diff --git a/cmd/migrate/migration/version/1600089797118_migrate.go b/cmd/migrate/migration/version/1600089797118_migrate.go index d18f2c47..12b603ba 100644 --- a/cmd/migrate/migration/version/1600089797118_migrate.go +++ b/cmd/migrate/migration/version/1600089797118_migrate.go @@ -20,7 +20,7 @@ func _1600089797118Migrate(db *gorm.DB, version string) error { f := &models.SysFileDir{ Label: "根目录", PId: 0, - //Sort: "0", + Sort: "0", Path: "", ControlBy: common.ControlBy{ CreateBy: 1, diff --git a/cmd/migrate/migration/version/1613638159444_migrate.go b/cmd/migrate/migration/version/1613638159444_migrate.go new file mode 100644 index 00000000..b8d4e930 --- /dev/null +++ b/cmd/migrate/migration/version/1613638159444_migrate.go @@ -0,0 +1,50 @@ +package version + +import ( + "go-admin/app/admin/models" + "go-admin/app/admin/models/system" + + //"go-admin/app/admin/models" + "gorm.io/gorm" + "runtime" + + "go-admin/cmd/migrate/migration" + common "go-admin/common/models" +) + +func init() { + _, fileName, _, _ := runtime.Caller(0) + migration.Migrate.SetVersion(migration.GetFilename(fileName), _1613638159444Test) +} + +func _1613638159444Test(db *gorm.DB, version string) error { + return db.Transaction(func(tx *gorm.DB) error { + + // TODO: 这里开始写入要变更的内容 + + // TODO: 例如 修改表字段 使用过程中请删除此段代码 + err := tx.Migrator().AlterColumn(&system.SysRole{}, "create_by") + if err != nil { + return err + } + err = tx.Migrator().AlterColumn(&system.SysRole{}, "update_by") + if err != nil { + return err + } + + err = tx.Migrator().AlterColumn(&models.SysMenu{}, "update_by") + if err != nil { + return err + } + err = tx.Migrator().AlterColumn(&models.SysMenu{}, "create_by") + if err != nil { + return err + } + + + + return tx.Create(&common.Migration{ + Version: version, + }).Error + }) +} diff --git a/common/models/by.go b/common/models/by.go index 89ad0abb..442fec96 100644 --- a/common/models/by.go +++ b/common/models/by.go @@ -3,8 +3,8 @@ package models import "time" type ControlBy struct { - CreateBy int `gorm:"index;comment:'创建者'"` - UpdateBy int `gorm:"index;comment:'更新者'"` + CreateBy int `json:"createBy" gorm:"index;comment:创建者"` + UpdateBy int `json:"updateBy" gorm:"index;comment:更新者"` } func (e *ControlBy) SetCreateBy(createBy int) { @@ -17,11 +17,12 @@ func (e *ControlBy) SetUpdateBy(updateBy int) { type Model struct { - ID int `gorm:"primaryKey;autoIncrement;comment:'主键编码'"` + ID int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"` } type ModelTime struct { - CreatedAt time.Time `gorm:"comment:'创建时间'"` - UpdatedAt time.Time `gorm:"comment:'最后更新时间'"` - DeletedAt *time.Time `gorm:"index;comment:'删除时间'"` + CreatedAt time.Time `json:"createdAt" gorm:"comment:创建时间"` + UpdatedAt time.Time `json:"updatedAt" gorm:"comment:最后更新时间"` + DeletedAt *time.Time `json:"-" gorm:"index;comment:删除时间"` } +