migrate from github

This commit is contained in:
2026-07-15 22:42:31 +08:00
commit 3ad559f05e
262 changed files with 21637 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package model
import (
"time"
"gorm.io/gorm"
)
type Attachment struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
ExternalID string `gorm:"size:100;unique;not null" json:"external_id"`
DocumentID int64 `gorm:"not null;index" json:"document_id"`
Name string `gorm:"size:255;not null" json:"name"`
Path string `gorm:"size:512;not null" json:"path"`
Size int64 `json:"size"`
MimeType string `gorm:"size:100" json:"mime_type"`
UserID int64 `gorm:"not null" json:"user_id"`
PresignedURL string `gorm:"-" json:"presigned_url"` // 预签名URL,不存储到数据库
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (Attachment) TableName() string {
return "attachments"
}
+24
View File
@@ -0,0 +1,24 @@
package model
import (
"time"
"gorm.io/gorm"
)
type DocumentComment struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
ExternalID string `gorm:"size:100;unique;index;not null" json:"external_id"`
DocumentID int64 `gorm:"index;not null" json:"document_id"`
ParentID int64 `gorm:"default:0;index" json:"parent_id"`
CreatorID int64 `gorm:"index;not null" json:"creator_id"`
Content string `gorm:"type:text;not null" json:"content"`
AnchorID string `gorm:"size:128;index" json:"anchor_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (DocumentComment) TableName() string {
return "document_comments"
}
+45
View File
@@ -0,0 +1,45 @@
package model
import (
"time"
"gorm.io/gorm"
)
type DocumentType string
const DocumentType_Markdown DocumentType = "markdown"
const DocumentType_Table DocumentType = "table"
const DocumentType_MarkdownSlide DocumentType = "markdown_slide"
const DocumentType_YoreseeRichText DocumentType = "yoresee_rich_text"
type ContainerType string
const ContainerType_Own ContainerType = "own"
const ContainerType_KnowledgeBase ContainerType = "knowledge_base"
type Document struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
ExternalID string `gorm:"size:100;unique;index;not null" json:"external_id"`
Title string `gorm:"size:200;not null" json:"title"`
Type DocumentType `gorm:"size:20;default:'markdown'" json:"type"`
Summary string `gorm:"type:text" json:"summary"`
ParentID int64 `gorm:"default:0;index" json:"parent_id"` // 0 means root
UserID int64 `gorm:"not null;index" json:"user_id"`
KnowledgeID *int64 `gorm:"index" json:"knowledge_id"`
ContainerType ContainerType `gorm:"not null;default:'own';index" json:"containter_type"`
IsPublic bool `gorm:"default:false;index" json:"is_public"`
Tags []string `gorm:"serializer:json" json:"tags"`
Path string `gorm:"type:ltree;not null;default:'';index:idx_path_gist,using:gist"`
Depth int `gorm:"not null;default:0;index"`
ViewCount int `gorm:"default:0" json:"view_count"`
EditCount int `gorm:"default:0" json:"edit_count"`
Content string `gorm:"type:text" json:"content"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (Document) TableName() string {
return "document_metas"
}
+18
View File
@@ -0,0 +1,18 @@
package model
import "time"
type DocumentVersion struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
DocumentID int64 `gorm:"not null;index" json:"document_id"`
Version int `gorm:"not null" json:"version"`
Title string `gorm:"size:200;not null" json:"title"`
Content string `gorm:"type:text" json:"content"`
UserID int64 `gorm:"not null;index" json:"user_id"`
ChangeSummary string `gorm:"type:text" json:"change_summary"`
CreatedAt time.Time `json:"created_at"`
}
func (DocumentVersion) TableName() string {
return "document_versions"
}
+14
View File
@@ -0,0 +1,14 @@
package model
import "time"
type DocumentYjsSnapshot struct {
DocID int64 `gorm:"primaryKey;column:doc_id" json:"doc_id"`
YjsState []byte `gorm:"type:bytea;not null" json:"yjs_state"`
Version int64 `gorm:"not null" json:"version"`
UpdatedAt time.Time `json:"updated_at"`
}
func (DocumentYjsSnapshot) TableName() string {
return "documents_yjs_snapshot"
}
+22
View File
@@ -0,0 +1,22 @@
package model
import (
"time"
)
type Invitation struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
Code string `gorm:"size:32;unique;not null" json:"code"`
CreatedBy int64 `gorm:"not null" json:"created_by"`
UsedCnt int64 `gorm:"default:0" json:"used_cnt"`
MaxUsedCnt *int64 `gorm:"default:1" json:"max_used_cnt"`
ExpiresAt *time.Time `json:"expires_at"`
Note *string `gorm:"type:text" json:"note"`
CreatedAt time.Time `json:"created_at"`
DeletedAt *time.Time `gorm:"index" json:"deleted_at"`
Disabled bool `gorm:"index,default:false" json:"disabled_at"`
}
func (Invitation) TableName() string {
return "invitations"
}
+17
View File
@@ -0,0 +1,17 @@
package model
import "time"
type InvitationRecord struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
Code string `gorm:"size:32;index;not null" json:"code"`
UsedByUserID *int64 `gorm:"index" json:"used_by_user_id"`
UsedBy string `gorm:"size:100" json:"used_by"`
Status string `gorm:"size:20;index" json:"status"`
UsedAt time.Time `json:"used_at"`
CreatedAt time.Time `json:"created_at"`
}
func (InvitationRecord) TableName() string {
return "invitation_records"
}
+33
View File
@@ -0,0 +1,33 @@
package model
import (
"time"
)
type KnowledgeBase struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
ExternalID string `gorm:"size:100;unique;not null;index" json:"external_id"`
Name string `gorm:"size:100;not null" json:"name"`
Description string `gorm:"size:255" json:"description"`
Cover string `gorm:"size:255" json:"cover"`
CreatorUserID int64 `gorm:"not null" json:"creator_user_id"` // creator user id
IsPublic bool `gorm:"default:false" json:"is_public"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt time.Time `gorm:"index" json:"deleted_at"`
}
type RecentKnowledgeBase struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
UserID int64 `gorm:"not null;index" json:"user_id"`
KnowledgeBaseID int64 `gorm:"not null;index" json:"knowledge_base_id"`
AccessedAt time.Time `gorm:"not null" json:"accessed_at"`
}
func (RecentKnowledgeBase) TableName() string {
return "recent_knowledge_bases"
}
func (KnowledgeBase) TableName() string {
return "knowledge_bases"
}
+24
View File
@@ -0,0 +1,24 @@
package model
type MembershipType int64
const (
MembershipType_UserGroup MembershipType = 1 // equals to SubjectTypeUserGroup
MembershipType_OrgNode MembershipType = 2 // equals to SubjectTypeOrgNode
)
type MembershipRelation struct {
ID int64 `gorm:"primaryKey;autoIncrement"`
Type MembershipType `gorm:"not null;index" json:"type"` // 1: UserGroup, 2: OrgNode
UserID int64 `gorm:"not null;index" json:"user_id"`
MembershipID int64 `gorm:"not null;index" json:"membership_id"` // user_group_id or org_node_id
// virtual field
User User `gorm:"foreignKey:UserID;references:ID"`
}
// query all user belong to membership with type and member_id
func (MembershipRelation) TableName() string {
return "membership"
}
+22
View File
@@ -0,0 +1,22 @@
package model
import (
"time"
)
type Notification struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
ExternalID string `gorm:"size:100;unique;index" json:"external_id"`
ReceiverID int64 `gorm:"index;not null" json:"receiver_id"`
Type string `gorm:"size:64;not null" json:"type"`
Status string `gorm:"size:32;not null;default:unread" json:"status"`
Title string `gorm:"size:255" json:"title"`
Content string `gorm:"size:1024" json:"content"`
Payload string `gorm:"type:jsonb" json:"payload"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (Notification) TableName() string {
return "notifications"
}
+15
View File
@@ -0,0 +1,15 @@
package model
type OrgNodeMeta struct {
ID int64 `gorm:"primaryKey;autoIncrement"` // org_node_id
ExternalID string `gorm:"not null;index;unique" json:"external_id"` // external org_node_id
ParentID int64 `gorm:"not null;index" json:"parent_id"` // org_node_id, root node is 0
Name string `gorm:"not null;index" json:"name"`
Path string `gorm:"type:ltree;not null;index" json:"path"` // format: n<ID>.n<ID>...
Description string `gorm:"type:text;index" json:"description"`
CreatorID int64 `gorm:"not null;index" json:"creator_id"` // user_id
}
func (OrgNodeMeta) TableName() string {
return "org_node_meta"
}
+14
View File
@@ -0,0 +1,14 @@
package model
import "time"
type RecentDocument struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
UserID int64 `gorm:"not null;index" json:"user_id"`
DocumentID int64 `gorm:"not null;index" json:"document_id"`
AccessedAt time.Time `gorm:"not null" json:"accessed_at"`
}
func (RecentDocument) TableName() string {
return "recent_documents"
}
+14
View File
@@ -0,0 +1,14 @@
package model
import "time"
type RecentTemplate struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
UserID int64 `gorm:"not null;index" json:"user_id"`
TemplateID int64 `gorm:"not null;index" json:"template_id"`
AccessedAt time.Time `gorm:"not null" json:"accessed_at"`
}
func (RecentTemplate) TableName() string {
return "recent_templates"
}
+24
View File
@@ -0,0 +1,24 @@
package model
import (
"time"
)
type Template struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
Name string `gorm:"size:100;not null" json:"name"`
Description string `gorm:"type:text" json:"description"`
DocumentType DocumentType `gorm:"column:document_type;size:20;default:'markdown'" json:"document_type"`
Content string `gorm:"type:text" json:"content"`
UserID int64 `gorm:"not null" json:"user_id"`
Scope string `gorm:"size:20;default:'private'" json:"scope"` // private, system, knowledge_base
KnowledgeBaseID *int64 `json:"knowledge_base_id"`
IsPublic bool `gorm:"default:false" json:"is_public"` // Deprecated, keep for migration
Tags []string `gorm:"serializer:json" json:"tags"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (Template) TableName() string {
return "templates"
}
+29
View File
@@ -0,0 +1,29 @@
package model
import (
"time"
"gorm.io/gorm"
)
type User struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
ExternalID string `gorm:"size:100;unique" json:"external_id"`
Username string `gorm:"size:50;not null" json:"username"`
Email string `gorm:"size:100;unique;not null" json:"email"`
PasswordHash string `gorm:"size:255;not null" json:"-"`
Nickname string `gorm:"size:50" json:"nickname"`
Avatar string `gorm:"size:255" json:"avatar"` // deprecated
AvatarObjectKey string `gorm:"size:255" json:"avatar_object_key"`
AvatarVersion int64 `gorm:"not null;default:0" json:"avatar_version"`
AvatarUpdatedAt *time.Time `json:"avatar_updated_at"`
Status int `gorm:"default:1" json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
InvitationCode *string `gorm:"size:32" json:"invitation_code"`
}
func (User) TableName() string {
return "users"
}
+13
View File
@@ -0,0 +1,13 @@
package model
type UserGroupMeta struct {
ID int64 `gorm:"primaryKey;autoIncrement"` // user_group_id
ExternalID string `gorm:"not null;index;unique" json:"external_id"` // external user_group_id
Name string `gorm:"not null;index" json:"name"`
CreatorID int64 `gorm:"not null;index" json:"creator_id"` // user_id
Description string `gorm:"type:text;index" json:"description"`
}
func (UserGroupMeta) TableName() string {
return "user_group_meta"
}