diff options
author | 2022-08-22 11:21:36 +0200 | |
---|---|---|
committer | 2022-08-22 11:21:36 +0200 | |
commit | b96533ca8f4d155e87e5325b4b192894d7d3e077 (patch) | |
tree | 936fc6fa01dd98a78adc4396e6e289bddf8344bc /internal/db | |
parent | [bugfix] Fix potential dereference of accounts on own instance (#757) (diff) | |
download | gotosocial-b96533ca8f4d155e87e5325b4b192894d7d3e077.tar.xz |
[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
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/bundb/bundb.go | 13 |
1 files changed, 11 insertions, 2 deletions
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 |