mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 02:04:09 +00:00
feat:date migrate
This commit is contained in:
@@ -18,7 +18,7 @@ func init() {
|
||||
}
|
||||
|
||||
func _1599190683659Tables(db *gorm.DB, version string) error {
|
||||
err := db.Migrator().AutoMigrate(
|
||||
err := db.Debug().Migrator().AutoMigrate(
|
||||
new(models.CasbinRule),
|
||||
new(models.SysDept),
|
||||
new(models.SysConfig),
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/cmd/migrate/migration"
|
||||
common "go-admin/common/models"
|
||||
"gorm.io/gorm"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_, fileName, _, _ := runtime.Caller(0)
|
||||
fileName = filepath.Base(fileName)
|
||||
fileName = fileName[:len(fileName)-3]
|
||||
migration.Migrate.SetVersion(fileName, _1599190683670Test)
|
||||
}
|
||||
|
||||
func _1599190683670Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
if err := models.InitDb(tx); err != nil {
|
||||
|
||||
}
|
||||
|
||||
|
||||
return tx.Create(&common.Migration{
|
||||
Version: version,
|
||||
}).Error
|
||||
})
|
||||
}
|
||||
+3
-3
@@ -13,10 +13,10 @@ func init() {
|
||||
_, fileName, _, _ := runtime.Caller(0)
|
||||
fileName = filepath.Base(fileName)
|
||||
fileName = fileName[:len(fileName)-3]
|
||||
migration.Migrate.SetVersion(fileName, _1599190683660Test)
|
||||
migration.Migrate.SetVersion(fileName, _1599190683680Test)
|
||||
}
|
||||
|
||||
func _1599190683660Test(db *gorm.DB, version string) error {
|
||||
func _1599190683680Test(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
var err error
|
||||
|
||||
@@ -48,7 +48,7 @@ func _1599190683660Test(db *gorm.DB, version string) error {
|
||||
{MenuId: 521, MenuName: "", Title: "删除内容管理", Icon: "bug", Path: "/api/v1/syscontent/:id", Paths: "/0/63/516/521", MenuType: "A", Action: "DELETE", Permission: "", ParentId: 516, NoCache: true, Breadcrumb: "", Component: "", Sort: 0, Visible: "1", CreateBy: "1", UpdateBy: "1", IsFrame: "0"},
|
||||
}
|
||||
|
||||
err = db.Create(list).Error
|
||||
err = tx.Create(list).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user