refactor: update config structure and data layer for Watermill CQRS

This commit is contained in:
向宁 2026-05-25 20:33:20 +08:00
parent 11315fd00b
commit 1cd46bc6db
2 changed files with 45 additions and 33 deletions

View File

@ -1,21 +1,21 @@
server: server:
http: http:
addr: 0.0.0.0:8080 addr: 0.0.0.0:8090
timeout: 30s timeout: 30s
grpc: grpc:
addr: 0.0.0.0:9000 addr: 0.0.0.0:9090
timeout: 30s timeout: 30s
data: data:
database: database:
driver: postgres driver: postgres
source: "postgres://postgres:postgres@localhost:5432/file_system?sslmode=disable" source: "postgres://rag:rag123@localhost:5432/file_system?sslmode=disable"
s3: s3:
endpoint: "http://192.168.1.154:9000" endpoint: "http://localhost:9000"
access_key: "${RUSTFS_ACCESS_KEY_ID}" access_key: "minioadmin"
secret_key: "${RUSTFS_SECRET_ACCESS_KEY}" secret_key: "minioadmin"
region: "us-east-1" region: "us-east-1"
auth: auth:
jwt_key: "RagJwtSecretKey2026MustBeAtLeast32CharsLong!" jwt_key: "RagJwtSecretKey2026MustBeAtLeast32CharsLong!"
grpc_addr: "rag-backend:50051" grpc_addr: "localhost:50051"

View File

@ -83,44 +83,56 @@ var ProviderSet = wire.NewSet(NewData, NewFileRepo, NewFolderRepo, NewFileMetaRe
// FolderPO maps to the "folders" table. // FolderPO maps to the "folders" table.
type FolderPO struct { type FolderPO struct {
ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid();comment:主键ID"`
ParentID *string `gorm:"type:uuid;index:idx_folders_parent"` ParentID *string `gorm:"type:uuid;index:idx_folders_parent;comment:父文件夹ID"`
Name string `gorm:"type:varchar(255);not null"` Name string `gorm:"type:varchar(255);not null;comment:文件夹名称"`
OwnerID string `gorm:"type:varchar(36);not null;index:idx_folders_owner"` OwnerID string `gorm:"type:varchar(36);not null;index:idx_folders_owner;comment:所有者ID"`
CreatedAt time.Time `gorm:"autoCreateTime"` CreatedBy string `gorm:"type:varchar(36);not null;default:'';comment:创建人ID"`
UpdatedAt time.Time `gorm:"autoUpdateTime"` CreatedAt time.Time `gorm:"autoCreateTime;comment:创建时间"`
UpdatedBy string `gorm:"type:varchar(36);not null;default:'';comment:更新人ID"`
UpdatedAt time.Time `gorm:"autoUpdateTime;comment:更新时间"`
IsDeleted bool `gorm:"not null;default:false;comment:是否软删除"`
OperatorIP string `gorm:"type:varchar(500);comment:操作人IP地址"`
} }
func (FolderPO) TableName() string { return "folders" } func (FolderPO) TableName() string { return "folders" }
// FileMetaPO maps to the "files" table. // FileMetaPO maps to the "files" table.
type FileMetaPO struct { type FileMetaPO struct {
ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid();comment:主键ID"`
FolderID string `gorm:"type:uuid;index:idx_files_folder"` FolderID string `gorm:"type:uuid;index:idx_files_folder;comment:所属文件夹ID"`
Name string `gorm:"type:varchar(255);not null"` Name string `gorm:"type:varchar(255);not null;comment:文件名称"`
S3Key string `gorm:"type:varchar(512);not null;index:idx_files_s3_key"` S3Key string `gorm:"type:varchar(512);not null;index:idx_files_s3_key;comment:S3对象键"`
S3Bucket string `gorm:"type:varchar(255);not null"` S3Bucket string `gorm:"type:varchar(255);not null;comment:S3存储桶名称"`
Size int64 `gorm:"default:0"` Size int64 `gorm:"default:0;comment:文件大小(字节)"`
ContentType string `gorm:"type:varchar(255);default:'application/octet-stream'"` ContentType string `gorm:"type:varchar(255);default:'application/octet-stream';comment:文件MIME类型"`
OwnerID string `gorm:"type:varchar(36);not null;index:idx_files_owner"` OwnerID string `gorm:"type:varchar(36);not null;index:idx_files_owner;comment:所有者ID"`
CreatedAt time.Time `gorm:"autoCreateTime"` CreatedBy string `gorm:"type:varchar(36);not null;default:'';comment:创建人ID"`
UpdatedAt time.Time `gorm:"autoUpdateTime"` CreatedAt time.Time `gorm:"autoCreateTime;comment:创建时间"`
UpdatedBy string `gorm:"type:varchar(36);not null;default:'';comment:更新人ID"`
UpdatedAt time.Time `gorm:"autoUpdateTime;comment:更新时间"`
IsDeleted bool `gorm:"not null;default:false;comment:是否软删除"`
OperatorIP string `gorm:"type:varchar(500);comment:操作人IP地址"`
} }
func (FileMetaPO) TableName() string { return "files" } func (FileMetaPO) TableName() string { return "files" }
// ShareLinkPO maps to the "share_links" table. // ShareLinkPO maps to the "share_links" table.
type ShareLinkPO struct { type ShareLinkPO struct {
ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid();comment:主键ID"`
ResourceType string `gorm:"type:varchar(10);not null"` ResourceType string `gorm:"type:varchar(10);not null;comment:资源类型folder/file"`
ResourceID string `gorm:"type:uuid;not null"` ResourceID string `gorm:"type:uuid;not null;comment:资源ID"`
Token string `gorm:"type:varchar(32);not null;uniqueIndex:idx_share_token"` Token string `gorm:"type:varchar(32);not null;uniqueIndex:idx_share_token;comment:分享令牌"`
Password *string `gorm:"type:varchar(255)"` Password *string `gorm:"type:varchar(255);comment:访问密码"`
ExpiresAt *time.Time `gorm:"type:timestamptz"` ExpiresAt *time.Time `gorm:"type:timestamptz;comment:过期时间"`
DownloadCount int `gorm:"default:0"` DownloadCount int `gorm:"default:0;comment:下载次数"`
MaxDownloads *int MaxDownloads *int `gorm:"comment:最大下载次数"`
CreatedBy string `gorm:"type:varchar(36);not null"` CreatedBy string `gorm:"type:varchar(36);not null;comment:创建人ID"`
CreatedAt time.Time `gorm:"autoCreateTime"` CreatedAt time.Time `gorm:"autoCreateTime;comment:创建时间"`
UpdatedBy string `gorm:"type:varchar(36);not null;default:'';comment:更新人ID"`
UpdatedAt time.Time `gorm:"autoUpdateTime;comment:更新时间"`
IsDeleted bool `gorm:"not null;default:false;comment:是否软删除"`
OperatorIP string `gorm:"type:varchar(500);comment:操作人IP地址"`
} }
func (ShareLinkPO) TableName() string { return "share_links" } func (ShareLinkPO) TableName() string { return "share_links" }