chore: V2 core loader + modules integration-tests (#6544)
This commit is contained in:
@@ -8,10 +8,7 @@ import { Express, NextFunction, Request, Response } from "express"
|
||||
import databaseLoader, { dataSource } from "./database"
|
||||
import pluginsLoader, { registerPluginModels } from "./plugins"
|
||||
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
isString
|
||||
} from "@medusajs/utils"
|
||||
import { ContainerRegistrationKeys, isString } from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import { createMedusaContainer } from "medusa-core-utils"
|
||||
import { track } from "medusa-telemetry"
|
||||
@@ -82,16 +79,75 @@ async function loadLegacyModulesEntities(configModules, container) {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMedusaV2({ directory, expressApp }) {
|
||||
const configModule = loadConfig(directory)
|
||||
|
||||
const container = createMedusaContainer()
|
||||
|
||||
// Add additional information to context of request
|
||||
expressApp.use((req: Request, res: Response, next: NextFunction) => {
|
||||
const ipAddress = requestIp.getClientIp(req) as string
|
||||
;(req as any).request_context = {
|
||||
ip_address: ipAddress,
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
const featureFlagRouter = featureFlagsLoader(configModule, Logger)
|
||||
|
||||
const pgConnection = await pgConnectionLoader({ container, configModule })
|
||||
|
||||
container.register({
|
||||
[ContainerRegistrationKeys.MANAGER]: asValue(dataSource.manager),
|
||||
[ContainerRegistrationKeys.LOGGER]: asValue(Logger),
|
||||
featureFlagRouter: asValue(featureFlagRouter),
|
||||
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
|
||||
["remoteQuery"]: asValue(null),
|
||||
})
|
||||
|
||||
await loadMedusaApp({
|
||||
configModule,
|
||||
container,
|
||||
})
|
||||
|
||||
await expressLoader({ app: expressApp, configModule })
|
||||
|
||||
expressApp.use((req: Request, res: Response, next: NextFunction) => {
|
||||
req.scope = container.createScope() as MedusaContainer
|
||||
req.requestId = (req.headers["x-request-id"] as string) ?? v4()
|
||||
next()
|
||||
})
|
||||
|
||||
// TODO: Add Subscribers loader
|
||||
|
||||
await apiLoader({
|
||||
container,
|
||||
app: expressApp,
|
||||
configModule,
|
||||
featureFlagRouter,
|
||||
})
|
||||
|
||||
return {
|
||||
container,
|
||||
app: expressApp,
|
||||
pgConnection,
|
||||
}
|
||||
}
|
||||
|
||||
export default async ({
|
||||
directory: rootDirectory,
|
||||
expressApp,
|
||||
isTest,
|
||||
}: Options): Promise<{
|
||||
container: MedusaContainer
|
||||
dbConnection: Connection
|
||||
dbConnection?: Connection
|
||||
app: Express
|
||||
pgConnection: unknown
|
||||
}> => {
|
||||
if (process.env.MEDUSA_FF_MEDUSA_V2 == "true") {
|
||||
return await loadMedusaV2({ directory: rootDirectory, expressApp })
|
||||
}
|
||||
|
||||
const configModule = loadConfig(rootDirectory)
|
||||
|
||||
const container = createMedusaContainer()
|
||||
|
||||
@@ -15,19 +15,15 @@ CREATE TABLE IF NOT EXISTS "region" (
|
||||
"deleted_at" timestamptz NULL,
|
||||
CONSTRAINT "region_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- Adjust "region" table
|
||||
ALTER TABLE "region" DROP CONSTRAINT IF EXISTS "FK_3bdd5896ec93be2f1c62a3309a5";
|
||||
ALTER TABLE "region" DROP CONSTRAINT IF EXISTS "FK_91f88052197680f9790272aaf5b";
|
||||
|
||||
${generatePostgresAlterColummnIfExistStatement(
|
||||
"region",
|
||||
["tax_rate", "gift_cards_taxable", "automatic_taxes", "includes_tax"],
|
||||
"DROP NOT NULL"
|
||||
)}
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "IDX_region_deleted_at" ON "region" ("deleted_at") WHERE "deleted_at" IS NOT NULL;
|
||||
|
||||
-- Create or update "region_country" table
|
||||
CREATE TABLE IF NOT EXISTS "region_country" (
|
||||
"id" text NOT NULL,
|
||||
@@ -40,7 +36,6 @@ CREATE TABLE IF NOT EXISTS "region_country" (
|
||||
CONSTRAINT "region_country_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "IDX_region_country_region_id_iso_2_unique" ON "region_country" (region_id, iso_2);
|
||||
|
||||
-- Adjust foreign keys for "region_country"
|
||||
ALTER TABLE "region_country" DROP CONSTRAINT IF EXISTS "FK_91f88052197680f9790272aaf5b";
|
||||
ALTER TABLE "region_country" ADD CONSTRAINT "region_country_region_id_foreign" FOREIGN KEY ("region_id") REFERENCES "region" ("id") ON UPDATE CASCADE;
|
||||
|
||||
Reference in New Issue
Block a user