Merge pull request #32 from vulcanize/plugin_migrations

Set order to run plugin transformer db migrations in config
This commit is contained in:
Ian Norden 2019-03-13 17:40:54 -05:00 committed by GitHub
commit a9513c1af6
229 changed files with 587 additions and 261 deletions

View File

@ -286,21 +286,25 @@ The config provides information for composing a set of transformers:
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "0"
[exporter.transformer2]
path = "path/to/transformer2"
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "0"
[exporter.transformer3]
path = "path/to/transformer3"
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "0"
[exporter.transformer4]
path = "path/to/transformer4"
type = "eth_storage"
repository = "github.com/account2/repo2"
migrations = "to/db/migrations"
rank = "1"
```
- `home` is the name of the package you are building the plugin for, in most cases this is github.com/vulcanize/vulcanizedb
- `name` is the name used for the plugin files (.so and .go)
@ -316,7 +320,13 @@ The config provides information for composing a set of transformers:
- `eth_event` indicates the transformer works with the [event watcher](https://github.com/vulcanize/maker-vulcanizedb/blob/staging/libraries/shared/watcher/event_watcher.go)
that fetches event logs from an ETH node
- `migrations` is the relative path from `repository` to the db migrations directory for the transformer
- Note: If any of the imported transformers need additional config variables those need to be included as well
- `rank` determines the order that migrations are ran, with lower ranked migrations running first
- this is to help isolate any potential conflicts between transformer migrations
- start at "0"
- use strings
- don't leave gaps
- transformers with identical migrations/migration paths should share the same rank
- Note: If any of the imported transformers need additional config variables those need to be included as well
This information is used to write and build a Go plugin which exports the configured transformers.
These transformers are loaded onto their specified watchers and executed.

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -18,6 +18,7 @@ package cmd
import (
"errors"
"fmt"
"strconv"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -58,21 +59,25 @@ var composeCmd = &cobra.Command{
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "0"
[exporter.transformer2]
path = "path/to/transformer2"
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "0"
[exporter.transformer3]
path = "path/to/transformer3"
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "0"
[exporter.transformer4]
path = "path/to/transformer4"
type = "eth_storage"
repository = "github.com/account2/repo2"
migrations = "to/db/migrations"
rank = "1"
Note: If any of the plugin transformer need additional
@ -132,21 +137,29 @@ func prepConfig() {
transformers := make(map[string]config.Transformer)
for _, name := range names {
transformer := viper.GetStringMapString("exporter." + name)
p, ok := transformer["path"]
if !ok || p == "" {
log.Fatal(fmt.Sprintf("%s transformer config is missing `path` value", name))
p, pOK := transformer["path"]
if !pOK || p == "" {
log.Fatal(name, "transformer config is missing `path` value")
}
r, ok := transformer["repository"]
if !ok || r == "" {
log.Fatal(fmt.Sprintf("%s transformer config is missing `repository` value", name))
r, rOK := transformer["repository"]
if !rOK || r == "" {
log.Fatal(name, "transformer config is missing `repository` value")
}
m, ok := transformer["migrations"]
if !ok || m == "" {
log.Fatal(fmt.Sprintf("%s transformer config is missing `migrations` value", name))
m, mOK := transformer["migrations"]
if !mOK || m == "" {
log.Fatal(name, "transformer config is missing `migrations` value")
}
t, ok := transformer["type"]
if !ok {
log.Fatal(fmt.Sprintf("%s transformer config is missing `type` value", name))
mr, mrOK := transformer["rank"]
if !mrOK || mr == "" {
log.Fatal(name, "transformer config is missing `rank` value")
}
rank, err := strconv.ParseUint(mr, 10, 64)
if err != nil {
log.Fatal(name, "migration `rank` can't be converted to an unsigned integer")
}
t, tOK := transformer["type"]
if !tOK {
log.Fatal(name, "transformer config is missing `type` value")
}
transformerType := config.GetTransformerType(t)
if transformerType == config.UnknownTransformerType {
@ -158,6 +171,7 @@ func prepConfig() {
Type: transformerType,
RepositoryPath: r,
MigrationPath: m,
MigrationRank: rank,
}
}

View File

@ -59,21 +59,25 @@ var composeAndExecuteCmd = &cobra.Command{
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "0"
[exporter.transformer2]
path = "path/to/transformer2"
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "2"
[exporter.transformer3]
path = "path/to/transformer3"
type = "eth_event"
repository = "github.com/account/repo"
migrations = "db/migrations"
rank = "0"
[exporter.transformer4]
path = "path/to/transformer4"
type = "eth_storage"
repository = "github.com/account2/repo2"
migrations = "to/db/migrations"
rank = "1"
Note: If any of the plugin transformer need additional

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
@ -17,6 +17,8 @@
package config
import (
"errors"
"fmt"
"path/filepath"
"strings"
@ -35,6 +37,7 @@ type Transformer struct {
Path string
Type TransformerType
MigrationPath string
MigrationRank uint64
RepositoryPath string
}
@ -51,10 +54,11 @@ func (c *Plugin) GetPluginPaths() (string, string, error) {
return goFile, soFile, nil
}
// Removes duplicate migration paths before returning them
func (c *Plugin) GetMigrationsPaths() (map[string]bool, error) {
paths := make(map[string]bool)
for _, transformer := range c.Transformers {
// Removes duplicate migration paths and returns them in ranked order
func (c *Plugin) GetMigrationsPaths() ([]string, error) {
paths := make(map[uint64]string)
highestRank := -1
for name, transformer := range c.Transformers {
repo := transformer.RepositoryPath
mig := transformer.MigrationPath
path := filepath.Join("$GOPATH/src", c.Home, "vendor", repo, mig)
@ -62,10 +66,33 @@ func (c *Plugin) GetMigrationsPaths() (map[string]bool, error) {
if err != nil {
return nil, err
}
paths[cleanPath] = true
// If there is a different path with the same rank then we have a conflict
_, ok := paths[transformer.MigrationRank]
if ok {
conflictingPath := paths[transformer.MigrationRank]
if conflictingPath != cleanPath {
return nil, errors.New(fmt.Sprintf("transformer %s has the same migration rank (%d) as another transformer", name, transformer.MigrationRank))
}
}
paths[transformer.MigrationRank] = cleanPath
if int(transformer.MigrationRank) >= highestRank {
highestRank = int(transformer.MigrationRank)
}
}
// Check for gaps and duplicates
if len(paths) != (highestRank + 1) {
return []string{}, errors.New("number of distinct ranks does not match number of distinct migration paths")
}
if anyDupes(paths) {
return []string{}, errors.New("duplicate paths with different ranks present")
}
return paths, nil
sortedPaths := make([]string, len(paths))
for rank, path := range paths {
sortedPaths[rank] = path
}
return sortedPaths, nil
}
// Removes duplicate repo paths before returning them
@ -114,3 +141,24 @@ func GetTransformerType(str string) TransformerType {
return UnknownTransformerType
}
func anyDupes(list map[uint64]string) bool {
seen := make([]string, 0, len(list))
for _, str := range list {
dupe := inList(str, seen)
if dupe {
return true
}
seen = append(seen, str)
}
return false
}
func inList(str string, list []string) bool {
for _, element := range list {
if str == element {
return true
}
}
return false
}

241
pkg/config/plugin_test.go Normal file
View File

@ -0,0 +1,241 @@
// VulcanizeDB
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package config_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/config"
"os"
"path/filepath"
)
var allDifferentPathsConfig = config.Plugin{
Transformers: map[string]config.Transformer{
"transformer1": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path1",
MigrationRank: 0,
RepositoryPath: "test/repo/path",
},
"transformer2": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path2",
MigrationRank: 2,
RepositoryPath: "test/repo/path",
},
"transformer3": {
Path: "test/init/path2",
Type: config.EthEvent,
MigrationPath: "test/migration/path3",
MigrationRank: 1,
RepositoryPath: "test/repo/path",
},
},
}
var overlappingPathsConfig = config.Plugin{
Transformers: map[string]config.Transformer{
"transformer1": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path1",
MigrationRank: 0,
RepositoryPath: "test/repo/path",
},
"transformer2": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path1",
MigrationRank: 0,
RepositoryPath: "test/repo/path",
},
"transformer3": {
Path: "test/init/path2",
Type: config.EthEvent,
MigrationPath: "test/migration/path3",
MigrationRank: 1,
RepositoryPath: "test/repo/path",
},
},
}
var conflictErrorConfig = config.Plugin{
Transformers: map[string]config.Transformer{
"transformer1": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path1",
MigrationRank: 0,
RepositoryPath: "test/repo/path",
},
"transformer2": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path2",
MigrationRank: 0,
RepositoryPath: "test/repo/path",
},
"transformer3": {
Path: "test/init/path2",
Type: config.EthEvent,
MigrationPath: "test/migration/path3",
MigrationRank: 1,
RepositoryPath: "test/repo/path",
},
},
}
var gapErrorConfig = config.Plugin{
Transformers: map[string]config.Transformer{
"transformer1": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path1",
MigrationRank: 0,
RepositoryPath: "test/repo/path",
},
"transformer2": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path2",
MigrationRank: 3,
RepositoryPath: "test/repo/path",
},
"transformer3": {
Path: "test/init/path2",
Type: config.EthEvent,
MigrationPath: "test/migration/path3",
MigrationRank: 1,
RepositoryPath: "test/repo/path",
},
},
}
var missingRankErrorConfig = config.Plugin{
Transformers: map[string]config.Transformer{
"transformer1": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path1",
MigrationRank: 0,
RepositoryPath: "test/repo/path",
},
"transformer2": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path2",
RepositoryPath: "test/repo/path",
},
"transformer3": {
Path: "test/init/path2",
Type: config.EthEvent,
MigrationPath: "test/migration/path3",
MigrationRank: 1,
RepositoryPath: "test/repo/path",
},
},
}
var duplicateErrorConfig = config.Plugin{
Transformers: map[string]config.Transformer{
"transformer1": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path1",
MigrationRank: 0,
RepositoryPath: "test/repo/path",
},
"transformer2": {
Path: "test/init/path",
Type: config.EthEvent,
MigrationPath: "test/migration/path1",
RepositoryPath: "test/repo/path",
MigrationRank: 2,
},
"transformer3": {
Path: "test/init/path2",
Type: config.EthEvent,
MigrationPath: "test/migration/path3",
MigrationRank: 1,
RepositoryPath: "test/repo/path",
},
},
}
var _ = Describe("GetMigrationsPaths", func() {
It("Sorts migration paths by rank", func() {
plugin := allDifferentPathsConfig
migrationPaths, err := plugin.GetMigrationsPaths()
Expect(err).ToNot(HaveOccurred())
Expect(len(migrationPaths)).To(Equal(3))
env := os.Getenv("GOPATH")
path1 := filepath.Join(env, "src/vendor/test/repo/path/test/migration/path1")
path2 := filepath.Join(env, "src/vendor/test/repo/path/test/migration/path3")
path3 := filepath.Join(env, "src/vendor/test/repo/path/test/migration/path2")
expectedMigrationPaths := []string{path1, path2, path3}
Expect(migrationPaths).To(Equal(expectedMigrationPaths))
})
It("Expects identical migration paths to have the same rank", func() {
plugin := overlappingPathsConfig
migrationPaths, err := plugin.GetMigrationsPaths()
Expect(err).ToNot(HaveOccurred())
Expect(len(migrationPaths)).To(Equal(2))
env := os.Getenv("GOPATH")
path1 := filepath.Join(env, "src/vendor/test/repo/path/test/migration/path1")
path2 := filepath.Join(env, "src/vendor/test/repo/path/test/migration/path3")
expectedMigrationPaths := []string{path1, path2}
Expect(migrationPaths).To(Equal(expectedMigrationPaths))
})
It("Fails if two different migration paths have the same rank", func() {
plugin := conflictErrorConfig
migrationPaths, err := plugin.GetMigrationsPaths()
Expect(err).To(HaveOccurred())
Expect(len(migrationPaths)).To(Equal(0))
Expect(err.Error()).To(ContainSubstring("has the same migration rank"))
})
It("Fails if there is a gap in the ranks of the migration paths", func() {
plugin := gapErrorConfig
migrationPaths, err := plugin.GetMigrationsPaths()
Expect(err).To(HaveOccurred())
Expect(len(migrationPaths)).To(Equal(0))
Expect(err.Error()).To(ContainSubstring("number of distinct ranks does not match number of distinct migration paths"))
})
It("Fails if a transformer is missing its rank", func() {
plugin := missingRankErrorConfig
migrationPaths, err := plugin.GetMigrationsPaths()
Expect(err).To(HaveOccurred())
Expect(len(migrationPaths)).To(Equal(0))
Expect(err.Error()).To(ContainSubstring("has the same migration rank"))
})
It("Fails if the same migration path has more than one rank", func() {
plugin := duplicateErrorConfig
migrationPaths, err := plugin.GetMigrationsPaths()
Expect(err).To(HaveOccurred())
Expect(len(migrationPaths)).To(Equal(0))
Expect(err.Error()).To(ContainSubstring("duplicate paths with different ranks present"))
})
})

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

View File

@ -1,5 +1,5 @@
// VulcanizeDB
// Copyright © 2018 Vulcanize
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by

Some files were not shown because too many files have changed in this diff Show More