Database guides
Database Reviews
-
If you're creating a database MR for review, check out our Database review guidelines.
It provides an introduction on database-related changes, migrations, and complex SQL queries.
-
If you're a database reviewer or want to become one, check out our introduction to reviewing database changes.
Tooling
- Understanding EXPLAIN plans
-
explain.depesz.com or explain.dalibo.com for visualizing the output of
EXPLAIN
- pgFormatter a PostgreSQL SQL syntax beautifier
Migrations
- Avoiding downtime in migrations
- SQL guidelines for working with SQL queries
- Migrations style guide for creating safe SQL migrations
- Testing Rails migrations guide
- Post deployment migrations
- Background migrations
- Swapping tables
- Deleting migrations
- Partitioning tables
Debugging
- Tracing the source of an SQL query using query comments with Marginalia
- Tracing the source of an SQL query in Rails console using Verbose Query Logs
Best practices
- Adding database indexes
- Foreign keys & associations
- Adding a foreign key constraint to an existing column
NOT NULL
constraints- Strings and the Text data type
- Single table inheritance
- Polymorphic associations
- Serializing data
- Hash indexes
- Storing SHA1 hashes as binary
- Iterating tables in batches
- Insert into tables in batches
- Ordering table columns
- Verifying database capabilities
- Database Debugging and Troubleshooting
- Query Count Limits
- Creating enums
- Client-side connection-pool
- Updating multiple values
- Constraints naming conventions
- Query performance guidelines
- Pagination guidelines
- Efficient
IN
operator queries