-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from joicemjoseph/feat/install
added method to install db schema
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 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,44 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func (app *App) installSchema(prompt bool) int { | ||
if prompt { | ||
fmt.Println("") | ||
fmt.Println("** first time installation **") | ||
fmt.Printf("** IMPORTANT: This will wipe existing dictmaker tables and types in the DB '%s' **", | ||
ko.String("db.db")) | ||
fmt.Println("") | ||
|
||
var ok string | ||
|
||
fmt.Print("continue (y/n)? ") | ||
|
||
if _, err := fmt.Scanf("%s", &ok); err != nil { | ||
app.logger.Fatalf("error reading value from terminal: %v", err) | ||
} | ||
|
||
if strings.ToLower(ok) != "y" { | ||
fmt.Println("install cancelled.") | ||
return 1 | ||
} | ||
} | ||
|
||
q, err := app.fs.Read("/schema.sql") | ||
if err != nil { | ||
app.logger.Fatal(err.Error()) | ||
return 1 | ||
} | ||
|
||
if _, err := app.db.Exec(string(q)); err != nil { | ||
app.logger.Fatal(err.Error()) | ||
return 1 | ||
} | ||
|
||
app.logger.Println("successfully installed schema") | ||
|
||
return 0 | ||
} |
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