Skip to content

Commit

Permalink
add task initial
Browse files Browse the repository at this point in the history
madneal committed Jan 23, 2024
1 parent abff297 commit 4ebab26
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/source/casbin.go
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ var carbines = []gormadapter.CasbinRule{
func (c *casbin) Init() error {
global.GVA_DB.AutoMigrate(gormadapter.CasbinRule{})
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Find(&[]gormadapter.CasbinRule{}).RowsAffected == 154 {
if tx.Find(&[]gormadapter.CasbinRule{}).RowsAffected > 1 {
color.Danger.Println("\n[Mysql] --> casbin_rule 表的初始数据已存在!")
return nil
}
28 changes: 28 additions & 0 deletions server/source/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package source

import (
"github.com/gookit/color"
"github.com/madneal/gshark/global"
"github.com/madneal/gshark/model"
"gorm.io/gorm"
)

var tasks = []model.Task{
{TaskType: "github", Name: "github task", TaskStatus: true},
{TaskType: "gitlab", Name: "github task", TaskStatus: true},
{TaskType: "postman", Name: "github task", TaskStatus: true},
{TaskType: "searchcode", Name: "github task", TaskStatus: true},
}

func Init() error {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if tx.Where("task_type in ?", []string{"github", "gitlab"}).Find(&[]model.Task{}).RowsAffected > 1 {
color.Danger.Println("\n[Mysql] --> task 表的初始数据已存在!")
}
if err := tx.Create(&tasks).Error; err != nil {
return err
}
color.Info.Println("\n[Mysql] --> task 表的初始数据成功!")
return nil
})
}

0 comments on commit 4ebab26

Please sign in to comment.