Avoiding a PostgreSQL DROP TABLE deadlock by taking LOCK TABLE NOWAIT in a Flyway beforeEachMigrate callback

A migration that only dropped an old table deadlocked in production twice and rolled back. DROP TABLE also takes the strongest lock on the tables its foreign keys reference, and a running worker read those tables in the opposite order. After comparing lock_timeout and plain reruns, I left the applied migration untouched and took all the needed locks up front with NOWAIT in a Flyway beforeEachMigrate callback.

October 30, 2026 | 4 min

Preventing Lost Updates on Full-Text Saves with a Line-Level 3-Way Merge

When writers save by replacing a whole document, last-write-wins causes lost updates, and an optimistic-locking conflict error pushes the merge onto every caller. This post does a line-level 3-way merge on the server, using an immutable base snapshot and SELECT … FOR UPDATE.

October 9, 2026 | 5 min

Testing ON CONFLICT and SKIP LOCKED Takes a Real PostgreSQL

In a backend that writes SQL by hand, retry idempotency and double-claim prevention live inside ON CONFLICT and FOR UPDATE SKIP LOCKED, where a mocked database never looks. This post starts the production PostgreSQL version with testcontainers, applies the real migrations, isolates tests with TRUNCATE, and splits pytest into unit and integration lanes in CI.

July 8, 2026 | 12 min