Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

01_insert_example.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const seedDb = require('../index')
  2. const h = require('../helpers')
  3. /**
  4. * What TYPE are you migrating?
  5. */
  6. const mainType = h.types.post
  7. module.exports = {
  8. up: async query => {
  9. const fromSeedDB = h.db(seedDb)
  10. const toCleanDB = h.db(query.sequelize)
  11. /**
  12. * Our base list of posts matching mainType to migrate
  13. */
  14. const matchingPosts = await fromSeedDB.wp_posts.findAll({
  15. where: {
  16. post_type: mainType,
  17. post_status: h.types.status
  18. }
  19. })
  20. const postsToWrite = h.getPostData(matchingPosts, mainType)
  21. /**
  22. * Attachments matching ID's in postsToWrite
  23. */
  24. const matchingAttachments = await h.findDescendants(
  25. postsToWrite,
  26. fromSeedDB.wp_posts,
  27. post => ({
  28. post_type: h.types.attachment,
  29. post_parent: post.ID
  30. })
  31. )
  32. const attachmentsToWrite = h.getPostData(matchingAttachments, h.types.attachment)
  33. /**
  34. * Attachments are POSTS too, so we combine the two lists
  35. * before we can find postmeta keys we care about
  36. *
  37. * 1. Meta keys are match anything in our h.metakeys list
  38. * using opt.in to evaluate h.metakeys.indexOf(post)
  39. */
  40. const postmeta = await h.findDescendants(
  41. [...matchingPosts, ...matchingAttachments],
  42. fromSeedDB.wp_postmeta,
  43. post => ({
  44. post_id: post.ID,
  45. /* 1 */
  46. meta_key: h.metakeys
  47. })
  48. )
  49. const postmetaToWrite = h.getPostData(postmeta, false)
  50. /**
  51. * INSERT in our new db with some options
  52. * 1. First we insert our episode POST and attachments
  53. * to the posts table
  54. * 2. Then we add our matching POSTMETA entries to
  55. * the postmeta table
  56. */
  57. const createOptions = { validate: true }
  58. /* 1 */
  59. await toCleanDB.wp_posts.bulkCreate([
  60. ...postsToWrite,
  61. ...attachmentsToWrite
  62. ], createOptions)
  63. /* 2 */
  64. await toCleanDB.wp_postmeta.bulkCreate([
  65. ...postmetaToWrite
  66. ], createOptions)
  67. },
  68. down: async query => {
  69. // Do nothing...
  70. },
  71. }