Data Architecture—Step 3: Build giftWishes Database - Woz-U-Group-Projects/team-the-grinchs-posse GitHub Wiki

Build giftWishes Database

by Robert Hieger

As of right now, all the code that is needed to generate the database is in place, but so it is comprehensible what steps I took, I will attempt to outline here the whole process, at least briefly.

All system dependencies should have been installed in the step on the previous page when you ran npm install. However, one dependency still needs to be installed. We have to add the makemigration package, which has a more sophisticated algorithm, according to Ammon, than that provided by Sequelize on its own.

  1. Install makemigration. To install makemigration, run the following command in the VSC terminal window:

npm install -g sequelize-auto-migrations

  1. Adjust the config.json file. Right now, the config.json style is configured as shown in Fig. 1.

config.json screenshot

You may wish, though it is certainly not required, to change the password found in the config.json file to match your root password. If you do not, you will need to change your mySQL password to match the one contained in the config.json file.

  1. Create the giftWishes database. Run sequelize db:create to create the database that will contain the three tables of which it is comprised. Why does this work? It works because Sequelize reads the config.json file and finds that the name of the database is giftWishes.

  2. Build database tables. Next run sequelize db:migrate. This will create the users, giftLists and gifts tables of which the database is comprised, but does not populate them with any sample data. To verify that the tables are made, in the MySQL Shell, you can run the SHOW TABLES; command as shown in Fig. 2 below.

SHOW TABLES;  run in MySQL Shell Fig. 2: Run SHOW TABLES; to verify that tables were built

As you can see above, the three tables of the database have been built by the sequelize db:migrate command. Additionally, there is a SequelizeMeta table. This contains metadata about the migrations run by Sequelize and consists of only one column called name. This column holds the name of each migration file that has been run.

  1. Populate tables with sample data. Now, populate the three tables of the database with sample data specified in the seeder files present in the seeders folder. Run npx sequelize db:seed:all. Once this is done you will find that running SELECT commands on all three tables will show sample data that may be used for the application.

Go Back to Step 2 | Return to Wiki Home