Skip to content

Commit

Permalink
fix(sqlite): support all sqlite pragma statement
Browse files Browse the repository at this point in the history
fixes #681

- remove the extra underscore in the key
- remove the pragma key check - let's support any pragma
  • Loading branch information
vbehar committed Sep 28, 2024
1 parent a9fb956 commit 9abb71e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 27 additions & 0 deletions temporalcli/commands.server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package temporalcli_test
import (
"context"
"net"
"os"
"path/filepath"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -41,6 +43,31 @@ func TestServer_StartDev_IPv4Unspecified(t *testing.T) {
)
}

func TestServer_StartDev_SQLitePragma(t *testing.T) {
port := strconv.Itoa(devserver.MustGetFreePort("0.0.0.0"))
dbFilename := filepath.Join(os.TempDir(), "devserver-sqlite-pragma.sqlite")
defer func() {
_ = os.Remove(dbFilename)
_ = os.Remove(dbFilename + "-shm")
_ = os.Remove(dbFilename + "-wal")
}()
startDevServerAndRunSimpleTest(
t,
[]string{
"server", "start-dev",
"-p", port, "--headless",
"--db-filename", dbFilename,
"--sqlite-pragma", "journal_mode=WAL",
"--sqlite-pragma", "synchronous=NORMAL",
"--sqlite-pragma", "busy_timeout=5000",
},
"0.0.0.0:"+port,
)
assert.FileExists(t, dbFilename, "sqlite database file not created")
assert.FileExists(t, dbFilename+"-shm", "sqlite shared memory file not created")
assert.FileExists(t, dbFilename+"-wal", "sqlite write-ahead log file not created")
}

func TestServer_StartDev_IPv6Unspecified(t *testing.T) {
_, err := net.InterfaceByName("::1")
if err != nil {
Expand Down
8 changes: 1 addition & 7 deletions temporalcli/devserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,7 @@ func (s *StartOptions) buildSQLConfig() (*config.SQL, error) {
conf.DatabaseName = s.DatabaseFile
}
for k, v := range s.SqlitePragmas {
// Only some pragmas allowed
switch k {
case "journal_mode", "synchronous":
default:
return nil, fmt.Errorf("unrecognized pragma %q, only 'journal_mode' and 'synchronous' allowed", k)
}
conf.ConnectAttributes["_"+k] = v
conf.ConnectAttributes[k] = v
}

// Apply migrations to sqlite if using file but it does not exist
Expand Down

0 comments on commit 9abb71e

Please sign in to comment.