🐛 Fixed data migration issues

This commit is contained in:
2025-11-14 20:16:16 +08:00
parent dec3ef5ef4
commit 1d7aee4cea
7 changed files with 2503 additions and 104 deletions

View File

@@ -132,29 +132,9 @@ func (ds *DatabaseService) registerAllModels() {
// ServiceStartup initializes the service when the application starts
func (ds *DatabaseService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
ds.ctx = ctx
ds.cancelObserver = ds.configService.Watch("general.dataPath", ds.onDataPathChange)
return ds.initDatabase()
}
// onDataPathChange 数据路径配置变更回调
func (ds *DatabaseService) onDataPathChange(oldValue, newValue interface{}) {
oldPath := ""
newPath := ""
if oldValue != nil {
oldPath = fmt.Sprintf("%v", oldValue)
}
if newValue != nil {
newPath = fmt.Sprintf("%v", newValue)
}
if oldPath != newPath {
_ = ds.OnDataPathChanged()
}
}
// initDatabase initializes the SQLite database
func (ds *DatabaseService) initDatabase() error {
dbPath, err := ds.getDatabasePath()
@@ -399,16 +379,3 @@ func (ds *DatabaseService) ServiceShutdown() error {
}
return nil
}
// OnDataPathChanged handles data path changes
func (ds *DatabaseService) OnDataPathChanged() error {
// 关闭当前连接
if ds.db != nil {
if err := ds.db.Close(); err != nil {
return err
}
}
// 用新路径重新初始化
return ds.initDatabase()
}