Move account relations into separate table
This commit is contained in:
parent
c9985ba48a
commit
5546d31e5d
6 changed files with 28 additions and 20 deletions
|
@ -68,8 +68,7 @@ func convertAccountStorageToLinstrom(
|
|||
BannerId: acc.Banner,
|
||||
Background: apiBackground,
|
||||
BackgroundId: acc.Background,
|
||||
FollowerIds: acc.Followers,
|
||||
FollowingIds: acc.Follows,
|
||||
RelationIds: acc.Relations,
|
||||
Indexable: acc.Indexable,
|
||||
RestrictedFollow: acc.RestrictedFollow,
|
||||
IdentifiesAs: sliceutils.Map(
|
||||
|
|
|
@ -7,6 +7,7 @@ import "time"
|
|||
var (
|
||||
_ = linstromNote{}
|
||||
_ = linstromRole{}
|
||||
_ = linstromRelation{}
|
||||
)
|
||||
|
||||
type linstromNote struct {
|
||||
|
@ -71,8 +72,7 @@ type linstromAccount struct {
|
|||
BannerId *string `jsonapi:"attr,banner-id"`
|
||||
Background *linstromMediaMetadata `jsonapi:"relation,background"`
|
||||
BackgroundId *string `jsonapi:"attr,background-id"`
|
||||
FollowerIds []string `jsonapi:"attr,follows-ids"`
|
||||
FollowingIds []string `jsonapi:"attr,following-ids"`
|
||||
RelationIds []uint `jsonapi:"attr,follows-ids"`
|
||||
Indexable bool `jsonapi:"attr,indexable"`
|
||||
RestrictedFollow bool `jsonapi:"attr,restricted-follow"`
|
||||
IdentifiesAs []string `jsonapi:"attr,identifies-as"`
|
||||
|
@ -90,6 +90,15 @@ type linstromCustomAccountField struct {
|
|||
BelongsToId string `jsonapi:"attr,belongs-to-id"`
|
||||
}
|
||||
|
||||
type linstromRelation struct {
|
||||
Id uint `jsonapi:"primary,relations"`
|
||||
CreatedAt time.Time `jsonapi:"attr,created-at"`
|
||||
UpdatedAt time.Time `jsonapi:"attr,updated-at"`
|
||||
FromId string `jsonapi:"attr,from-id"`
|
||||
ToId string `jsonapi:"attr,to-id"`
|
||||
Accepted bool `jsonapi:"attr,accepted"`
|
||||
}
|
||||
|
||||
// Role is essentially just a carbon copy of storage/roles.go
|
||||
type linstromRole struct {
|
||||
Id uint `jsonapi:"primary,roles"`
|
||||
|
|
12
storage/accountRelations.go
Normal file
12
storage/accountRelations.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type AccountRelation struct {
|
||||
gorm.Model
|
||||
FromId string
|
||||
ToId string
|
||||
Accepted bool
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package storage
|
||||
|
||||
import "time"
|
||||
|
||||
type FollowRequest struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
CreatedAt time.Time
|
||||
FromId string
|
||||
ToId string
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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{}
|
||||
|
|
Loading…
Reference in a new issue