Chapter 1 · Practice 5 of 5
Use lowercase snake_case names and avoid quoted identifiers
Why it matters
PostgreSQL folds unquoted names to lowercase. If an ORM creates a table called "UserAccounts" with quotes, every hand-written query must quote it exactly, forever. Lowercase snake_case names avoid that trap.
Pick your conventions once and write them down:
- Plural or singular table names, but not both
_idsuffixes for foreign keys, such asuser_id_atsuffixes for timestamps, such ascreated_at- Explicit names for constraints and indexes, such as
orders_user_id_idx
Explicit names keep migration diffs and error messages readable, instead of showing generated names nobody recognises.
A quick check that your conventions work: you should be able to guess a table's foreign key and index names without looking them up.
Do
- Name foreign keys
user_id, timestampscreated_at - Name indexes like
orders_user_id_idx - Configure your ORM to emit snake_case