Merge branch 'worktree-agent-afad54f12aef2cccf'
# Conflicts: # app/storage/schema.py # app/storage/store.py # tests/test_storage.py
This commit is contained in:
commit
706b127bc0
10 files changed
+459
-37
No files matched your search
@@ -377,12 +377,58 @@ ALTER TABLE companies ADD COLUMN ats_slug TEXT NOT NULL DEFAULT '';
|
||||
"""),
|
||||
(10, "roles.posted_at: recency and the newest feed count from when a role "
|
||||
"was posted, not just when the app found it", _migrate_posted_at),
|
||||
# A Python step, not SQL: classify() lives in plugins/ats.py, and running
|
||||
# its current rules is the whole point (see _recompute_function below).
|
||||
(11, "roles.function recomputed for every not-yet-extracted role, word-boundary "
|
||||
"classifier fix", lambda conn: _recompute_function(conn)),
|
||||
)
|
||||
|
||||
#: What a file created from `SCHEMA` today is already at.
|
||||
LATEST = MIGRATIONS[-1][0]
|
||||
|
||||
|
||||
def _recompute_function(conn: sqlite3.Connection) -> None:
|
||||
"""Migration 11's step. `roles.function` used to be filled by a keyword
|
||||
classifier that matched substrings (" it" inside "Italy"), never
|
||||
returned '' (only "other", outside the declared vocabulary) and checked
|
||||
department before title; `plugins.ats.classify` no longer does any of
|
||||
that (see its own docstring). A role `extract` has already read keeps
|
||||
whatever it decided — `function` is extract's from then on, see
|
||||
`Store.set_extracted` — so only roles with no `extracted_at` are
|
||||
recomputed here, from their stored title and department (department
|
||||
lives in `raw`, not its own column: docs/decisions.md, "raw is
|
||||
transport, columns are storage").
|
||||
|
||||
A Python step because the classifier is Python, not SQL; `plugins` is a
|
||||
top-level package outside `app`'s own tree, so it is reached the same
|
||||
way `app/jobs/extract.py` reaches `FUNCTIONS`: inserted onto `sys.path`
|
||||
rather than imported as an installed dependency, since `plugins` is not
|
||||
in `pyproject.toml`'s packages."""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
if str(root) not in sys.path:
|
||||
sys.path.insert(0, str(root))
|
||||
from plugins.ats import classify
|
||||
|
||||
rows = conn.execute(
|
||||
"SELECT uid, title, raw, function FROM roles WHERE extracted_at IS NULL").fetchall()
|
||||
updates = []
|
||||
for uid, title, raw, old in rows:
|
||||
try:
|
||||
department = json.loads(raw or "{}").get("department") or ""
|
||||
except (TypeError, ValueError):
|
||||
department = ""
|
||||
new = classify(department, title)
|
||||
if new != old:
|
||||
updates.append((new, uid))
|
||||
if updates:
|
||||
conn.executemany("UPDATE roles SET function = ? WHERE uid = ?", updates)
|
||||
log.info("migration 11: recomputed function for %d of %d not-yet-extracted roles",
|
||||
len(updates), len(rows))
|
||||
|
||||
|
||||
def user_version(conn: sqlite3.Connection) -> int:
|
||||
return int(conn.execute("PRAGMA user_version").fetchone()[0])
|
||||
|
||||
|
||||
Reference in new issue
Block a user