Legacy Schemas Are Sediment, Not Design

tmp_orders is the main orders table. old_price holds the current price. flag1 means something nobody remembers. Every mature schema drifts this way: names that stopped describing their data, conventions from three different eras, tables whose temporary prefix is locked in permanently. The fix isn't renaming; it's making the drift legible to the next reader.

Polymorphic References Are Not Foreign Keys

resource_id BIGINT, resource_type VARCHAR(50), no REFERENCES clause, because the ID can point to orders, invoices, tickets, or anything else, depending on what the sibling column says today. ORMs make this a one-liner. The database can't enforce any of it: no FK, no cascade, no planner metadata, no schema-level description of what the column actually references.

Schema Conventions Don't Survive Without Automation

A schema with three ways to spell `created_at` (`createdAt`, `created_date`, `date_created`), four PK strategies (BIGINT here, UUID there, two flavors of composite key in the analytics tables), and a deleted_at column on 80% of tables: the 20% that don't have it are the ones whose queries silently return soft-deleted rows. Nobody broke a rule. There was no rule to break.

Where Business Logic Lives - Database vs. Application

A counter-cache trigger fires on every comment insert and serializes every concurrent write on the parent post's row lock. A CHECK constraint and an application validator drift apart over five years until a migration tightening the constraint fails on 4,000 legacy rows. Where each rule belongs comes down to scope, cadence, cost, and how many things write to the schema.

Database Deadlocks, Part 2: Diagnosis, Retries, and Prevention

An on-call engineer reads `LATEST DETECTED DEADLOCK` and sees `lock_mode S locks rec but not gap` on the unique index. That's a duplicate-key conflict on insert, not the lock-ordering bug everyone assumed. Tuning the retry limit would have hidden it for another quarter. Reading the log first is what separates fixes from cosmetics.