:::warning AUTO-GENERATED — do not edit
This page is generated from the MCP server snapshot content/backend-mcp.json.
Edit the source MCP server (not this file), then run npm run generate.
:::
Write data via dbconnect.update_table() (DELETE+INSERT by fk_user)
When to use: A route must persist user-scoped data (the standard replace-by-user write path).
Prerequisites
- The route handler exists, is auth-guarded, and validates its payload.
- You have the authenticated fk_user and the rows to persist.
Steps
Step 1: Fetch the canonical database access pattern.
Tools: get_db_pattern
Step 2: Derive fk_user from the authenticated principal, not from the request body.
Step 3: Call dbconnect.update_table() to replace the user's rows (DELETE existing by fk_user, then INSERT the new set).
Step 4: Return the standard success envelope (and the persisted state if the contract requires it).
Step 5: Run the verify gate.
Tools: validate_backend_endpoint
Full recipe definition
The complete machine-readable recipe as returned by the MCP server:
{
"id": "wire-db-write",
"title": "Write data via dbconnect.update_table() (DELETE+INSERT by fk_user)",
"when": "A route must persist user-scoped data (the standard replace-by-user write path).",
"prerequisites": [
"The route handler exists, is auth-guarded, and validates its payload.",
"You have the authenticated fk_user and the rows to persist."
],
"steps": [
{
"action": "Fetch the canonical database access pattern.",
"tools": [
"get_db_pattern"
],
"note": "Returns the dbconnect.update_table() signature and semantics. Do not invent an INSERT/UPDATE flow."
},
{
"action": "Derive fk_user from the authenticated principal, not from the request body.",
"files": [
"src/routes/<domain>_routes.py"
],
"note": "Trusting a client-supplied fk_user lets a user overwrite another user's data."
},
{
"action": "Call dbconnect.update_table() to replace the user's rows (DELETE existing by fk_user, then INSERT the new set).",
"files": [
"src/routes/<domain>_routes.py"
],
"note": "update_table performs the DELETE+INSERT atomically per fk_user — pass the table, the fk_user, and the new rows exactly as the pattern shows."
},
{
"action": "Return the standard success envelope (and the persisted state if the contract requires it).",
"files": [
"src/routes/<domain>_routes.py"
]
},
{
"action": "Run the verify gate.",
"tools": [
"validate_backend_endpoint"
],
"note": "Follow run-verify."
}
],
"filesToCreate": [],
"validation": [
"Write goes through dbconnect.update_table() (not a hand-rolled INSERT).",
"fk_user is taken from the token, not the payload.",
"Existing rows for the user are replaced (DELETE+INSERT), not duplicated."
],
"doneCriteria": [
"Persistence uses dbconnect.update_table() scoped by the authenticated fk_user.",
"run-verify passes."
],
"commonMistakes": [
"Reading fk_user from request.json (lets one user clobber another's data).",
"Hand-writing DELETE/INSERT instead of dbconnect.update_table().",
"Appending rows instead of replacing, causing duplicates.",
"Writing before validating the payload."
],
"relatedRecipes": [
"create-endpoint",
"add-auth-guard",
"wire-db-read",
"run-verify"
]
}