Use this template to get started.
- Use an ORM to create migrations for managing your tables
- Use an ORM to query your database
Exciting news! Yawp has received Series A funding, but the new investors want you to expand from restaurant reviews to movie reviews. Thankfully, you have Sequelize installed to make adding new tables and data to your database much easier!
For this spotlight, we're going to talk a little about some concepts then break off and work on them with a pair, then we'll come back and cover more concepts.
- One partner should use this repo as a template and then add partner 2 as a collaborator
- Both partners should clone the repo, and run:
npm install- check the settings in config.js to ensure the postgres user and password match your local setup
npm run db:resetnpx sequelize-cli db:seed:all
- Open BeeKeeper and confirm that you have 5 tables in your
yawp_developmentdatabase:Restaurants,Reviews,SequelizeData,SequelizeMetaandUsers - Decide which partner will drive first, and which will navigate
Add migrations for movies and genres. Each movie belongs to one genre. Each genre can have many movies. The genre table should have the following field
| Column | Type |
|---|---|
| name | string |
The movies table should have the following columns:
| Column | Type |
|---|---|
| title | string |
| description | string |
| image | string (validate isUrl) |
| releaseYear | integer |
| genre_id | integer - foreign key to Genre table |
- At the end of this step you should have 2 migration files in your migrations folder. The partner who is driving should run the migrations using
npx sequelize-cli db:migrate. Be sure to look at BeeKeeper and make sure that your columns looks correct. - ACP the migrations and push to your shared repo
- Have the partner who was navigating, pull down the code and run the migrations
- At the end of this step you should both have 2 additional tables in your database, Movies and Genres but there should be no data -- you should also have 2 additional rows in your
SequelizeMetatable
We need to add our relationships to our migrations and our models. Movies belong to a Genre and Genre's can have many movies.
- Check your migration to ensure that
genre_idis setup as a Foreign Key (you may have done this in step one -- if not, look at the Review migration to see how to do this) - Update your Movie model to add a
belongsTorelationship to Genres and update your Genre model to have ahasManyrelationship to Movies - If you made any changes to your migrations, be sure to run
npm run db:resetto make sure your db has picked up the changes
- Add a new seeder file called
demo-genresusing the sequelize-cli - Add code in the seeder file to create some demo genres (use existing seeders as examples)
- Add a new seeder file called
demo-moviesusing the sequelize-cli - Add code in the seeder file to create some demo movies
- Run
npx sequelize-cli db:seeds:alland check BeeKeeper to confirm you have data in your Genres and Movies tables - ACP the seeders and push to your shared repo
- Have the partner who was navigating, pull down the code and run the seeds
- TDD a
/moviesroute that returns the list of movies (including the genre) - TDD a
/genresroute that return the list of genres - TDD a
/genre/:idroute that reutrns a genre with the list of movies in that genre