Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlite): support all sqlite pragma statement #682

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines -330 to +324
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I suspect we just didn't have test cases. Would you be willing to add a test (or adjust an existing one) that just adds any innocuous pragma just to ensure it works?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll add one

}

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