Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(database): Set up MongoDB container for local dev & test #47

Merged
merged 1 commit into from
Jan 20, 2022

Conversation

oliver-pham
Copy link
Collaborator

@oliver-pham oliver-pham commented Jan 19, 2022

Related issue

Fixes #24

Type of Change

  • Feat: Change which adds functionality/new feature
  • Fix: Change which fixes an issue
  • Refactor: Change which improves the structure of the code
  • Docs: Change which improves documentation

Description

Backend can now connect to MongoDB inside the app container. I also included some scripts to initialize & reset the database. You can also access an admin dashboard to perform CRUD operations in your database.

As a side effect, the workflow for getting started with development changes a little bit. We don't need to run npm install in backend or frontend anymore. All we have to do is to install Docker & run docker-compose up -d in our project folder (seeksi/). Everything should be automatically set up for you.

Edited: The database should automatically run scripts to populate itself with mock data on initialization. This should help automate database configuration process and ensure everyone uses their own separate database that is built exactly the same as others'.

Screenshot

Docker Dashboard (open Docker Desktop app)
Screen Shot 2022-01-19 at 5 40 55 PM

Admin Dashboard: (http://localhost:8081)
Screen Shot 2022-01-19 at 5 41 01 PM

Testing

Run docker-compose up -d inside the project directory.

Note

The title of your PR should follow this format: [Type](area): Title

@vercel
Copy link

vercel bot commented Jan 19, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tuanthanh2067/seeksi/2wLZqcwUCAzuyVJUt5LVD7tGDjZD
✅ Preview: https://seeksi-git-feature-24-local-mongo-setup-tuanthanh2067.vercel.app

Copy link
Collaborator

@dtnguyen22 dtnguyen22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job LGTM

@tuanthanh2067
Copy link
Owner

Hi @oliver-pham, is this just for us to experiment. If not, can you please also include steps to set up Docker on both windows and mac, and how to use it?

@tuanthanh2067
Copy link
Owner

I have a question regarding test data. Is it just 1 piece of same data we all use, or everything we run api, it will supply a set of data again. For example, in the first case, we only have 1 test database, and all devs will test using that database. Second case, all devs have their own database but the same records. @oliver-pham

@oliver-pham
Copy link
Collaborator Author

Thanks for the feedback & question, @tuanthanh2067!

I think, for now, my goal is to have every dev test/experiment their feature in development in the same environment as others. We should use the same database that is already configured and populated with specific records. As a result, once it's all set up correctly, we don't need to bother setting up our own local database and mock data again. Plus, using the same version of the database & the same records should help us reproduce & troubleshoot issues more productively.

@oliver-pham
Copy link
Collaborator Author

oliver-pham commented Jan 19, 2022

Hi @oliver-pham, is this just for us to experiment. If not, can you please also include steps to set up Docker on both windows and mac, and how to use it?

Yeah that's good idea. I'll add some Docker setup & usage guide in CONTRIBUTING.md in this PR.

@tuanthanh2067
Copy link
Owner

Feeding the database can be taken care by docker. Because with the same database, one can change a record that affects other dev. I'm thinking we all have our own database with the same records. So every dev has a chance to test their code without affecting anyone else.

One shared test database is no difference to production database.

@tuanthanh2067
Copy link
Owner

In case, I was testing delete accounts or banning someone, but you were using that account to match with another one, it will cause unknown bug that we don't know until we talk to each other. @oliver-pham

@oliver-pham
Copy link
Collaborator Author

Feeding the database can be taken care by docker. Because with the same database, one can change a record that affects other dev. I'm thinking we all have our own database with the same records. So every dev has a chance to test their code without affecting anyone else.

One shared test database is no difference to production database.

Oh sorry I totally misunderstood you there. What I meant was everybody has their own database container, but each container is built the same way. For example, if I delete all the accounts in my database container, your database will not be affected.

I totally agree with your opinion on using a shared database. We should never do that during development.

@tuanthanh2067
Copy link
Owner

Ok it's perfect. How about the scripts, because when doing development, if I want to make a change to something or add new table. How do we do that?

@oliver-pham
Copy link
Collaborator Author

Ok it's perfect. How about the scripts, because when doing development, if I want to make a change to something or add new table. How do we do that?

Right now, the scripts are for initializing a database. If you want to modify your database, you'd have to go into the container (through your terminal) and run mongo Shell commands.

Or a better solution is to write more scripts to automate these tasks (e.g. resetting the database to default state) and/or add an Admin Dashboard with mongo-express.

@tuanthanh2067
Copy link
Owner

Sounds good!

Local MongoDB database can be configured easily with Docker Compose.
Utility Mongo Shell scripts to initialize & reset the database are added
to ensure everyone works on the same data set.
@oliver-pham
Copy link
Collaborator Author

oliver-pham commented Jan 19, 2022

Since this is a large PR involving a new technology & affecting our workflow, I hope everyone can spend about 3 - 5 minutes to try it out. Just follow the guide in the docs and let me know if it doesn't work or if the docs are not clear enough. 🙏

Copy link
Collaborator

@minhhang107 minhhang107 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Docker is up and running for me

@oliver-pham oliver-pham merged commit 96fc55f into main Jan 20, 2022
@oliver-pham oliver-pham deleted the feature/24-local-mongo-setup branch January 20, 2022 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MongoDB setup for local development & testing
4 participants