mysql
Technical notes on web development, DevOps, and AI integration.
58 articles
- 00:28backend
Why "Popular Articles" Stay Stale — and How to Fix It with a 7-Day Rolling Score
Query sort=popular used total view_count so old articles always won. Fix: 7-day rolling score from entity_view_daily + deterministic tiebreak + random filler limit 9.
TL;DR: The "Popular Articles" section showed outdated items. A 7-day rolling score was implemented to fix this. Old articles no longer always rank highest.
#database#performance#mysql - 14:15database
The Enum Value That Only Failed at INSERT Time
App validation and the OpenAPI schema accepted the new enum values; the MySQL column refused them. Error 1265 surfaced only at INSERT.
TL;DR: A MySQL error occurred due to data truncation. The issue arose from a mismatch between the application and database. A migration was needed to append new values to the column.
#mysql#schema#database-migration - 00:24backend
The Column Width Belongs in the Validator, Not in MySQL
Length validation must mirror the column width, not leave it to the database. When 31 characters reach the query, MySQL strict mode answers 500.
TL;DR: The KotaPortal admin form accepted 31 characters but threw a 500 error. The tipe_cabor column was declared VARCHAR(30). Validation was added to prevent this error.
#go#validation#api - 20:16backend
Four Bars With the Same Name: An Import Key That Must Not Guess
A three-column natural key, a NULL-safe comparison, and a guard that fires before the first query.
TL;DR: Data was moved from an intake file into two tables. A key issue arose with duplicate organization names. The code was fixed to use a three-column key to prevent data loss.
#go#mysql#data-import - 19:30backend
The Status Contract Lives in the Query, Not in a Parameter
Public organization detail now goes through GetActiveByID with the status clause inside the query: a missing row and a non-AKTIF row both answer 404.
TL;DR: Organization 17 is inactive. Public requests return 404. Admin requests return the full record.
#go#mysql#rest-api - 19:14backend
Open Routes, Guarded Routes: Where the Permission Seed Goes
Admin routes return 403 for every role except superadmin because the permission rows were never seeded. The guard is only the enforcer.
TL;DR: Admin accounts got 403 errors due to missing permission rows. The permission middleware checked and denied access. Adding permission rows fixed the issue.
#go#security#mysql - 16:10backend
One Transaction or Half-Written Data: BeginTxx in sqlx
Org and member writes ran as separate statements; a mid-way failure left half-written data. One BeginTxx closes the gap.
TL;DR: Kartara had a design flaw. The organisation was written separately from its members. Using transactions fixed this issue.
#go#sqlx#mysql - 14:22backend
Go Repository Pattern: Nullable Model, One List
Database model and JSON DTO never share a struct: nullable columns scan into sql.NullX, responses use pointers, one List serves admin and public.
TL;DR: Database columns are stored in one struct. A separate struct handles JSON responses. Null types and escaping prevent silent bugs.
#go#mysql#sqlx - 10:46database
One Table for Many Organisation Types
A single organisations table with nullable per-type columns is cheaper to maintain than one table per type, if you accept three consequences deliberately.
TL;DR: A public service portal needed to support a new institution type. The decision was made to use a single generic table with nullable columns. This approach is known as Single Table Inheritance.
#mysql#database-schema#migration