In this episode, we're tackling the setup for our "endpoints." You'll see how we create the database migration and model for endpoints, and we spend a bit of time discussing how endpoints relate to sites. To kick things off, we generate a migration for the endpoints table and start filling out the expected fields, like the site foreign key, location, and frequency (which we store in seconds, even though it's shown as minutes in the UI).
We also talk about handling the situation where if a site is deleted, its endpoints should be deleted too—so we'll set up cascading deletes. Once the basic fields are in, we add a really important one: next_check
, which tells us when to check the endpoint next. This gets kept up to date by adding the frequency to it each time the endpoint is checked.
After those fields are set up, we migrate the changes, and then it's time to wire up model relationships—so sites can easily access their endpoints, and each endpoint knows which site it belongs to.
We finish by noting we'll need an enum for allowed frequencies soon, but leave that for the next episode. You'll come out of this video with a solid endpoint table and model ready to roll.