feat: enhance system information display with database version
- Added `db_version` field to the `SystemInfo` interface to expose the current database migration version. - Updated the system information response to include the database version, reflecting its state during application runtime. - Enhanced the UI in the SystemInfo component to display the database version with appropriate labels and descriptions in multiple languages. This update improves transparency regarding the database state within the system information settings.
This commit is contained in:
@@ -5,7 +5,7 @@ tmp_dir = "tmp"
|
||||
[build]
|
||||
args_bin = []
|
||||
bin = "./tmp/main"
|
||||
cmd = "CGO_CFLAGS='-Wno-deprecated-declarations -Wno-gnu-folding-constant' CGO_LDFLAGS='-Wl,-no_warn_duplicate_libraries' go build -ldflags=\"-X 'google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn'\" -o ./tmp/main ./cmd/server"
|
||||
cmd = "CGO_CFLAGS='-Wno-deprecated-declarations -Wno-gnu-folding-constant' CGO_LDFLAGS='-Wl,-no_warn_duplicate_libraries' go build -ldflags=\"$(./scripts/get_version.sh ldflags) -X 'google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn'\" -o ./tmp/main ./cmd/server"
|
||||
delay = 1000
|
||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "frontend", "migrations", "node_modules", "docs"]
|
||||
exclude_file = []
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface SystemInfo {
|
||||
vector_store_engine?: string
|
||||
graph_database_engine?: string
|
||||
minio_enabled?: boolean
|
||||
db_version?: string
|
||||
}
|
||||
|
||||
export interface ToolDefinition {
|
||||
|
||||
@@ -1698,6 +1698,8 @@ export default {
|
||||
buildTimeDescription: 'Time when the system was built',
|
||||
goVersionLabel: 'Go Version',
|
||||
goVersionDescription: 'Go language version used by the backend',
|
||||
dbVersionLabel: 'Database Version',
|
||||
dbVersionDescription: 'Current database migration version',
|
||||
keywordIndexEngineLabel: 'Keyword Index Engine',
|
||||
keywordIndexEngineDescription: 'Currently used keyword index engine',
|
||||
vectorStoreEngineLabel: 'Vector Store Engine',
|
||||
|
||||
@@ -1194,6 +1194,8 @@ export default {
|
||||
buildTimeDescription: "시스템이 빌드된 시간",
|
||||
goVersionLabel: "Go 버전",
|
||||
goVersionDescription: "백엔드에서 사용하는 Go 언어 버전",
|
||||
dbVersionLabel: "데이터베이스 버전",
|
||||
dbVersionDescription: "현재 데이터베이스 마이그레이션 버전",
|
||||
keywordIndexEngineLabel: "키워드 인덱스 엔진",
|
||||
keywordIndexEngineDescription: "현재 사용 중인 키워드 인덱스 엔진",
|
||||
vectorStoreEngineLabel: "벡터 저장소 엔진",
|
||||
|
||||
@@ -815,6 +815,8 @@ export default {
|
||||
buildTimeDescription: 'Время, когда система была собрана',
|
||||
goVersionLabel: 'Версия Go',
|
||||
goVersionDescription: 'Версия языка Go, используемая backend',
|
||||
dbVersionLabel: 'Версия базы данных',
|
||||
dbVersionDescription: 'Текущая версия миграции базы данных',
|
||||
keywordIndexEngineLabel: 'Движок индексации ключевых слов',
|
||||
keywordIndexEngineDescription: 'Используемый в настоящее время движок индексации ключевых слов',
|
||||
vectorStoreEngineLabel: 'Движок векторного хранилища',
|
||||
|
||||
@@ -1174,6 +1174,8 @@ export default {
|
||||
buildTimeDescription: "系统构建的时间",
|
||||
goVersionLabel: "Go 版本",
|
||||
goVersionDescription: "后端使用的 Go 语言版本",
|
||||
dbVersionLabel: "数据库版本",
|
||||
dbVersionDescription: "当前数据库迁移版本号",
|
||||
keywordIndexEngineLabel: "关键词索引引擎",
|
||||
keywordIndexEngineDescription: "当前使用的关键词索引引擎",
|
||||
vectorStoreEngineLabel: "向量存储引擎",
|
||||
|
||||
@@ -67,6 +67,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DB Version -->
|
||||
<div v-if="systemInfo?.db_version" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('system.dbVersionLabel') }}</label>
|
||||
<p class="desc">{{ $t('system.dbVersionDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ systemInfo.db_version }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Keyword Index Engine -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
@@ -13,6 +14,27 @@ import (
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
)
|
||||
|
||||
var (
|
||||
currentMigrationVersion uint
|
||||
currentMigrationDirty bool
|
||||
migrationVersionOnce sync.Once
|
||||
migrationVersionSet bool
|
||||
)
|
||||
|
||||
// CachedMigrationVersion returns the migration version captured at startup.
|
||||
// Returns (version, dirty, ok). ok is false if the version was never captured.
|
||||
func CachedMigrationVersion() (uint, bool, bool) {
|
||||
return currentMigrationVersion, currentMigrationDirty, migrationVersionSet
|
||||
}
|
||||
|
||||
func setMigrationVersion(version uint, dirty bool) {
|
||||
migrationVersionOnce.Do(func() {
|
||||
currentMigrationVersion = version
|
||||
currentMigrationDirty = dirty
|
||||
migrationVersionSet = true
|
||||
})
|
||||
}
|
||||
|
||||
// RunMigrations executes all pending database migrations
|
||||
// This should be called during application startup
|
||||
func RunMigrations(dsn string) error {
|
||||
@@ -142,6 +164,8 @@ func RunMigrationsWithOptions(dsn string, opts MigrationOptions) error {
|
||||
return fmt.Errorf("failed to get migration version: %w", err)
|
||||
}
|
||||
|
||||
setMigrationVersion(version, dirty)
|
||||
|
||||
if oldVersion != version {
|
||||
logger.Infof(ctx, "Database migrated from version %d to %d", oldVersion, version)
|
||||
} else {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/application/service/file"
|
||||
"github.com/Tencent/WeKnora/internal/config"
|
||||
"github.com/Tencent/WeKnora/internal/database"
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser"
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
@@ -48,6 +49,7 @@ type GetSystemInfoResponse struct {
|
||||
VectorStoreEngine string `json:"vector_store_engine,omitempty"`
|
||||
GraphDatabaseEngine string `json:"graph_database_engine,omitempty"`
|
||||
MinioEnabled bool `json:"minio_enabled,omitempty"`
|
||||
DBVersion string `json:"db_version,omitempty"`
|
||||
}
|
||||
|
||||
// 编译时注入的版本信息
|
||||
@@ -82,6 +84,14 @@ func (h *SystemHandler) GetSystemInfo(c *gin.Context) {
|
||||
// Get MinIO enabled status
|
||||
minioEnabled := h.isMinioConfigured(c)
|
||||
|
||||
var dbVersion string
|
||||
if ver, dirty, ok := database.CachedMigrationVersion(); ok {
|
||||
dbVersion = fmt.Sprintf("%d", ver)
|
||||
if dirty {
|
||||
dbVersion += " (dirty)"
|
||||
}
|
||||
}
|
||||
|
||||
response := GetSystemInfoResponse{
|
||||
Version: Version,
|
||||
Edition: Edition,
|
||||
@@ -92,6 +102,7 @@ func (h *SystemHandler) GetSystemInfo(c *gin.Context) {
|
||||
VectorStoreEngine: vectorStoreEngine,
|
||||
GraphDatabaseEngine: graphDatabaseEngine,
|
||||
MinioEnabled: minioEnabled,
|
||||
DBVersion: dbVersion,
|
||||
}
|
||||
|
||||
logger.Info(ctx, "System info retrieved successfully")
|
||||
|
||||
+2
-1
@@ -282,7 +282,8 @@ start_app() {
|
||||
log_info "未检测到 Air,使用普通模式启动"
|
||||
log_warning "提示: 安装 Air 可以实现代码修改后自动重启"
|
||||
log_info "安装命令: go install github.com/air-verse/air@latest"
|
||||
go run -ldflags="-X 'google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn'" cmd/server/main.go
|
||||
LDFLAGS="$(./scripts/get_version.sh ldflags) -X 'google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn'"
|
||||
go run -ldflags="$LDFLAGS" cmd/server/main.go
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user