Skip to main content

Practice: Change DB Structure in "Live" Project

Premium
6 min read

In this lesson, you will see an example of restructuring the database.

Imagine a scenario:

  1. You have Posts that belong to one Category
  2. At some point, you decide to have multiple categories

So, from one-to-many to many-to-many. But the project is already live. What should you do?


Step 1: What Changes Are Needed?

First, let's identify the behavior changes.

Change 1. When viewing a post, instead of showing a single category, it should list all categories with a foreach loop.

Change 2. When showing posts by a category, the query should also be changed.

Where do we start, and how do we do it safely?


Step 2: Automated Tests

Let's start with a different question: "How will you test everything after you make the changes in the code?"

To answer that question, I have a personal rule of thumb. For making any big structure refactorings in a big project: first, write automated tests.

You need to write tests of all the features and how...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 41 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

LA
Luis Antonio Parrado ✓ Link copied!

Awesome lesson! thanks!

MS
Mike Swan ✓ Link copied!

Haven't really been able to get into the text only courses. I think you've spoiled us with all the youtube videos haha...

But know I see the value of reading it once and then being able to scan quickly for tips.

Thanks for the course!

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.