From 3589b847ab988ffcc699f30a14ea34c60a378c55 Mon Sep 17 00:00:00 2001 From: Daniel Escribano Date: Thu, 17 Oct 2024 18:07:46 +0200 Subject: [PATCH 1/2] 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) { From 790b871497329cb863b7af531f61cd2d722571b9 Mon Sep 17 00:00:00 2001 From: Daniel Escribano Date: Thu, 17 Oct 2024 18:16:43 +0200 Subject: [PATCH 2/2] fix: add missing DATABASE --- schemas.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas.go b/schemas.go index a07539c..bd52a4d 100644 --- a/schemas.go +++ b/schemas.go @@ -240,7 +240,7 @@ func dbCreateStmt(db *sql.DB, dbName string) (string, error) { return "", fmt.Errorf("getting database %s create statement: %v", dbName, err) } - return strings.Replace(createStmt, "CREATE", "CREATE IF NOT EXISTS", 1), 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) {