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

296 lines
12 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-08 21:25:44 +00:00
db.AutoMigrate(&ChannelSlot{});
db.AutoMigrate(&Channel{});
2022-02-03 06:13:46 +00:00
db.AutoMigrate(&CardSlot{});
2022-01-11 22:14:06 +00:00
db.AutoMigrate(&Card{});
db.AutoMigrate(&ArticleSlot{});
2022-01-11 22:14:06 +00:00
db.AutoMigrate(&Article{});
2022-02-08 21:25:44 +00:00
db.AutoMigrate(&TopicSlot{});
db.AutoMigrate(&Topic{});
2022-02-08 21:25:44 +00:00
db.AutoMigrate(&Asset{});
db.AutoMigrate(&TagSlot{});
db.AutoMigrate(&Tag{});
}
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-03-08 18:18:31 +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"`
2022-02-08 20:24:42 +00:00
ArticleRevision int64 `gorm:"not null;default:1"`
2022-01-17 05:11:24 +00:00
GroupRevision int64 `gorm:"not null;default:1"`
2022-02-08 20:24:42 +00:00
ChannelRevision int64 `gorm:"not null;default:1"`
2022-01-17 05:11:24 +00:00
CardRevision int64 `gorm:"not null;default:1"`
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-01-17 06:46:55 +00:00
Disabled bool `gorm:"not null;default:false"`
2022-03-08 21:31:04 +00:00
Searchable bool `gorm:"not null;default:false"`
Forward string
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"`
AccountID uint
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"`
2022-02-12 08:08:30 +00:00
Channels []Channel `gorm:"many2many:channel_groups"`
Articles []Article `gorm:"many2many:article_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
AccountID uint
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"`
DetailRevision int64 `gorm:"not null;default:1"`
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
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
ViewRevision int64 `gorm:"not null;default:1"`
NotifiedView int64
2022-02-08 20:24:42 +00:00
NotifiedArticle int64
NotifiedChannel 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-02-12 08:08:30 +00:00
Channels []Channel `gorm:"many2many:channel_cards"`
2022-02-03 19:18:50 +00:00
CardSlot CardSlot
2022-01-11 22:14:06 +00:00
}
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"`
AccountID uint
DataType string `gorm:"index"`
2022-01-11 22:14:06 +00:00
Data string
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-02-02 07:55:16 +00:00
Groups []Group `gorm:"many2many:article_groups;"`
ArticleSlot ArticleSlot
2022-01-11 22:14:06 +00:00
}
2022-02-08 21:25:44 +00:00
type ChannelSlot struct {
ID uint
ChannelSlotId string `gorm:"not null;index:channelslot,unique"`
AccountID uint `gorm:"not null;index:channelslot,unique"`
Revision int64 `gorm:"not null"`
2022-02-08 21:25:44 +00:00
ChannelID uint `gorm:"not null;default:0"`
Channel *Channel
Account Account
2022-01-11 22:14:06 +00:00
}
2022-02-08 21:25:44 +00:00
type Channel struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
AccountID uint
TopicRevision int64 `gorm:"not null"`
2022-02-08 21:25:44 +00:00
DetailRevision int64 `gorm:"not null"`
DataType string `gorm:"index"`
2022-02-15 22:30:04 +00:00
Data string
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-02-12 08:08:30 +00:00
Groups []Group `gorm:"many2many:channel_groups;"`
Cards []Card `gorm:"many2many:channel_cards;"`
2022-03-03 05:46:21 +00:00
Topics []Topic
2022-02-08 21:25:44 +00:00
ChannelSlot ChannelSlot
}
2022-01-11 22:14:06 +00:00
2022-02-08 21:25:44 +00:00
type TopicSlot struct {
ID uint
2022-02-18 20:21:15 +00:00
TopicSlotId string `gorm:"not null;index:topicaccount,unique;index:topicchannel,unique"`
AccountID uint `gorm:"not null;index:topicaccount,unique"`
ChannelID uint `gorm:"not null;index:topicchannel,unique"`
2022-02-08 21:25:44 +00:00
Revision int64 `gorm:"not null"`
Topic *Topic
2022-02-18 20:21:15 +00:00
Channel *Channel
2022-02-08 21:25:44 +00:00
Account Account
}
2022-01-11 22:14:06 +00:00
type Topic struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
2022-02-08 21:25:44 +00:00
DetailRevision int64 `gorm:"not null"`
AccountID uint
2022-03-03 05:46:21 +00:00
ChannelID uint
TopicSlotID uint `gorm:"not null;index:topictopicslot,unique"`
2022-02-08 21:25:44 +00:00
Guid string
DataType string `gorm:"index"`
Data string
Status string `gorm:"not null;index"`
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-02-18 07:56:30 +00:00
TagRevision int64 `gorm:"not null"`
2022-03-03 05:46:21 +00:00
Channel *Channel
2022-02-08 21:25:44 +00:00
Assets []Asset
Tags []Tag
2022-03-01 08:28:36 +00:00
TopicSlot TopicSlot
}
2022-02-08 21:25:44 +00:00
type Asset struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
2022-02-08 21:25:44 +00:00
AssetId string `gorm:"not null;index:asset,unique"`
AccountID uint `gorm:"not null;index:asset,unique"`
2022-03-01 08:28:36 +00:00
ChannelID uint
2022-01-13 18:06:19 +00:00
TopicID uint
2022-02-08 21:25:44 +00:00
Status string `gorm:"not null;index"`
2022-02-28 22:59:29 +00:00
Size int64
2022-02-08 21:25:44 +00:00
Crc uint32
Transform string
TransformId string
2022-03-01 18:35:14 +00:00
TransformParams string
TransformQueue string
2022-02-08 21:25:44 +00:00
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
Account Account
2022-03-01 08:28:36 +00:00
Channel *Channel
2022-02-08 21:25:44 +00:00
Topic *Topic
}
2022-02-08 21:25:44 +00:00
type TagSlot struct {
ID uint
2022-03-02 22:30:14 +00:00
TagSlotId string `gorm:"not null;index:tagslot,unique"`
AccountID uint `gorm:"not null;index:tagslot,unique"`
2022-03-03 08:46:32 +00:00
ChannelID uint `gorm:"not null"`
2022-03-03 06:27:45 +00:00
TopicID uint `gorm:"not null;index:tagtopic"`
Revision int64 `gorm:"not null"`
2022-02-08 21:25:44 +00:00
Tag *Tag
Account Account
2022-03-03 08:46:32 +00:00
Channel *Channel
2022-03-03 06:27:45 +00:00
Topic *Topic
2022-02-08 21:25:44 +00:00
}
type Tag struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
2022-03-02 22:30:14 +00:00
TagSlotID uint `gorm:"not null;index:tagtagslot,unique"`
AccountID uint
2022-03-02 22:30:14 +00:00
ChannelID uint `gorm:"not null;index:channeltag"`
TopicID uint `gorm:"not null;index:topictag"`
Guid string `gorm:"not null"`
DataType string `gorm:"index"`
Data string
Created int64 `gorm:"autoCreateTime"`
Updated int64 `gorm:"autoUpdateTime"`
2022-03-02 22:30:14 +00:00
Channel *Channel
2022-02-08 21:25:44 +00:00
Topic *Topic
2022-03-02 22:30:14 +00:00
TagSlot TagSlot
}
2022-01-11 22:14:06 +00:00