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

Commit

Permalink
Check if the db file path dir exists before setting up schema (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
theverything committed Aug 4, 2022
1 parent 95f1070 commit 41343b6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -55,6 +56,12 @@ func NewServer(opts ...ServerOption) (*Server, error) {
if !c.Ephemeral {
// Apply migrations if file does not already exist
if _, err := os.Stat(c.DatabaseFilePath); os.IsNotExist(err) {
// Check if any of the parent dirs are missing
dir := filepath.Dir(c.DatabaseFilePath)
if _, err := os.Stat(dir); err != nil {
return nil, fmt.Errorf("error setting up schema: %w", err)
}

if err := sqlite.SetupSchema(sqlConfig); err != nil {
return nil, fmt.Errorf("error setting up schema: %w", err)
}
Expand Down

0 comments on commit 41343b6

Please sign in to comment.