Adding user accounts

As mentioned in the introduction for this chapter, we want to add user accounts to our polling application to facilitate linking polls to a user and giving a user ways to control access and information concerning each of the polls that they create. The process of actually tying all of this into our application is going to involve quite a few steps in the long run. We need to do the following:

  • Figure out what the database table should look like
  • Figure out what the code representation should look like
  • Determine if the addition of this table should introduce changes into other models or schemas
  • Write the migration code that introduces the new table
  • Write the migration code that modifies existing tables and data (if necessary)
  • Modify an existing context or create a new context
  • Create a new schema
  • Modify existing schemas that are affected by this addition
  • Tie the new context logic back into our controllers
  • Write tests for the database side of things
  • Write tests for the controller and request sides of things

Wow, that's a lot of work just to introduce a new table! It may seem difficult or tricky, but at the end of the day the point of designing all of this up front and thinking about the potential consequences of our actions is that it allows us to plan ahead and make better-informed decisions about the impacts of these changes. This is a lengthy exercise but also a very good one, and part of a great engineering habit of thinking about both the short-term and long-term effects of our changes!

This is also an exercise that you'll want to repeat every time you're thinking about adding something. When you think you just need to add a table to something, it's very easy to just do it and forget about it. This is one of the most common ways that web applications tend to bloat over time; the mentality of just do it and forget it tends to lead to duplicate tables or duplicate information, legacy portions of the code base, and other maintenance nightmares and headaches that will compound very quickly over the course of your engineering career!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset