2019-07-09 11:24:05 -04:00

42 lines
952 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.setParent(1)
await c2.addReply(3)
await c3.setParent(2)
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()