From b52c6876437c871954b8a3489a7379bd214f1663 Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 31 Mar 2023 17:27:54 +0200 Subject: [PATCH] feat(sqlite): add default pragmas to dsn --- internal/agent/controller/app/app_handler.go | 4 +++- internal/config/database.go | 2 +- misc/packaging/common/config-server.yml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/agent/controller/app/app_handler.go b/internal/agent/controller/app/app_handler.go index a647041..971337c 100644 --- a/internal/agent/controller/app/app_handler.go +++ b/internal/agent/controller/app/app_handler.go @@ -28,6 +28,8 @@ import ( "github.com/pkg/errors" ) +const defaultSQLiteParams = "?_pragma=foreign_keys(1)&_pragma=journal_mode(WAL)&_txlock=immediate" + func (c *Controller) getHandlerOptions(ctx context.Context, appKey string, specs *spec.Spec) ([]edgeHTTP.HandlerOptionFunc, error) { dataDir, err := c.ensureAppDataDir(ctx, appKey) if err != nil { @@ -35,7 +37,7 @@ func (c *Controller) getHandlerOptions(ctx context.Context, appKey string, specs } dbFile := filepath.Join(dataDir, appKey+".sqlite") - db, err := sqlite.Open(dbFile) + db, err := sqlite.Open(dbFile + defaultSQLiteParams) if err != nil { return nil, errors.Wrapf(err, "could not open database file '%s'", dbFile) } diff --git a/internal/config/database.go b/internal/config/database.go index 189c129..566c83a 100644 --- a/internal/config/database.go +++ b/internal/config/database.go @@ -15,6 +15,6 @@ type DatabaseConfig struct { func NewDefaultDatabaseConfig() DatabaseConfig { return DatabaseConfig{ Driver: "sqlite", - DSN: "sqlite://emissary.sqlite?_fk=true&_journal=WAL", + DSN: "sqlite://emissary.sqlite?_pragma=foreign_keys(1)&_pragma=journal_mode(WAL)&_txlock=immediate", } } diff --git a/misc/packaging/common/config-server.yml b/misc/packaging/common/config-server.yml index 8f150eb..d4b7ae7 100644 --- a/misc/packaging/common/config-server.yml +++ b/misc/packaging/common/config-server.yml @@ -9,7 +9,7 @@ server: port: 3000 database: driver: sqlite - dsn: sqlite:///var/lib/emissary/data.sqlite?_fk=true&_journal=WAL + dsn: sqlite:///var/lib/emissary/data.sqlite?_pragma=foreign_keys(1)&_pragma=journal_mode(WAL)&_txlock=immediate cors: allowedOrigins: [] allowCredentials: true