From 2a835cae135370fc665390bfc69dd1833e91bd1f Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Wed, 17 Apr 2024 17:57:41 +0200 Subject: [PATCH] feat(pricing): pricing uses big number (#7075) what: - pricing model price#amount uses big number. blocker: - upsertWithReplace decoration fix --- .../migrations/.snapshot-medusa-pricing.json | 215 +++++++++++++----- .../src/migrations/Migration20230929122253.ts | 2 +- packages/pricing/src/models/price.ts | 9 +- 3 files changed, 172 insertions(+), 54 deletions(-) diff --git a/packages/pricing/src/migrations/.snapshot-medusa-pricing.json b/packages/pricing/src/migrations/.snapshot-medusa-pricing.json index 2a08657936..a849810aa9 100644 --- a/packages/pricing/src/migrations/.snapshot-medusa-pricing.json +++ b/packages/pricing/src/migrations/.snapshot-medusa-pricing.json @@ -1,5 +1,7 @@ { - "namespaces": ["public"], + "namespaces": [ + "public" + ], "name": "public", "tables": [ { @@ -39,7 +41,10 @@ "primary": false, "nullable": false, "default": "'draft'", - "enumItems": ["active", "draft"], + "enumItems": [ + "active", + "draft" + ], "mappedType": "enum" }, "type": { @@ -50,7 +55,10 @@ "primary": false, "nullable": false, "default": "'sale'", - "enumItems": ["sale", "override"], + "enumItems": [ + "sale", + "override" + ], "mappedType": "enum" }, "starts_at": { @@ -121,7 +129,9 @@ "indexes": [ { "keyName": "IDX_price_list_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -129,7 +139,9 @@ }, { "keyName": "price_list_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -187,7 +199,9 @@ "indexes": [ { "keyName": "IDX_price_set_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -195,7 +209,9 @@ }, { "keyName": "price_set_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -242,6 +258,15 @@ "nullable": false, "mappedType": "decimal" }, + "raw_amount": { + "name": "raw_amount", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, "min_quantity": { "name": "min_quantity", "type": "numeric", @@ -326,7 +351,9 @@ "indexes": [ { "keyName": "IDX_price_currency_code", - "columnNames": ["currency_code"], + "columnNames": [ + "currency_code" + ], "composite": false, "primary": false, "unique": false, @@ -334,7 +361,9 @@ }, { "keyName": "IDX_price_price_set_id", - "columnNames": ["price_set_id"], + "columnNames": [ + "price_set_id" + ], "composite": false, "primary": false, "unique": false, @@ -342,7 +371,9 @@ }, { "keyName": "IDX_price_price_list_id", - "columnNames": ["price_list_id"], + "columnNames": [ + "price_list_id" + ], "composite": false, "primary": false, "unique": false, @@ -350,7 +381,9 @@ }, { "keyName": "IDX_price_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -358,7 +391,9 @@ }, { "keyName": "price_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -368,18 +403,26 @@ "foreignKeys": { "price_price_set_id_foreign": { "constraintName": "price_price_set_id_foreign", - "columnNames": ["price_set_id"], + "columnNames": [ + "price_set_id" + ], "localTableName": "public.price", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.price_set", "deleteRule": "cascade", "updateRule": "cascade" }, "price_price_list_id_foreign": { "constraintName": "price_price_list_id_foreign", - "columnNames": ["price_list_id"], + "columnNames": [ + "price_list_id" + ], "localTableName": "public.price", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.price_list", "deleteRule": "cascade", "updateRule": "cascade" @@ -463,7 +506,9 @@ "indexes": [ { "keyName": "IDX_rule_type_rule_attribute", - "columnNames": ["rule_attribute"], + "columnNames": [ + "rule_attribute" + ], "composite": false, "primary": false, "unique": false, @@ -471,7 +516,9 @@ }, { "keyName": "IDX_rule_type_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -479,7 +526,9 @@ }, { "keyName": "rule_type_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -555,7 +604,9 @@ "indexes": [ { "keyName": "IDX_price_set_rule_type_price_set_id", - "columnNames": ["price_set_id"], + "columnNames": [ + "price_set_id" + ], "composite": false, "primary": false, "unique": false, @@ -563,7 +614,9 @@ }, { "keyName": "IDX_price_set_rule_type_rule_type_id", - "columnNames": ["rule_type_id"], + "columnNames": [ + "rule_type_id" + ], "composite": false, "primary": false, "unique": false, @@ -571,7 +624,9 @@ }, { "keyName": "IDX_price_set_rule_type_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -579,7 +634,9 @@ }, { "keyName": "price_set_rule_type_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -589,18 +646,26 @@ "foreignKeys": { "price_set_rule_type_price_set_id_foreign": { "constraintName": "price_set_rule_type_price_set_id_foreign", - "columnNames": ["price_set_id"], + "columnNames": [ + "price_set_id" + ], "localTableName": "public.price_set_rule_type", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.price_set", "deleteRule": "cascade", "updateRule": "cascade" }, "price_set_rule_type_rule_type_id_foreign": { "constraintName": "price_set_rule_type_rule_type_id_foreign", - "columnNames": ["rule_type_id"], + "columnNames": [ + "rule_type_id" + ], "localTableName": "public.price_set_rule_type", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.rule_type", "deleteRule": "cascade", "updateRule": "cascade" @@ -702,7 +767,9 @@ "indexes": [ { "keyName": "IDX_price_rule_price_set_id", - "columnNames": ["price_set_id"], + "columnNames": [ + "price_set_id" + ], "composite": false, "primary": false, "unique": false, @@ -710,7 +777,9 @@ }, { "keyName": "IDX_price_rule_rule_type_id", - "columnNames": ["rule_type_id"], + "columnNames": [ + "rule_type_id" + ], "composite": false, "primary": false, "unique": false, @@ -718,7 +787,9 @@ }, { "keyName": "IDX_price_rule_price_id_rule_type_id_unique", - "columnNames": ["price_id"], + "columnNames": [ + "price_id" + ], "composite": false, "primary": false, "unique": false, @@ -726,7 +797,9 @@ }, { "keyName": "IDX_price_rule_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -734,7 +807,9 @@ }, { "keyName": "price_rule_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -744,26 +819,38 @@ "foreignKeys": { "price_rule_price_set_id_foreign": { "constraintName": "price_rule_price_set_id_foreign", - "columnNames": ["price_set_id"], + "columnNames": [ + "price_set_id" + ], "localTableName": "public.price_rule", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.price_set", "deleteRule": "cascade", "updateRule": "cascade" }, "price_rule_rule_type_id_foreign": { "constraintName": "price_rule_rule_type_id_foreign", - "columnNames": ["rule_type_id"], + "columnNames": [ + "rule_type_id" + ], "localTableName": "public.price_rule", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.rule_type", "updateRule": "cascade" }, "price_rule_price_id_foreign": { "constraintName": "price_rule_price_id_foreign", - "columnNames": ["price_id"], + "columnNames": [ + "price_id" + ], "localTableName": "public.price_rule", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.price", "deleteRule": "cascade", "updateRule": "cascade" @@ -837,7 +924,9 @@ "indexes": [ { "keyName": "IDX_price_list_rule_rule_type_id_unique", - "columnNames": ["rule_type_id"], + "columnNames": [ + "rule_type_id" + ], "composite": false, "primary": false, "unique": false, @@ -845,7 +934,9 @@ }, { "keyName": "IDX_price_list_rule_price_list_id", - "columnNames": ["price_list_id"], + "columnNames": [ + "price_list_id" + ], "composite": false, "primary": false, "unique": false, @@ -853,7 +944,9 @@ }, { "keyName": "IDX_price_list_rule_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -861,7 +954,9 @@ }, { "keyName": "price_list_rule_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -871,17 +966,25 @@ "foreignKeys": { "price_list_rule_rule_type_id_foreign": { "constraintName": "price_list_rule_rule_type_id_foreign", - "columnNames": ["rule_type_id"], + "columnNames": [ + "rule_type_id" + ], "localTableName": "public.price_list_rule", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.rule_type", "updateRule": "cascade" }, "price_list_rule_price_list_id_foreign": { "constraintName": "price_list_rule_price_list_id_foreign", - "columnNames": ["price_list_id"], + "columnNames": [ + "price_list_id" + ], "localTableName": "public.price_list_rule", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.price_list", "deleteRule": "cascade", "updateRule": "cascade" @@ -955,7 +1058,9 @@ "indexes": [ { "keyName": "IDX_price_list_rule_value_price_list_rule_id", - "columnNames": ["price_list_rule_id"], + "columnNames": [ + "price_list_rule_id" + ], "composite": false, "primary": false, "unique": false, @@ -963,7 +1068,9 @@ }, { "keyName": "IDX_price_list_rule_value_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -971,7 +1078,9 @@ }, { "keyName": "price_list_rule_value_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -981,9 +1090,13 @@ "foreignKeys": { "price_list_rule_value_price_list_rule_id_foreign": { "constraintName": "price_list_rule_value_price_list_rule_id_foreign", - "columnNames": ["price_list_rule_id"], + "columnNames": [ + "price_list_rule_id" + ], "localTableName": "public.price_list_rule_value", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.price_list_rule", "deleteRule": "cascade", "updateRule": "cascade" diff --git a/packages/pricing/src/migrations/Migration20230929122253.ts b/packages/pricing/src/migrations/Migration20230929122253.ts index bb17a46bb8..655da74d46 100644 --- a/packages/pricing/src/migrations/Migration20230929122253.ts +++ b/packages/pricing/src/migrations/Migration20230929122253.ts @@ -11,7 +11,7 @@ export class Migration20230929122253 extends Migration { ) this.addSql( - 'create table "price" ("id" text not null, "title" text, "price_set_id" text not null, "money_amount_id" text not null, "rules_count" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_pkey" primary key ("id"));' + 'create table "price" ("id" text not null, "title" text, "price_set_id" text not null, "money_amount_id" text not null, "raw_amount" jsonb not null, "rules_count" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_pkey" primary key ("id"));' ) this.addSql( diff --git a/packages/pricing/src/models/price.ts b/packages/pricing/src/models/price.ts index 38773e259d..ee54d95b31 100644 --- a/packages/pricing/src/models/price.ts +++ b/packages/pricing/src/models/price.ts @@ -1,8 +1,10 @@ import { DAL } from "@medusajs/types" import { + BigNumber, createPsqlIndexStatementHelper, DALUtils, generateEntityId, + MikroOrmBigNumberProperty, } from "@medusajs/utils" import { BeforeCreate, @@ -63,8 +65,11 @@ export default class Price { @Property({ columnType: "text" }) currency_code: string - @Property({ columnType: "numeric", serializer: Number }) - amount: number + @MikroOrmBigNumberProperty() + amount: BigNumber | number + + @Property({ columnType: "jsonb" }) + raw_amount: Record @Property({ columnType: "numeric", nullable: true }) min_quantity: number | null = null