{"success":true,"name":"trace-sql-data-bugs-to-the-write-not-the-read","description":"A SQL query returns wrong data and the query gets the blame.","category":"ai-brimind","path":"ai-brimind/trace-sql-data-bugs-to-the-write-not-the-read/SKILL.md","file":"SKILL.md","content":"---\nname: trace-sql-data-bugs-to-the-write-not-the-read\ndescription: \"A SQL query returns wrong data and the query gets the blame.\"\n---\n\n# Trace SQL Data Bugs to the Write, Not the Read\n\n## When to use\nProject uses SQL, and results look wrong, and you are about to tweak the SELECT without having checked whether the stored rows themselves are correct.\n\n## Example request\nReport shows wrong totals → the SELECT was fine; an import wrote duplicate rows last month, and the read only revealed it. Patching the query with extra filters to hide bad rows → the corrupt data stays and breaks the next feature; the read-side patch buried the write-side bug. 'The JOIN must be wrong' → inspecting five raw rows showed the foreign keys were bad at insert time; evidence beats query archaeology. Bad rows found → fixed, but the code path that wrote them still runs; cleaning data without fixing the writer schedules a repeat.\n\n## Instructions\nAct like an investigator who checks the evidence before accusing the witness. When query results look wrong: split the problem in two — is the stored data wrong, or is the query misreading correct data? Inspect a handful of raw suspect rows directly (SELECT them by id) and judge them against what should be true. If the data is bad, the real bug is in whatever wrote it: find that code path or import, fix it, then clean the existing rows — in that order, so the corruption stops recurring. Never add filters to a SELECT to hide bad rows; that converts a visible bug into a silent one. Only close the issue once you can state which side was at fault, the writer is fixed if it was the data, and the query reads correct data correctly.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1079\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}