Skip to content

Commit

Permalink
added method to install db schema
Browse files Browse the repository at this point in the history
  • Loading branch information
joicemjoseph committed Sep 30, 2020
1 parent 3314385 commit b895e5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

func (app *App) installSchema() int {
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
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func main() {
logger: logger,
}

// Install schema.
if ko.Bool("install") {
os.Exit(app.installSchema())
}

// Load SQL queries.
qB, err := fs.Read("/queries.sql")
if err != nil {
Expand Down

0 comments on commit b895e5d

Please sign in to comment.