chore(medusa): Typeorm upgrade to 0.3.11 (#3041)
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
|
||||
import dotenv from "dotenv"
|
||||
import { createConnection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity"
|
||||
import Logger from "../loaders/logger"
|
||||
import {
|
||||
DiscountCondition,
|
||||
DiscountConditionOperator,
|
||||
DiscountConditionType,
|
||||
} from "../models/discount-condition"
|
||||
import { DiscountCondition, DiscountConditionOperator, DiscountConditionType, } from "../models/discount-condition"
|
||||
import { DiscountConditionProduct } from "../models/discount-condition-product"
|
||||
import { DiscountRule } from "../models/discount-rule"
|
||||
import { DiscountConditionRepository } from "../repositories/discount-condition"
|
||||
@@ -16,11 +11,12 @@ import { typeormConfig } from "./db-config"
|
||||
dotenv.config()
|
||||
|
||||
const migrate = async function ({ typeormConfig }): Promise<void> {
|
||||
const connection = await createConnection(typeormConfig)
|
||||
const dataSource = new DataSource(typeormConfig)
|
||||
await dataSource.initialize()
|
||||
|
||||
const BATCH_SIZE = 1000
|
||||
|
||||
await connection.transaction(async (manager) => {
|
||||
await dataSource.transaction(async (manager) => {
|
||||
const discountRuleCount = await manager
|
||||
.createQueryBuilder()
|
||||
.from(DiscountRule, "dr")
|
||||
@@ -42,18 +38,22 @@ const migrate = async function ({ typeormConfig }): Promise<void> {
|
||||
.offset(offset)
|
||||
.getRawMany()
|
||||
|
||||
const discountConditionRepo = manager
|
||||
.getCustomRepository(DiscountConditionRepository)
|
||||
const discountConditionRepo = manager.withRepository(
|
||||
DiscountConditionRepository
|
||||
)
|
||||
await manager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(DiscountCondition)
|
||||
.values(
|
||||
discountRules.map((dr) => discountConditionRepo.create({
|
||||
type: DiscountConditionType.PRODUCTS,
|
||||
operator: DiscountConditionOperator.IN,
|
||||
discount_rule_id: dr.dr_id,
|
||||
}) as QueryDeepPartialEntity<DiscountCondition>)
|
||||
discountRules.map(
|
||||
(dr) =>
|
||||
discountConditionRepo.create({
|
||||
type: DiscountConditionType.PRODUCTS,
|
||||
operator: DiscountConditionOperator.IN,
|
||||
discount_rule_id: dr.dr_id,
|
||||
}) as QueryDeepPartialEntity<DiscountCondition>
|
||||
)
|
||||
)
|
||||
.orIgnore()
|
||||
.execute()
|
||||
@@ -98,11 +98,13 @@ const migrate = async function ({ typeormConfig }): Promise<void> {
|
||||
})
|
||||
|
||||
// Validate results
|
||||
const noDanglingProductsValidation = await connection.manager
|
||||
.query(`SELECT drp.discount_rule_id, drp.product_id, dcp.product_id FROM "discount_rule_products" drp
|
||||
LEFT JOIN discount_condition dc ON dc.discount_rule_id = drp.discount_rule_id
|
||||
LEFT JOIN discount_condition_product dcp ON dcp.condition_id = dc.id AND dcp.product_id = drp.product_id
|
||||
WHERE dcp.product_id IS NULL`)
|
||||
const noDanglingProductsValidation = await dataSource.manager
|
||||
.query(`SELECT drp.discount_rule_id, drp.product_id, dcp.product_id
|
||||
FROM "discount_rule_products" drp
|
||||
LEFT JOIN discount_condition dc ON dc.discount_rule_id = drp.discount_rule_id
|
||||
LEFT JOIN discount_condition_product dcp
|
||||
ON dcp.condition_id = dc.id AND dcp.product_id = drp.product_id
|
||||
WHERE dcp.product_id IS NULL`)
|
||||
|
||||
if (
|
||||
noDanglingProductsValidation &&
|
||||
|
||||
Reference in New Issue
Block a user