1+ import { asValue } from "@medusajs/deps/awilix"
12import { RemoteFetchDataCallback } from "@medusajs/orchestration"
23import {
34 ConfigModule ,
@@ -21,6 +22,7 @@ import {
2122 createMedusaContainer ,
2223 discoverFeatureFlagsFromDir ,
2324 dynamicImport ,
25+ executeWithConcurrency ,
2426 FeatureFlag ,
2527 GraphQLUtils ,
2628 isObject ,
@@ -33,7 +35,6 @@ import {
3335 promiseAll ,
3436 registerFeatureFlag ,
3537} from "@medusajs/utils"
36- import { asValue } from "@medusajs/deps/awilix"
3738import { Link } from "./link"
3839import {
3940 MedusaModule ,
@@ -501,12 +502,14 @@ async function MedusaApp_({
501502 modulesNames : string [ ]
502503 action ?: "run" | "revert" | "generate"
503504 } ) => {
504- const moduleResolutions = modulesNames . map ( ( moduleName ) => {
505- return {
506- moduleName,
507- resolution : MedusaModule . getModuleResolutions ( moduleName ) ,
505+ const moduleResolutions = Array . from ( new Set ( modulesNames ) ) . map (
506+ ( moduleName ) => {
507+ return {
508+ moduleName,
509+ resolution : MedusaModule . getModuleResolutions ( moduleName ) ,
510+ }
508511 }
509- } )
512+ )
510513
511514 const missingModules = moduleResolutions
512515 . filter ( ( { resolution } ) => ! resolution )
@@ -524,7 +527,7 @@ async function MedusaApp_({
524527 throw error
525528 }
526529
527- for ( const { resolution : moduleResolution } of moduleResolutions ) {
530+ const run = async ( { resolution : moduleResolution } ) => {
528531 if (
529532 ! moduleResolution . options ?. database &&
530533 moduleResolution . moduleDeclaration ?. scope === MODULE_SCOPE . INTERNAL
@@ -554,6 +557,11 @@ async function MedusaApp_({
554557 await MedusaModule . migrateGenerate ( migrationOptions )
555558 }
556559 }
560+
561+ await executeWithConcurrency (
562+ moduleResolutions . map ( ( a ) => ( ) => run ( a ) ) ,
563+ 8 // parallel migrations
564+ )
557565 }
558566
559567 const runMigrations : RunMigrationFn = async ( ) : Promise < void > => {
0 commit comments