migration
Technical notes on web development, DevOps, and AI integration.
14 articles
- 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 - 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:42backend
Four Contracts Behind a Public Upload Form
One multipart endpoint enforces four contracts: closed enums, conditional file slots, bounded streaming, and safe schema migration.
TL;DR: The upload form enforces four contracts: hand-maintained Go enums for validation, files that become required only when a flag says so, streaming writes capped at 10 MiB with magic-byte checks into private storage, and schema migrations that clean up enum values before narrowing on rollback. All four must stay synchronized server-side. Any drift breaks the endpoint predictably.
#go#multipart#file-upload - 01:34database
Flipping a Column Default: A Behavior Switch for New Rows
Changing one column DEFAULT is instant and metadata-only. The real work is auditing the INSERT paths whose meaning silently changed.
TL;DR: Changing a column default in MySQL is instant metadata-only, no table lock or rebuild. Existing rows keep their values; only INSERTs that omit the column flip behavior. Audit those callers first, then ship the migration.
#mysql#database-migration#schema - 23:53database
Down to Zero: The Rollback Path That Never Ran
Checkpoint v56 was built on an untested theory. Two down-file bugs, errors 1553 and 1364, surfaced the day down-to-0 ran again.
TL;DR: Migrations down to zero failed below checkpoint 56, disproving the untested ENUM theory behind it. Two rotted down files broke: a missing slug column and a dropped index that a foreign key depended on. A roundtrip test now proves the chain reversibility, replacing theory with measurable guarantees.
#database-migration#mysql#golang-migrate - 23:52database
Loyal CASCADE: When Deleting an Account Takes the Content With It
The 409 guard never fired because CASCADE removed the content first. Migration 000067 flips the order: RESTRICT refuses at the database, then the guard speaks.
TL;DR: A delete endpoint removed a citizen account plus all its content because the foreign keys used ON DELETE CASCADE, letting InnoDB wipe child rows before the app's ErrHasContent guard could check them. Migration 000067 switched those constraints to RESTRICT, MySQL's default, so the database refuses first. Five integration tests verify both up and down migrations.
#mysql#go#security - 21:53database
Slugs Carrying Curly-Quote Bytes: Fixed via HEX, Not Regex
Seven public slugs carried curly-quote bytes from a bad import. The fix: a HEX-guarded idempotent SQL migration with a byte-identical down path.
TL;DR: A HEX spot-check found seven venue slugs carrying curly quotes and en dashes from a bad import, not charset truncation. The fix skips regex, using manual ASCII maps guarded byte-exact by HEX checks, so migrations stay idempotent and rollbacks restore identical bytes. Same commit also blocks staging user-data overwrites and misdirected E2E runs.
#mysql#sql#data-migration - 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