From 3589b847ab988ffcc699f30a14ea34c60a378c55 Mon Sep 17 00:00:00 2001 From: Daniel Escribano Date: Thu, 17 Oct 2024 18:07:46 +0200 Subject: [PATCH] chore: add ; and create if not exists to database statement --- schemas.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/schemas.go b/schemas.go index 6a8e948..a07539c 100644 --- a/schemas.go +++ b/schemas.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" "os" + "strings" log "github.com/sirupsen/logrus" ) @@ -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) } @@ -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) {