mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 09:42:26 -05:00
Pg to bun (#148)
* start moving to bun * changing more stuff * more * and yet more * tests passing * seems stable now * more big changes * small fix * little fixes
This commit is contained in:
parent
071eca20ce
commit
2dc9fc1626
713 changed files with 98694 additions and 22704 deletions
|
|
@ -24,7 +24,7 @@ import (
|
|||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/pg"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
)
|
||||
|
|
@ -68,9 +68,9 @@ func NewTestDB() db.DB {
|
|||
|
||||
l := logrus.New()
|
||||
l.SetLevel(logrus.TraceLevel)
|
||||
testDB, err := pg.NewPostgresService(context.Background(), config, l)
|
||||
testDB, err := bundb.NewBunDBService(context.Background(), config, l)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
logrus.Panic(err)
|
||||
}
|
||||
return testDB
|
||||
}
|
||||
|
|
@ -84,112 +84,124 @@ func NewTestDB() db.DB {
|
|||
// signatures with, otherwise this function will randomly generate new keys for accounts and signature
|
||||
// verification will fail.
|
||||
func StandardDBSetup(db db.DB, accounts map[string]*gtsmodel.Account) {
|
||||
if db == nil {
|
||||
logrus.Panic("db setup: db was nil")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
for _, m := range testModels {
|
||||
if err := db.CreateTable(m); err != nil {
|
||||
panic(err)
|
||||
if err := db.CreateTable(ctx, m); err != nil {
|
||||
logrus.Panicf("error creating table for %+v: %s", m, err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestTokens() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestClients() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestApplications() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestUsers() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if accounts == nil {
|
||||
for _, v := range NewTestAccounts() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, v := range accounts {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestAttachments() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestStatuses() {
|
||||
if err := db.PutStatus(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.PutStatus(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestEmojis() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestTags() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestMentions() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestFaves() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestFollows() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range NewTestNotifications() {
|
||||
if err := db.Put(v); err != nil {
|
||||
panic(err)
|
||||
if err := db.Put(ctx, v); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := db.CreateInstanceAccount(); err != nil {
|
||||
panic(err)
|
||||
if err := db.CreateInstanceAccount(ctx); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
|
||||
if err := db.CreateInstanceInstance(); err != nil {
|
||||
panic(err)
|
||||
if err := db.CreateInstanceInstance(ctx); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
|
||||
logrus.Debug("testing db setup complete")
|
||||
}
|
||||
|
||||
// StandardDBTeardown drops all the standard testing tables/models from the database to ensure it's clean for the next test.
|
||||
func StandardDBTeardown(db db.DB) {
|
||||
ctx := context.Background()
|
||||
if db == nil {
|
||||
logrus.Panic("db teardown: db was nil")
|
||||
}
|
||||
for _, m := range testModels {
|
||||
if err := db.DropTable(m); err != nil {
|
||||
panic(err)
|
||||
if err := db.DropTable(ctx, m); err != nil {
|
||||
logrus.Panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue