-
Notifications
You must be signed in to change notification settings - Fork 108
/
parse_migration.go
39 lines (33 loc) · 998 Bytes
/
parse_migration.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
package rillv1
import (
"strings"
)
// MigrationYAML is the raw structure of a Migration resource defined in YAML (does not include common fields)
type MigrationYAML struct {
Version uint `yaml:"version" mapstructure:"version"`
}
// parseMigration parses a migration definition and adds the resulting resource to p.Resources.
func (p *Parser) parseMigration(node *Node) error {
// Parse YAML
tmp := &MigrationYAML{}
err := p.decodeNodeYAML(node, false, tmp)
if err != nil {
return err
}
// Add resource
r, err := p.insertResource(ResourceKindMigration, node.Name, node.Paths, node.Refs...)
if err != nil {
return err
}
// NOTE: After calling insertResource, an error must not be returned. Any validation should be done before calling it.
if node.Connector != "" {
r.MigrationSpec.Connector = node.Connector
}
if node.SQL != "" {
r.MigrationSpec.Sql = strings.TrimSpace(node.SQL)
}
if tmp.Version > 0 {
r.MigrationSpec.Version = uint32(tmp.Version)
}
return nil
}