database
Technical notes on web development, DevOps, and AI integration.
32 articles
- 20:00backend
The Settings Row Was Right and the API Was Wrong
A direct SQL insert updated the row but the settings API kept serving the old value from its boot-time snapshot. The three-layer debug order.
TL;DR: A direct SQL write updated the row, but the settings API kept serving the old value because it answers from an in-memory snapshot built at boot. The footer and JSON-LD disagreeing in one render signaled a freshness problem, not a storage one. Restart the API after direct writes, and verify layer by layer before trusting any single reader.
#caching#cache-invalidation#debugging - 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 - 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 - 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 - 04:28backend
Seed Migration and Status Mapping for Government Facility Data Import
Creating new categories through idempotent seed migrations, then importing facility data with status-based publish mapping for existing and planned facilities.
TL;DR: A missing Sarana Budaya category blocked importing eight cultural facilities, so the team added it via an idempotent seed migration using ON DUPLICATE KEY UPDATE. Existing facilities import as published, planned ones as drafts with admin notes. The importer ships with dry-run mode, a development-only guard, and slug-based deduplication for safe, repeatable runs.
#go#mysql#data-import - 04:23backend
Corrective Cultural Heritage Data: Pool Matching Without a Unique Key
The corrective import of PPKD cultural heritage data failed because the SK number wasn't unique. Candidate pools and overlap coefficient solve 1:1 matching.
TL;DR: Importing PPKD heritage data broke when SK numbers turned out to be shared across multiple objects, so direct key matching corrupted good records. The fix pairs each row with the best name match from an SK's candidate pool using the overlap coefficient, plus a used guard preventing double assignment. Column ownership rules keep verified coordinates and media untouched.
#go#mysql#data-import - 05:37backend
Out-of-System Payments: a Marker, Not a Module
An externally verified payment modeled as two nullable columns: required *bool contract, a dedicated 409, and a two-arm union SQL.
TL;DR: The system never handles payments, so the fix adds just two nullable columns, payment_marked and payment_marked_at, to track when treasury verifies fees externally. A guarded endpoint uses *bool decoding so missing fields fail loudly instead of silently clearing the marker. Public API hides the columns, admin API exposes them, and submission status stays untouched.
#go#mysql#api