const db = require('../db') const { Task, Project, User } = 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' }, ] 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) 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()