Skip to content

Commit

Permalink
Merge pull request #13 from PostHog/if-not-exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Daesgar authored Oct 17, 2024
2 parents 6c94be7 + 790b871 commit ebdb9e9
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 DATABASE", "CREATE DATABASE IF NOT EXISTS", 1), nil
}

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

0 comments on commit ebdb9e9

Please sign in to comment.