Files
quark-go/pkg/app/install/install.go
tangtanglove 5244508c40 first commit
2023-01-18 13:40:07 +08:00

67 lines
1.3 KiB
Go

package install
import (
"os"
"github.com/quarkcms/quark-go/pkg/app/model"
"github.com/quarkcms/quark-go/pkg/builder"
"github.com/quarkcms/quark-go/pkg/dal/db"
)
// 判断路径是否存在
func PathExist(path string) bool {
_, err := os.Stat(path) //os.Stat获取文件信息
if err != nil {
if os.IsExist(err) {
return true
}
return false
}
return true
}
// 执行安装操作
func Handle(request *builder.Request) error {
// 如果锁定文件存在则不执行安装步骤
if PathExist("install.lock") {
return nil
}
// 迁移数据
db.Client.AutoMigrate(
&model.ActionLog{},
&model.Admin{},
&model.Config{},
&model.Menu{},
&model.File{},
&model.FileCategory{},
&model.Picture{},
&model.PictureCategory{},
&model.Permission{},
&model.Role{},
&model.ModelHasRole{},
&model.RoleHasPermission{},
&model.ModelHasPermission{},
)
// 如果超级管理员不存在,初始化数据库数据
adminInfo, err := (&model.Admin{}).GetInfoById(1)
if err != nil && err.Error() != "record not found" {
panic(err)
}
if adminInfo.Id == 0 {
// 数据填充
(&model.Admin{}).Seeder()
(&model.Config{}).Seeder()
(&model.Menu{}).Seeder()
}
// 创建锁定文件
file, _ := os.Create("install.lock")
file.Close()
return nil
}