backend
Technical notes on web development, DevOps, and AI integration.
157 articles
- 10:49frontend
Moving /wisata: a 308 Redirect and a Menu That Survives
Renaming a public route is three moves at once: relocate the route tree, install a permanent 308, and migrate menu rows without stomping admin edits.
TL;DR: Renaming the public /wisata route to /pariwisata took more than a file move. The team added permanent 308 redirects for the old path and wildcard subpaths to preserve bookmarks and POST requests. A guarded MySQL migration renamed only untouched menu rows, shifted ordering, and left CMS-edited content intact.
#nextjs#redirect#mysql - 10:44testing
The Guard That Says No and the Migration Road Home
A test-only commit: proving the global guard via httptest, and the migration down path on MySQL 5.7 really goes backward, then comes home.
TL;DR: We finally tested two long-ignored paths: the RequireGlobalBidang guard that should block bidang access and the down migrations that had never run. A table-driven unit test now locks in the guard's behavior, including its intentional fail-open for empty contexts. An integration test migrates down to version 56 and back up, verifying columns disappear and reappear correctly.
#go#testing#mysql - 10:44backend
One Query Param, Three Layers: A Safe ?module= Filter
Adding a ?module= filter is not just a WHERE clause: 400 validation at the handler, a parameterized subquery, and a cache key per filter combination.
TL;DR: A naive SQL-only module filter would poison the shared mappoints:all cache, leaking filtered results to unfiltered requests and vice versa. The fix layers validation against six allowed modules with a 400 error, a parameterized subquery, and branched cache keys by module and category. This isolates each response variant and prevents cross-contamination.
#go#api#caching - 13:00backend
Saving Without Changes Returns 404? RowsAffected Fooled Me
A no-op form save got a 404 because MySQL counts changed rows, not matched rows. The fix: an existence check only on the zero path.
TL;DR: Hitting Save without changes returned 404 because MySQL reports zero affected rows when nothing actually changes. The default driver setting means zero is ambiguous and doesn't reliably indicate a missing record. The fix adds a quick existence check on zero instead of changing the global DSN setting.
#mysql#go#debugging - 11:09backend
Do Not Trust omitempty When Exposing a JSON-TEXT Column
A nullable JSON-TEXT column is not covered by omitempty alone: omitempty only knows Go emptiness, not SQL NULL. The story of a four-layer exposure.
TL;DR: A public detail page wasn't showing saved additional info even though the data was in the database. The fix required passing a nullable JSON column through four layers, and realizing Go's omitempty only drops nil, not empty strings. Normalizing null values to nil in the mapper and adding a fallback on the frontend finally hid the empty field correctly.
#go#mysql#api - 09:17backend
Moving a Category Between Modules Is a Two-Part Job
One UPDATE sounds finished. If the importer map keeps the old value, the next import quietly resurrects stale data.
TL;DR: Moving the souvenir category to tourism required more than a database update. The migration uses a guarded WHERE clause to stay idempotent and reversible, while the importer map was updated in the same commit to prevent the old value from resurrecting. Wrapping it in a transaction would not help since MySQL auto-commits DDL.
#mysql#database-migration#golang - 09:04frontend
Hiding Sidebar Links Is UX, Not Authorization
Hiding a sidebar item is a UX decision, not an authorization boundary. Layout checks go stale; the API must fail closed.
TL;DR: Hiding sidebar links isn't security since Next.js layouts don't recheck auth on navigation and typed URLs can bypass the UI. The fix belongs at the API layer, where the backend validates scopes and returns an empty list instead of a 403 to avoid leaking modules. Frontend caching keeps it efficient while tests ensure restricted URLs just show empty tables.
#nextjs#react#go - 08:16backend
The One Forgotten Line: How a DTO Mapper Crashed the Frontend
A field existed on the entity but never made it into the response mapper: the API answered with an empty string and the edit page crashed. One line plus a regression test closed it.
TL;DR: Saving announcements crashed because the backend mapper forgot to copy Status, sending an empty string that broke the frontend badge lookup. The fix added the missing field, added a regression test, and made the UI whitelist statuses to default to draft. Navigation was also switched to router push and refresh to keep toast feedback without a full reload.
#golang#react#typescript - 07:30database
A Cosmetic Request That Forced a Data Contract Overhaul
Lowercasing an enum looks trivial; the values are compared literally in scope enforcement, so DDL, rows, constants, spec, and label maps move together.
TL;DR: A simple request to lowercase bidang values became a contract change since backend scopes match strings exactly and fail closed. Migration 000059 updated three database columns, backend constants, API specs and frontend types, normalizing rows while keeping ALL uppercase as the superadmin sentinel. The separate categories module was left untouched and a down migration was added for a clean rollback.
#mysql#go#migration