1
0
mwe-comments/server/db/seed.js
2019-07-13 07:56:06 -04:00

41 lines
934 B
JavaScript
Executable File

const db = require('../db')
const { Comment } = require('./models')
const tc1 = { text: 'c1' }
const tc2 = { text: 'c2' }
const tc3 = { text: 'c3' }
const tc4 = { text: 'c4' }
const tc5 = { text: 'c5' }
const tc6 = { text: 'c6' }
async function runSeed() {
await db.sync({ force: true })
console.log('db synced!')
console.log('seeding...')
try {
const c1 = await Comment.create(tc1)
const c2 = await Comment.create(tc2)
const c3 = await Comment.create(tc3)
const c4 = await Comment.create(tc4)
const c5 = await Comment.create(tc5)
const c6 = await Comment.create(tc6)
await c1.addReply(2)
await c2.addReplies([c3, c4, c5])
await c6.setParent(c1)
console.log('seeded successfully')
} catch (err) {
console.error(err)
process.exitCode = 1
} finally {
console.log('closing db connection')
await db.close()
console.log('db connection closed')
}
}
runSeed()