Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Database Rule

  1. Avoid hard deletes in the database; use soft delete instead.
  2. Avoid SELECT * FROM ... in query apps. Please define your columns explicitly.
  3. Example: l = Location.where(id: id).select(:name, :website, :city).first
  4. Don’t JOIN different schema databases.
  5. Column comparisons used in JOIN conditions must be INT or UUID. Make sure the column is default not null.
  6. Handle possible null values in your app.
  7. Avoid the functions now() and CURRENT_TIMESTAMP() in the WHERE clause. Please generate dates on the app side. Because this function is costly when executed in queries.
  8. Ordering data except for pagination purposes must be executed in the app.
  9. Consult the DBE team for new queries, indexing, or large data retrieval.
  10. Instead of using OR for filter values in the same column, please use IN. E.g.: where a in (1,2) instead of where a=1 or a=2
  11. Every table must have created_at, updated_at, deleted_at, and is_deleted. These columns are used for CRUD and also for soft delete.
  12. Maximum 100 items in a WHERE clause IN (values 1–100)