fix instance count query using string literal instead of gtsmodel const type

This commit is contained in:
kim 2024-11-21 17:32:14 +00:00
parent d7104dfe57
commit 25a4758557
2 changed files with 24 additions and 4 deletions

View file

@ -104,7 +104,7 @@ func (i *instanceDB) CountInstanceStatuses(ctx context.Context, domain string) (
q = q.Where("NOT ? = ?", bun.Ident("status.pending_approval"), true) q = q.Where("NOT ? = ?", bun.Ident("status.pending_approval"), true)
// Ignore statuses that are direct messages. // Ignore statuses that are direct messages.
q = q.Where("NOT ? = ?", bun.Ident("status.visibility"), "direct") q = q.Where("NOT ? = ?", bun.Ident("status.visibility"), gtsmodel.VisibilityDirect)
count, err := q.Count(ctx) count, err := q.Count(ctx)
if err != nil { if err != nil {

View file

@ -165,15 +165,35 @@ func convertEnums[OldType ~string, NewType ~int](
return err return err
} }
// Update existing values via mapping. // Get a count of all in table.
total, err := tx.NewSelect().
Table(table).
Count(ctx)
if err != nil {
return err
}
var updated int
for old, new := range mapping { for old, new := range mapping {
if _, err := tx.NewUpdate().
// Update old to new values.
res, err := tx.NewUpdate().
Table(table). Table(table).
Where("? = ?", bun.Ident(column), old). Where("? = ?", bun.Ident(column), old).
Set("? = ?", bun.Ident(newColumn), new). Set("? = ?", bun.Ident(newColumn), new).
Exec(ctx); err != nil { Exec(ctx)
if err != nil {
return err return err
} }
// Count number items updated.
n, _ := res.RowsAffected()
updated += int(n)
}
// Check total updated.
if total != updated {
log.Warnf(ctx, "total=%d does not match updated=%d", total, updated)
} }
// Drop the old column from table. // Drop the old column from table.