Skip to content

Commit 585ff30

Browse files
authored
Merge pull request #35 from dev-cloverlab/drop-table-only-for-if-json-file-exist
Drop table only for if JSON file exist (as default)
2 parents 37f9796 + 80e4ea0 commit 585ff30

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## 0.6.0 (2018-07-05)
2+
3+
### Added
4+
5+
- drop table only for if JSON file exist (as a default)
6+
7+
### Deprecated
8+
9+
- Nothing
10+
11+
### Removed
12+
13+
- Nothing
14+
15+
### Fixed
16+
17+
- Nothing
18+
19+
120
## 0.5.4 (2018-02-15)
221

322
### Added

builder/builder.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/dev-cloverlab/carpenter/dialect/mysql"
99
)
1010

11-
func Build(db *sql.DB, old, new *mysql.Table) (queries []string, err error) {
11+
func Build(db *sql.DB, old, new *mysql.Table, withDrop bool) (queries []string, err error) {
1212
if old == nil && new == nil {
1313
return queries, fmt.Errorf("err: Both pointer of the specified new and old is nil.")
1414
}
@@ -21,8 +21,10 @@ func Build(db *sql.DB, old, new *mysql.Table) (queries []string, err error) {
2121
if q := willCreate(old, new); len(q) > 0 {
2222
queries = append(queries, q)
2323
}
24-
if q := willDrop(old, new); len(q) > 0 {
25-
queries = append(queries, q)
24+
if withDrop {
25+
if q := willDrop(old, new); len(q) > 0 {
26+
queries = append(queries, q)
27+
}
2628
}
2729
if q := willAlterTableCharacterSet(old, new); len(q) > 0 {
2830
queries = append(queries, q)

cmd/carpenter/command/build.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import (
1515
func CmdBuild(c *cli.Context) {
1616
// Write your code here
1717
dirPath := c.String("dir")
18-
queries, errs := makeBuildQueries(dirPath)
18+
withDrop := c.Bool("with-drop")
19+
queries, errs := makeBuildQueries(dirPath, withDrop)
1920
if len(errs) > 0 {
2021
panic(fmt.Errorf("err: makeQueries failed for reason\n%s", strings.Join(getErrorMessages(errs), "\n")))
2122
}
@@ -24,7 +25,7 @@ func CmdBuild(c *cli.Context) {
2425
}
2526
}
2627

27-
func makeBuildQueries(path string) (queries []string, errs []error) {
28+
func makeBuildQueries(path string, withDrop bool) (queries []string, errs []error) {
2829
files, err := walk(path, ".json")
2930
if err != nil {
3031
return nil, []error{err}
@@ -73,7 +74,7 @@ func makeBuildQueries(path string) (queries []string, errs []error) {
7374
wg.Add(1)
7475
go func(o, n *mysql.Table) {
7576
defer wg.Done()
76-
queries, err := builder.Build(db, o, n)
77+
queries, err := builder.Build(db, o, n, withDrop)
7778
if err != nil {
7879
errCh <- err
7980
return

cmd/carpenter/commands.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ var Commands = []cli.Command{
7878
Usage: "path to JSON file directory (required)",
7979
Hidden: false,
8080
},
81+
cli.BoolFlag{
82+
Name: "with-drop",
83+
Usage: "drop table when if JSON file does not exist",
84+
Hidden: false,
85+
},
8186
},
8287
},
8388
{

cmd/carpenter/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package main
22

33
const Name string = "carpenter"
4-
const Version string = "0.5.4"
4+
const Version string = "0.6.0"

0 commit comments

Comments
 (0)