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,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 {
|
||||
|
||||
Reference in New Issue
Block a user