From b96533ca8f4d155e87e5325b4b192894d7d3e077 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 22 Aug 2022 11:21:36 +0200 Subject: [bugfix] Fix loss of account info on export/import, add tests (#759) * start adding additional tests * use random database address for in-memory sqlite * add more fields to account export --- internal/db/bundb/bundb.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'internal/db') diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go index 191350d06..ca123543a 100644 --- a/internal/db/bundb/bundb.go +++ b/internal/db/bundb/bundb.go @@ -31,6 +31,7 @@ import ( "strings" "time" + "github.com/google/uuid" "github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4/stdlib" "github.com/superseriousbusiness/gotosocial/internal/cache" @@ -229,6 +230,15 @@ func sqliteConn(ctx context.Context) (*DBConn, error) { // Append our own SQLite preferences dbAddress = "file:" + dbAddress + "?cache=shared" + var inMem bool + + if dbAddress == "file::memory:?cache=shared" { + dbAddress = fmt.Sprintf("file:%s?mode=memory&cache=shared", uuid.NewString()) + log.Infof("using in-memory database address " + dbAddress) + log.Warn("sqlite in-memory database should only be used for debugging") + inMem = true + } + // Open new DB instance sqldb, err := sql.Open("sqlite", dbAddress) if err != nil { @@ -240,8 +250,7 @@ func sqliteConn(ctx context.Context) (*DBConn, error) { tweakConnectionValues(sqldb) - if dbAddress == "file::memory:?cache=shared" { - log.Warn("sqlite in-memory database should only be used for debugging") + if inMem { // don't close connections on disconnect -- otherwise // the SQLite database will be deleted when there // are no active connections -- cgit v1.2.3