Browse Source

add gva error message

main
SliverHorn 4 years ago
parent
commit
8025d7d691
  1. 10
      server/cmd/datas/AuthorityMenu.go
  2. 5
      server/cmd/datas/apis.go
  3. 5
      server/cmd/datas/authorities.go
  4. 5
      server/cmd/datas/authority_Ids.go
  5. 5
      server/cmd/datas/authority_menus.go
  6. 5
      server/cmd/datas/casbins.go
  7. 5
      server/cmd/datas/customers.go
  8. 20
      server/cmd/datas/dictionaries.go
  9. 5
      server/cmd/datas/dictionary_details.go
  10. 5
      server/cmd/datas/files.go
  11. 5
      server/cmd/datas/menus.go
  12. 5
      server/cmd/datas/users.go
  13. 2
      server/cmd/gva/version.go

10
server/cmd/datas/AuthorityMenu.go

@ -1,7 +1,13 @@
package datas package datas
import "gorm.io/gorm"
import (
"github.com/gookit/color"
"gorm.io/gorm"
)
func InitAuthorityMenu(db *gorm.DB) (err error) { func InitAuthorityMenu(db *gorm.DB) (err error) {
return db.Exec("CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `authority_menu` AS select `sys_base_menus`.`id` AS `id`,`sys_base_menus`.`created_at` AS `created_at`, `sys_base_menus`.`updated_at` AS `updated_at`, `sys_base_menus`.`deleted_at` AS `deleted_at`, `sys_base_menus`.`menu_level` AS `menu_level`,`sys_base_menus`.`parent_id` AS `parent_id`,`sys_base_menus`.`path` AS `path`,`sys_base_menus`.`name` AS `name`,`sys_base_menus`.`hidden` AS `hidden`,`sys_base_menus`.`component` AS `component`, `sys_base_menus`.`title` AS `title`,`sys_base_menus`.`icon` AS `icon`,`sys_base_menus`.`sort` AS `sort`,`sys_authority_menus`.`sys_authority_authority_id` AS `authority_id`,`sys_authority_menus`.`sys_base_menu_id` AS `menu_id`,`sys_base_menus`.`keep_alive` AS `keep_alive`,`sys_base_menus`.`default_menu` AS `default_menu` from (`sys_authority_menus` join `sys_base_menus` on ((`sys_authority_menus`.`sys_base_menu_id` = `sys_base_menus`.`id`)))").Error
if err := db.Exec("CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `authority_menu` AS select `sys_base_menus`.`id` AS `id`,`sys_base_menus`.`created_at` AS `created_at`, `sys_base_menus`.`updated_at` AS `updated_at`, `sys_base_menus`.`deleted_at` AS `deleted_at`, `sys_base_menus`.`menu_level` AS `menu_level`,`sys_base_menus`.`parent_id` AS `parent_id`,`sys_base_menus`.`path` AS `path`,`sys_base_menus`.`name` AS `name`,`sys_base_menus`.`hidden` AS `hidden`,`sys_base_menus`.`component` AS `component`, `sys_base_menus`.`title` AS `title`,`sys_base_menus`.`icon` AS `icon`,`sys_base_menus`.`sort` AS `sort`,`sys_authority_menus`.`sys_authority_authority_id` AS `authority_id`,`sys_authority_menus`.`sys_base_menu_id` AS `menu_id`,`sys_base_menus`.`keep_alive` AS `keep_alive`,`sys_base_menus`.`default_menu` AS `default_menu` from (`sys_authority_menus` join `sys_base_menus` on ((`sys_authority_menus`.`sys_base_menu_id` = `sys_base_menus`.`id`)))").Error; err != nil {
color.Danger.Println("authority_menu视图已存在!")
}
return nil
} }

5
server/cmd/datas/apis.go

@ -2,6 +2,7 @@ package datas
import ( import (
"gin-vue-admin/model" "gin-vue-admin/model"
"github.com/gookit/color"
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
@ -78,6 +79,10 @@ var Apis = []model.SysApi{
func InitSysApi(db *gorm.DB) (err error) { func InitSysApi(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 67}).Find(&[]model.SysApi{}).RowsAffected == 2 {
color.Danger.Println("sys_apis表的初始数据已存在!")
return nil
}
if tx.Create(&Apis).Error != nil { // 遇到错误时回滚事务 if tx.Create(&Apis).Error != nil { // 遇到错误时回滚事务
return err return err
} }

5
server/cmd/datas/authorities.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"time" "time"
"gin-vue-admin/model" "gin-vue-admin/model"
@ -15,6 +16,10 @@ var Authorities = []model.SysAuthority{
func InitSysAuthority(db *gorm.DB) (err error) { func InitSysAuthority(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if tx.Where("authority_id IN ? ", []string{"888", "9528"}).Find(&[]model.SysAuthority{}).RowsAffected == 2 {
color.Danger.Println("sys_authorities表的初始数据已存在!")
return nil
}
if tx.Create(&Authorities).Error != nil { // 遇到错误时回滚事务 if tx.Create(&Authorities).Error != nil { // 遇到错误时回滚事务
return err return err
} }

5
server/cmd/datas/authority_Ids.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -19,6 +20,10 @@ var DataAuthorityId = []SysDataAuthorityId{
func InitSysDataAuthorityId(db *gorm.DB) (err error) { func InitSysDataAuthorityId(db *gorm.DB) (err error) {
return db.Table("sys_data_authority_id").Transaction(func(tx *gorm.DB) error { return db.Table("sys_data_authority_id").Transaction(func(tx *gorm.DB) error {
if tx.Where("sys_authority_authority_id IN ?", []string{"888", "9528"}).Find(&[]SysDataAuthorityId{}).RowsAffected == 5 {
color.Danger.Println("sys_data_authority_id表的初始数据已存在!")
return nil
}
if tx.Create(&DataAuthorityId).Error != nil { // 遇到错误时回滚事务 if tx.Create(&DataAuthorityId).Error != nil { // 遇到错误时回滚事务
return err return err
} }

5
server/cmd/datas/authority_menus.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -67,6 +68,10 @@ var AuthorityMenus = []SysAuthorityMenus{
func InitSysAuthorityMenus(db *gorm.DB) (err error) { func InitSysAuthorityMenus(db *gorm.DB) (err error) {
return db.Table("sys_authority_menus").Transaction(func(tx *gorm.DB) error { return db.Table("sys_authority_menus").Transaction(func(tx *gorm.DB) error {
if tx.Where("sys_authority_authority_id IN ?", []string{"888", "8881", "9528"}).Find(&[]SysAuthorityMenus{}).RowsAffected == 53 {
color.Danger.Println("sys_authority_menus表的初始数据已存在!")
return nil
}
if tx.Create(&AuthorityMenus).Error != nil { // 遇到错误时回滚事务 if tx.Create(&AuthorityMenus).Error != nil { // 遇到错误时回滚事务
return err return err
} }

5
server/cmd/datas/casbins.go

@ -2,6 +2,7 @@ package datas
import ( import (
gormadapter "github.com/casbin/gorm-adapter/v3" gormadapter "github.com/casbin/gorm-adapter/v3"
"github.com/gookit/color"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -157,6 +158,10 @@ func InitCasbinModel(db *gorm.DB) (err error) {
return err 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 tx.Create(&Carbines).Error != nil { // 遇到错误时回滚事务
return err return err
} }

5
server/cmd/datas/customers.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"time" "time"
"gin-vue-admin/model" "gin-vue-admin/model"
@ -13,6 +14,10 @@ var Customers = []model.ExaCustomer{
func InitExaCustomer(db *gorm.DB) (err error) { func InitExaCustomer(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ? ", []int{1}).Find(&[]model.ExaCustomer{}).RowsAffected == 1 {
color.Danger.Println("exa_customers表的初始数据已存在!")
return nil
}
if tx.Create(&Customers).Error != nil { // 遇到错误时回滚事务 if tx.Create(&Customers).Error != nil { // 遇到错误时回滚事务
return err return err
} }

20
server/cmd/datas/dictionaries.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"time" "time"
"gin-vue-admin/model" "gin-vue-admin/model"
@ -28,6 +29,10 @@ func InitSysDictionary(db *gorm.DB) (err error) {
{Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"}, {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
} }
return db.Transaction(func(tx *gorm.DB) error { 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 tx.Create(&Dictionaries).Error != nil { // 遇到错误时回滚事务
return err return err
} }
@ -38,8 +43,7 @@ func InitSysDictionary(db *gorm.DB) (err error) {
func InitSysDictionaryToPostgresql(db *gorm.DB) (err error) { func InitSysDictionaryToPostgresql(db *gorm.DB) (err error) {
status := new(bool) status := new(bool)
*status = true *status = true
tx := db.Begin() // 开始事务
insert := []SysDictionaryToPostgresql{
Dictionaries := []SysDictionaryToPostgresql{
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Description: "性别字典"}, {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Description: "性别字典"},
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Description: "int类型对应的数据库类型"}, {Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Description: "int类型对应的数据库类型"},
{Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Description: "数据库时间日期类型"}, {Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Description: "数据库时间日期类型"},
@ -47,8 +51,14 @@ func InitSysDictionaryToPostgresql(db *gorm.DB) (err error) {
{Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Description: "数据库字符串"}, {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Description: "数据库字符串"},
{Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Description: "数据库bool类型"}, {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Description: "数据库bool类型"},
} }
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
tx.Rollback()
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
} }
return tx.Commit().Error
if tx.Create(&Dictionaries).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
} }

5
server/cmd/datas/dictionary_details.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"time" "time"
"gin-vue-admin/model" "gin-vue-admin/model"
@ -36,6 +37,10 @@ func InitSysDictionaryDetail(db *gorm.DB) (err error) {
{gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6}, {gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6},
} }
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 23}).Find(&[]model.SysDictionaryDetail{}).RowsAffected == 2 {
color.Danger.Println("sys_dictionary_details表的初始数据已存在!")
return nil
}
if tx.Create(&DictionaryDetail).Error != nil { // 遇到错误时回滚事务 if tx.Create(&DictionaryDetail).Error != nil { // 遇到错误时回滚事务
return err return err
} }

5
server/cmd/datas/files.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"time" "time"
"gin-vue-admin/model" "gin-vue-admin/model"
@ -14,6 +15,10 @@ var Files = []model.ExaFileUploadAndDownload{
func InitExaFileUploadAndDownload(db *gorm.DB) (err error) { func InitExaFileUploadAndDownload(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.ExaFileUploadAndDownload{}).RowsAffected == 2 {
color.Danger.Println("exa_file_upload_and_downloads表的初始数据已存在!")
return nil
}
if tx.Create(&Files).Error != nil { // 遇到错误时回滚事务 if tx.Create(&Files).Error != nil { // 遇到错误时回滚事务
return err return err
} }

5
server/cmd/datas/menus.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"time" "time"
"gin-vue-admin/model" "gin-vue-admin/model"
@ -39,6 +40,10 @@ var BaseMenus = []model.SysBaseMenu{
func InitSysBaseMenus(db *gorm.DB) (err error) { func InitSysBaseMenus(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 27}).Find(&[]model.SysBaseMenu{}).RowsAffected == 2 {
color.Danger.Println("sys_base_menus表的初始数据已存在!")
return nil
}
if tx.Create(&BaseMenus).Error != nil { // 遇到错误时回滚事务 if tx.Create(&BaseMenus).Error != nil { // 遇到错误时回滚事务
return err return err
} }

5
server/cmd/datas/users.go

@ -1,6 +1,7 @@
package datas package datas
import ( import (
"github.com/gookit/color"
"time" "time"
"gin-vue-admin/model" "gin-vue-admin/model"
@ -15,6 +16,10 @@ var Users = []model.SysUser{
func InitSysUser(db *gorm.DB) (err error) { func InitSysUser(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.SysUser{}).RowsAffected == 2 {
color.Danger.Println("sys_users表的初始数据已存在!")
return nil
}
if tx.Create(&Users).Error != nil { // 遇到错误时回滚事务 if tx.Create(&Users).Error != nil { // 遇到错误时回滚事务
return err return err
} }

2
server/cmd/gva/version.go

@ -27,7 +27,7 @@ var versionCmd = &cobra.Command{
Short: "版本信息", Short: "版本信息",
Long: `版本的长信息`, Long: `版本的长信息`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
color.Green.Println("v0.0.2")
color.Green.Println("v0.0.3")
}, },
} }

Loading…
Cancel
Save