Laravel: 10 tips for your new database

From the obvious, to the guilty misconceptions

Photo by Tobias Fischer on Unsplash

1. Pen & paper first

2. Be explicit

3. Be vertical

4. Follow conventions

  • Primary keys are always named id whatever the data type is.
  • Timestamps are past tense, suffixed …_at
  • Date, Time, and Datetime are not timestamps, name them freely.
  • Booleans are always positive and start with is_…
  • Numeric columns should be plural, like guesses or failures
  • Lists as JSON columns are plural, and may end with …_list
  • Complex JSON trees can be named freely, but may end with …_tree
  • Foreign columns always end with …_id, like author_id
  • Foreign columns using non-id foreign columns can be suffixed as …_as_id
  • Multiple text columns may end with …_body
  • Multiple text columns for binary-encoded data may end with …_data
  • Binary columns always end with …_blob or …_binary
  • Columns for encoded data always end with …_encoded
  • Columns for encrypted data always end with …_encrypted

5. Don’t go overboard with data sizes

6. Always think SQL-agnostic

7. Have a backup plan

8. SQLite can do so much

  • It can be very slow outside a transaction.
  • Testing in memory may be slower than other database engines.
  • It only works with few types of columns, as other more complex are emulated.

9. Avoid enums

10. Keep binaries under control

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Italo Baeza Cabrera

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor. https://italobc.com