In this episode, we're tackling how to store the email addresses that should be alerted when a site goes down. Remember that panel from the introduction, where users could add emails for notifications? Instead of spinning up a whole new model and table for these notification emails, we decide it's more practical to just add a JSON column directly on the sites
table to keep track of them.
Here's what we do: we create a migration that adds a new, nullable JSON column called notification_emails
to the sites
table, with an empty array as the default. This way, each site can store an array of email addresses right there in the row—no extra tables needed. We also set up the down migration for this change, in case we ever want to roll it back.
After running the migration (fixing a tiny typo along the way), we update our Site model to make sure that notification_emails
is fillable and is properly cast to an array. That way, we don’t get stuck dealing with raw JSON strings in our code.
By the end, our database and model are ready to start handling notification emails per site. Next time, we’ll look at building out the user interface so folks can add and manage these emails directly from the app.