MylesBock commented on a change in pull request #5327:
URL: https://github.com/apache/trafficcontrol/pull/5327#discussion_r529786414
##########
File path: traffic_ops/app/db/admin.go
##########
@@ -171,68 +173,73 @@ func parseDBConfig() error {
return nil
}
-func createDB() {
- dbExistsCmd := exec.Command("psql", "-h", HostIP, "-U", DBSuperUser,
"-p", HostPort, "-tAc", "SELECT 1 FROM pg_database WHERE datname='"+DBName+"'")
- out, err := dbExistsCmd.Output()
- if err != nil {
- die("unable to check if DB already exists: " + err.Error())
- }
- if len(out) > 0 {
- fmt.Println("Database " + DBName + " already exists")
- return
- }
- createDBCmd := exec.Command("createdb", "-h", HostIP, "-p", HostPort,
"-U", DBSuperUser, "-e", "--owner", DBUser, DBName)
- out, err = createDBCmd.CombinedOutput()
- fmt.Printf("%s", out)
- if err != nil {
- die("Can't create db " + DBName)
+func connectAndExecute(query string, queryErrPrefix string, returnRows bool)
*sql.Rows {
+ //todo prepared statements
+ //todo inspect results of executing the above query for all possible
cases (db exists, db dne, db inaccessible)
+ //todo determine test coverage of this portion
+ if db, err := dburl.Open(fmt.Sprintf("pg://%s:%s@%s:%s/", DBSuperUser,
DBPassword, HostIP, HostPort)); err == nil {
+ if !returnRows {
+ if _, err := db.Exec(query); err != nil {
Review comment:
If it's preferred I could parse in the DML/DDL files and break them down
into individual queries
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]