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,
|
BannerId: acc.Banner,
|
||||||
Background: apiBackground,
|
Background: apiBackground,
|
||||||
BackgroundId: acc.Background,
|
BackgroundId: acc.Background,
|
||||||
FollowerIds: acc.Followers,
|
RelationIds: acc.Relations,
|
||||||
FollowingIds: acc.Follows,
|
|
||||||
Indexable: acc.Indexable,
|
Indexable: acc.Indexable,
|
||||||
RestrictedFollow: acc.RestrictedFollow,
|
RestrictedFollow: acc.RestrictedFollow,
|
||||||
IdentifiesAs: sliceutils.Map(
|
IdentifiesAs: sliceutils.Map(
|
||||||
|
|
|
@ -7,6 +7,7 @@ import "time"
|
||||||
var (
|
var (
|
||||||
_ = linstromNote{}
|
_ = linstromNote{}
|
||||||
_ = linstromRole{}
|
_ = linstromRole{}
|
||||||
|
_ = linstromRelation{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type linstromNote struct {
|
type linstromNote struct {
|
||||||
|
@ -71,8 +72,7 @@ type linstromAccount struct {
|
||||||
BannerId *string `jsonapi:"attr,banner-id"`
|
BannerId *string `jsonapi:"attr,banner-id"`
|
||||||
Background *linstromMediaMetadata `jsonapi:"relation,background"`
|
Background *linstromMediaMetadata `jsonapi:"relation,background"`
|
||||||
BackgroundId *string `jsonapi:"attr,background-id"`
|
BackgroundId *string `jsonapi:"attr,background-id"`
|
||||||
FollowerIds []string `jsonapi:"attr,follows-ids"`
|
RelationIds []uint `jsonapi:"attr,follows-ids"`
|
||||||
FollowingIds []string `jsonapi:"attr,following-ids"`
|
|
||||||
Indexable bool `jsonapi:"attr,indexable"`
|
Indexable bool `jsonapi:"attr,indexable"`
|
||||||
RestrictedFollow bool `jsonapi:"attr,restricted-follow"`
|
RestrictedFollow bool `jsonapi:"attr,restricted-follow"`
|
||||||
IdentifiesAs []string `jsonapi:"attr,identifies-as"`
|
IdentifiesAs []string `jsonapi:"attr,identifies-as"`
|
||||||
|
@ -90,6 +90,15 @@ type linstromCustomAccountField struct {
|
||||||
BelongsToId string `jsonapi:"attr,belongs-to-id"`
|
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
|
// Role is essentially just a carbon copy of storage/roles.go
|
||||||
type linstromRole struct {
|
type linstromRole struct {
|
||||||
Id uint `jsonapi:"primary,roles"`
|
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{},
|
AccessToken{},
|
||||||
Emote{},
|
Emote{},
|
||||||
UserInfoField{},
|
UserInfoField{},
|
||||||
FollowRequest{},
|
AccountRelation{},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to apply migrations: %w", err)
|
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)
|
// 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
|
// Assume unchangable (once set by a user) to be kind to other implementations
|
||||||
// Would be an easy avenue to fuck with them though
|
// 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
|
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
|
// When this account was last updated. Will also be used for refreshing remote accounts. Automatically set by gorm
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
|
@ -40,8 +40,7 @@ type Account struct {
|
||||||
Description string // The description of a user account
|
Description string // The description of a user account
|
||||||
Tags []string `gorm:"serializer:json"` // Hashtags
|
Tags []string `gorm:"serializer:json"` // Hashtags
|
||||||
IsBot bool // Whether to mark this account as a script controlled one
|
IsBot bool // Whether to mark this account as a script controlled one
|
||||||
Follows []string `gorm:"serializer:json"` // List of account ids this account follows
|
Relations []uint `gorm:"serializer:json"` // List of ids of all relations this account has. Both follows and followers
|
||||||
Followers []string `gorm:"serializer:json"` // List of account ids that follow this account
|
|
||||||
Icon string // ID of a media file used as icon
|
Icon string // ID of a media file used as icon
|
||||||
Background *string // ID of a media file used as background image
|
Background *string // ID of a media file used as background image
|
||||||
Banner *string // ID of a media file used as banner
|
Banner *string // ID of a media file used as banner
|
||||||
|
@ -332,9 +331,8 @@ func (s *Storage) NewEmptyAccount() (*Account, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
acc.WebAuthnId = data
|
acc.WebAuthnId = data
|
||||||
acc.Followers = []string{}
|
acc.Relations = []uint{}
|
||||||
acc.Tags = []string{}
|
acc.Tags = []string{}
|
||||||
acc.Follows = []string{}
|
|
||||||
acc.Gender = []string{}
|
acc.Gender = []string{}
|
||||||
acc.CustomFields = []uint{}
|
acc.CustomFields = []uint{}
|
||||||
acc.IdentifiesAs = []Being{}
|
acc.IdentifiesAs = []Being{}
|
||||||
|
|
Loading…
Reference in a new issue