backend
Technical notes on web development, DevOps, and AI integration.
157 articles
- 23:12backend
Permanent Delete Without Orphan Media Rows or Files
The database rows disappear with the record, but the files stay on the server. A permanent delete collects its references before any row is dropped.
TL;DR: Database cascades only delete rows, never files, leaving orphaned uploads on disk. The fix collects upload URLs before deletion, then counts references across all URL-bearing columns to decide what is truly unused, removing files best-effort afterward with strict path validation. Failures are logged, not fatal, and tests force the orphan scenario to verify cleanup.
#golang#mysql#api - 22:09backend
A Phone Column of 'not-a-number': Birth of a Shared Validator
The same QA finding hit two admin modules: non-digit phones accepted. The fix: one backend validator, a frontend mirror, one 400 INVALID_PHONE contract.
TL;DR: KotaPortal's phone fields accepted garbage like bukan-angka because validation existed only client-side, never at the backend trust boundary. The fix was one allowlist validator in Go shared by both modules, mirrored in TypeScript on the frontend, with a length cap matching the database column. They skipped libphonenumber since the need was simple format checks, not international parsing.
#input-validation#go#typescript - 21:06backend
When the ALL Sentinel Emptied the Admin List
One ALL string from the middleware was treated as a column value, and the announcement list lost every scoped record.
TL;DR: A super admin's announcement list returned zero rows because the ALL sentinel from auth was passed straight into SQL as a literal division filter. Since global rows use NULL, only IS NULL catches them, so nothing matched. Fix: treat ALL and empty string as no-filter at the repository boundary, backed by a regression test.
#golang#mysql#sql - 14:45tooling
Executed Specs Are Decision Records, Not Trash
Executed specifications are decision records: archive them as a status change, keep them immutable with the ADR append-only pattern.
#documentation#adr#workflow - 04:43backend
The Client IP You Can Actually Trust
The first X-Forwarded-For entry is attacker-controlled. Which address behind Cloudflare and nginx actually deserves a rate limiter's trust.
TL;DR: A burst of password guesses on an admin login exposed a flaw: the rate limiter trusted an attacker-controlled X-Forwarded-For entry. The fix prefers Cloudflare's CF-Connecting-IP header, then the last proxy entry, then X-Real-IP, and finally the raw connection address. Per-account keys pairing IP with email, 429 responses with Retry-After, and bounded memory keep the limiter effective.
#go#security#nginx - 20:10backend
Three Mapper Gaps Only Real Data Reveals
Green fixtures prove nothing: a nested object, camelCase keys, and full datetimes only surfaced once 5,330 real rows hit the pipeline.
TL;DR: A 5,330-row blacklist dump mapped error-free yet left company and date columns empty, because real rows broke three assumptions: nested provider objects, camelCase keys, and full RFC 3339 datetimes. Fixes layered a fallback resolver, one shared field registry, and regex date extraction. All 5,330 rows then ingested cleanly, confirming the lesson: start from row zero of real data.
#python#data-engineering#schema - 18:58backend
The event_date Column That Was Always NULL
Indonesian month-name dates kept an event_date column empty. The stdlib locale is not the answer; an explicit month table is.
TL;DR: Date-range queries kept returning empty because Indonesian date strings silently failed ISO parsing. Locale-based fixes proved fragile, so the team chose a simple 13-entry month table with one shared field list in the domain layer. Fifty-three tests plus a live remap of 20 cases filled every date with zero errors.
#python#locale#data-engineering - 18:58database
One Rule, One Place: Email Identity in the Database Schema
Two constraints guarded one email identity rule. Dropping the redundant one is not cosmetics; it closes a duplicate-specification trap.
TL;DR: Migration 0005 dropped a redundant composite tenant-email constraint, leaving the global unique email index to enforce email identity. The key insight: two constraints guarding one rule are two specifications, and a forgotten duplicate can resurface during later refactors. Three checks validated the change: clean migration roundtrip, zero autogenerate drift, and a cross-tenant insert probe rejected at the database.
#postgresql#alembic#sqlalchemy - 17:59database
Database Validation That Does Not Punish Value Evolution
Three enum-like columns were guarded by the app alone. CHECK constraints move the guarantee into the database, and value evolution gets cheap.
TL;DR: DemandScope's Migration 0004 adds CHECK constraints to three enum-like columns that were only validated in the app. Database-level guards block rogue writes that bypass Pydantic, while avoiding native ENUMs that make evolving values painful. Small tables validate instantly, but the team documented a NOT VALID plus VALIDATE pattern to avoid locking once tables grow.
#postgresql#database#testing