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{});
|
2022-01-11 22:44:40 +00:00
|
|
|
db.AutoMigrate(&Config{});
|
2022-01-11 20:14:32 +00:00
|
|
|
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{});
|
2022-02-02 21:44:41 +00:00
|
|
|
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{});
|
2022-01-11 22:44:40 +00:00
|
|
|
db.AutoMigrate(&Topic{});
|
2022-02-08 21:25:44 +00:00
|
|
|
db.AutoMigrate(&Asset{});
|
|
|
|
db.AutoMigrate(&TagSlot{});
|
|
|
|
db.AutoMigrate(&Tag{});
|
2022-01-11 22:44:40 +00:00
|
|
|
}
|
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2022-01-11 22:44:40 +00:00
|
|
|
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 {
|
2022-01-11 22:44:40 +00:00
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
|
|
|
AccountID uint `gorm:"index"`
|
2022-01-18 08:30:27 +00:00
|
|
|
TokenType string `gorm:"not null;`
|
2022-01-11 22:44:40 +00:00
|
|
|
Token string `gorm:"not null;uniqueIndex"`
|
2022-01-18 05:48:42 +00:00
|
|
|
Expires int64 `gorm:"not null"`
|
2022-01-11 22:44:40 +00:00
|
|
|
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 {
|
2022-01-11 22:44:40 +00:00
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
2022-01-18 08:30:27 +00:00
|
|
|
AccountDetailID uint `gorm:"not null"`
|
2022-01-17 05:11:24 +00:00
|
|
|
Guid string `gorm:"not null;uniqueIndex"`
|
2022-01-11 22:44:40 +00:00
|
|
|
Username string `gorm:"not null;uniqueIndex"`
|
2022-01-12 21:12:40 +00:00
|
|
|
Password []byte `gorm:"not null"`
|
2022-03-25 07:33:22 +00:00
|
|
|
AccountRevision int64 `gorm:"not null;default:1"`
|
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"`
|
2022-01-11 22:44:40 +00:00
|
|
|
Created int64 `gorm:"autoCreateTime"`
|
2022-03-02 08:01:01 +00:00
|
|
|
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
|
2022-01-18 08:30:27 +00:00
|
|
|
AccountDetail AccountDetail
|
2022-01-11 22:14:06 +00:00
|
|
|
Apps []App
|
2022-01-11 20:14:32 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 08:30:27 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-01-11 20:14:32 +00:00
|
|
|
type App struct {
|
2022-01-11 22:44:40 +00:00
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
2022-01-22 18:45:39 +00:00
|
|
|
AccountID string `gorm:"not null;index:appguid,unique"`
|
2022-01-11 20:14:32 +00:00
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
Image string
|
|
|
|
Url string
|
2022-01-22 18:45:39 +00:00
|
|
|
Token string `gorm:"not null;index:appguid,unique"`
|
2022-01-11 22:44:40 +00:00
|
|
|
Created int64 `gorm:"autoCreateTime"`
|
2022-01-22 18:16:33 +00:00
|
|
|
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 {
|
2022-01-11 22:44:40 +00:00
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
2022-02-02 18:55:45 +00:00
|
|
|
GroupDataID uint `gorm:"not null;index:groupdata"`
|
2022-03-10 06:18:37 +00:00
|
|
|
AccountID uint
|
2022-01-11 22:44:40 +00:00
|
|
|
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"`
|
2022-02-02 18:55:45 +00:00
|
|
|
GroupData GroupData
|
2022-02-03 07:48:17 +00:00
|
|
|
GroupSlot GroupSlot
|
2022-02-02 18:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GroupData struct {
|
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
|
|
|
Data string
|
2022-03-10 06:18:37 +00:00
|
|
|
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 {
|
2022-01-11 22:44:40 +00:00
|
|
|
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"`
|
2022-01-11 22:44:40 +00:00
|
|
|
Node string `gorm:"not null"`
|
2022-01-20 23:19:26 +00:00
|
|
|
ProfileRevision int64 `gorm:"not null"`
|
2022-02-04 08:20:57 +00:00
|
|
|
DetailRevision int64 `gorm:"not null;default:1"`
|
2022-01-11 22:44:40 +00:00
|
|
|
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
|
2022-01-11 22:44:40 +00:00
|
|
|
Created int64 `gorm:"autoCreateTime"`
|
|
|
|
Updated int64 `gorm:"autoUpdateTime"`
|
2022-02-04 08:20:57 +00:00
|
|
|
ViewRevision int64 `gorm:"not null;default:1"`
|
2022-01-28 21:39:31 +00:00
|
|
|
NotifiedView int64
|
2022-02-08 20:24:42 +00:00
|
|
|
NotifiedArticle int64
|
|
|
|
NotifiedChannel int64
|
2022-01-28 21:39:31 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-02-02 21:44:41 +00:00
|
|
|
type ArticleSlot struct {
|
2022-01-11 22:44:40 +00:00
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
2022-02-02 21:44:41 +00:00
|
|
|
ArticleSlotId string `gorm:"not null;index:articleslot,unique"`
|
|
|
|
AccountID uint `gorm:"not null;index:articleslot,unique"`
|
2022-01-11 22:44:40 +00:00
|
|
|
Revision int64 `gorm:"not null"`
|
2022-02-02 21:44:41 +00:00
|
|
|
ArticleID uint `gorm:"not null;default:0"`
|
|
|
|
Article *Article
|
2022-02-01 18:03:04 +00:00
|
|
|
Account Account
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:44:41 +00:00
|
|
|
type Article struct {
|
2022-02-01 18:03:04 +00:00
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
2022-03-10 06:18:37 +00:00
|
|
|
AccountID uint
|
2022-01-11 22:44:40 +00:00
|
|
|
DataType string `gorm:"index"`
|
2022-01-11 22:14:06 +00:00
|
|
|
Data string
|
2022-01-11 22:44:40 +00:00
|
|
|
Created int64 `gorm:"autoCreateTime"`
|
|
|
|
Updated int64 `gorm:"autoUpdateTime"`
|
2022-02-02 07:55:16 +00:00
|
|
|
Groups []Group `gorm:"many2many:article_groups;"`
|
2022-02-04 21:26:52 +00:00
|
|
|
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"`
|
2022-01-11 22:44:40 +00:00
|
|
|
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 {
|
2022-01-11 22:44:40 +00:00
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
2022-03-10 06:18:37 +00:00
|
|
|
AccountID uint
|
2022-03-04 20:03:33 +00:00
|
|
|
TopicRevision int64 `gorm:"not null"`
|
2022-02-08 21:25:44 +00:00
|
|
|
DetailRevision int64 `gorm:"not null"`
|
2022-01-11 22:44:40 +00:00
|
|
|
DataType string `gorm:"index"`
|
2022-02-15 22:30:04 +00:00
|
|
|
Data string
|
2022-01-11 22:44:40 +00:00
|
|
|
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:44:40 +00:00
|
|
|
}
|
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:44:40 +00:00
|
|
|
}
|
2022-01-11 22:14:06 +00:00
|
|
|
|
2022-01-11 22:44:40 +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"`
|
2022-03-10 06:18:37 +00:00
|
|
|
AccountID uint
|
2022-03-03 05:46:21 +00:00
|
|
|
ChannelID uint
|
2022-03-03 08:03:32 +00:00
|
|
|
TopicSlotID uint `gorm:"not null;index:topictopicslot,unique"`
|
2022-02-08 21:25:44 +00:00
|
|
|
Guid string
|
2022-01-11 22:44:40 +00:00
|
|
|
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-01-11 22:44:40 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 21:25:44 +00:00
|
|
|
type Asset struct {
|
2022-01-11 22:44:40 +00:00
|
|
|
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-01-11 22:44:40 +00:00
|
|
|
}
|
|
|
|
|
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"`
|
2022-01-11 22:44:40 +00:00
|
|
|
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"`
|
2022-03-10 06:18:37 +00:00
|
|
|
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"`
|
2022-01-11 22:44:40 +00:00
|
|
|
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:44:40 +00:00
|
|
|
}
|
2022-01-11 22:14:06 +00:00
|
|
|
|
|
|
|
|