103 lines
2.5 KiB
JavaScript
Executable File
103 lines
2.5 KiB
JavaScript
Executable File
const db = require('../db')
|
|
const { Task, Project, User, Article, Tag, Comment, Vote } = require('./models')
|
|
|
|
const testTasks = [
|
|
{
|
|
desc: 'make app',
|
|
completed: false,
|
|
projectId: 1,
|
|
},
|
|
{
|
|
desc: 'update backend',
|
|
completed: false,
|
|
projectId: 1,
|
|
},
|
|
{
|
|
desc: 'eat dinner',
|
|
completed: false,
|
|
projectId: 1,
|
|
},
|
|
]
|
|
|
|
const testProjects = [{ name: 'Anarchy Planet' }, { name: 'Tilde' }]
|
|
|
|
const testUsers = [
|
|
{ name: 'nn', email: 'nn@ap.org' },
|
|
{ name: 'dn', email: 'dn@ap.org' },
|
|
]
|
|
|
|
const testArticles = [{ title: 'latest news', text: 'waddup?!' }]
|
|
|
|
const testTags = [{ name: 'dox' }]
|
|
|
|
const tc1 = { text: 'pretty good' }
|
|
const tc2 = { text: 'yeah!' }
|
|
const tc3 = { text: 'could be more detailed tho' }
|
|
const tc4 = { text: 'BUT THE INSECTS' }
|
|
const tc5 = { text: 'HAHAHAHAHA' }
|
|
const tc6 = { text: 'oh shut up' }
|
|
|
|
const testVotes = [{ upvote: 0, downvote: 1 }]
|
|
|
|
async function runSeed() {
|
|
await db.sync({ force: true })
|
|
console.log('db synced!')
|
|
console.log('seeding...')
|
|
try {
|
|
const p1 = await Project.create(testProjects[0])
|
|
const p2 = await Project.create(testProjects[1])
|
|
|
|
const u1 = await User.create(testUsers[0])
|
|
const u2 = await User.create(testUsers[1])
|
|
|
|
const t1 = await Task.create(testTasks[0])
|
|
const t2 = await Task.create(testTasks[1])
|
|
const t3 = await Task.create(testTasks[2])
|
|
|
|
await p1.addTask(t1)
|
|
await p1.addTask(t2)
|
|
await p2.addTask(t3)
|
|
|
|
await u1.addTasks([t1, t2])
|
|
await u2.addTask(t3)
|
|
|
|
const a1 = await Article.create(testArticles[0])
|
|
const t4 = await Tag.create(testTags[0])
|
|
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)
|
|
const v1 = await Vote.create(testVotes[0])
|
|
|
|
await a1.setUser(u1)
|
|
await a1.addTag(t4)
|
|
await a1.addComments(c1, c2, c3, c4, c5, c6)
|
|
|
|
await c1.setUser(u2)
|
|
await c2.setUser(u1)
|
|
await c3.setUser(u2)
|
|
await c4.setUser(u1)
|
|
await c5.setUser(u1)
|
|
await c6.setUser(u2)
|
|
|
|
await c1.addVote(v1)
|
|
await c1.addReply(2)
|
|
await c2.addReplies([c3, c4])
|
|
await c5.setParent(c4)
|
|
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()
|