# TA-ATS — Migration & Seeder Commands

> Run from: `E:\xampp\htdocs\python\TA-ATS-interns\backend`
> One-click alternative: `database\ats_seeder_akn.bat`
> Login after seeding: **ats@admin.com / ats@2468** (all seed users share `ats@2468`)
> Last updated: **09-Jul-2026** (added LLM/AI-Ranking, Interview rounds R2/R3, LinkedIn posting, Login History, Notifications, Comments).

---

## 0. One-time: environment config (`backend/.env`)

These keys must exist in `backend/.env` for the new features to work:

```env
# Email (real delivery — Notify, OTP, unsubscribe). Blank host-user = console only.
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USE_TLS=true
EMAIL_HOST_USER=<smtp user>
EMAIL_HOST_PASSWORD=<smtp app password>
DEFAULT_FROM_EMAIL=TA-ATS <no-reply@ta-ats.local>

# LLM API-key encryption (Fernet). Generate once:
#   python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
LLM_ENCRYPTION_KEY=<fernet key>

# LinkedIn job posting (JD-006). Optional — leave blank to simulate.
LINKEDIN_CLIENT_ID=<app client id>
LINKEDIN_CLIENT_SECRET=<app client secret>
LINKEDIN_ACCESS_TOKEN=
LINKEDIN_AUTHOR_URN=
```

> LLM provider keys (Gemini / OpenRouter) are NOT set here — add them in the UI at
> **Master Data → AI / LLM Providers** (stored encrypted in the DB).

---

## Full seed sequence

All seeders now live in **`backend/master_seeder/`** and run through one
centralized entry point, **`seed_all.py`** (it runs `migrate` first, then every
seeder in the correct order).

```bat
REM 0. Go to the backend folder
cd E:\xampp\htdocs\python\TA-ATS-interns\backend

REM 1. Run the WHOLE seed (migrations + roles/users + permissions + ALL sidebar
REM    menus incl. Login History / AI-LLM Providers / AI Ranking Parameters
REM    (under Master Data) + Country/State/City + pipeline/skills/designations).
.\venv\Scripts\python.exe master_seeder\seed_all.py

REM 1b. (optional) also seed demo clients, JDs and candidates:
.\venv\Scripts\python.exe master_seeder\seed_all.py --with-demo

REM 2. Start the backend server
.\venv\Scripts\python.exe manage.py runserver 8002
```

> Linux:  `./database/ats_seeder_akn.sh`  (add `--with-demo` for demo data).
> To run a single seeder:  `.\venv\Scripts\python.exe master_seeder\<name>.py`
---
## What the new seeder (`seed_akn_updates.py`) adds

| Item | Detail |
|------|--------|
| Menu: Login History | `/admin/login-history` (admin) — auth events with device fingerprint |
| Menu: AI / LLM Providers | `/admin/llm-providers` (admin) — Gemini/OpenRouter/OpenAI config |
| Menu: AI Ranking Parameters | `/admin/rank-parameters` (admin) — no-code scoring params |
| Menu: Country / State / City | `/master-data/*` (admin) |
| Removed: Draft Candidates | deprecated menu deleted |
| AI ranking parameters | skills(40), experience(25), qualifications(15), role_fit(20) |
| Pipeline stage: Offer | ensures an 'Offer' stage exists (used when a candidate is Selected) |

## What the 2026-07-14 seeders add (candidate portal + config)

| Seeder | Adds |
|--------|------|
| `seed_education_master.py` | Master Data → **Master Education** menu (`/master-data/education`) + 10 default qualifications (10th…Diploma). Drives the candidate Qualification dropdown. |
| `add_export_menu.py` | Master Data → **Export** menu (`/reports`). |
| `add_company_linkedin_menu.py` | Master Data → **Company LinkedIn** menu (`/master-data/company-linkedin`) for per-company LinkedIn credentials. |

New DB tables (created by `migrate`): `master_educations`, `company_linkedin_config`,
plus the candidate-portal endpoints (`/api/v1/public/*`, `/api/v1/auth/register/`).

## Post-seed manual steps (features that need external credentials)

1. **LLM (AI Ranking / transcript notes):** Master Data → AI / LLM Providers →
   Add provider (Gemini or OpenRouter) → paste API key → mark Default → Test.

2. **LinkedIn posting (JD-006):** generate a Member (3-legged) access token with
   `w_member_social` scope. Configure it **per company** at Master Data → **Company
   LinkedIn** (paste the access token + organization URN per client) — a JD posts
   under its own company's credentials, falling back to the global `.env`/DB token.
   Tokens are **encrypted at rest** (Fernet, `LLM_ENCRYPTION_KEY`). Company-page
   posting needs the Community Management API product.
   
3. **WhatsApp / SMS / telephony:** require a provider (`WHATSAPP_GATEWAY_URL` /
   `SMS_GATEWAY_URL`) — not yet configured; email works out of the box.
