Files
skillfactor-pipeline/pipeline/migrate_mssql.py
skillfactor-pipeline 63c325baf1 feat(batch): full-catalog batch runner + MSSQL migration
- batch_run.py: implement all 4 TODO stubs (esco_occupations, stage_packages,
  stage_evidence, stage_tier) — resumable, budget-capped, QA-gated
- p2_generate.py: add all_occupations() (LEFT JOIN, all 3039 ESCO occupations);
  gen_package handles None onet_id for ESCO-only occupations gracefully
- p3b_store_evidence.py: add store_for_occupation(cn, ads_dict, extractions, slug)
  with deadlock retry; ensure_schema for fresh installs
- p3c_aggregate.py: add aggregate_for_occupation(cn, slug, skills_dir) with
  deadlock retry; _write_market_report parameterized by slug
- migrate_mssql.py: idempotent ALTER TABLE adding occupation_slug + index
- data/evidence/recruitment-consultant.jsonl: recruiter evidence in per-slug format
- Smoke-tested: 3039 occupations load, gen_package OK for no-onet case, stage_tier correct
2026-07-07 12:52:38 +02:00

41 lines
1.3 KiB
Python

"""Apply the evidence_job schema change from batch-architecture.md §MSSQL.
Run once. Idempotent: checks whether occupation_slug already exists before
adding it, so re-running is safe.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
from db import connect
def main():
cn = connect()
cur = cn.cursor()
cur.execute("""
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='evidence_job' AND COLUMN_NAME='occupation_slug'
""")
if cur.fetchone()[0]:
print("occupation_slug already present — skipping DDL")
else:
cur.execute("ALTER TABLE evidence_job ADD occupation_slug NVARCHAR(200) NULL")
cur.execute(
"UPDATE evidence_job SET occupation_slug = 'recruitment-consultant' "
"WHERE occupation_slug IS NULL"
)
cur.execute("CREATE INDEX ix_evidence_job_occ ON evidence_job(occupation_slug)")
cn.commit()
print("evidence_job.occupation_slug added and backfilled (350 rows -> 'recruitment-consultant')")
cnt = cur.execute(
"SELECT COUNT(*) FROM evidence_job WHERE occupation_slug='recruitment-consultant'"
).fetchone()[0]
print(f"Rows with occupation_slug='recruitment-consultant': {cnt}")
cn.close()
if __name__ == "__main__":
main()