Item 5 – Use ENUM Types for Fixed Sets of Values

The Problem: String Columns Without Constraints You’re building an order management system. Orders have statuses like “pending”, “processing”, “shipped”, and “delivered”. The naive approach uses a TEXT column: What could go wrong? Problem 1: Typos Create Invalid Data Problem 2: No Discoverability New developers (or AI assistants!) don’t know what valid statuses are: Problem 3: … Read more

Item 4 – Prefer DOMAIN Types for Reusable Validation

The Problem: Repeating Validation Logic Everywhere You’re building a system with email addresses scattered across multiple tables: Problems with this approach: Problem 1: Copy-Paste Error Prone One typo in the regex and you have inconsistent validation: Problem 2: Difficult to Update Validation Rules Business decides to allow longer TLDs (.museum, .international): Problem 3: No Self-Documentation … Read more

Item 3 – Use EXCLUSION Constraints for Temporal Data

The Problem: Overlapping Reservations Are Hard to Prevent You’re building a conference room booking system. Each reservation has a start and end time. The business rule is simple: no two reservations can overlap for the same room. Here’s the naive approach using a UNIQUE constraint: Why this fails: The UNIQUE (room_id, start_time) only prevents exact … Read more

Item 2 – Use citext for Case-Insensitive Identifiers

The Problem: Case Sensitivity Creates User Experience Nightmares You’ve built a user registration system. Alice signs up with [email protected]. A week later, she tries to log in but types [email protected]. Your login fails because PostgreSQL’s TEXT type is case-sensitive: This is frustrating for users and creates duplicate account problems: The Naive Solution: LOWER() Everywhere The … Read more

Item 1: Favor CHECK constraints over application-level validation

The Problem: Application-Level Validation is Fragile Picture this: You’re building an e-commerce platform. Your product pricing logic is carefully implemented in your API layer: Looks solid, right? But here’s what can go wrong: Scenario 1: The Midnight Migration Your DevOps engineer runs a data migration script at 2 AM to fix some corrupted records: Scenario … Read more

SQLite Deep Dive

Overview This blog post is a summary of the following talk on YouTube, credits to the presenter. What is SQLite? SQLite is a widely used, serverless, and self-contained database engine known for its simplicity, speed, and reliability. Its key features contribute to its popularity and versatility across various applications. Ease of Use and Deployment Performance … Read more