The applications tracker, leads inbox, email pipeline and capture userscript move here from web_server's backend, Python service and Vue app, as one Go binary that serves its own Vue SPA under /jobs/. - The Go services, resolvers and tests move over almost unchanged. - The three Claude calls are ported from Python to Go (internal/claude), with the same prompts, per-model request shaping and error messages. - There is no login: internal/auth asks the site backend's /auth/validate-admin with the visitor's cookies, and relays refreshed cookies back. - A Settings page replaces the admin-panel capture token card and adds the Microsoft sign-in link and a manual email sync. - The userscript is 2.0.0, at /jobs/, and migrates a saved API base. - Dockerfile, a standalone compose with Postgres, Makefile, and a Gitea CI workflow that tests and publishes the image. Co-Authored-By: Claude Opus 5.5 <[email protected]>
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package services
|
|
|
|
import (
|
|
"adam-french.co.uk/job-tracker/internal/models"
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// migrateDatabase brings the schema up to date. There are no migration
|
|
// files: GORM's AutoMigrate is the only schema source, so it will add tables,
|
|
// columns and indexes but never drop or rename anything. Removing a field
|
|
// from a model therefore leaves the column behind, and a renamed field
|
|
// appears as a brand-new column with no data. Any model added to models.go
|
|
// must also be listed here or its table will never be created.
|
|
//
|
|
// The tables were created by the main site's backend before the tracker
|
|
// became its own app, and were copied across with pg_dump, so on a migrated
|
|
// database this finds nothing to do.
|
|
func migrateDatabase(db *gorm.DB) error {
|
|
return db.AutoMigrate(
|
|
&models.JobApplication{},
|
|
&models.JobAppReference{},
|
|
&models.ProcessedEmail{},
|
|
&models.JobSource{},
|
|
&models.JobLead{},
|
|
&models.JobSearchProfile{},
|
|
)
|
|
}
|
|
|
|
// InitDatabase connects to Postgres at dsn and runs the auto-migration. dsn
|
|
// is DATABASE_URL, in either of the forms pgx accepts
|
|
// (postgres://user:pass@host:port/db?sslmode=disable, or key=value pairs).
|
|
// sslmode=disable is fine only because Postgres is reachable exclusively on
|
|
// the private Docker network.
|
|
func InitDatabase(dsn string) (*gorm.DB, error) {
|
|
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := migrateDatabase(db); err != nil {
|
|
return nil, err
|
|
}
|
|
return db, nil
|
|
}
|