reconcile and rep ids sorted

This commit is contained in:
Miloš Jovanović 2026-09-10 12:39:36 +02:00
parent ede7884b31
commit e0911df455
5 changed files with 112 additions and 12 deletions

View file

@ -18,9 +18,18 @@ var schemaStatements = []string{
department TEXT NOT NULL,
rep_user_id INTEGER NOT NULL,
status TEXT NOT NULL,
last_user_id INTEGER,
started_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
ended_at TEXT
)`,
`CREATE TABLE IF NOT EXISTS skips (
id INTEGER PRIMARY KEY,
run_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
existing_agent INTEGER NOT NULL,
would_have_assigned INTEGER NOT NULL,
at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
)`,
`CREATE UNIQUE INDEX IF NOT EXISTS one_run_per_dept
ON runs(chapter_id, department) WHERE status = 'running'`,
`CREATE TABLE IF NOT EXISTS people (
@ -61,14 +70,14 @@ func OpenStore(path string) (*SQLStore, error) {
// ID so assignment is deterministic across runs.
func (s *SQLStore) RepsFor(chapterID int64, dept string) ([]int64, error) {
return s.userIDs(`SELECT id FROM people
WHERE is_rep = 1 AND chapter_id = ? AND department = ?
ORDER BY id`, chapterID, dept)
WHERE is_rep = 1 AND chapter_id = ? AND department = ?
ORDER BY id`, chapterID, dept)
}
func (s *SQLStore) EligibleMembers(chapterID int64, dept string) ([]int64, error) {
return s.userIDs(`SELECT id FROM people
WHERE is_eligible = 1 AND is_rep = 0 AND chapter_id = ? AND department = ?
ORDER BY id`, chapterID, dept)
WHERE is_eligible = 1 AND is_rep = 0 AND chapter_id = ? AND department = ?
ORDER BY id`, chapterID, dept)
}
func (s *SQLStore) userIDs(query string, args ...any) ([]int64, error) {
@ -179,3 +188,19 @@ func (s *SQLStore) AcquireLock(chapterID int64, dept string, repID int64) (int64
strconv.FormatInt(ts, 10))
return err
}
// LogSkip records a member left alone because they already had an agent.
// This is the manual-fix queue: nothing else records what fill-only cost.
func (s *SQLStore) LogSkip(runID, userID, existingAgent, wouldHaveAssigned int64) error {
_, err := s.db.Exec(
`INSERT INTO skips (run_id, user_id, existing_agent, would_have_assigned)
VALUES (?, ?, ?, ?)`,
runID, userID, existingAgent, wouldHaveAssigned)
return err
}
func (s *SQLStore) SetProgress(runID, lastUserID int64) error {
_, err := s.db.Exec(
`UPDATE runs SET last_user_id = ? WHERE id = ?`, lastUserID, runID)
return err
}