Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
- docker install postgres in same line as mysql
- fixed README
- add default empty string sql type mapping to mysql
- moved sql type check to main and make it only check selected db configs
  • Loading branch information
jackyzhen committed Oct 23, 2018
1 parent 7eab526 commit 757000a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM golang:1.11

RUN apt-get update && apt-get install -y --no-install-recommends mysql-client && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y postgresql-client
RUN apt-get update && apt-get install -y --no-install-recommends mysql-client postgresql-client && rm -rf /var/lib/apt/lists/*

ENTRYPOINT [ "go", "test", "-v", "." ]
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ sql all "SELECT * FROM users WHERE name = 'John'"

## Dependencies

- mysql
- psql
- mysql-client and/or postgresql-client
- ssh (only if you configure an "appServer")

## Contribute
Expand Down
13 changes: 0 additions & 13 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type database struct {
User string
Pass string
SQLType string
_sqlType sqlType
}

func mustReadDatabasesConfigFile() map[string]database {
Expand Down Expand Up @@ -68,17 +67,5 @@ func mustReadDatabasesConfigFile() map[string]database {
usage("Couldn't find any database configurations on .databases.json. Looked like this:\n\n%v\n", string(byts))
}

for dbName, db := range databases {
typeStr := db.SQLType
if typeStr == "" {
typeStr = "mysql"
}
if _, ok := validSQLTypes[typeStr]; !ok {
usage("Unknown sql type %v for %v", typeStr, dbName)
}
db._sqlType = validSQLTypes[typeStr]
databases[dbName] = db
}

return databases
}
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ func _main(databases map[string]database, databasesArgs []string, query string,
sqlTypes := map[sqlType]exists{}
var sqlType sqlType
for _, db := range targetDatabases {
sqlType = databases[db]._sqlType
database := databases[db]
typ, ok := validSQLTypes[database.SQLType]
if !ok {
usage("Unknown sql type %v for %v", database.SQLType, db)
}
sqlType = typ
sqlTypes[sqlType] = exists{}
if len(sqlTypes) > 1 {
usage("More than one sql types specified in target databases.")
Expand Down
12 changes: 6 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func Test_MySQL(t *testing.T) {

var (
testConfig = map[string]database{
"db1": database{DbServer: "test-mysql", DbName: "db1", User: "root", Pass: "", _sqlType: mySQL},
"db2": database{DbServer: "test-mysql", DbName: "db2", User: "root", Pass: "", _sqlType: mySQL},
"db3": database{DbServer: "test-mysql", DbName: "db3", User: "root", Pass: "", _sqlType: mySQL},
"db1": database{DbServer: "test-mysql", DbName: "db1", User: "root", Pass: "", SQLType: "mysql"},
"db2": database{DbServer: "test-mysql", DbName: "db2", User: "root", Pass: "", SQLType: ""},
"db3": database{DbServer: "test-mysql", DbName: "db3", User: "root", Pass: "", SQLType: ""},
}
ts = []struct {
name string
Expand Down Expand Up @@ -129,9 +129,9 @@ func Test_PostgreSQL(t *testing.T) {

var (
testConfig = map[string]database{
"db1": database{DbServer: "test-postgres", DbName: "db1", User: "root", Pass: "", _sqlType: postgreSQL},
"db2": database{DbServer: "test-postgres", DbName: "db2", User: "root", Pass: "", _sqlType: postgreSQL},
"db3": database{DbServer: "test-postgres", DbName: "db3", User: "root", Pass: "", _sqlType: postgreSQL},
"db1": database{DbServer: "test-postgres", DbName: "db1", User: "root", Pass: "", SQLType: "postgres"},
"db2": database{DbServer: "test-postgres", DbName: "db2", User: "root", Pass: "", SQLType: "postgres"},
"db3": database{DbServer: "test-postgres", DbName: "db3", User: "root", Pass: "", SQLType: "postgres"},
}
ts = []struct {
name string
Expand Down
1 change: 1 addition & 0 deletions sql_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type sqlOptions struct {
}

var validSQLTypes = map[string]sqlType{
"": mySQL,
"mysql": mySQL,
"postgres": postgreSQL,
}
Expand Down

0 comments on commit 757000a

Please # to comment.