All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 4m40s
Background poller fetches emails via IMAP or Microsoft Graph API, classifies them with Claude Haiku, and creates/updates JobApplication records automatically. Includes manual sync endpoint and OAuth callback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
package services
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"adam-french.co.uk/backend/models"
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type SQLConfig struct {
|
|
User string
|
|
Password string
|
|
DBName string
|
|
Host string
|
|
Port string
|
|
}
|
|
|
|
func connectToPostgreSQL(config *SQLConfig) (*gorm.DB, error) {
|
|
dsn := fmt.Sprintf(
|
|
"user=%s password=%s dbname=%s host=%s port=%s sslmode=disable",
|
|
config.User, config.Password, config.DBName, config.Host, config.Port,
|
|
)
|
|
|
|
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return db, nil
|
|
}
|
|
|
|
func migrateDatabase(db *gorm.DB) error {
|
|
err := db.AutoMigrate(
|
|
&models.User{},
|
|
&models.Post{},
|
|
&models.Activity{},
|
|
&models.Favorite{},
|
|
&models.Rowing{},
|
|
&models.Message{},
|
|
&models.JobApplication{},
|
|
&models.JobAppReference{},
|
|
&models.Bookmark{},
|
|
&models.ProcessedEmail{},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func InitDatabase(config *SQLConfig) (*gorm.DB, error) {
|
|
db, err := connectToPostgreSQL(config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = migrateDatabase(db)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return db, nil
|
|
}
|