[add] migrate model
This commit is contained in:
parent
c7bf0f4350
commit
725162b0f5
3 changed files with 18 additions and 11 deletions
|
|
@ -1 +0,0 @@
|
||||||
# Model
|
|
||||||
|
|
@ -10,7 +10,10 @@ import (
|
||||||
// Load 加载数据模型
|
// Load 加载数据模型
|
||||||
func Load(cfg config.Config) error {
|
func Load(cfg config.Config) error {
|
||||||
exts := []string{"*.mod.yao", "*.mod.json", "*.mod.jsonc"}
|
exts := []string{"*.mod.yao", "*.mod.json", "*.mod.jsonc"}
|
||||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
return application.App.Walk("models", func(root, file string, isdir bool) error {
|
||||||
|
if isdir {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
_, err := model.Load(file, share.ID(root, file))
|
_, err := model.Load(file, share.ID(root, file))
|
||||||
return err
|
return err
|
||||||
}, exts...)
|
}, exts...)
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,28 @@ import (
|
||||||
|
|
||||||
"github.com/yaoapp/gou/model"
|
"github.com/yaoapp/gou/model"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
share.DBConnect(config.Conf.DB)
|
test.Prepare(t)
|
||||||
|
defer test.Clean()
|
||||||
|
|
||||||
Load(config.Conf)
|
Load(config.Conf)
|
||||||
check(t)
|
check(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func check(t *testing.T) {
|
func check(t *testing.T) {
|
||||||
keys := []string{}
|
ids := map[string]bool{}
|
||||||
for key := range model.Models {
|
for id := range model.Models {
|
||||||
keys = append(keys, key)
|
ids[id] = true
|
||||||
}
|
}
|
||||||
assert.Equal(t, 11, len(keys))
|
|
||||||
|
|
||||||
demo := model.Select("demo")
|
assert.True(t, ids["user"])
|
||||||
assert.Equal(t, demo.MetaData.Name, "::Demo")
|
assert.True(t, ids["category"])
|
||||||
assert.Equal(t, demo.Columns["action"].Label, "::Action")
|
assert.True(t, ids["tag"])
|
||||||
|
assert.True(t, ids["pet"])
|
||||||
|
assert.True(t, ids["pet.tag"])
|
||||||
|
assert.True(t, ids["user.pet"])
|
||||||
|
assert.True(t, ids["tests.user"])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue