refactor backend packages and global db service
This commit is contained in:
39
backend/internal/models/new.go
Normal file
39
backend/internal/models/new.go
Normal 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{},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user