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-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{});
|
2022-02-02 21:44:41 +00:00
|
|
|
db.AutoMigrate(&ArticleSlot{});
|
2022-01-11 22:14:06 +00:00
|
|
|
db.AutoMigrate(&Article{});
|
|
|
|
db.AutoMigrate(&ArticleAsset{});
|
|
|
|
db.AutoMigrate(&ArticleTag{});
|
2022-01-11 22:44:40 +00:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
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-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 {
|
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-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"`
|
2022-01-11 22:44:40 +00:00
|
|
|
Created int64 `gorm:"autoCreateTime"`
|
2022-01-17 06:46:55 +00:00
|
|
|
Disabled bool `gorm:"not null;default:false"`
|
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-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-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-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 {
|
2022-01-11 22:44:40 +00:00
|
|
|
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
2022-02-02 18:55:45 +00:00
|
|
|
LabelDataID uint `gorm:"not null;index:labeldata"`
|
2022-01-11 22:44:40 +00:00
|
|
|
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;"`
|
2022-02-02 18:55:45 +00:00
|
|
|
LabelData LabelData
|
2022-02-03 06:52:06 +00:00
|
|
|
LabelSlot LabelSlot
|
2022-02-02 18:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
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-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
|
|
|
|
DataRevision int64 `gorm:"not null"`
|
2022-01-11 22:44:40 +00:00
|
|
|
Created int64 `gorm:"autoCreateTime"`
|
|
|
|
Updated int64 `gorm:"autoUpdateTime"`
|
2022-01-21 21:18:35 +00:00
|
|
|
ViewRevision int64 `gorm:"not null"`
|
2022-01-28 21:39:31 +00:00
|
|
|
NotifiedView int64
|
|
|
|
NotifiedContent int64
|
2022-02-03 08:30:43 +00:00
|
|
|
NotifiedLabel 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-03 19:18:50 +00:00
|
|
|
CardSlot CardSlot
|
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
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
Status string `gorm:"not null;index"`
|
2022-01-25 05:22:33 +00:00
|
|
|
Expires int64
|
2022-01-11 22:44:40 +00:00
|
|
|
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 {
|
2022-01-11 22:44:40 +00:00
|
|
|
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 {
|
2022-01-11 22:44:40 +00:00
|
|
|
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
|
2022-01-11 22:44:40 +00:00
|
|
|
Revision int64 `gorm:"not null"`
|
|
|
|
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-01-11 22:14:06 +00:00
|
|
|
Article Article
|
|
|
|
Card Card
|
|
|
|
}
|
|
|
|
|
2022-01-11 22:44:40 +00:00
|
|
|
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;"`
|
2022-01-11 22:44:40 +00:00
|
|
|
Account Account
|
|
|
|
}
|
2022-01-11 22:14:06 +00:00
|
|
|
|
2022-01-11 22:44:40 +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
|
|
|
|
2022-01-11 22:44:40 +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
|
2022-01-11 22:44:40 +00:00
|
|
|
Topic Topic
|
2022-01-13 18:06:19 +00:00
|
|
|
Asset Asset
|
2022-01-11 22:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|