Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Skip migrations when db file already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jlegrone committed Oct 9, 2021
1 parent b2bcb51 commit 94be8e0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package temporalite
import (
"context"
"fmt"
"os"
"time"

"github.com/DataDog/temporalite/internal/liteconfig"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 94be8e0

Please sign in to comment.