2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2018 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/>.
|
|
|
|
|
2019-02-02 22:15:09 +00:00
|
|
|
package config
|
2017-10-19 14:22:12 +00:00
|
|
|
|
2019-01-31 01:38:56 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2019-02-02 22:15:09 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/plugin/helpers"
|
2019-01-31 01:38:56 +00:00
|
|
|
)
|
|
|
|
|
2019-02-02 22:15:09 +00:00
|
|
|
type Plugin struct {
|
2019-01-31 23:14:42 +00:00
|
|
|
Initializers map[string]string // Map of import aliases to transformer initializer paths
|
2019-01-31 01:38:56 +00:00
|
|
|
Dependencies map[string]string // Map of vendor dep names to their repositories
|
2019-01-31 23:14:42 +00:00
|
|
|
Migrations map[string]string // Map of vendor dep names to relative path from repository to db migrations
|
2019-01-31 01:38:56 +00:00
|
|
|
FilePath string
|
|
|
|
FileName string
|
2019-01-31 23:14:42 +00:00
|
|
|
Save bool
|
2019-01-31 01:38:56 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 22:15:09 +00:00
|
|
|
func (c *Plugin) GetPluginPaths() (string, string, error) {
|
|
|
|
path, err := helpers.CleanPath(c.FilePath)
|
2019-01-31 01:38:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
name := strings.Split(c.FileName, ".")[0]
|
|
|
|
goFile := filepath.Join(path, name+".go")
|
|
|
|
soFile := filepath.Join(path, name+".so")
|
|
|
|
|
|
|
|
return goFile, soFile, nil
|
|
|
|
}
|
|
|
|
|
2019-02-02 22:15:09 +00:00
|
|
|
func (c *Plugin) GetMigrationsPaths() ([]string, error) {
|
2019-01-31 01:38:56 +00:00
|
|
|
paths := make([]string, 0, len(c.Migrations))
|
|
|
|
for key, relPath := range c.Migrations {
|
|
|
|
repo, ok := c.Dependencies[key]
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New(fmt.Sprintf("migration %s with path %s missing repository", key, relPath))
|
|
|
|
}
|
|
|
|
path := filepath.Join("$GOPATH/src/github.com/vulcanize/vulcanizedb/vendor", repo, relPath)
|
2019-02-02 22:15:09 +00:00
|
|
|
cleanPath, err := helpers.CleanPath(path)
|
2019-01-31 01:38:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
paths = append(paths, cleanPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
return paths, nil
|
2017-10-19 14:22:12 +00:00
|
|
|
}
|