* add pricing integraiton feature flag * init * first endpoint * cleanup * remove console.logs * refactor to util and implement across endpoints * add changeset * rename variables * remove mistype * feat(medusa): move price module integration to pricing service (#5322) * initial changes * chore: make product service always internal for pricing module * add notes --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * nit * cleanup * update to object querying * update cart integration test * remove uppercase currency_code * nit * Feat/admin product pricing module reads (#5354) * initial changes to list prices for admin * working price module implementation of list prices * nit * variant pricing * redo integration test changes * cleanup * cleanup * fix unit tests * [wip] Core <> Pricing - price updates (#5364) * chore: update medusa-app * wip * get links and modules working with migration * wip * chore: make test pass * Feat/rule type utils (#5371) * initial rule type utils * update migration script * chore: cleanup * ensure prices are always decorated * chore: use seed instead * chore: fix oas conflict * region id add to admin price read! --------- Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com> Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com> * pr feedback * create remoteQueryFunction type * fix merge * fix loaders issue * Feat(medusa, types, pricing): pricing module migration script (#5409) * add migration script for money amounts in pricing module * add changeset * rename file * cleanup imports * update changeset * add check for pricing module and ff * feat(medusa,workflows,types): update prices on product and variant update (#5412) * wip * chore: update product prices through workflow * chore: cleanup * chore: update product handler updates prices for variants * chore: handle reverts * chore: address pr comments * chore: scope workflow handlers to flag handlers * chore: update return * chore: update db url * chore: remove migration * chore: increase jest timeout * Feat(medusa): update migration and initDb to run link-migrations (#5437) * initial * loader update * more progress on loaders * update integration tests and remote-query loader * remove helper * migrate isolated modules * fix test * fix integration test * update with pr feedback * unregister medusa-app * re-register medusaApp * fix featureflag * set timeout * set timeout * conditionally run link-module migrations * pr feedback 1 * add driver options for db * throw if link is not defined in migration script * pass config module directly * include container in migrate command * chore: increase timeout * rm redis from api integration tests to test * chore: temporarily skip tests * chore: undo skips + add timeout for workflow tests * chore: increase timeout for order edits * re-add redis * include final resolution * add sharedcontainer to medusaapp loader * chore: move migration under run command * try removing redis_url from api tests * chore: cleanup server on process exit * chore: clear container on exit * chore: adjustments * chore: remove consoles * chore: close express app on finish * chore: destroy pg connection on shutdown * chore: skip * chore: unskip test * chore: cleanup container pg connection * chore: skip --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
188 lines
5.0 KiB
JavaScript
188 lines
5.0 KiB
JavaScript
const path = require("path")
|
|
|
|
const { getConfigFile } = require("medusa-core-utils")
|
|
const { isObject, createMedusaContainer } = require("@medusajs/utils")
|
|
const { dropDatabase } = require("pg-god")
|
|
const { DataSource } = require("typeorm")
|
|
const dbFactory = require("./use-template-db")
|
|
const { getContainer } = require("./use-container")
|
|
const { ContainerRegistrationKeys } = require("@medusajs/utils")
|
|
|
|
const DB_HOST = process.env.DB_HOST
|
|
const DB_USERNAME = process.env.DB_USERNAME
|
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
|
const DB_NAME = process.env.DB_TEMP_NAME
|
|
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
|
|
|
|
const pgGodCredentials = {
|
|
user: DB_USERNAME,
|
|
password: DB_PASSWORD,
|
|
host: DB_HOST,
|
|
}
|
|
|
|
const keepTables = [
|
|
"store",
|
|
"staged_job",
|
|
"shipping_profile",
|
|
"fulfillment_provider",
|
|
"payment_provider",
|
|
"country",
|
|
"currency",
|
|
]
|
|
|
|
const DbTestUtil = {
|
|
db_: null,
|
|
pgConnection_: null,
|
|
|
|
setDb: function (dataSource) {
|
|
this.db_ = dataSource
|
|
},
|
|
|
|
setPgConnection: function (pgConnection) {
|
|
this.pgConnection_ = pgConnection
|
|
},
|
|
|
|
clear: async function () {
|
|
this.db_.synchronize(true)
|
|
},
|
|
|
|
teardown: async function ({ forceDelete } = {}) {
|
|
forceDelete = forceDelete || []
|
|
const entities = this.db_.entityMetadatas
|
|
const manager = this.db_.manager
|
|
|
|
await manager.query(`SET session_replication_role = 'replica';`)
|
|
|
|
for (const entity of entities) {
|
|
if (
|
|
keepTables.includes(entity.tableName) &&
|
|
!forceDelete.includes(entity.tableName)
|
|
) {
|
|
continue
|
|
}
|
|
|
|
await manager.query(`DELETE
|
|
FROM "${entity.tableName}";`)
|
|
}
|
|
|
|
await manager.query(`SET session_replication_role = 'origin';`)
|
|
},
|
|
|
|
shutdown: async function () {
|
|
const container = getContainer()
|
|
const containerPgConnection = container.resolve(
|
|
ContainerRegistrationKeys.PG_CONNECTION
|
|
)
|
|
|
|
await this.db_.destroy()
|
|
await this.pgConnection_?.context?.destroy()
|
|
await containerPgConnection?.context?.destroy()
|
|
|
|
return await dropDatabase({ DB_NAME }, pgGodCredentials)
|
|
},
|
|
}
|
|
|
|
const instance = DbTestUtil
|
|
|
|
module.exports = {
|
|
initDb: async function ({ cwd, database_extra, env }) {
|
|
if (isObject(env)) {
|
|
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
|
|
}
|
|
|
|
const { configModule } = getConfigFile(cwd, `medusa-config`)
|
|
|
|
const featureFlagsLoader =
|
|
require("@medusajs/medusa/dist/loaders/feature-flags").default
|
|
|
|
const featureFlagRouter = featureFlagsLoader(configModule)
|
|
const modelsLoader = require("@medusajs/medusa/dist/loaders/models").default
|
|
const entities = modelsLoader({}, { register: false })
|
|
|
|
await dbFactory.createFromTemplate(DB_NAME)
|
|
|
|
// get migrations with enabled featureflags
|
|
const migrationDir = path.resolve(
|
|
path.join(
|
|
__dirname,
|
|
`../../`,
|
|
`node_modules`,
|
|
`@medusajs`,
|
|
`medusa`,
|
|
`dist`,
|
|
`migrations`,
|
|
`*.js`
|
|
)
|
|
)
|
|
|
|
const {
|
|
getEnabledMigrations,
|
|
getModuleSharedResources,
|
|
} = require("@medusajs/medusa/dist/commands/utils/get-migrations")
|
|
|
|
const { migrations: moduleMigrations, models: moduleModels } =
|
|
getModuleSharedResources(configModule, featureFlagRouter)
|
|
|
|
const enabledMigrations = getEnabledMigrations([migrationDir], (flag) =>
|
|
featureFlagRouter.isFeatureEnabled(flag)
|
|
)
|
|
|
|
const enabledEntities = entities.filter(
|
|
(e) => typeof e.isFeatureEnabled === "undefined" || e.isFeatureEnabled()
|
|
)
|
|
|
|
const dbDataSource = new DataSource({
|
|
type: "postgres",
|
|
url: DB_URL,
|
|
entities: enabledEntities.concat(moduleModels),
|
|
migrations: enabledMigrations.concat(moduleMigrations),
|
|
extra: database_extra ?? {},
|
|
name: "integration-tests",
|
|
})
|
|
|
|
await dbDataSource.initialize()
|
|
|
|
await dbDataSource.runMigrations()
|
|
|
|
instance.setDb(dbDataSource)
|
|
|
|
const IsolateProductDomainFeatureFlag =
|
|
require("@medusajs/medusa/dist/loaders/feature-flags/isolate-product-domain").default
|
|
const IsolatePricingDomainFeatureFlag =
|
|
require("@medusajs/medusa/dist/loaders/feature-flags/isolate-pricing-domain").default
|
|
|
|
if (
|
|
featureFlagRouter.isFeatureEnabled(IsolateProductDomainFeatureFlag.key) ||
|
|
featureFlagRouter.isFeatureEnabled(IsolatePricingDomainFeatureFlag.key)
|
|
) {
|
|
const pgConnectionLoader =
|
|
require("@medusajs/medusa/dist/loaders/pg-connection").default
|
|
|
|
const medusaAppLoader =
|
|
require("@medusajs/medusa/dist/loaders/medusa-app").default
|
|
|
|
const container = createMedusaContainer()
|
|
|
|
const pgConnection = await pgConnectionLoader({ configModule, container })
|
|
instance.setPgConnection(pgConnection)
|
|
|
|
const { runMigrations } = await medusaAppLoader(
|
|
{ configModule, container },
|
|
{ registerInContainer: false }
|
|
)
|
|
|
|
const options = {
|
|
database: {
|
|
clientUrl: DB_URL,
|
|
},
|
|
}
|
|
await runMigrations(options)
|
|
}
|
|
|
|
return dbDataSource
|
|
},
|
|
useDb: function () {
|
|
return instance
|
|
},
|
|
}
|