3
1

seed.ts 732 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import db from './db'
  2. import {
  3. Block,
  4. Event,
  5. Category,
  6. Channel,
  7. Council,
  8. Consul,
  9. ConsulStake,
  10. Member,
  11. Post,
  12. Proposal,
  13. Thread,
  14. } from './models'
  15. const blocks: any[] = [] //require('../../blocks.json')
  16. async function runSeed() {
  17. await db.sync({ force: true })
  18. console.log('db synced!')
  19. console.log('seeding...')
  20. try {
  21. if (blocks.length) {
  22. console.log('importing blocks')
  23. const b = await Block.bulkCreate(blocks)
  24. console.log(`${b.length} blocks imported`)
  25. }
  26. } catch (err) {
  27. console.error(`sequelize error:`, err)
  28. process.exitCode = 1
  29. } finally {
  30. console.log('closing db connection')
  31. await db.close()
  32. console.log('db connection closed')
  33. }
  34. }
  35. runSeed()