Files
adamfandClaude Opus 5.5 67cb8137f9
Test and publish / test (push) Successful in 6m39s
Test and publish / publish (push) Failing after 0s
Split the job tracker out of web_server into its own app
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]>
2026-10-14 16:24:16 +01:00

74 lines
4.4 KiB
Go

package services
import (
"log"
"time"
"adam-french.co.uk/job-tracker/internal/models"
"gorm.io/gorm"
)
// SeedDatabase populates an empty database with demo content for local
// development. It is called from main only when SEED_DB=true, which the
// standalone docker-compose.yml and the main site's dev override set.
func SeedDatabase(db *gorm.DB) {
// "The profile row exists" is the whole idempotency check: if it does,
// nothing is seeded, even if the other tables were emptied.
var count int64
if db.Model(&models.JobSearchProfile{}).Count(&count); count > 0 {
log.Println("Database already has data, skipping seed")
return
}
log.Println("Seeding database with test data...")
now := time.Now()
applied := now.AddDate(0, 0, -10)
london := "London"
applications := []models.JobApplication{
{JobTitle: "Backend Engineer", Company: "Acme", Location: &london, Status: "interviewing", AppliedAt: &applied},
{JobTitle: "Platform Engineer", Company: "Globex", Status: "applied", AppliedAt: &applied},
{JobTitle: "Go Developer", Company: "Initech", Status: "saved"},
{JobTitle: "Software Engineer", Company: "Umbrella", Status: "rejected", AppliedAt: &applied},
}
db.Create(&applications)
db.Create(&[]models.JobAppReference{
{Category: "Links", Label: "GitHub", Value: "https://example.com/github", SortOrder: 0},
{Category: "Answers", Label: "Notice period", Value: "One month", SortOrder: 0},
})
// Leads, so /jobs/leads has something to show without a poll: the dev
// stack usually has no Claude key, and the scheduler is off by default.
// The sources are real public boards, so "Check now" works against them.
db.Create(&models.JobSearchProfile{
ID: jobSearchProfileID,
Profile: "Five years of backend work in Go and Python. Looking for a mid-level or senior backend or platform role, in London or remote in the UK.",
IncludeKeywords: "engineer\ndeveloper",
ExcludeKeywords: "intern\nmanager",
Locations: "london\nremote",
MinScore: 60,
})
sources := []models.JobSource{
{Kind: SourceGreenhouse, Label: "Monzo", Token: "monzo", Enabled: true},
{Kind: SourceAshby, Label: "Ramp", Token: "ramp", Enabled: false},
}
db.Create(&sources)
high, mid, low := 86, 64, 35
highWhy := "Your Go and platform experience matches the core requirements; no payments background."
midWhy := "Backend fit is good, but the role wants Kotlin, which your profile does not mention."
lowWhy := "The role is a staff-level position leading several teams, above the level you are after."
posted := now.AddDate(0, 0, -3)
leads := []models.JobLead{
{SourceID: sources[0].ID, SourceKind: SourceGreenhouse, ExternalID: "monzo/seed-1", JobTitle: "Backend Engineer, Platform", Company: "Monzo", Location: "London or Remote (UK)", URL: "https://example.com/jobs/1", Description: "We are looking for a backend engineer to join our platform team.\n\nYou will build and run Go services.", PostedAt: &posted, LastSeenAt: now, Matched: true, State: LeadNew, Score: &high, ScoreReasons: &highWhy},
{SourceID: sources[0].ID, SourceKind: SourceGreenhouse, ExternalID: "monzo/seed-2", JobTitle: "Senior Backend Engineer", Company: "Monzo", Location: "London", URL: "https://example.com/jobs/2", Description: "Kotlin services at scale.", LastSeenAt: now, Matched: true, State: LeadNew, Score: &mid, ScoreReasons: &midWhy},
{SourceID: sources[0].ID, SourceKind: SourceGreenhouse, ExternalID: "monzo/seed-3", JobTitle: "Staff Engineer", Company: "Monzo", Location: "London", URL: "https://example.com/jobs/3", LastSeenAt: now, Matched: true, State: LeadNew, Score: &low, ScoreReasons: &lowWhy},
{SourceID: sources[0].ID, SourceKind: SourceGreenhouse, ExternalID: "monzo/seed-4", JobTitle: "Software Engineer, Data", Company: "Monzo", Location: "Remote (UK)", URL: "https://example.com/jobs/4", LastSeenAt: now, Matched: true, State: LeadNew},
{SourceID: sources[0].ID, SourceKind: SourceGreenhouse, ExternalID: "monzo/seed-5", JobTitle: "Account Executive", Company: "Monzo", Location: "London", URL: "https://example.com/jobs/5", LastSeenAt: now, Matched: false, State: LeadNew},
{SourceID: sources[0].ID, SourceKind: SourceGreenhouse, ExternalID: "monzo/seed-6", JobTitle: "Android Engineer", Company: "Monzo", Location: "London", URL: "https://example.com/jobs/6", LastSeenAt: now, Matched: true, State: LeadDismissed, Score: &low},
}
db.Create(&leads)
log.Println("Database seeded successfully")
}