diff --git a/server/cmd/datas/apis.go b/server/cmd/datas/apis.go index fd3a275a..2d070d5e 100644 --- a/server/cmd/datas/apis.go +++ b/server/cmd/datas/apis.go @@ -84,7 +84,7 @@ func InitSysApi(db *gorm.DB) (err error) { color.Danger.Println("sys_apis表的初始数据已存在!") return nil } - if tx.Create(&Apis).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&Apis).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/authorities.go b/server/cmd/datas/authorities.go index 56f0b2b5..e47715df 100644 --- a/server/cmd/datas/authorities.go +++ b/server/cmd/datas/authorities.go @@ -20,7 +20,7 @@ func InitSysAuthority(db *gorm.DB) (err error) { color.Danger.Println("sys_authorities表的初始数据已存在!") return nil } - if tx.Create(&Authorities).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&Authorities).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/authority_Ids.go b/server/cmd/datas/authority_Ids.go index e303051e..126ae4dd 100644 --- a/server/cmd/datas/authority_Ids.go +++ b/server/cmd/datas/authority_Ids.go @@ -24,7 +24,7 @@ func InitSysDataAuthorityId(db *gorm.DB) (err error) { color.Danger.Println("sys_data_authority_id表的初始数据已存在!") return nil } - if tx.Create(&DataAuthorityId).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&DataAuthorityId).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/authority_menus.go b/server/cmd/datas/authority_menus.go index 8052f470..d5d314ed 100644 --- a/server/cmd/datas/authority_menus.go +++ b/server/cmd/datas/authority_menus.go @@ -72,7 +72,7 @@ func InitSysAuthorityMenus(db *gorm.DB) (err error) { color.Danger.Println("sys_authority_menus表的初始数据已存在!") return nil } - if tx.Create(&AuthorityMenus).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&AuthorityMenus).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/casbins.go b/server/cmd/datas/casbins.go index a4110ae3..642fa061 100644 --- a/server/cmd/datas/casbins.go +++ b/server/cmd/datas/casbins.go @@ -153,16 +153,11 @@ var Carbines = []gormadapter.CasbinRule{ func InitCasbinModel(db *gorm.DB) (err error) { return db.Transaction(func(tx *gorm.DB) error { - if !tx.Migrator().HasTable("casbin_rule") { - if err := tx.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil { - return err - } - } if tx.Where("p_type = ? AND v0 IN ?", "p", []string{"888", "8881", "9528"}).Find(&[]gormadapter.CasbinRule{}).RowsAffected == 142 { color.Danger.Println("casbin_rule表的初始数据已存在!") return nil } - if tx.Create(&Carbines).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&Carbines).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/customers.go b/server/cmd/datas/customers.go index a57d5b38..d2f91b00 100644 --- a/server/cmd/datas/customers.go +++ b/server/cmd/datas/customers.go @@ -19,7 +19,7 @@ func InitExaCustomer(db *gorm.DB) (err error) { color.Danger.Println("exa_customers表的初始数据已存在!") return nil } - if tx.Create(&Customers).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&Customers).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/dictionaries.go b/server/cmd/datas/dictionaries.go index ae6de717..c3567225 100644 --- a/server/cmd/datas/dictionaries.go +++ b/server/cmd/datas/dictionaries.go @@ -9,15 +9,6 @@ import ( "gorm.io/gorm" ) -type SysDictionaryToPostgresql struct { - global.GVA_MODEL - Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"` - Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"` - Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"` - Description string `json:"description" form:"description" gorm:"column:description;comment:'描述'"` - SysDictionaryDetails []model.SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"` -} - func InitSysDictionary(db *gorm.DB) (err error) { var status = new(bool) *status = true @@ -34,32 +25,9 @@ func InitSysDictionary(db *gorm.DB) (err error) { color.Danger.Println("sys_dictionaries表的初始数据已存在!") return nil } - if tx.Create(&Dictionaries).Error != nil { // 遇到错误时回滚事务 - return err - } - return nil - }) -} - -func InitSysDictionaryToPostgresql(db *gorm.DB) (err error) { - status := new(bool) - *status = true - Dictionaries := []SysDictionaryToPostgresql{ - {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Description: "性别字典"}, - {GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Description: "int类型对应的数据库类型"}, - {GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Description: "数据库时间日期类型"}, - {GVA_MODEL: global.GVA_MODEL{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Description: "数据库浮点型"}, - {GVA_MODEL: global.GVA_MODEL{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Description: "数据库字符串"}, - {GVA_MODEL: global.GVA_MODEL{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Description: "数据库bool类型"}, - } - return db.Transaction(func(tx *gorm.DB) error { - if tx.Where("id IN ?", []int{1, 6}).Find(&[]model.SysDictionary{}).RowsAffected == 2 { - color.Danger.Println("sys_dictionaries表的初始数据已存在!") - return nil - } - if tx.Create(&Dictionaries).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&Dictionaries).Error; err != nil { // 遇到错误时回滚事务 return err } return nil }) -} +} \ No newline at end of file diff --git a/server/cmd/datas/dictionary_details.go b/server/cmd/datas/dictionary_details.go index 89826067..9a1cfd81 100644 --- a/server/cmd/datas/dictionary_details.go +++ b/server/cmd/datas/dictionary_details.go @@ -42,7 +42,7 @@ func InitSysDictionaryDetail(db *gorm.DB) (err error) { color.Danger.Println("sys_dictionary_details表的初始数据已存在!") return nil } - if tx.Create(&DictionaryDetail).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&DictionaryDetail).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/files.go b/server/cmd/datas/files.go index 502dbe42..05e88a37 100644 --- a/server/cmd/datas/files.go +++ b/server/cmd/datas/files.go @@ -20,7 +20,7 @@ func InitExaFileUploadAndDownload(db *gorm.DB) (err error) { color.Danger.Println("exa_file_upload_and_downloads表的初始数据已存在!") return nil } - if tx.Create(&Files).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&Files).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/init.go b/server/cmd/datas/init.go index 33bba52e..7e7e9cd2 100644 --- a/server/cmd/datas/init.go +++ b/server/cmd/datas/init.go @@ -30,54 +30,6 @@ func InitMysqlData(db *gorm.DB) { } func InitMysqlTables(db *gorm.DB) { - var err error - err = db.AutoMigrate( - model.SysApi{}, - model.SysUser{}, - model.ExaFile{}, - model.ExaCustomer{}, - model.SysBaseMenu{}, - model.SysWorkflow{}, - model.SysAuthority{}, - model.JwtBlacklist{}, - model.ExaFileChunk{}, - model.SysDictionary{}, - model.ExaSimpleUploader{}, - model.SysOperationRecord{}, - model.SysWorkflowStepInfo{}, - model.SysDictionaryDetail{}, - model.SysBaseMenuParameter{}, - model.ExaFileUploadAndDownload{}, - ) - if err != nil { - color.Warn.Printf("[Mysql]-->初始化数据表失败,err: %v\n", err) - os.Exit(0) - } - color.Info.Println("[Mysql]-->初始化数据表成功") -} - -func InitPostgresqlData(db *gorm.DB) { - var err error - err = InitSysApi(db) - err = InitSysUser(db) - err = InitExaCustomer(db) - err = InitCasbinModel(db) - err = InitSysAuthority(db) - err = InitSysBaseMenus(db) - err = InitAuthorityMenu(db) - err = InitSysAuthorityMenus(db) - err = InitSysDataAuthorityId(db) - err = InitSysDictionaryDetail(db) - err = InitExaFileUploadAndDownload(db) - err = InitSysDictionaryToPostgresql(db) - if err != nil { - color.Error.Printf("[Postgresql]-->初始化数据失败,err: %v\n", err) - os.Exit(0) - } - color.Info.Println("[Postgresql]-->初始化数据成功") -} - -func InitPostgresqlTables(db *gorm.DB) { var err error if !db.Migrator().HasTable("casbin_rule") { err = db.Migrator().CreateTable(&gormadapter.CasbinRule{}) @@ -92,17 +44,17 @@ func InitPostgresqlTables(db *gorm.DB) { model.SysAuthority{}, model.JwtBlacklist{}, model.ExaFileChunk{}, + model.SysDictionary{}, model.ExaSimpleUploader{}, model.SysOperationRecord{}, model.SysWorkflowStepInfo{}, model.SysDictionaryDetail{}, model.SysBaseMenuParameter{}, model.ExaFileUploadAndDownload{}, - SysDictionaryToPostgresql{}, ) if err != nil { - color.Error.Printf("[Postgresql]-->初始化数据表失败,err: %v\n", err) + color.Warn.Printf("[Mysql]-->初始化数据表失败,err: %v\n", err) os.Exit(0) } - color.Info.Println("[Postgresql]-->初始化数据表成功") -} + color.Info.Println("[Mysql]-->初始化数据表成功") +} \ No newline at end of file diff --git a/server/cmd/datas/menus.go b/server/cmd/datas/menus.go index 97e6d9f4..acd7a799 100644 --- a/server/cmd/datas/menus.go +++ b/server/cmd/datas/menus.go @@ -45,7 +45,7 @@ func InitSysBaseMenus(db *gorm.DB) (err error) { color.Danger.Println("sys_base_menus表的初始数据已存在!") return nil } - if tx.Create(&BaseMenus).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&BaseMenus).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/datas/users.go b/server/cmd/datas/users.go index 24a73956..55677985 100644 --- a/server/cmd/datas/users.go +++ b/server/cmd/datas/users.go @@ -21,7 +21,7 @@ func InitSysUser(db *gorm.DB) (err error) { color.Danger.Println("sys_users表的初始数据已存在!") return nil } - if tx.Create(&Users).Error != nil { // 遇到错误时回滚事务 + if err := tx.Create(&Users).Error; err != nil { // 遇到错误时回滚事务 return err } return nil diff --git a/server/cmd/gva/initdb.go b/server/cmd/gva/initdb.go index 7dcfe7b7..a02ea0e0 100644 --- a/server/cmd/gva/initdb.go +++ b/server/cmd/gva/initdb.go @@ -47,8 +47,7 @@ var initdbCmd = &cobra.Command{ datas.InitMysqlTables(db) datas.InitMysqlData(db) case "postgresql": - datas.InitPostgresqlTables(db) - datas.InitPostgresqlData(db) + color.Info.Println("postgresql功能开发中") case "sqlite": color.Info.Println("sqlite功能开发中") case "sqlserver": @@ -56,7 +55,6 @@ var initdbCmd = &cobra.Command{ default: datas.InitMysqlTables(db) datas.InitMysqlData(db) - color.Info.Println("sqlserver功能开发中") } frame, _ := cmd.Flags().GetString("frame") if frame == "gf" {