Skip to content

Commit

Permalink
chore: add ; and create if not exists to database statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Daesgar committed Oct 17, 2024
1 parent 6c94be7 commit 3589b84
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"fmt"
"os"
"strings"

log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -132,7 +133,7 @@ func Write(opts *Options) error {
if err != nil {
return err
}
_, err = fd.Write([]byte(dbCreateStmt + "\n\n"))
_, err = fd.Write([]byte(dbCreateStmt + ";\n\n"))
if err != nil {
return fmt.Errorf("writing database '%s' create statement: %v", dbName, err)
}
Expand Down Expand Up @@ -239,7 +240,7 @@ func dbCreateStmt(db *sql.DB, dbName string) (string, error) {
return "", fmt.Errorf("getting database %s create statement: %v", dbName, err)
}

return createStmt, nil
return strings.Replace(createStmt, "CREATE", "CREATE IF NOT EXISTS", 1), nil
}

func fetchTableCreateStmt(db *sql.DB, dbName string, tableName string) (string, error) {
Expand Down

0 comments on commit 3589b84

Please sign in to comment.