I Let an AI Edit My Database
Published on October 30, 2026
Fight Embedded tracks hundreds of UFC athletes, and keeping their records and rankings current by hand got old. So I connected Grok Bot to the site. It started with one locked-down database login and ended up keeping every division and both pound-for-pound lists in line with UFC, with me approving each change.
Step 1: A login of its own
My main database URL can read everything, including users and sessions, so the bot doesn't get that one. Grok Bot asked for one thing instead: a connection string for a limited database role. Here's how I set it up in Neon:
-
I generated a strong password with
openssl rand -hex 32. -
In the project's SQL Editor, I pasted this with that password and clicked Run:
CREATE ROLE stats_bot WITH LOGIN PASSWORD '...'; GRANT USAGE ON SCHEMA public TO stats_bot; GRANT SELECT ON public."Athlete" TO stats_bot; GRANT UPDATE ("wins","losses","draws","winsByKo","winsBySubmission", "rank","poundForPoundRank","followers","age","weightDivision", "retired","updatedAt") ON public."Athlete" TO stats_bot; -
I clicked Connect, picked the
neondbdatabase and thestats_botrole, and copied thepostgresql://connection string. -
I pasted it into Grok Bot's secret field,
NEON_STATS_DATABASE_URL.
Postgres enforces those grants, so the limits hold even if the bot gets something wrong.
Step 2: A bot API route
The first update landed in Neon, but the live site didn't change. Fight Embedded caches pages for days, and the cache only clears when I save from the dashboard.
So Grok Bot created a new API route under /api/bot in my GitHub repository. It runs the same validation and cache clearing as the dashboard, so changes go live in seconds. Over a few pull requests it grew to cover:
| Area | What the bot does |
|---|---|
| Stats | Updates records, KO and submission wins, weight divisions, ages, and followers |
| Athletes | Full CRUD on the Athlete table, including adding athletes who show up in the rankings but not on the site |
| Events | Full CRUD on the Event table from UFC.com, checking for duplicates and marking events completed or cancelled |
| Rankings | Replaces a whole division's ranking in one request |
| Pound-for-pound | Replaces the men's or women's pound-for-pound list in one request |
Step 3: Tell it where to look
Before letting it update anyone, I pinned down its sources. I told Grok Bot to use specific sites, and it saved that as a standing rule:
Step 4: Rankings and weight-class moves
Athletes move up and down weight classes, and my rankings didn't always keep up. When the bot compared my divisions against UFC's rankings, a lot didn't match.
What it caught
- Athletes still listed in a division they'd left, like Rakić after moving up to heavyweight, which broke that division's ranking
- Two #13s on my heavyweight page
- Athletes who weren't in my database at all
- Unranked athletes who had moved into the rankings, which also broke the rankings
The guardrails
Fixing that means creating missing athletes, moving others to their correct divisions, bringing newly ranked athletes in, and re-ranking both sides, which is easy to get wrong. The rankings endpoint has three guardrails:
- It takes the full list for a division, with unique ranks in order. No gaps, no duplicates.
- Every athlete has to be in that division and not retired.
- Any request can be a dry run that returns the before-and-after diff without saving. The bot sends me that diff, and nothing changes until I approve.
The API refuses to delete an athlete who's still ranked. The bot has to remove them from the division or pound-for-pound rankings first, or explicitly force it.
A single pass in practice
Here's what that looks like when I ask for the men's pound-for-pound list:
That's the whole loop now: Grok Bot pulls the list from UFC, I check the preview, and nothing saves until I approve it.
This is still a beta setup. The whole bot API went in over a couple of days, and I'm still finding edge cases, so treat it as an experiment, not a pattern to copy as is. The bot reads other sites and can get things wrong, which is why the database role, the guardrails, and the approval step exist.
If you try something like this on your own site, it's at your own risk. Start with the smallest permission that's useful, put every write behind a code path your app already trusts, and make dry runs the default for anything you'd hate to get wrong.