42 lines
739 B
Go
42 lines
739 B
Go
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{},
|
|
&SenlinAgentProjectChannel{},
|
|
&SenlinAgentCronPlan{},
|
|
&SenlinAgentProjectEvent{},
|
|
&SenlinAgentAIKey{},
|
|
&SenlinAgentAICallLog{},
|
|
&SenlinAgentTaskShare{},
|
|
)
|
|
}
|