Move account relations into separate table

This commit is contained in:
Melody Becker 2024-11-11 09:04:42 +01:00
parent c9985ba48a
commit 5546d31e5d
6 changed files with 28 additions and 20 deletions

View file

@ -0,0 +1,12 @@
package storage
import (
"gorm.io/gorm"
)
type AccountRelation struct {
gorm.Model
FromId string
ToId string
Accepted bool
}

View file

@ -1,10 +0,0 @@
package storage
import "time"
type FollowRequest struct {
ID uint `gorm:"primarykey"`
CreatedAt time.Time
FromId string
ToId string
}

View file

@ -49,7 +49,7 @@ func NewStorage(dbUrl string, cache *cache.Cache) (*Storage, error) {
AccessToken{},
Emote{},
UserInfoField{},
FollowRequest{},
AccountRelation{},
)
if err != nil {
return nil, fmt.Errorf("failed to apply migrations: %w", err)

View file

@ -25,7 +25,7 @@ type Account struct {
// Username of the user (eg "max" if the full username is @max@example.com)
// Assume unchangable (once set by a user) to be kind to other implementations
// Would be an easy avenue to fuck with them though
Username string
Username string `gorm:"unique"`
CreatedAt time.Time // When this entry was created. Automatically set by gorm
// When this account was last updated. Will also be used for refreshing remote accounts. Automatically set by gorm
UpdatedAt time.Time
@ -40,8 +40,7 @@ type Account struct {
Description string // The description of a user account
Tags []string `gorm:"serializer:json"` // Hashtags
IsBot bool // Whether to mark this account as a script controlled one
Follows []string `gorm:"serializer:json"` // List of account ids this account follows
Followers []string `gorm:"serializer:json"` // List of account ids that follow this account
Relations []uint `gorm:"serializer:json"` // List of ids of all relations this account has. Both follows and followers
Icon string // ID of a media file used as icon
Background *string // ID of a media file used as background image
Banner *string // ID of a media file used as banner
@ -332,9 +331,8 @@ func (s *Storage) NewEmptyAccount() (*Account, error) {
}
acc.WebAuthnId = data
acc.Followers = []string{}
acc.Relations = []uint{}
acc.Tags = []string{}
acc.Follows = []string{}
acc.Gender = []string{}
acc.CustomFields = []uint{}
acc.IdentifiesAs = []Being{}