Merge pull request #32 from vulcanize/plugin_migrations
Set order to run plugin transformer db migrations in config
This commit is contained in:
commit
a9513c1af6
10
README.md
10
README.md
@ -286,21 +286,25 @@ The config provides information for composing a set of transformers:
|
|||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "0"
|
||||||
[exporter.transformer2]
|
[exporter.transformer2]
|
||||||
path = "path/to/transformer2"
|
path = "path/to/transformer2"
|
||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "0"
|
||||||
[exporter.transformer3]
|
[exporter.transformer3]
|
||||||
path = "path/to/transformer3"
|
path = "path/to/transformer3"
|
||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "0"
|
||||||
[exporter.transformer4]
|
[exporter.transformer4]
|
||||||
path = "path/to/transformer4"
|
path = "path/to/transformer4"
|
||||||
type = "eth_storage"
|
type = "eth_storage"
|
||||||
repository = "github.com/account2/repo2"
|
repository = "github.com/account2/repo2"
|
||||||
migrations = "to/db/migrations"
|
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
|
- `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)
|
- `name` is the name used for the plugin files (.so and .go)
|
||||||
@ -316,6 +320,12 @@ 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)
|
- `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
|
that fetches event logs from an ETH node
|
||||||
- `migrations` is the relative path from `repository` to the db migrations directory for the transformer
|
- `migrations` is the relative path from `repository` to the db migrations directory for the transformer
|
||||||
|
- `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
|
- 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.
|
This information is used to write and build a Go plugin which exports the configured transformers.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -18,6 +18,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -58,21 +59,25 @@ var composeCmd = &cobra.Command{
|
|||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "0"
|
||||||
[exporter.transformer2]
|
[exporter.transformer2]
|
||||||
path = "path/to/transformer2"
|
path = "path/to/transformer2"
|
||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "0"
|
||||||
[exporter.transformer3]
|
[exporter.transformer3]
|
||||||
path = "path/to/transformer3"
|
path = "path/to/transformer3"
|
||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "0"
|
||||||
[exporter.transformer4]
|
[exporter.transformer4]
|
||||||
path = "path/to/transformer4"
|
path = "path/to/transformer4"
|
||||||
type = "eth_storage"
|
type = "eth_storage"
|
||||||
repository = "github.com/account2/repo2"
|
repository = "github.com/account2/repo2"
|
||||||
migrations = "to/db/migrations"
|
migrations = "to/db/migrations"
|
||||||
|
rank = "1"
|
||||||
|
|
||||||
|
|
||||||
Note: If any of the plugin transformer need additional
|
Note: If any of the plugin transformer need additional
|
||||||
@ -132,21 +137,29 @@ func prepConfig() {
|
|||||||
transformers := make(map[string]config.Transformer)
|
transformers := make(map[string]config.Transformer)
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
transformer := viper.GetStringMapString("exporter." + name)
|
transformer := viper.GetStringMapString("exporter." + name)
|
||||||
p, ok := transformer["path"]
|
p, pOK := transformer["path"]
|
||||||
if !ok || p == "" {
|
if !pOK || p == "" {
|
||||||
log.Fatal(fmt.Sprintf("%s transformer config is missing `path` value", name))
|
log.Fatal(name, "transformer config is missing `path` value")
|
||||||
}
|
}
|
||||||
r, ok := transformer["repository"]
|
r, rOK := transformer["repository"]
|
||||||
if !ok || r == "" {
|
if !rOK || r == "" {
|
||||||
log.Fatal(fmt.Sprintf("%s transformer config is missing `repository` value", name))
|
log.Fatal(name, "transformer config is missing `repository` value")
|
||||||
}
|
}
|
||||||
m, ok := transformer["migrations"]
|
m, mOK := transformer["migrations"]
|
||||||
if !ok || m == "" {
|
if !mOK || m == "" {
|
||||||
log.Fatal(fmt.Sprintf("%s transformer config is missing `migrations` value", name))
|
log.Fatal(name, "transformer config is missing `migrations` value")
|
||||||
}
|
}
|
||||||
t, ok := transformer["type"]
|
mr, mrOK := transformer["rank"]
|
||||||
if !ok {
|
if !mrOK || mr == "" {
|
||||||
log.Fatal(fmt.Sprintf("%s transformer config is missing `type` value", name))
|
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)
|
transformerType := config.GetTransformerType(t)
|
||||||
if transformerType == config.UnknownTransformerType {
|
if transformerType == config.UnknownTransformerType {
|
||||||
@ -158,6 +171,7 @@ func prepConfig() {
|
|||||||
Type: transformerType,
|
Type: transformerType,
|
||||||
RepositoryPath: r,
|
RepositoryPath: r,
|
||||||
MigrationPath: m,
|
MigrationPath: m,
|
||||||
|
MigrationRank: rank,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,21 +59,25 @@ var composeAndExecuteCmd = &cobra.Command{
|
|||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "0"
|
||||||
[exporter.transformer2]
|
[exporter.transformer2]
|
||||||
path = "path/to/transformer2"
|
path = "path/to/transformer2"
|
||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "2"
|
||||||
[exporter.transformer3]
|
[exporter.transformer3]
|
||||||
path = "path/to/transformer3"
|
path = "path/to/transformer3"
|
||||||
type = "eth_event"
|
type = "eth_event"
|
||||||
repository = "github.com/account/repo"
|
repository = "github.com/account/repo"
|
||||||
migrations = "db/migrations"
|
migrations = "db/migrations"
|
||||||
|
rank = "0"
|
||||||
[exporter.transformer4]
|
[exporter.transformer4]
|
||||||
path = "path/to/transformer4"
|
path = "path/to/transformer4"
|
||||||
type = "eth_storage"
|
type = "eth_storage"
|
||||||
repository = "github.com/account2/repo2"
|
repository = "github.com/account2/repo2"
|
||||||
migrations = "to/db/migrations"
|
migrations = "to/db/migrations"
|
||||||
|
rank = "1"
|
||||||
|
|
||||||
|
|
||||||
Note: If any of the plugin transformer need additional
|
Note: If any of the plugin transformer need additional
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -17,6 +17,8 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ type Transformer struct {
|
|||||||
Path string
|
Path string
|
||||||
Type TransformerType
|
Type TransformerType
|
||||||
MigrationPath string
|
MigrationPath string
|
||||||
|
MigrationRank uint64
|
||||||
RepositoryPath string
|
RepositoryPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +54,11 @@ func (c *Plugin) GetPluginPaths() (string, string, error) {
|
|||||||
return goFile, soFile, nil
|
return goFile, soFile, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes duplicate migration paths before returning them
|
// Removes duplicate migration paths and returns them in ranked order
|
||||||
func (c *Plugin) GetMigrationsPaths() (map[string]bool, error) {
|
func (c *Plugin) GetMigrationsPaths() ([]string, error) {
|
||||||
paths := make(map[string]bool)
|
paths := make(map[uint64]string)
|
||||||
for _, transformer := range c.Transformers {
|
highestRank := -1
|
||||||
|
for name, transformer := range c.Transformers {
|
||||||
repo := transformer.RepositoryPath
|
repo := transformer.RepositoryPath
|
||||||
mig := transformer.MigrationPath
|
mig := transformer.MigrationPath
|
||||||
path := filepath.Join("$GOPATH/src", c.Home, "vendor", repo, mig)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// Removes duplicate repo paths before returning them
|
||||||
@ -114,3 +141,24 @@ func GetTransformerType(str string) TransformerType {
|
|||||||
|
|
||||||
return UnknownTransformerType
|
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
241
pkg/config/plugin_test.go
Normal 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"))
|
||||||
|
})
|
||||||
|
})
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// VulcanizeDB
|
// VulcanizeDB
|
||||||
// Copyright © 2018 Vulcanize
|
// Copyright © 2019 Vulcanize
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// 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
Loading…
Reference in New Issue
Block a user