backend
Technical notes on web development, DevOps, and AI integration.
157 articles
- 01:06backend
Reject Unknown Status Filters, Do Not Ignore Them
A characterization test demanded total = 3 for status=bogus, so the API answered 200 with every live row. One switch statement flipped it to fail-closed 400.
TL;DR: The endpoint silently ignored unrecognized status filters, returning all rows with 200 OK, and a green test had pinned that fail-open behavior as intended. A strict switch now separates empty string from invalid values, rejecting the latter with 400. Guidelines like AIP-160 agree, proving green tests don't guarantee a correct contract.
#golang#api#rest-api - 00:13backend
When a Comma Cuts the Description: YAML Under the Linter
Eight of ten OpenAPI lint errors were not contract drift: an unquoted comma in a flow-mapping description became a bogus null-keyed entry.
TL;DR: Ten OpenAPI lint errors weren't contract drift but YAML parsing: unquoted commas inside flow mappings silently truncate description values. Linting grades the parsed debris, not the source, so Redocly flagged symptoms far below the real cause. Quoting descriptions fixed it; openapi-typescript regeneration produced byte-identical output, proving the fix was pure hygiene.
#openapi#yaml#api - 23:31backend
When the Source Shrinks: Reconcile in the Importer
63 rows in, 65 rows in the database: the importer itself deletes entities the source no longer lists.
TL;DR: The importer treats deletion as part of its contract: any category entity whose attributes.no is missing from the source JSON gets removed in the same run. Idempotency keys use source numbers instead of slugs to prevent resurrection, and ON DELETE CASCADE cleans up media. Dry-run plus result counters verified it: 65 seeded, 63 kept, 2 deleted, then zero changes on rerun.
#data-engineering#importer#database - 22:42backend
Human-Readable Type Tables, Not ENUMs
Service types carry metadata ENUMs cannot: category bindings, active windows, stable codes.
TL;DR: Lookup tables beat ENUMs for service types since adding values needs a plain INSERT instead of a schema change. The design uses a nullable category_id with ON DELETE SET NULL so deleting a category never destroys rows. Go validates first, the FK backs it up, and INSERT ...
#mysql#postgresql#skema-database - 22:34backend
Swapped Coordinates and the Honest Import
22 heritage records, one swapped column pair, and six drafts: what an honest data import looks like.
TL;DR: While importing a heritage site spreadsheet, the author found latitude and longitude columns swapped, plus typo'd prefixes, duplicate coordinates, and one missing record. The fixed importer parses with column swap, preserves raw DMS strings, and routes suspect rows to draft with a geo_review flag instead of publishing. Result: 16 records published, 6 drafted, and reruns are fully idempotent.
#data-engineering#importer#geospasial - 19:31backend
Removing a Status Guard, Keeping One Hard Rule
Dropping a forward-only guard on a booking state machine, and why one hard rule beats a total ban for real accountability.
TL;DR: The author replaced a rigid forward-only state machine guard with one hard rule: rejecting a ticket requires a written note and notifies the applicant. The guard blocked legitimate fixes and pushed admins into duplicate-ticket workarounds. Removing it shifted safety from blind prevention to auditable accountability.
#workflow#backend#state-machine - 00:57backend
The Handler Received %2C: chi Does Not Decode Path Params
A slug with a comma returns 404 while the data exists: chi keeps path params encoded and decoding is the API owner's contract.
TL;DR: Special characters in slug path params broke lookups because chi stores route params in encoded form, so handlers queried the DB with %2C and got empty results. Fix: a DecodePathParams middleware wired with r.With runs after routing, once, with strict rules. Handlers stay clean and the failing slugs now return 200.
#go#chi#routing - 00:12devops
Keeping the Users Table Alive When db-push Swaps the Database
db-push replaced staging from a dev dump and accounts vanished. Two small dumps and honest guards keep them alive.
TL;DR: Staging users kept vanishing because db-push replaces the whole database with a dev dump that excludes the users table. The fix: dump staging users beforehand, then restore them after the import using --no-data, --complete-insert, and --no-create-info. Key lesson: dump and verify before any DROP, validate injected names, and lock down the hash-bearing file.
#mysql#mysqldump#ssh - 00:12frontend
Why a Form Date Slips Back One Day: the Payload Follows the Data
A date input ships a plain string, the old payload carried a UTC instant. How one day vanished and the contract that stopped it.
TL;DR: A date input saved as December 20 came back as December 19 because wrapping the plain yyyy-mm-dd string in a Date, then calling toISOString, shifted local midnight to the previous day in UTC-negative timezones. The fix anchors the input string at UTC midnight explicitly. Keeping the Go backend strict on RFC 3339 prevents this class of bug entirely.
#javascript#golang#api