diff options
author | 2021-08-26 17:22:41 +0200 | |
---|---|---|
committer | 2021-08-26 17:22:41 +0200 | |
commit | 14ebc94fd97dcbe19f524e6da3cd1f0340e87ec9 (patch) | |
tree | 975dc895e05c70b75c2b1519a6ea56f94a5baf9f /internal/db/bundb/admin.go | |
parent | update drone yml (#153) (diff) | |
download | gotosocial-14ebc94fd97dcbe19f524e6da3cd1f0340e87ec9.tar.xz |
fix error with instance not created on startup (#156)
Diffstat (limited to 'internal/db/bundb/admin.go')
-rw-r--r-- | internal/db/bundb/admin.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/internal/db/bundb/admin.go b/internal/db/bundb/admin.go index 09f2d3bff..53b6ae0c2 100644 --- a/internal/db/bundb/admin.go +++ b/internal/db/bundb/admin.go @@ -235,17 +235,17 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { domain := a.config.Host // check if instance entry already exists - existsQ := a.conn. + q := a.conn. NewSelect(). Model(>smodel.Instance{}). Where("domain = ?", domain) - count, err := existsQ.Count(ctx) - if err != nil && count == 1 { - a.log.Infof("instance instance %s already exists", domain) - return nil - } else if err != sql.ErrNoRows { - return processErrorResponse(err) + exists, err := exists(ctx, q) + if err != nil { + return err + } + if exists { + a.log.Infof("instance entry already exists") } iID, err := id.NewRandomULID() @@ -264,9 +264,11 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { NewInsert(). Model(i) - if _, err := insertQ.Exec(ctx); err != nil { - return err + _, err = insertQ.Exec(ctx) + err = processErrorResponse(err) + + if err == nil { + a.log.Infof("created instance instance %s with id %s", domain, i.ID) } - a.log.Infof("created instance instance %s with id %s", domain, i.ID) - return nil + return err } |