From 94be8e0c521c22d5f4e3c37f282ade156a0c2add Mon Sep 17 00:00:00 2001 From: Jacob LeGrone Date: Fri, 8 Oct 2021 23:26:37 -0400 Subject: [PATCH] Skip migrations when db file already exists --- server.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 71890819..292452e6 100644 --- a/server.go +++ b/server.go @@ -7,6 +7,7 @@ package temporalite import ( "context" "fmt" + "os" "time" "github.com/DataDog/temporalite/internal/liteconfig" @@ -41,9 +42,15 @@ func NewServer(opts ...ServerOption) (*Server, error) { cfg := liteconfig.Convert(c) sqlConfig := cfg.Persistence.DataStores[liteconfig.PersistenceStoreName].SQL - // Apply migrations - if err := sqlite.SetupSchema(sqlConfig); err != nil { - return nil, fmt.Errorf("error setting up schema: %w", err) + // Apply migrations if file does not already exist + if c.Ephemeral { + if err := sqlite.SetupSchema(sqlConfig); err != nil { + return nil, fmt.Errorf("error setting up schema: %w", err) + } + } else if _, err := os.Stat(c.DatabaseFilePath); os.IsNotExist(err) { + if err := sqlite.SetupSchema(sqlConfig); err != nil { + return nil, fmt.Errorf("error setting up schema: %w", err) + } } // Pre-create namespaces