-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,094 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.15 | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build | ||
run: go build -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
lint: | ||
golangci-lint run | ||
|
||
test: | ||
go test ./... -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,6 @@ It uses the underlying introspection API from your RDMS to retrieve automaticall | |
|
||
## Usage | ||
|
||
Tunnel backup database: | ||
|
||
```console | ||
ssh -L 5432:localhost:5433 [email protected] | ||
``` | ||
|
||
Export configuration to a environment variable: | ||
|
||
```console | ||
|
@@ -27,11 +21,11 @@ mkdir -p output | |
Extract data from backup database: | ||
|
||
```console | ||
run main.go -dsn "postgresql://ulule:ulule@localhost:5433/ulule" -path output -action load | ||
go run cmd/mover/main.go -dsn "postgresql://user:password@localhost:5433/dbname" -path output -action extract -query "SELECT * FROM user WHERE id = 1" -table "user" | ||
``` | ||
|
||
Load data to your local database: | ||
|
||
```console | ||
go run main.go -dsn "postgresql://ulule:ulule@localhost/ulule" -path output -action load | ||
go run cmd/mover/main.go -dsn "postgresql://user:password@localhost:5433/dbname" -path output -action load | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/ulule/mover/config" | ||
"github.com/ulule/mover/etl" | ||
) | ||
|
||
var ( | ||
tableName string | ||
query string | ||
path string | ||
dsn string | ||
verbose bool | ||
action string | ||
) | ||
|
||
func main() { | ||
flag.StringVar(&query, "query", "", "query to execute") | ||
flag.StringVar(&tableName, "table", "", "table name to export") | ||
flag.StringVar(&path, "path", "", "directory output") | ||
flag.StringVar(&dsn, "dsn", "", "database dsn") | ||
flag.StringVar(&action, "action", "", "action to execute") | ||
flag.BoolVar(&verbose, "verbose", false, "verbose logs") | ||
flag.Parse() | ||
|
||
var ( | ||
ctx = context.Background() | ||
logger *zap.Logger | ||
) | ||
if verbose { | ||
logger, _ = zap.NewDevelopment() | ||
} else { | ||
logger, _ = zap.NewProduction() | ||
|
||
} | ||
// nolint:errcheck | ||
defer logger.Sync() | ||
|
||
var cfg config.Config | ||
if conf := os.Getenv("MOVER_CONF"); conf != "" { | ||
if err := config.Load(conf, &cfg); err != nil { | ||
logger.Error("unable to config", zap.Error(err), zap.String("config_path", conf)) | ||
} | ||
} | ||
|
||
engine, err := etl.NewEngine(ctx, cfg, dsn, logger) | ||
if err != nil { | ||
logger.Error("unable to initialize engine", zap.Error(err)) | ||
return | ||
} | ||
defer func() { | ||
if err := engine.Shutdown(ctx); err != nil { | ||
logger.Error("unable to shutdown engine", zap.Error(err)) | ||
} | ||
}() | ||
|
||
switch action { | ||
case "extract": | ||
if err := engine.Extract(ctx, path, tableName, query); err != nil { | ||
logger.Error("unable to extract data", | ||
zap.Error(err), | ||
zap.String("table_name", tableName), | ||
zap.String("query", query)) | ||
} | ||
case "load": | ||
if err := engine.Load(ctx, path); err != nil { | ||
logger.Error("unable to load data", | ||
zap.Error(err), | ||
zap.String("path", path)) | ||
} | ||
case "describe": | ||
table, err := engine.Describe(ctx, tableName) | ||
if err != nil { | ||
logger.Error("unable to describe table", | ||
zap.Error(err), | ||
zap.String("table_name", tableName)) | ||
} | ||
|
||
fmt.Printf("%v+\n", table) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
|
||
"github.com/ulule/mover/dialect" | ||
) | ||
|
||
type Query struct { | ||
TableName string `json:"table_name"` | ||
Query string `json:"query"` | ||
Table dialect.Table `json:"-"` | ||
} | ||
|
||
type DownloadHTTP struct { | ||
BaseURL string `json:"base_url"` | ||
} | ||
|
||
func (d DownloadHTTP) URL(path string) string { | ||
return d.BaseURL + path | ||
} | ||
|
||
type Download struct { | ||
Type string `json:"type"` | ||
HTTP DownloadHTTP `json:"http"` | ||
} | ||
|
||
type Column struct { | ||
Name string `json:"name"` | ||
Fake string `json:"fake"` | ||
Unique bool `json:"unique"` | ||
Replace *string `json:"replace"` | ||
Sanitize bool `json:"sanitize"` | ||
Download *Download `json:"download"` | ||
} | ||
|
||
type Schema struct { | ||
TableName string `json:"table_name"` | ||
ReferenceKeys []string `json:"reference_keys"` | ||
Queries []Query `json:"queries"` | ||
Columns []Column `json:"columns"` | ||
Table dialect.Table `json:"-"` | ||
} | ||
|
||
type Config struct { | ||
Locale string `json:"locale"` | ||
Schema []Schema `json:"schema"` | ||
Extra []Schema `json:"extra"` | ||
} | ||
|
||
// Load loads the configuration from configuration file path. | ||
func Load(path string, out interface{}) error { | ||
var err error | ||
|
||
f, err := os.Open(path) | ||
if f != nil { | ||
defer func() { | ||
ferr := f.Close() | ||
if ferr != nil { | ||
log.Println(ferr) | ||
} | ||
}() | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
dec := json.NewDecoder(f) | ||
err = dec.Decode(out) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.