Skip to content

Commit 54f8cd5

Browse files
author
Youen Péron
authored
* feat(sequence): add new verb to manage sequence (#52)
* feat(table) sequence * feat(sequence) new sequence verb * refactor(table): rollback to main version * feat(sequence): add oracle support * chore(neon): speed integration test focus on dev * fix(sequence): unecessary use of fmt * doc(changelog): create version v1.9.0
1 parent 3279eaa commit 54f8cd5

File tree

18 files changed

+1011
-4
lines changed

18 files changed

+1011
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Types of changes
1414
- `Fixed` for any bug fixes.
1515
- `Security` in case of vulnerabilities.
1616

17+
## [1.9.0]
18+
19+
- `Added` new verb to extract, to get status and to update sequences
20+
1721
## [1.8.0]
1822

1923
- `Added` new parameter to pull only distinct values from the start table

build.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ properties:
4040
ldflags: "" # Specify a additional ldflags with `-props "{ldflags: '<flags>'}"`
4141
tags: [] # Specify additional tags with `-props "{tags: ['tag']}"`
4242
buildpaths: [] # By default, all paths under the cmd/ folder are built, specify a different folder list with `-props "{buildpaths: ["other/path", "to/build"]}"`
43-
43+
testmod: "table" # Test only one module
4444
# List of linters to run on the lint target, if left empty : run all linters
4545
linters: [
4646
# TODO: review these linters, and consider using more
@@ -273,6 +273,19 @@ targets:
273273
todir: =TEST_WS_DIR
274274
- $: export COMPOSE_PROJECT_NAME=lino; venom run --stop-on-failure ={TEST_WS_DIR}/*/*.yml
275275

276+
# run "neon -props '{testmod: table}' test-int-dev
277+
test-int-dev:
278+
doc: "Run all integration tests"
279+
# depends: ["info", "refresh", "lint", "test"]
280+
depends: ["compile"]
281+
steps:
282+
- delete: ={TEST_WS_DIR}/**
283+
- mkdir: ={TEST_WS_DIR}/={testmod}/
284+
- copy: "*.yml"
285+
dir: "tests/suites/={testmod}/"
286+
todir: ={TEST_WS_DIR}/={testmod}
287+
- $: export COMPOSE_PROJECT_NAME=lino; venom run ={TEST_WS_DIR}/={testmod}/*.yml
288+
276289
# run "neon -props '{buildpaths: ["path/to/main/package1","path/to/main/package2"]}' publish" to publish specific targets
277290
# example : neon -props '{buildpaths: ["cmd/cli"]}' publish
278291
publish:

cmd/lino/dep_sequence.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (C) 2021 CGI France
2+
//
3+
// This file is part of LINO.
4+
//
5+
// LINO is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// LINO is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with LINO. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package main
19+
20+
import (
21+
infra "github.com/cgi-fr/lino/internal/infra/sequence"
22+
domain "github.com/cgi-fr/lino/pkg/sequence"
23+
)
24+
25+
func sequenceStorage() domain.Storage {
26+
return infra.NewYAMLStorage()
27+
}
28+
29+
func sequenceUpdatorFactory() map[string]domain.UpdatorFactory {
30+
return map[string]domain.UpdatorFactory{
31+
"postgres": infra.NewPostgresUpdatorFactory(),
32+
"godror": infra.NewOracleUpdatorFactory(),
33+
"godror-raw": infra.NewOracleUpdatorFactory(),
34+
// "db2": infra.NewDb2UpdatorFactory(),
35+
// "http": infra.NewHTTPUpdatorFactory(),
36+
}
37+
}

cmd/lino/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/cgi-fr/lino/internal/app/pull"
3131
"github.com/cgi-fr/lino/internal/app/push"
3232
"github.com/cgi-fr/lino/internal/app/relation"
33+
"github.com/cgi-fr/lino/internal/app/sequence"
3334
"github.com/cgi-fr/lino/internal/app/table"
3435
"github.com/mattn/go-isatty"
3536
"github.com/rs/zerolog"
@@ -113,6 +114,7 @@ func init() {
113114
rootCmd.PersistentFlags().StringVar(&colormode, "color", "auto", "use colors in log outputs : yes, no or auto")
114115
rootCmd.AddCommand(dataconnector.NewCommand("lino", os.Stderr, os.Stdout, os.Stdin))
115116
rootCmd.AddCommand(table.NewCommand("lino", os.Stderr, os.Stdout, os.Stdin))
117+
rootCmd.AddCommand(sequence.NewCommand("lino", os.Stderr, os.Stdout, os.Stdin))
116118
rootCmd.AddCommand(relation.NewCommand("lino", os.Stderr, os.Stdout, os.Stdin))
117119
rootCmd.AddCommand(id.NewCommand("lino", os.Stderr, os.Stdout, os.Stdin))
118120
rootCmd.AddCommand(pull.NewCommand("lino", os.Stderr, os.Stdout, os.Stdin))
@@ -165,6 +167,7 @@ func initConfig() {
165167
dataconnector.Inject(dataconnectorStorage(), dataPingerFactory())
166168
relation.Inject(dataconnectorStorage(), relationStorage(), relationExtractorFactory())
167169
table.Inject(dataconnectorStorage(), tableStorage(), tableExtractorFactory())
170+
sequence.Inject(dataconnectorStorage(), tableStorage(), sequenceStorage(), sequenceUpdatorFactory())
168171
id.Inject(idStorageFile, relationStorage(), idExporter(), idJSONStorage(*os.Stdout))
169172
pull.Inject(dataconnectorStorage(), relationStorage(), tableStorage(), idStorageFactory(), pullDataSourceFactory(), pullRowExporterFactory(), pullRowReaderFactory(), traceListner(os.Stderr))
170173
push.Inject(dataconnectorStorage(), relationStorage(), tableStorage(), idStorageFactory(), pushDataDestinationFactory(), pushRowIteratorFactory(), pushRowExporterFactory())

internal/app/sequence/cli.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (C) 2021 CGI France
2+
//
3+
// This file is part of LINO.
4+
//
5+
// LINO is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// LINO is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with LINO. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package sequence
19+
20+
import (
21+
"fmt"
22+
"os"
23+
24+
"github.com/cgi-fr/lino/pkg/dataconnector"
25+
"github.com/cgi-fr/lino/pkg/sequence"
26+
"github.com/cgi-fr/lino/pkg/table"
27+
"github.com/spf13/cobra"
28+
)
29+
30+
var (
31+
dataconnectorStorage dataconnector.Storage
32+
tableStorage table.Storage
33+
sequenceStorage sequence.Storage
34+
sequenceUpdatorFactories map[string]sequence.UpdatorFactory
35+
)
36+
37+
// Inject dependencies
38+
func Inject(dbas dataconnector.Storage, rs table.Storage, ss sequence.Storage, exmap map[string]sequence.UpdatorFactory) {
39+
dataconnectorStorage = dbas
40+
tableStorage = rs
41+
sequenceStorage = ss
42+
sequenceUpdatorFactories = exmap
43+
}
44+
45+
// NewCommand implements the cli dataconnector command
46+
func NewCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra.Command {
47+
cmd := &cobra.Command{
48+
Use: "sequence {extract|status|update} [arguments ...]",
49+
Short: "Manage sequences",
50+
Long: "",
51+
Example: fmt.Sprintf(" %[1]s sequence extract mydatabase", fullName),
52+
Aliases: []string{"seq"},
53+
}
54+
cmd.AddCommand(newExtractCommand(fullName, err, out, in))
55+
cmd.AddCommand(newStatusCommand(fullName, err, out, in))
56+
cmd.AddCommand(newUpdateCommand(fullName, err, out, in))
57+
cmd.SetOut(out)
58+
cmd.SetErr(err)
59+
cmd.SetIn(in)
60+
return cmd
61+
}

internal/app/sequence/extract.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (C) 2021 CGI France
2+
//
3+
// This file is part of LINO.
4+
//
5+
// LINO is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// LINO is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with LINO. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package sequence
19+
20+
import (
21+
"fmt"
22+
"os"
23+
24+
"github.com/cgi-fr/lino/internal/app/urlbuilder"
25+
"github.com/cgi-fr/lino/pkg/dataconnector"
26+
"github.com/cgi-fr/lino/pkg/sequence"
27+
"github.com/spf13/cobra"
28+
)
29+
30+
// newExtractCommand implements the cli relation extract command
31+
func newExtractCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra.Command {
32+
cmd := &cobra.Command{
33+
Use: "extract [DB Alias Name]",
34+
Short: "Extract sequence name from database",
35+
Long: "",
36+
Example: fmt.Sprintf(" %[1]s sequence extract mydatabase", fullName),
37+
Args: cobra.ExactArgs(1),
38+
Run: func(cmd *cobra.Command, args []string) {
39+
alias, e1 := dataconnector.Get(dataconnectorStorage, args[0])
40+
if e1 != nil {
41+
fmt.Fprintln(err, e1.Description)
42+
os.Exit(1)
43+
}
44+
45+
if alias == nil {
46+
fmt.Fprintln(err, "no dataconnector named "+args[0])
47+
os.Exit(1)
48+
}
49+
50+
u := urlbuilder.BuildURL(alias, err)
51+
52+
factory, ok := sequenceUpdatorFactories[u.Unaliased]
53+
if !ok {
54+
fmt.Fprintln(err, "no extractor found for database type")
55+
os.Exit(1)
56+
}
57+
58+
extractor := factory.New(u.URL.String(), alias.Schema)
59+
60+
tableTables, e2 := tableStorage.List()
61+
if e2 != nil {
62+
fmt.Fprintln(err, e2.Description)
63+
os.Exit(1)
64+
}
65+
66+
tables := []sequence.Table{}
67+
for _, tbl := range tableTables {
68+
tables = append(tables, sequence.Table{Name: tbl.Name, Keys: tbl.Keys})
69+
}
70+
71+
e3 := sequence.Extract(extractor, tables, sequenceStorage)
72+
if e3 != nil {
73+
fmt.Fprintln(err, e2.Description)
74+
os.Exit(1)
75+
}
76+
},
77+
}
78+
cmd.SetOut(out)
79+
cmd.SetErr(err)
80+
cmd.SetIn(in)
81+
return cmd
82+
}

internal/app/sequence/status.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (C) 2021 CGI France
2+
//
3+
// This file is part of LINO.
4+
//
5+
// LINO is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// LINO is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with LINO. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package sequence
19+
20+
import (
21+
"fmt"
22+
"os"
23+
24+
"github.com/cgi-fr/lino/internal/app/urlbuilder"
25+
"github.com/cgi-fr/lino/pkg/dataconnector"
26+
"github.com/cgi-fr/lino/pkg/sequence"
27+
"github.com/spf13/cobra"
28+
)
29+
30+
// newStatus implements the cli sequence status command
31+
func newStatusCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra.Command {
32+
cmd := &cobra.Command{
33+
Use: "status [DB Alias Name]",
34+
Short: "status Get sequence status from database",
35+
Long: "",
36+
Example: fmt.Sprintf(" %[1]s sequence status mydatabase", fullName),
37+
Args: cobra.ExactArgs(1),
38+
Run: func(cmd *cobra.Command, args []string) {
39+
alias, e1 := dataconnector.Get(dataconnectorStorage, args[0])
40+
if e1 != nil {
41+
fmt.Fprintln(err, e1.Description)
42+
os.Exit(1)
43+
}
44+
45+
if alias == nil {
46+
fmt.Fprintln(err, "no dataconnector named "+args[0])
47+
os.Exit(1)
48+
}
49+
50+
u := urlbuilder.BuildURL(alias, err)
51+
52+
factory, ok := sequenceUpdatorFactories[u.Unaliased]
53+
if !ok {
54+
fmt.Fprintln(err, "no extractor found for database type")
55+
os.Exit(1)
56+
}
57+
58+
extractor := factory.New(u.URL.String(), alias.Schema)
59+
60+
sequences, e3 := sequence.Status(sequenceStorage, extractor)
61+
if e3 != nil {
62+
fmt.Fprintln(err, e3.Description)
63+
os.Exit(1)
64+
}
65+
for _, seq := range sequences {
66+
fmt.Fprintln(out, seq.Name, seq.Value)
67+
}
68+
},
69+
}
70+
cmd.SetOut(out)
71+
cmd.SetErr(err)
72+
cmd.SetIn(in)
73+
return cmd
74+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (C) 2021 CGI France
2+
//
3+
// This file is part of LINO.
4+
//
5+
// LINO is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// LINO is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with LINO. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package sequence
19+
20+
import (
21+
"fmt"
22+
"os"
23+
24+
"github.com/cgi-fr/lino/internal/app/urlbuilder"
25+
"github.com/cgi-fr/lino/pkg/dataconnector"
26+
"github.com/cgi-fr/lino/pkg/sequence"
27+
"github.com/spf13/cobra"
28+
)
29+
30+
// newUpdateCommand implements the cli sequence update
31+
func newUpdateCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra.Command {
32+
cmd := &cobra.Command{
33+
Use: "update [DB Alias Name]",
34+
Short: "",
35+
Long: "",
36+
Example: fmt.Sprintf(" %[1]s sequence update mydatabase", fullName),
37+
Args: cobra.ExactArgs(1),
38+
Run: func(cmd *cobra.Command, args []string) {
39+
alias, e1 := dataconnector.Get(dataconnectorStorage, args[0])
40+
if e1 != nil {
41+
fmt.Fprintln(err, e1.Description)
42+
os.Exit(1)
43+
}
44+
45+
if alias == nil {
46+
fmt.Fprintln(err, "no dataconnector named "+args[0])
47+
os.Exit(1)
48+
}
49+
50+
u := urlbuilder.BuildURL(alias, err)
51+
52+
factory, ok := sequenceUpdatorFactories[u.Unaliased]
53+
if !ok {
54+
fmt.Fprintln(err, "no extractor found for database type")
55+
os.Exit(1)
56+
}
57+
58+
updater := factory.New(u.URL.String(), alias.Schema)
59+
60+
e2 := sequence.Update(sequenceStorage, updater)
61+
if e2 != nil {
62+
fmt.Fprintln(err, e2.Description)
63+
os.Exit(1)
64+
}
65+
},
66+
}
67+
cmd.SetOut(out)
68+
cmd.SetErr(err)
69+
cmd.SetIn(in)
70+
return cmd
71+
}

0 commit comments

Comments
 (0)