From 1cd46bc6db919c76079684c6a467693f697088d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E5=AE=81?= <1772105645@qq.com> Date: Mon, 25 May 2026 20:33:20 +0800 Subject: [PATCH] refactor: update config structure and data layer for Watermill CQRS --- configs/config.yaml | 14 +++++----- internal/data/data.go | 64 +++++++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/configs/config.yaml b/configs/config.yaml index a747517..a8b0a46 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -1,21 +1,21 @@ server: http: - addr: 0.0.0.0:8080 + addr: 0.0.0.0:8090 timeout: 30s grpc: - addr: 0.0.0.0:9000 + addr: 0.0.0.0:9090 timeout: 30s data: database: driver: postgres - source: "postgres://postgres:postgres@localhost:5432/file_system?sslmode=disable" + source: "postgres://rag:rag123@localhost:5432/file_system?sslmode=disable" s3: - endpoint: "http://192.168.1.154:9000" - access_key: "${RUSTFS_ACCESS_KEY_ID}" - secret_key: "${RUSTFS_SECRET_ACCESS_KEY}" + endpoint: "http://localhost:9000" + access_key: "minioadmin" + secret_key: "minioadmin" region: "us-east-1" auth: jwt_key: "RagJwtSecretKey2026MustBeAtLeast32CharsLong!" - grpc_addr: "rag-backend:50051" + grpc_addr: "localhost:50051" diff --git a/internal/data/data.go b/internal/data/data.go index 1769917..478968b 100644 --- a/internal/data/data.go +++ b/internal/data/data.go @@ -83,44 +83,56 @@ var ProviderSet = wire.NewSet(NewData, NewFileRepo, NewFolderRepo, NewFileMetaRe // FolderPO maps to the "folders" table. type FolderPO struct { - ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` - ParentID *string `gorm:"type:uuid;index:idx_folders_parent"` - Name string `gorm:"type:varchar(255);not null"` - OwnerID string `gorm:"type:varchar(36);not null;index:idx_folders_owner"` - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` + ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid();comment:主键ID"` + ParentID *string `gorm:"type:uuid;index:idx_folders_parent;comment:父文件夹ID"` + Name string `gorm:"type:varchar(255);not null;comment:文件夹名称"` + OwnerID string `gorm:"type:varchar(36);not null;index:idx_folders_owner;comment:所有者ID"` + CreatedBy string `gorm:"type:varchar(36);not null;default:'';comment:创建人ID"` + 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" } // FileMetaPO maps to the "files" table. type FileMetaPO struct { - ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` - FolderID string `gorm:"type:uuid;index:idx_files_folder"` - Name string `gorm:"type:varchar(255);not null"` - S3Key string `gorm:"type:varchar(512);not null;index:idx_files_s3_key"` - S3Bucket string `gorm:"type:varchar(255);not null"` - Size int64 `gorm:"default:0"` - ContentType string `gorm:"type:varchar(255);default:'application/octet-stream'"` - OwnerID string `gorm:"type:varchar(36);not null;index:idx_files_owner"` - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` + ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid();comment:主键ID"` + FolderID string `gorm:"type:uuid;index:idx_files_folder;comment:所属文件夹ID"` + Name string `gorm:"type:varchar(255);not null;comment:文件名称"` + S3Key string `gorm:"type:varchar(512);not null;index:idx_files_s3_key;comment:S3对象键"` + S3Bucket string `gorm:"type:varchar(255);not null;comment:S3存储桶名称"` + Size int64 `gorm:"default:0;comment:文件大小(字节)"` + ContentType string `gorm:"type:varchar(255);default:'application/octet-stream';comment:文件MIME类型"` + OwnerID string `gorm:"type:varchar(36);not null;index:idx_files_owner;comment:所有者ID"` + CreatedBy string `gorm:"type:varchar(36);not null;default:'';comment:创建人ID"` + 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" } // ShareLinkPO maps to the "share_links" table. type ShareLinkPO struct { - ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` - ResourceType string `gorm:"type:varchar(10);not null"` - ResourceID string `gorm:"type:uuid;not null"` - Token string `gorm:"type:varchar(32);not null;uniqueIndex:idx_share_token"` - Password *string `gorm:"type:varchar(255)"` - ExpiresAt *time.Time `gorm:"type:timestamptz"` - DownloadCount int `gorm:"default:0"` - MaxDownloads *int - CreatedBy string `gorm:"type:varchar(36);not null"` - CreatedAt time.Time `gorm:"autoCreateTime"` + ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid();comment:主键ID"` + ResourceType string `gorm:"type:varchar(10);not null;comment:资源类型(folder/file)"` + ResourceID string `gorm:"type:uuid;not null;comment:资源ID"` + Token string `gorm:"type:varchar(32);not null;uniqueIndex:idx_share_token;comment:分享令牌"` + Password *string `gorm:"type:varchar(255);comment:访问密码"` + ExpiresAt *time.Time `gorm:"type:timestamptz;comment:过期时间"` + DownloadCount int `gorm:"default:0;comment:下载次数"` + MaxDownloads *int `gorm:"comment:最大下载次数"` + CreatedBy string `gorm:"type:varchar(36);not null;comment:创建人ID"` + 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" }