Seeding data with Sequelize
We should fill the empty Posts
table with our fake data. To accomplish this, we will use Sequelize's feature for seeding data to our database.
Create a new folder called seeders
:
mkdir src/server/seeders
Now, we can run our next Sequelize CLI command to generate a boilerplate file:
sequelize seed:generate --name fake-posts --seeders-path src/server/seeders
Seeders are great for importing test data into a database for development. Our seed
file has the timestamp and the words fake-posts
in the name, and should look as follows:
'use strict'; module.exports = { up: (queryInterface, Sequelize) => { /* Add altering commands here. Return a promise to correctly handle asynchronicity. Example: return queryInterface...