fix(link-modules): Fix link module initialization (#4990)

**What**
Add a new configuration on the relationship to specify if the relation is consumed from an internal service (from medusa core). In that case do not check if the service is part of the loaded modules
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2023-09-11 08:49:23 +00:00
1 parent d971d5cf91
commit a87d07655b
5 files changed
+18 -5

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
---
"@medusajs/link-modules": patch
"@medusajs/types": patch
---
fix(link-modules): Fix link module initialization
@@ -1,3 +1,4 @@
export * from "./inventory-level-stock-location" export * from "./inventory-level-stock-location"
export * from "./product-variant-inventory-item" export * from "./product-variant-inventory-item"
export * from "./product-variant-money-amount" export * from "./product-variant-money-amount"
export * from "./product-shipping-profile"
@@ -24,9 +24,10 @@ export const ProductShippingProfile: ModuleJoinerConfig = {
}, },
{ {
serviceName: "shippingProfileService", serviceName: "shippingProfileService",
isInternalService: true,
primaryKey: "id", primaryKey: "id",
foreignKey: "profile_id", foreignKey: "profile_id",
alias: "shipping_profile", alias: "profile",
}, },
], ],
extends: [ extends: [
@@ -90,8 +90,10 @@ export const initialize = async (
continue continue
} }
} else if ( } else if (
!modulesLoadedKeys.includes(primary.serviceName) || (!primary.isInternalService &&
!modulesLoadedKeys.includes(foreign.serviceName) !modulesLoadedKeys.includes(primary.serviceName)) ||
(!foreign.isInternalService &&
!modulesLoadedKeys.includes(foreign.serviceName))
) { ) {
continue continue
} }
@@ -176,8 +178,10 @@ export async function runMigrations(
allLinks.add(serviceKey) allLinks.add(serviceKey)
if ( if (
!modulesLoadedKeys.includes(primary.serviceName) || (!primary.isInternalService &&
!modulesLoadedKeys.includes(foreign.serviceName) !modulesLoadedKeys.includes(primary.serviceName)) ||
(!foreign.isInternalService &&
!modulesLoadedKeys.includes(foreign.serviceName))
) { ) {
continue continue
} }
+1
View File
@@ -168,6 +168,7 @@ export type ModuleJoinerConfig = Omit<
} }
export declare type ModuleJoinerRelationship = JoinerRelationship & { export declare type ModuleJoinerRelationship = JoinerRelationship & {
isInternalService?: boolean // If true, the relationship is an internal service from the medusa core TODO: Remove when there are no more "internal" services
deleteCascade?: boolean // If true, the link joiner will cascade deleting the relationship deleteCascade?: boolean // If true, the link joiner will cascade deleting the relationship
} }