-
Notifications
You must be signed in to change notification settings - Fork 88
/
schema.go
49 lines (38 loc) · 924 Bytes
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package persistence
import (
"os"
"path/filepath"
"github.com/pkg/errors"
schemaherodb "github.com/schemahero/schemahero/pkg/database"
)
func UpdateDBSchema(driver string, uri string, schemaDir string) error {
statements := []string{}
schemaheroDB := schemaherodb.Database{
Driver: driver,
URI: uri,
}
err := filepath.Walk(schemaDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
if ext := filepath.Ext(path); ext != ".yaml" && ext != ".yml" {
return nil
}
stmnts, err := schemaheroDB.PlanSyncFromFile(path, "table")
if err != nil {
return err
}
statements = append(statements, stmnts...)
return nil
})
if err != nil {
return errors.Wrap(err, "failed to walk")
}
if err := schemaheroDB.ApplySync(statements); err != nil {
return errors.Wrap(err, "failed to apply sync")
}
return nil
}