From 1578c81a8950a95869260a9da42aa2f53699a8a1 Mon Sep 17 00:00:00 2001 From: yanweidong Date: Fri, 24 Jul 2026 12:20:39 +0800 Subject: [PATCH] refactor(documents): split document models --- backend/internal/models/document.go | 83 +++++---------------- backend/internal/models/document_blob.go | 18 +++++ backend/internal/models/document_content.go | 15 ++++ backend/internal/models/document_share.go | 19 +++++ 4 files changed, 72 insertions(+), 63 deletions(-) create mode 100644 backend/internal/models/document_blob.go create mode 100644 backend/internal/models/document_content.go create mode 100644 backend/internal/models/document_share.go diff --git a/backend/internal/models/document.go b/backend/internal/models/document.go index 043b1dc..ac0aca8 100644 --- a/backend/internal/models/document.go +++ b/backend/internal/models/document.go @@ -12,26 +12,26 @@ const ( ) type SaDocument struct { - ID uint `gorm:"primaryKey"` - Identity string `gorm:"type:char(36);uniqueIndex"` - ProjectID uint `gorm:"index;not null;uniqueIndex:uidx_sa_document_sibling,priority:1"` - ProjectIdentity string `gorm:"type:char(36);index"` - ParentID *uint `gorm:"index"` - ParentIdentity *string `gorm:"type:char(36);index"` - ParentScope string `gorm:"type:char(36);not null;default:'';uniqueIndex:uidx_sa_document_sibling,priority:2"` - CreatedBy uint `gorm:"index;not null"` - CreatedByIdentity string `gorm:"type:char(36);index"` - SourceInboxItemID *uint `gorm:"index"` - SourceInboxItemIdentity *string `gorm:"type:char(36);index"` - Kind string `gorm:"size:16;not null"` - Name string `gorm:"not null"` - NormalizedName string `gorm:"not null;uniqueIndex:uidx_sa_document_sibling,priority:3"` - Extension string `gorm:"size:32"` - MimeType string `gorm:"size:255"` - Size int64 `gorm:"not null;default:0"` - Revision uint64 `gorm:"not null;default:1"` - SortOrder int `gorm:"not null;default:0"` - ScanStatus string `gorm:"size:24;not null;default:'not_scanned'"` + ID uint `gorm:"primaryKey"` + Identity string `gorm:"type:char(36);uniqueIndex"` + ProjectID uint `gorm:"index;not null;uniqueIndex:uidx_sa_document_sibling,priority:1"` + ProjectIdentity string `gorm:"type:char(36);index"` + ParentID *uint `gorm:"index"` + ParentIdentity *string `gorm:"type:char(36);index"` + ParentScope string `gorm:"type:char(36);not null;default:'';uniqueIndex:uidx_sa_document_sibling,priority:2"` + CreatedBy uint `gorm:"index;not null"` + CreatedByIdentity string `gorm:"type:char(36);index"` + SourceInboxItemID *uint `gorm:"index"` + SourceInboxItemIdentity *string `gorm:"type:char(36);index"` + Kind string `gorm:"size:16;not null"` + Name string `gorm:"not null"` + NormalizedName string `gorm:"not null;uniqueIndex:uidx_sa_document_sibling,priority:3"` + Extension string `gorm:"size:32"` + MimeType string `gorm:"size:255"` + Size int64 `gorm:"not null;default:0"` + Revision uint64 `gorm:"not null;default:1"` + SortOrder int `gorm:"not null;default:0"` + ScanStatus string `gorm:"size:24;not null;default:'not_scanned'"` CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` @@ -40,46 +40,3 @@ type SaDocument struct { func (SaDocument) TableName() string { return "sa_documents" } - -type SaDocumentContent struct { - ID uint `gorm:"primaryKey"` - DocumentID uint `gorm:"uniqueIndex;not null"` - Markdown string `gorm:"type:text"` - CreatedAt time.Time - UpdatedAt time.Time -} - -func (SaDocumentContent) TableName() string { - return "sa_document_contents" -} - -type SaDocumentBlob struct { - ID uint `gorm:"primaryKey"` - DocumentID uint `gorm:"uniqueIndex;not null"` - StorageKey string `gorm:"size:64;uniqueIndex;not null"` - RelativePath string `gorm:"not null"` - OriginalName string `gorm:"not null"` - Checksum string `gorm:"size:64;not null"` - CreatedAt time.Time - UpdatedAt time.Time -} - -func (SaDocumentBlob) TableName() string { - return "sa_document_blobs" -} - -type SaDocumentShare struct { - ID uint `gorm:"primaryKey"` - Identity string `gorm:"type:char(36);uniqueIndex"` - DocumentID uint `gorm:"index;not null"` - DocumentIdentity string `gorm:"type:char(36);index"` - CreatedBy uint `gorm:"index;not null"` - TokenHash string `gorm:"size:64;uniqueIndex;not null"` - ExpiresAt time.Time `gorm:"index;not null"` - RevokedAt *time.Time `gorm:"index"` - CreatedAt time.Time -} - -func (SaDocumentShare) TableName() string { - return "sa_document_shares" -} diff --git a/backend/internal/models/document_blob.go b/backend/internal/models/document_blob.go new file mode 100644 index 0000000..4bb3978 --- /dev/null +++ b/backend/internal/models/document_blob.go @@ -0,0 +1,18 @@ +package models + +import "time" + +type SaDocumentBlob struct { + ID uint `gorm:"primaryKey"` + DocumentID uint `gorm:"uniqueIndex;not null"` + StorageKey string `gorm:"size:64;uniqueIndex;not null"` + RelativePath string `gorm:"not null"` + OriginalName string `gorm:"not null"` + Checksum string `gorm:"size:64;not null"` + CreatedAt time.Time + UpdatedAt time.Time +} + +func (SaDocumentBlob) TableName() string { + return "sa_document_blobs" +} diff --git a/backend/internal/models/document_content.go b/backend/internal/models/document_content.go new file mode 100644 index 0000000..edb01eb --- /dev/null +++ b/backend/internal/models/document_content.go @@ -0,0 +1,15 @@ +package models + +import "time" + +type SaDocumentContent struct { + ID uint `gorm:"primaryKey"` + DocumentID uint `gorm:"uniqueIndex;not null"` + Markdown string `gorm:"type:text"` + CreatedAt time.Time + UpdatedAt time.Time +} + +func (SaDocumentContent) TableName() string { + return "sa_document_contents" +} diff --git a/backend/internal/models/document_share.go b/backend/internal/models/document_share.go new file mode 100644 index 0000000..21d5108 --- /dev/null +++ b/backend/internal/models/document_share.go @@ -0,0 +1,19 @@ +package models + +import "time" + +type SaDocumentShare struct { + ID uint `gorm:"primaryKey"` + Identity string `gorm:"type:char(36);uniqueIndex"` + DocumentID uint `gorm:"index;not null"` + DocumentIdentity string `gorm:"type:char(36);index"` + CreatedBy uint `gorm:"index;not null"` + TokenHash string `gorm:"size:64;uniqueIndex;not null"` + ExpiresAt time.Time `gorm:"index;not null"` + RevokedAt *time.Time `gorm:"index"` + CreatedAt time.Time +} + +func (SaDocumentShare) TableName() string { + return "sa_document_shares" +}