Skip to content

Commit

Permalink
fix(medusa,pricing): Fix migrations for existing databases (#5730)
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan authored Nov 27, 2023
1 parent 5f6751a commit 2e6b110
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/rare-apples-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/pricing": patch
"@medusajs/medusa": patch
---

fix(medusa,pricing): fix migrations for existing databases
5 changes: 2 additions & 3 deletions packages/medusa/src/scripts/migrate-to-pricing-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ const migratePriceLists = async (container: AwilixContainer) => {

for (const corePriceList of corePriceLists) {
if (priceListIdsToUpdateSet.has(corePriceList.id)) {
priceListsToCreate.push(corePriceList)
} else {
priceListsToUpdate.push(corePriceList)
} else {
priceListsToCreate.push(corePriceList)
}

const corePrices = corePriceList.prices || []
Expand Down Expand Up @@ -93,7 +93,6 @@ const migratePriceLists = async (container: AwilixContainer) => {
priceListsToUpdate.map((priceList) => {
const updateData: PricingTypes.UpdatePriceListDTO = {
id: priceList.id,
title: priceList.name,
}

if (priceList?.customer_groups?.length) {
Expand Down
7 changes: 2 additions & 5 deletions packages/pricing/src/migrations/Migration20231101232834.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Migration20231101232834 extends Migration {
`ALTER TABLE price_list
ADD COLUMN IF NOT EXISTS number_rules integer not null default 0`
)

this.addSql(
'alter table "price_set_money_amount" drop constraint "price_set_money_amount_price_list_id_foreign";'
)
Expand All @@ -35,10 +35,7 @@ export class Migration20231101232834 extends Migration {
SET title = name
`)

this.addSql(`alter table "price_list"
alter column "title" set not null `)

this.addSql('alter table "price_list" drop column if exists "name";')
this.addSql(`alter table "price_list" alter column "title" set not null `)

this.addSql(
'create index if not exists "IDX_price_list_deleted_at" on "price_list" ("deleted_at");'
Expand Down

0 comments on commit 2e6b110

Please sign in to comment.