{"version":3,"file":"multiple-workflows.mjs","sources":["../../../server/src/migrations/multiple-workflows.ts"],"sourcesContent":["import { get, keys, pickBy, pipe } from 'lodash/fp';\nimport { WORKFLOW_MODEL_UID } from '../constants/workflows';\n\nasync function migrateWorkflowsContentTypes({ oldContentTypes, contentTypes }: any) {\n  // Look for RW contentTypes attribute\n  const hadContentTypes = !!oldContentTypes?.[WORKFLOW_MODEL_UID]?.attributes?.contentTypes;\n  const hasContentTypes = !!contentTypes?.[WORKFLOW_MODEL_UID]?.attributes?.contentTypes;\n\n  if (!hadContentTypes && hasContentTypes) {\n    // Initialize contentTypes with an empty array and assign only to one\n    // workflow the Content Types which were using Review Workflow before.\n    await strapi.db.query(WORKFLOW_MODEL_UID).updateMany({ data: { contentTypes: [] } });\n\n    // Find Content Types which were using Review Workflow before\n    const contentTypes = pipe([pickBy(get('options.reviewWorkflows')), keys])(oldContentTypes);\n\n    if (contentTypes.length) {\n      // Update only one workflow with the contentTypes\n      // Before this release there was only one workflow, so this operation is safe.\n      await strapi.db\n        .query(WORKFLOW_MODEL_UID)\n        .update({ where: { id: { $notNull: true } }, data: { contentTypes } });\n    }\n  }\n}\n\nexport default migrateWorkflowsContentTypes;\n"],"names":["migrateWorkflowsContentTypes","oldContentTypes","contentTypes","hadContentTypes","WORKFLOW_MODEL_UID","attributes","hasContentTypes","strapi","db","query","updateMany","data","pipe","pickBy","get","keys","length","update","where","id","$notNull"],"mappings":";;;AAGA,eAAeA,4BAAAA,CAA6B,EAAEC,eAAe,EAAEC,YAAY,EAAO,EAAA;;AAEhF,IAAA,MAAMC,kBAAkB,CAAC,CAACF,kBAAkBG,kBAAAA,CAAmB,EAAEC,UAAAA,EAAYH,YAAAA;AAC7E,IAAA,MAAMI,kBAAkB,CAAC,CAACJ,eAAeE,kBAAAA,CAAmB,EAAEC,UAAAA,EAAYH,YAAAA;IAE1E,IAAI,CAACC,mBAAmBG,eAAAA,EAAiB;;;AAGvC,QAAA,MAAMC,OAAOC,EAAE,CAACC,KAAK,CAACL,kBAAAA,CAAAA,CAAoBM,UAAU,CAAC;YAAEC,IAAAA,EAAM;AAAET,gBAAAA,YAAAA,EAAc;AAAG;AAAE,SAAA,CAAA;;AAGlF,QAAA,MAAMA,eAAeU,IAAAA,CAAK;AAACC,YAAAA,MAAAA,CAAOC,GAAAA,CAAI,yBAAA,CAAA,CAAA;AAA6BC,YAAAA;SAAK,CAAA,CAAEd,eAAAA,CAAAA;QAE1E,IAAIC,YAAAA,CAAac,MAAM,EAAE;;;AAGvB,YAAA,MAAMT,OAAOC,EAAE,CACZC,KAAK,CAACL,kBAAAA,CAAAA,CACNa,MAAM,CAAC;gBAAEC,KAAAA,EAAO;oBAAEC,EAAAA,EAAI;wBAAEC,QAAAA,EAAU;AAAK;AAAE,iBAAA;gBAAGT,IAAAA,EAAM;AAAET,oBAAAA;AAAa;AAAE,aAAA,CAAA;AACxE,QAAA;AACF,IAAA;AACF;;;;"}