refactor backend packages and global db service

This commit is contained in:
2026-07-18 21:58:15 +08:00
parent 62bd3d0455
commit 7800b07d42
51 changed files with 719 additions and 647 deletions

View File

@@ -0,0 +1,39 @@
package models
import (
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
var DBService *gorm.DB
func New(dsn string) error {
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
return err
}
if err := AutoMigrate(db); err != nil {
return err
}
DBService = db
return nil
}
func AutoMigrate(database *gorm.DB) error {
return database.AutoMigrate(
&SenlinAgentUser{},
&SenlinAgentProject{},
&SenlinAgentInboxItem{},
&SenlinAgentTask{},
&SenlinAgentNote{},
&SenlinAgentSource{},
&SenlinAgentAISession{},
&SenlinAgentTag{},
&SenlinAgentProjectEvent{},
&SenlinAgentAIKey{},
&SenlinAgentAICallLog{},
&SenlinAgentTaskShare{},
)
}