[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
This commit is contained in:
tobi 2022-08-22 11:21:36 +02:00 committed by GitHub
commit b96533ca8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 10 deletions

View file

@ -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