Files
evig/scripts/ops/purge-demo-content.sql
GandClaude Opus 4.8 f40453ddce fix(technicians): kill fabricated stats (SSOT), show avatars; purge demo data (#167)
The public technician profile showed fabricated data — "George" (a seeded test
account) with 80 reviews / 80 jobs / 5.0★ / verified / professional but ZERO
backing review rows. Root cause: aggregate columns were seeded with fake numbers
and `recomputeTechnicianAggregate` only updated technicians that HAD reviews
(inner join), so a 0-review tech kept stale/seeded values forever.

- recomputeTechnicianAggregate now LEFT JOINs a base row + COALESCE, so a
  technician with no published reviews is reset to 0/0.0 — fake aggregates can
  no longer survive a recompute.
- Technician profile now shows the real avatar (user_profiles.avatar_url, joined
  in getTechnicianById) with the initial-letter fallback. Avatar upload already
  works at /dashboard/profile → /api/uploads → Cloudflare R2 (storage was never
  missing — it's R2, verified live).
- scripts/ops/purge-demo-content.sql: the one-time prod cleanup (already applied)
  that TRUNCATEd the E2E/demo content (159 listings, 150 IT-Hilfe requests, 82
  appointments, 75 erfassung items, reviews, conversations) + removed the
  fabricated technician profiles, keeping all user accounts and org tables.

The profile's stats render was already guarded (>0), so with truthful data a
no-review technician simply shows no rating/jobs line.

typecheck + lint clean; full suite zero new failures vs baseline.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 21:02:37 +02:00

33 lines
1.4 KiB
PL/PgSQL

-- One-time prod cleanup (2026-06-29): purge E2E/demo content.
--
-- Context: the prod DB had been filled by E2E test runs — 159 listings (144
-- "E2E …" titled), 150 IT-Hilfe requests, 82 service appointments, 75 erfassung
-- inventory items, plus a fabricated "George" technician (80 reviews / 80 jobs /
-- 5.0★ with ZERO backing review rows). None of it is real content.
--
-- This wipes the public demo content ONLY. It deliberately does NOT touch:
-- - user accounts (all 55 kept)
-- - org tables (tasks, decisions, meeting_protocols, workshops, blog_posts,
-- job_postings, …) — those are ambiguous (real-vs-seed) and out of scope here.
--
-- Run manually against prod inside a transaction (dry-run with ROLLBACK first):
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f scripts/ops/purge-demo-content.sql
-- (wrap in BEGIN; \i …; COMMIT;). NOT auto-applied by deploy.
TRUNCATE TABLE
listings,
it_hilfe_requests,
service_appointments,
reviews,
conversations,
ai_extracted_products,
inventory_items
CASCADE;
-- Fabricated technician profiles: keep only the real staff user's honest profile.
DELETE FROM repairer_profiles
WHERE user_id NOT IN (SELECT id FROM users WHERE email = 'georgy.butaev@revamp-it.ch');
-- Reset any remaining technician aggregates to truth (no reviews left -> 0).
UPDATE repairer_profiles SET average_rating = 0.0, total_reviews = 0, total_jobs_completed = 0;