Describe all types for the new storage system
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Melody Becker 2025-03-27 10:45:57 +01:00
parent 8d4ba2ecae
commit 67b507f4bd
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
25 changed files with 74 additions and 27 deletions

View file

@ -45,12 +45,12 @@ func migrateTypes(db *gorm.DB) error {
&models.Role{},
&models.User{},
&models.UserAuthMethod{},
&models.UserBeings{},
&models.UserToBeing{},
&models.UserInfoField{},
&models.UserRelation{},
&models.UserToUserRelation{},
&models.UserRemoteLinks{},
&models.UserRole{},
&models.UserTag{},
&models.UserToRole{},
&models.UserToTag{},
); err != nil {
return err
}

View file

@ -2,11 +2,15 @@ package models
import "gorm.io/gorm"
// An emote is effectively an assignment of a name and server
type Emote struct {
gorm.Model
// Metadata MediaMetadata // `gorm:"foreignKey:MetadataId"`
// Media used for this emote
Metadata MediaMetadata // `gorm:"foreignKey:MetadataId"`
MetadataId string
// Name of the emote. Also the text for using it in a message (ex. :bob:)
Name string
// Server RemoteServer // `gorm:"foreignKey:ServerId;references:ID"`
// Server the emote is from
Server RemoteServer // `gorm:"foreignKey:ServerId;references:ID"`
ServerId uint
}

View file

@ -6,6 +6,9 @@ import (
"gorm.io/gorm"
)
// Metadata for describing some media
// Media is, at least for Linstrom, always stored on a separate server,
// be that the remote server it originated from or an s3 bucket
type MediaMetadata struct {
ID string `gorm:"primarykey"` // The unique ID of this media file
CreatedAt time.Time // When this entry was created

View file

@ -6,7 +6,10 @@ import (
"gorm.io/gorm"
)
// Data defined in extra structs:
// User created content, containing some message, maybe attachments,
// tags, pings or other extra things
//
// Data defined in extra structs (links are included at the bottom):
// - Attachments: models.NoteToAttachment
// - Emotes: models.NoteToEmote
// - Pings: models.NoteToPing

View file

@ -2,6 +2,7 @@ package models
import "database/sql/driver"
// The access level required to view a note
type NoteAccessLevel uint8
const (

View file

@ -1,5 +1,6 @@
package models
// A binding of one note to one media attachment
type NoteToAttachment struct {
Note Note
NoteId string

View file

@ -1,5 +1,6 @@
package models
// A binding of one note to one emote
type NoteToEmote struct {
Note Note
NoteId string

View file

@ -1,5 +1,6 @@
package models
// A binding of one note to one mentioned account
type NoteToPing struct {
Note Note
NoteId string

View file

@ -1,5 +1,6 @@
package models
// A binding of one note to one string (hash)tag
type NoteTag struct {
Note Note
NoteId string

View file

@ -2,6 +2,7 @@ package models
import "gorm.io/gorm"
// A binding of one note to one account reacting to it with one emote
type Reaction struct {
gorm.Model
Note Note

View file

@ -2,6 +2,8 @@ package models
import "gorm.io/gorm"
// RemoteServer describes an ActivityPub server
// This includes self too
type RemoteServer struct {
gorm.Model
ServerType ServerSoftwareType // What software the server is running. Useful for formatting

View file

@ -4,6 +4,7 @@ import (
"database/sql/driver"
)
// The software a server is running
type ServerSoftwareType string
const (

View file

@ -6,6 +6,9 @@ import (
"gorm.io/gorm"
)
// A user describes an account for creating content.
// This may be controlled by either a human or some external script
//
// Data stored in external types:
// - Custom info fields
// - Being types

View file

@ -1,5 +1,10 @@
package models
// One authentication method linked to one account.
// Contains the method and whatever the token may be
// For a password, this would be a hash of that password,
// totp would be the seed,
// and passkey would be the webauthn.Credential, marshalled into json
type UserAuthMethod struct {
User User
UserId string

View file

@ -2,6 +2,7 @@ package models
import "database/sql/driver"
// Authentication methods available
type AuthenticationMethodType string
const (

View file

@ -4,6 +4,9 @@ import (
"database/sql/driver"
)
// The type of being an account identifies as
// This is distinctly separate from the account being as being controlled by script
// or other automated method
type BeingType string
const (

View file

@ -1,6 +1,8 @@
package models
type UserBeings struct {
// Defines an account to be a being of the set type
// Multiple are possible for combination
type UserToBeing struct {
User User
UserId string
Being BeingType `gorm:"type:being_type"`

View file

@ -6,6 +6,10 @@ import (
"gorm.io/gorm"
)
// One key-value field attached to an account
// If the value is an uri, the server may attempt to verify ownership
// over that uri by checking the content for a `rel="me"` anchor
// linking back to the account the field is attached to
type UserInfoField struct {
gorm.Model // Can actually just embed this as is here as those are not something directly exposed :3
Name string

View file

@ -1,9 +0,0 @@
package models
type UserRelation struct {
User User
UserId string
TargetUser User
TargetUserId string
Relation RelationType `gorm:"type:relation_type"`
}

View file

@ -2,6 +2,7 @@ package models
import "database/sql/driver"
// How one account relates to another
type RelationType string
const (

View file

@ -2,6 +2,7 @@ package models
import "gorm.io/gorm"
// "Cached" extra data for accounts, in case they are remote
type UserRemoteLinks struct {
// ---- Section: gorm
// Sets this struct up as a value that an Account may have

View file

@ -1,8 +0,0 @@
package models
type UserRole struct {
User User
UserId string
Role Role
RoleId uint
}

View file

@ -1,6 +1,8 @@
package models
type UserTag struct {
// A (hash)tag appearing on an account's profile description
// Accounts may have multiple tags, but each tag may only be stored once at most
type UserToTag struct {
User User
UserId string
Tag string

View file

@ -0,0 +1,11 @@
package models
// A link of one account to one role
// There may be multiple of these links per user and per role
// But a role may only be linked at most once to the same user
type UserToRole struct {
User User
UserId string
Role Role
RoleId uint
}

View file

@ -0,0 +1,12 @@
package models
// A relation between two accounts
// There may be multiple relations from an account X to an account Y,
// each describing a different aspect
type UserToUserRelation struct {
User User
UserId string
TargetUser User
TargetUserId string
Relation RelationType `gorm:"type:relation_type"`
}