[add] migrate model

This commit is contained in:
Max 2023-02-02 10:05:50 +08:00
parent c7bf0f4350
commit 725162b0f5
3 changed files with 18 additions and 11 deletions

View file

@ -1 +0,0 @@
# Model

View file

@ -10,7 +10,10 @@ import (
// Load 加载数据模型
func Load(cfg config.Config) error {
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))
return err
}, exts...)

View file

@ -7,23 +7,28 @@ import (
"github.com/yaoapp/gou/model"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/share"
"github.com/yaoapp/yao/test"
)
func TestLoad(t *testing.T) {
share.DBConnect(config.Conf.DB)
test.Prepare(t)
defer test.Clean()
Load(config.Conf)
check(t)
}
func check(t *testing.T) {
keys := []string{}
for key := range model.Models {
keys = append(keys, key)
ids := map[string]bool{}
for id := range model.Models {
ids[id] = true
}
assert.Equal(t, 11, len(keys))
demo := model.Select("demo")
assert.Equal(t, demo.MetaData.Name, "::Demo")
assert.Equal(t, demo.Columns["action"].Label, "::Action")
assert.True(t, ids["user"])
assert.True(t, ids["category"])
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"])
}