Draft - Feature #3: Database Redesign #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When adding a feature for three or more users, I would update the conversation model. So let's say I wanted to have five people in each conversation. I would add multiple users to it like so:
After updating the model, I would then make the necessary associations between the User and Conversation entity.
Once done with updating the associations, we would have to make the necessary changes in the routing functions in conversations.js and a few other files in the code.
If our application is already deployed, I hope it's integrated with some form of CI/CD connected to GitHub. That way, we can create a separate development branch and work on this feature, and when we are done with creating the feature, we can make another branch called staging. This is where we test and review our application a bit more before we merge our branch to the main branch. Once the team reviews all the code, then we can merge, and once joined, the changes will automatically go live.
Update
Database Design
So after thinking it through, I think a better way to represent users and conversations in a database is to have a Many-to-Many relationship between both entities.
Users have many Conversations.
Conversations have many Users.
One way to achieve this would be to have a separate model or table (junction model) representing their relationship.
Instead of having a foreign key in each table, the junction model will use the IDs from the associated tables as a composite primary key.
So if I were to put this into practice, instead of updating the Conversations or Users Model, I would define a separate model called ConversationUsers:
As far as the frontend UI design, assuming the conversations can have two or more participants. I would keep the same layout overall but tweak the chat sidebar and the active chat.
Here is what I would do on the front end.
One thing we can change is maybe adding an invite function to the UI, but that may be outside the scope of this ticket for now.
After changing the schema, I would have to update or add route handlers to reflect the schema.
Here is how I would build the routes:
api/conversations.js
api/messages.js
Sockets?
As for the sockets? Well, I think the only change I would make is creating a socket that fires when a user enters and leaves the group since we are now trying to support group conversations.
Redux State?
I would change the redux state to reflect the group conversation feature we just implemented on the backend on the client-side. I would remove the recipientId from the state due to having more than two users.
I would create a way to monitor an array of otherUsers, which would be an array of users who aren't the current logged-in user.
I would also make a thunkCreator function to create a new conversation. Those are the only changes that come to mind when redesigning this application.
Deployment?
When it comes to deploying the application, we can go in a few different directions. But doing a bit of research, I think it may be best to take a Blue/Green deployment pattern for this particular application. This pattern is when we can run two versions of the application. The existing version of the application is Blue, and the updated version of our application is the Green application. Both being active, but only one is public. (Typically the blue version). We can choose which version is live (blue version) with this approach while running tests on the other. (green version). Once we complete all the tests, we can then point all the traffic to the green version, and if anything goes wrong, we can switch back to the blue version.
When it comes to this app, we can have blue and green versions of both the frontend and the backend. We can use Docker and Kubernetes to isolate these versions, making it a bit easier to separate versions.