🐛 Fixed data migration issues
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user