databag/net/server/internal/store/schema.go

322 lines
13 KiB
Go
Raw Normal View History

2022-01-11 19:31:45 +00:00
package store
import "gorm.io/gorm"
func AutoMigrate(db *gorm.DB) {
2022-01-21 21:18:35 +00:00
db.AutoMigrate(&Notification{});
db.AutoMigrate(&Config{});
db.AutoMigrate(&App{});
2022-01-11 19:31:45 +00:00
db.AutoMigrate(&Account{});
2022-01-11 22:14:06 +00:00
db.AutoMigrate(&AccountToken{});
2022-02-03 07:48:17 +00:00
db.AutoMigrate(&GroupSlot{});
db.AutoMigrate(&GroupData{});
2022-01-11 22:14:06 +00:00
db.AutoMigrate(&Group{});
2022-02-03 06:52:06 +00:00
db.AutoMigrate(&LabelSlot{});
db.AutoMigrate(&LabelData{});
2022-01-11 22:14:06 +00:00
db.AutoMigrate(&Label{});
2022-02-03 06:13:46 +00:00
db.AutoMigrate(&CardSlot{});
2022-01-11 22:14:06 +00:00
db.AutoMigrate(&Card{});
2022-01-13 21:14:30 +00:00
db.AutoMigrate(&Asset{});
db.AutoMigrate(&ArticleSlot{});
2022-01-11 22:14:06 +00:00
db.AutoMigrate(&Article{});
db.AutoMigrate(&ArticleAsset{});
db.AutoMigrate(&ArticleTag{});
db.AutoMigrate(&Dialogue{});
db.AutoMigrate(&Insight{});
db.AutoMigrate(&Topic{});
db.AutoMigrate(&TopicAsset{});
db.AutoMigrate(&TopicTag{});
}
2022-01-21 21:18:35 +00:00
type Notification struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
2022-01-21 22:26:31 +00:00
Node string `gorm:"not null"`
Module string `gorm:"not null"`
2022-01-21 21:18:35 +00:00
Token string `gorm:"not null"`
Revision int64 `gorm:"not null"`
}
type Config struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
ConfigId string `gorm:"not null;uniqueIndex"`
StrValue string
NumValue int64
BoolValue bool
2022-01-12 21:12:40 +00:00
BinValue []byte
2022-01-11 22:14:06 +00:00
}
type AccountToken struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
AccountID uint `gorm:"index"`
TokenType string `gorm:"not null;`
Token string `gorm:"not null;uniqueIndex"`
2022-01-18 05:48:42 +00:00
Expires int64 `gorm:"not null"`
Created int64 `gorm:"autoCreateTime"`
2022-01-11 22:14:06 +00:00
Account Account
2022-01-11 19:31:45 +00:00
}
2022-01-25 05:22:33 +00:00
// NOTE: card & app reference account by guid, all other tables by id
// because token lookup uses guid and is most common and wanted to avoid join
// int foreign key should be faster, so left other tables with id reference
2022-01-11 19:31:45 +00:00
type Account struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
AccountDetailID uint `gorm:"not null"`
2022-01-17 05:11:24 +00:00
Guid string `gorm:"not null;uniqueIndex"`
Username string `gorm:"not null;uniqueIndex"`
2022-01-12 21:12:40 +00:00
Password []byte `gorm:"not null"`
2022-01-17 05:11:24 +00:00
ProfileRevision int64 `gorm:"not null;default:1"`
ContentRevision int64 `gorm:"not null;default:1"`
GroupRevision int64 `gorm:"not null;default:1"`
LabelRevision int64 `gorm:"not null;default:1"`
CardRevision int64 `gorm:"not null;default:1"`
DialogueRevision int64 `gorm:"not null;default:1"`
2022-01-19 19:00:20 +00:00
InsightRevision int64 `gorm:"not null;default:1"`
2022-01-21 21:18:35 +00:00
ViewRevision int64 `gorm:"not null;default:1"`
Created int64 `gorm:"autoCreateTime"`
2022-01-17 06:46:55 +00:00
Disabled bool `gorm:"not null;default:false"`
AccountDetail AccountDetail
2022-01-11 22:14:06 +00:00
Apps []App
}
type AccountDetail struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
PublicKey string `gorm:"not null"`
PrivateKey string `gorm:"not null"`
KeyType string `gorm:"not null"`
Name string
Description string
Location string
Image string
}
type App struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
2022-01-22 18:45:39 +00:00
AccountID string `gorm:"not null;index:appguid,unique"`
Name string
Description string
Image string
Url string
2022-01-22 18:45:39 +00:00
Token string `gorm:"not null;index:appguid,unique"`
Created int64 `gorm:"autoCreateTime"`
Account Account `gorm:"references:Guid"`
2022-01-11 22:14:06 +00:00
}
2022-02-03 07:48:17 +00:00
type GroupSlot struct {
ID uint
GroupSlotId string `gorm:"not null;index:groupslot,unique"`
AccountID uint `gorm:"not null;index:groupslot,unique"`
Revision int64 `gorm:"not null"`
GroupID uint `gorm:"not null;default:0"`
Group *Group
Account Account
}
2022-01-11 22:14:06 +00:00
type Group struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
GroupDataID uint `gorm:"not null;index:groupdata"`
DataType string `gorm:"index"`
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-02-02 07:39:25 +00:00
Cards []Card `gorm:"many2many:card_groups"`
GroupData GroupData
2022-02-03 07:48:17 +00:00
GroupSlot GroupSlot
}
type GroupData struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
Data string
2022-01-11 22:14:06 +00:00
}
2022-02-03 06:52:06 +00:00
type LabelSlot struct {
ID uint
LabelSlotId string `gorm:"not null;index:labelslot,unique"`
AccountID uint `gorm:"not null;index:labelslot,unique"`
Revision int64 `gorm:"not null"`
LabelID uint `gorm:"not null;default:0"`
Label *Label
Account Account
}
2022-01-11 22:14:06 +00:00
type Label struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
LabelDataID uint `gorm:"not null;index:labeldata"`
DataType string `gorm:"index"`
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-01-25 05:22:33 +00:00
Groups []Group `gorm:"many2many:label_groups;"`
LabelData LabelData
2022-02-03 06:52:06 +00:00
LabelSlot LabelSlot
}
type LabelData struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
Data string
2022-01-11 22:14:06 +00:00
}
2022-02-03 06:13:46 +00:00
type CardSlot struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
CardSlotId string `gorm:"not null;index:cardslot,unique"`
AccountID uint `gorm:"not null;index:cardslot,unique"`
Revision int64 `gorm:"not null"`
CardID uint `gorm:"not null;default:0"`
Card *Card
Account Account
}
2022-01-11 22:14:06 +00:00
type Card struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
2022-02-03 06:13:46 +00:00
AccountID string `gorm:"not null;index:cardguid,unique"`
2022-01-22 18:45:39 +00:00
Guid string `gorm:"not null;index:cardguid,unique"`
2022-01-11 22:14:06 +00:00
Username string
Name string
Description string
Location string
Image string
2022-01-20 23:19:26 +00:00
Version string `gorm:"not null"`
Node string `gorm:"not null"`
2022-01-20 23:19:26 +00:00
ProfileRevision int64 `gorm:"not null"`
Status string `gorm:"not null"`
2022-01-22 18:45:39 +00:00
InToken string `gorm:"not null;index:cardguid,unique"`
2022-01-21 01:01:02 +00:00
OutToken string
2022-01-20 23:19:26 +00:00
Notes string
DataRevision int64 `gorm:"not null"`
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-01-21 21:18:35 +00:00
ViewRevision int64 `gorm:"not null"`
NotifiedView int64
NotifiedContent int64
NotifiedProfile int64
2022-01-22 18:45:39 +00:00
Account Account `gorm:"references:Guid"`
2022-02-02 07:39:25 +00:00
Groups []Group `gorm:"many2many:card_groups"`
2022-01-11 22:14:06 +00:00
}
2022-01-13 18:06:19 +00:00
type Asset struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
AssetId string `gorm:"not null;index:asset,unique"`
AccountID uint `gorm:"not null;index:asset,unique"`
Status string `gorm:"not null;index"`
Size uint64
Crc uint32
Transform string
TransformId string
TransformData string
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
Account Account
}
type ArticleSlot struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
ArticleSlotId string `gorm:"not null;index:articleslot,unique"`
AccountID uint `gorm:"not null;index:articleslot,unique"`
Revision int64 `gorm:"not null"`
ArticleID uint `gorm:"not null;default:0"`
Article *Article
Account Account
}
type Article struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
DataType string `gorm:"index"`
2022-01-11 22:14:06 +00:00
Data string
Status string `gorm:"not null;index"`
2022-01-25 05:22:33 +00:00
Expires int64
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
TagUpdated int64 `gorm:"not null"`
2022-02-02 07:39:25 +00:00
TagCount int32 `gorm:"not null"`
2022-01-28 07:01:17 +00:00
TagRevision int64 `gorm:"not null"`
2022-02-02 07:55:16 +00:00
Groups []Group `gorm:"many2many:article_groups;"`
2022-01-25 05:22:33 +00:00
Labels []Label `gorm:"many2many:article_labels;"`
2022-01-11 22:14:06 +00:00
}
type ArticleAsset struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
2022-01-13 18:06:19 +00:00
AssetID uint
ArticleID uint
2022-01-11 22:14:06 +00:00
Article Article
2022-01-13 18:06:19 +00:00
Asset Asset
2022-01-11 22:14:06 +00:00
}
type ArticleTag struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
TagId string `gorm:"not null;index:articletag,unique"`
ArticleID uint `gorm:"not null;index:articletag,unique"`
2022-01-11 22:14:06 +00:00
CardID uint
Revision int64 `gorm:"not null"`
DataType string `gorm:"index"`
2022-01-11 22:14:06 +00:00
Data string
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-01-11 22:14:06 +00:00
Article Article
Card Card
}
type Dialogue struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
DialogueId string `gorm:"not null;index:dialogue,unique"`
AccountID uint `gorm:"not null;index:dialogue,unique"`
Revision int64 `gorm:"not null"`
DataType string `gorm:"index"`
Data string
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
Active bool `gorm:"not null"`
MemberRevision uint64 `gorm:"not null"`
TopicUpdated int64
TopicRevision uint64 `gorm:"not null"`
2022-01-25 05:22:33 +00:00
Cards []Card `gorm:"many2many:dialog_cards;"`
Account Account
}
2022-01-11 22:14:06 +00:00
type Insight struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
InsightId string `gorm:"not null;index:insight,unique"`
CardID uint `gorm:"not null;index:insight,unique"`
dialogueRevision uint64 `gorm:"not null"`
memberRevision uint64 `gorm:"not null"`
topicRevision uint64 `gorm:"not null"`
Card Card
}
2022-01-11 22:14:06 +00:00
type Topic struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
TopicId string `gorm:"not null;index:topic,unique"`
AccountID uint `gorm:"not null;index:topic,unique"`
CardID uint
Revision int64 `gorm:"not null"`
DataType string `gorm:"index"`
Data string
Status string `gorm:"not null;index"`
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
TagUpdated int64 `gorm:"not null"`
TagRevision uint64 `gorm:"not null"`
Account Account
Card Card
}
type TopicAsset struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
2022-01-13 18:06:19 +00:00
AssetID uint
TopicID uint
Topic Topic
2022-01-13 18:06:19 +00:00
Asset Asset
}
type TopicTag struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
TagId string `gorm:"not null;index:topictag,unique"`
TopicID uint `gorm:"not null;index:topictag,unique"`
CardID uint
Revision int64 `gorm:"not null"`
DataType string `gorm:"index"`
Data string
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
Topic Topic
Card Card
}
2022-01-11 22:14:06 +00:00