path : src/seeders/....
const fs = require('fs');
const path = require('path');
module.exports = {
up: async (queryInterface, Sequelize) => {
/**
* Add seed commands here.
*
* Example:
*/
const users = JSON.parse(fs.readFileSync(`${path.resolve()}/_dummyData/user.json`, 'utf-8'));
const plant_status = JSON.parse(
fs.readFileSync(`${path.resolve()}/_dummyData/plant_status.json`, 'utf-8')
);
const plant = JSON.parse(fs.readFileSync(`${path.resolve()}/_dummyData/plant.json`, 'utf-8'));
const cherish = JSON.parse(
fs.readFileSync(`${path.resolve()}/_dummyData/cherish.json`, 'utf-8')
);
const water = JSON.parse(fs.readFileSync(`${path.resolve()}/_dummyData/water.json`, 'utf-8'));
const plant_level = JSON.parse(
fs.readFileSync(`${path.resolve()}/_dummyData/plant_level.json`, 'utf-8')
);
// await queryInterface.bulkInsert('user', users, {});
// await queryInterface.bulkInsert('plant_status', plant_status, {});
// await queryInterface.bulkInsert('plant', plant, {});
// await queryInterface.bulkInsert('cherish', cherish, {});
// await queryInterface.bulkInsert('water', water, {});
// await queryInterface.bulkInsert('plant_level', plant_level, {});
},
down: async (queryInterface, Sequelize) => {
/**
* Add commands to revert seed here.
*
* Example:
* await queryInterface.bulkDelete('People', null, {});
*/
},
};
더미 데이터를 json형태로 만듭니다.
그 후 다음과 같이 넣어줍니다.
const plant_level = JSON.parse(
fs.readFileSync(`${path.resolve()}/_dummyData/plant_level.json`, 'utf-8')
);
더미 데이터를 넣고 싶은 부분만 주석처리를 풀어줍니다.
await queryInterface.bulkInsert('plant_level', plant_level, {});
터미널에서 다음 명령어를 입력합니다.
sequelize db:seed:all
<aside> 💡 sequelize 명령어가 에러난다면? npm i -g sequelize-cli 로 설치해줘야 합니다!
</aside>