From cf9605fe6f6f0e3290c2292def2ec1fa294c3658 Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Sun, 5 May 2024 19:43:13 +0200 Subject: [PATCH] feat(order): Add display_id to order table (#7242) Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com> --- .../modules/__tests__/order/order.spec.ts | 1 + .../src/api-v2/admin/orders/query-config.ts | 2 + .../__tests__/create-order.ts | 2 + .../migrations/.snapshot-medusa-order.json | 744 ++++++++++++++---- .../src/migrations/Migration20240219102530.ts | 6 + packages/modules/order/src/models/order.ts | 10 + 6 files changed, 633 insertions(+), 132 deletions(-) diff --git a/integration-tests/modules/__tests__/order/order.spec.ts b/integration-tests/modules/__tests__/order/order.spec.ts index a2902c717f..8fef73445a 100644 --- a/integration-tests/modules/__tests__/order/order.spec.ts +++ b/integration-tests/modules/__tests__/order/order.spec.ts @@ -153,6 +153,7 @@ medusaIntegrationTestRunner({ id: expect.any(String), status: "pending", version: 1, + display_id: 1, summary: expect.objectContaining({ // TODO: add all summary fields }), diff --git a/packages/medusa/src/api-v2/admin/orders/query-config.ts b/packages/medusa/src/api-v2/admin/orders/query-config.ts index 0d3e127710..7f8d5e1953 100644 --- a/packages/medusa/src/api-v2/admin/orders/query-config.ts +++ b/packages/medusa/src/api-v2/admin/orders/query-config.ts @@ -1,5 +1,6 @@ export const defaultAdminOrderFields = [ "id", + "display_id", "status", "version", "summary", @@ -10,6 +11,7 @@ export const defaultAdminOrderFields = [ export const defaultAdminRetrieveOrderFields = [ "id", + "display_id", "status", "version", "summary", diff --git a/packages/modules/order/integration-tests/__tests__/create-order.ts b/packages/modules/order/integration-tests/__tests__/create-order.ts index 9975d120e3..b5cf3ada3a 100644 --- a/packages/modules/order/integration-tests/__tests__/create-order.ts +++ b/packages/modules/order/integration-tests/__tests__/create-order.ts @@ -122,6 +122,7 @@ moduleIntegrationTestRunner({ const expectation = expect.objectContaining({ id: expect.stringContaining("order_"), version: 1, + display_id: 1, summary: expect.objectContaining({ // TODO: add all summary fields }), @@ -203,6 +204,7 @@ moduleIntegrationTestRunner({ const getOrder = await service.retrieve(createdOrder.id, { select: [ "id", + "display_id", "version", "items.id", "summary", diff --git a/packages/modules/order/src/migrations/.snapshot-medusa-order.json b/packages/modules/order/src/migrations/.snapshot-medusa-order.json index b690cc29be..4b752994e2 100644 --- a/packages/modules/order/src/migrations/.snapshot-medusa-order.json +++ b/packages/modules/order/src/migrations/.snapshot-medusa-order.json @@ -1,5 +1,7 @@ { - "namespaces": ["public"], + "namespaces": [ + "public" + ], "name": "public", "tables": [ { @@ -149,7 +151,9 @@ "indexes": [ { "keyName": "IDX_order_address_customer_id", - "columnNames": ["customer_id"], + "columnNames": [ + "customer_id" + ], "composite": false, "primary": false, "unique": false, @@ -157,7 +161,9 @@ }, { "keyName": "order_address_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -319,7 +325,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "true", "mappedType": "boolean" }, "is_discountable": { @@ -329,7 +334,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "true", "mappedType": "boolean" }, "is_tax_inclusive": { @@ -339,7 +343,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "false", "mappedType": "boolean" }, "compare_at_unit_price": { @@ -378,6 +381,15 @@ "nullable": false, "mappedType": "json" }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -406,7 +418,9 @@ "indexes": [ { "keyName": "IDX_order_line_item_variant_id", - "columnNames": ["variant_id"], + "columnNames": [ + "variant_id" + ], "composite": false, "primary": false, "unique": false, @@ -414,7 +428,9 @@ }, { "keyName": "IDX_order_line_item_product_id", - "columnNames": ["product_id"], + "columnNames": [ + "product_id" + ], "composite": false, "primary": false, "unique": false, @@ -422,7 +438,9 @@ }, { "keyName": "order_line_item_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -524,7 +542,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" } }, @@ -533,7 +551,9 @@ "indexes": [ { "keyName": "IDX_order_line_item_adjustment_item_id", - "columnNames": ["item_id"], + "columnNames": [ + "item_id" + ], "composite": false, "primary": false, "unique": false, @@ -541,7 +561,9 @@ }, { "keyName": "order_line_item_adjustment_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -551,11 +573,16 @@ "foreignKeys": { "order_line_item_adjustment_item_id_foreign": { "constraintName": "order_line_item_adjustment_item_id_foreign", - "columnNames": ["item_id"], + "columnNames": [ + "item_id" + ], "localTableName": "public.order_line_item_adjustment", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order_line_item", - "deleteRule": "cascade" + "deleteRule": "cascade", + "updateRule": "cascade" } } }, @@ -661,7 +688,9 @@ "indexes": [ { "keyName": "IDX_order_line_item_tax_line_item_id", - "columnNames": ["item_id"], + "columnNames": [ + "item_id" + ], "composite": false, "primary": false, "unique": false, @@ -669,7 +698,9 @@ }, { "keyName": "order_line_item_tax_line_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -679,11 +710,16 @@ "foreignKeys": { "order_line_item_tax_line_item_id_foreign": { "constraintName": "order_line_item_tax_line_item_id_foreign", - "columnNames": ["item_id"], + "columnNames": [ + "item_id" + ], "localTableName": "public.order_line_item_tax_line", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order_line_item", - "deleteRule": "cascade" + "deleteRule": "cascade", + "updateRule": "cascade" } } }, @@ -698,6 +734,15 @@ "nullable": false, "mappedType": "text" }, + "display_id": { + "name": "display_id", + "type": "serial", + "unsigned": true, + "autoincrement": true, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, "region_id": { "name": "region_id", "type": "text", @@ -716,15 +761,6 @@ "nullable": true, "mappedType": "text" }, - "original_order_id": { - "name": "original_order_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, "version": { "name": "version", "type": "integer", @@ -762,6 +798,16 @@ ], "mappedType": "enum" }, + "is_draft_order": { + "name": "is_draft_order", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, "email": { "name": "email", "type": "text", @@ -807,15 +853,6 @@ "nullable": true, "mappedType": "boolean" }, - "summary": { - "name": "summary", - "type": "jsonb", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "mappedType": "json" - }, "metadata": { "name": "metadata", "type": "jsonb", @@ -871,9 +908,21 @@ "name": "order", "schema": "public", "indexes": [ + { + "keyName": "IDX_order_display_id", + "columnNames": [ + "display_id" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_display_id\" ON \"order\" (display_id) WHERE deleted_at IS NOT NULL" + }, { "keyName": "IDX_order_region_id", - "columnNames": ["region_id"], + "columnNames": [ + "region_id" + ], "composite": false, "primary": false, "unique": false, @@ -881,31 +930,39 @@ }, { "keyName": "IDX_order_customer_id", - "columnNames": ["customer_id"], + "columnNames": [ + "customer_id" + ], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_customer_id\" ON \"order\" (customer_id) WHERE deleted_at IS NOT NULL" }, - { - "keyName": "IDX_order_original_order_id", - "columnNames": ["original_order_id"], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_original_order_id\" ON \"order\" (original_order_id) WHERE deleted_at IS NOT NULL" - }, { "keyName": "IDX_order_customer_id", - "columnNames": ["sales_channel_id"], + "columnNames": [ + "sales_channel_id" + ], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_customer_id\" ON \"order\" (customer_id) WHERE deleted_at IS NOT NULL" }, + { + "keyName": "IDX_order_is_draft_order", + "columnNames": [ + "is_draft_order" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_is_draft_order\" ON \"order\" (is_draft_order) WHERE deleted_at IS NOT NULL" + }, { "keyName": "IDX_order_currency_code", - "columnNames": ["currency_code"], + "columnNames": [ + "currency_code" + ], "composite": false, "primary": false, "unique": false, @@ -913,7 +970,9 @@ }, { "keyName": "IDX_order_shipping_address_id", - "columnNames": ["shipping_address_id"], + "columnNames": [ + "shipping_address_id" + ], "composite": false, "primary": false, "unique": false, @@ -921,7 +980,9 @@ }, { "keyName": "IDX_order_billing_address_id", - "columnNames": ["billing_address_id"], + "columnNames": [ + "billing_address_id" + ], "composite": false, "primary": false, "unique": false, @@ -929,7 +990,9 @@ }, { "keyName": "IDX_order_deleted_at", - "columnNames": ["deleted_at"], + "columnNames": [ + "deleted_at" + ], "composite": false, "primary": false, "unique": false, @@ -937,7 +1000,9 @@ }, { "keyName": "order_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -947,18 +1012,26 @@ "foreignKeys": { "order_shipping_address_id_foreign": { "constraintName": "order_shipping_address_id_foreign", - "columnNames": ["shipping_address_id"], + "columnNames": [ + "shipping_address_id" + ], "localTableName": "public.order", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order_address", "deleteRule": "set null", "updateRule": "cascade" }, "order_billing_address_id_foreign": { "constraintName": "order_billing_address_id_foreign", - "columnNames": ["billing_address_id"], + "columnNames": [ + "billing_address_id" + ], "localTableName": "public.order", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order_address", "deleteRule": "set null", "updateRule": "cascade" @@ -1035,7 +1108,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "text" }, "requested_by": { @@ -1160,7 +1233,9 @@ "indexes": [ { "keyName": "IDX_order_change_order_id", - "columnNames": ["order_id"], + "columnNames": [ + "order_id" + ], "composite": false, "primary": false, "unique": false, @@ -1168,7 +1243,9 @@ }, { "keyName": "IDX_order_change_order_id_version", - "columnNames": ["version"], + "columnNames": [ + "version" + ], "composite": false, "primary": false, "unique": false, @@ -1176,7 +1253,9 @@ }, { "keyName": "IDX_order_change_status", - "columnNames": ["status"], + "columnNames": [ + "status" + ], "composite": false, "primary": false, "unique": false, @@ -1192,7 +1271,9 @@ }, { "keyName": "order_change_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -1202,9 +1283,13 @@ "foreignKeys": { "order_change_order_id_foreign": { "constraintName": "order_change_order_id_foreign", - "columnNames": ["order_id"], + "columnNames": [ + "order_id" + ], "localTableName": "public.order_change", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order", "deleteRule": "cascade", "updateRule": "cascade" @@ -1222,13 +1307,40 @@ "nullable": false, "mappedType": "text" }, + "ordering": { + "name": "ordering", + "type": "integer", + "unsigned": true, + "autoincrement": true, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "integer" + }, "order_change_id": { "name": "order_change_id", "type": "text", "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "text" }, "reference": { @@ -1237,7 +1349,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "text" }, "reference_id": { @@ -1246,11 +1358,20 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "mappedType": "text" }, "action": { "name": "action", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "details": { + "name": "details", "type": "jsonb", "unsigned": false, "autoincrement": false, @@ -1258,8 +1379,17 @@ "nullable": false, "mappedType": "json" }, - "metadata": { - "name": "metadata", + "amount": { + "name": "amount", + "type": "numeric", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "decimal" + }, + "raw_amount": { + "name": "raw_amount", "type": "jsonb", "unsigned": false, "autoincrement": false, @@ -1276,6 +1406,16 @@ "nullable": true, "mappedType": "text" }, + "applied": { + "name": "applied", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -1302,25 +1442,41 @@ "name": "order_change_action", "schema": "public", "indexes": [ + { + "keyName": "IDX_order_change_action_ordering", + "columnNames": [ + "ordering" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_ordering\" ON \"order_change_action\" (ordering)" + }, + { + "keyName": "IDX_order_change_action_order_id", + "columnNames": [ + "order_id" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_id\" ON \"order_change_action\" (order_id)" + }, { "keyName": "IDX_order_change_action_order_change_id", - "columnNames": ["order_change_id"], + "columnNames": [ + "order_change_id" + ], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_order_change_id\" ON \"order_change_action\" (order_change_id)" }, - { - "keyName": "IDX_order_change_action_reference_reference_id", - "columnNames": [], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_change_action_reference_reference_id\" ON \"order_change_action\" (reference, reference_id)" - }, { "keyName": "order_change_action_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -1328,11 +1484,28 @@ ], "checks": [], "foreignKeys": { + "order_change_action_order_id_foreign": { + "constraintName": "order_change_action_order_id_foreign", + "columnNames": [ + "order_id" + ], + "localTableName": "public.order_change_action", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order", + "deleteRule": "cascade", + "updateRule": "cascade" + }, "order_change_action_order_change_id_foreign": { "constraintName": "order_change_action_order_change_id_foreign", - "columnNames": ["order_change_id"], + "columnNames": [ + "order_change_id" + ], "localTableName": "public.order_change_action", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order_change", "deleteRule": "cascade", "updateRule": "cascade" @@ -1402,7 +1575,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "0", "mappedType": "decimal" }, "raw_fulfilled_quantity": { @@ -1421,7 +1593,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "0", "mappedType": "decimal" }, "raw_shipped_quantity": { @@ -1440,7 +1611,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "0", "mappedType": "decimal" }, "raw_return_requested_quantity": { @@ -1459,7 +1629,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "0", "mappedType": "decimal" }, "raw_return_received_quantity": { @@ -1478,7 +1647,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "0", "mappedType": "decimal" }, "raw_return_dismissed_quantity": { @@ -1497,7 +1665,6 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "0", "mappedType": "decimal" }, "raw_written_off_quantity": { @@ -1539,6 +1706,16 @@ "length": 6, "default": "now()", "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" } }, "name": "order_item", @@ -1546,38 +1723,81 @@ "indexes": [ { "keyName": "IDX_order_item_order_id", - "columnNames": ["order_id"], + "columnNames": [ + "order_id" + ], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id)" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_order_id\" ON \"order_item\" (order_id) WHERE deleted_at IS NOT NULL" }, { "keyName": "IDX_order_item_version", - "columnNames": ["version"], + "columnNames": [ + "version" + ], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_version\" ON \"order_item\" (version)" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_version\" ON \"order_item\" (version) WHERE deleted_at IS NOT NULL" }, { "keyName": "IDX_order_item_item_id", - "columnNames": ["item_id"], + "columnNames": [ + "item_id" + ], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id)" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_item_item_id\" ON \"order_item\" (item_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_deleted_at", + "columnNames": [ + "deleted_at" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NOT NULL" }, { "keyName": "order_item_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true } ], "checks": [], - "foreignKeys": {} + "foreignKeys": { + "order_item_order_id_foreign": { + "constraintName": "order_item_order_id_foreign", + "columnNames": [ + "order_id" + ], + "localTableName": "public.order_item", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order", + "updateRule": "cascade" + }, + "order_item_item_id_foreign": { + "constraintName": "order_item_item_id_foreign", + "columnNames": [ + "item_id" + ], + "localTableName": "public.order_item", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order_line_item", + "updateRule": "cascade" + } + } }, { "columns": { @@ -1609,6 +1829,107 @@ "default": "1", "mappedType": "integer" }, + "totals": { + "name": "totals", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "json" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + } + }, + "name": "order_summary", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_deleted_at", + "columnNames": [ + "deleted_at" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_summary_order_id_version", + "columnNames": [], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_summary_order_id_version\" ON \"order_summary\" (order_id, version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_summary_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": { + "order_summary_order_id_foreign": { + "constraintName": "order_summary_order_id_foreign", + "columnNames": [ + "order_id" + ], + "localTableName": "public.order_summary", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order", + "deleteRule": "cascade", + "updateRule": "cascade" + } + } + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, "name": { "name": "name", "type": "text", @@ -1708,33 +2029,148 @@ "name": "order_shipping_method", "schema": "public", "indexes": [ - { - "keyName": "IDX_order_shipping_method_order_id", - "columnNames": ["order_id"], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_order_id\" ON \"order_shipping_method\" (order_id)" - }, { "keyName": "IDX_order_shipping_method_shipping_option_id", - "columnNames": ["shipping_option_id"], + "columnNames": [ + "shipping_option_id" + ], "composite": false, "primary": false, "unique": false, "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_shipping_option_id\" ON \"order_shipping_method\" (shipping_option_id)" }, { - "keyName": "IDX_order_shipping_method_order_id_version", - "columnNames": [], + "keyName": "order_shipping_method_pkey", + "columnNames": [ + "id" + ], + "composite": false, + "primary": true, + "unique": true + } + ], + "checks": [], + "foreignKeys": {} + }, + { + "columns": { + "id": { + "name": "id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "order_id": { + "name": "order_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "version": { + "name": "version", + "type": "integer", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "integer" + }, + "shipping_method_id": { + "name": "shipping_method_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "mappedType": "text" + }, + "created_at": { + "name": "created_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "length": 6, + "default": "now()", + "mappedType": "datetime" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + } + }, + "name": "order_shipping", + "schema": "public", + "indexes": [ + { + "keyName": "IDX_order_shipping_order_id", + "columnNames": [ + "order_id" + ], "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_method_order_id_version\" ON \"order_shipping_method\" (order_id, version)" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_order_id\" ON \"order_shipping\" (order_id) WHERE deleted_at IS NOT NULL" }, { - "keyName": "order_shipping_method_pkey", - "columnNames": ["id"], + "keyName": "IDX_order_shipping_version", + "columnNames": [ + "version" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_version\" ON \"order_shipping\" (version) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_shipping_shipping_method_id", + "columnNames": [ + "shipping_method_id" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_shipping_shipping_method_id\" ON \"order_shipping\" (shipping_method_id) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "IDX_order_deleted_at", + "columnNames": [ + "deleted_at" + ], + "composite": false, + "primary": false, + "unique": false, + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_order_deleted_at\" ON \"order\" (deleted_at) WHERE deleted_at IS NOT NULL" + }, + { + "keyName": "order_shipping_pkey", + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -1742,13 +2178,29 @@ ], "checks": [], "foreignKeys": { - "order_shipping_method_order_id_foreign": { - "constraintName": "order_shipping_method_order_id_foreign", - "columnNames": ["order_id"], - "localTableName": "public.order_shipping_method", - "referencedColumnNames": ["id"], + "order_shipping_order_id_foreign": { + "constraintName": "order_shipping_order_id_foreign", + "columnNames": [ + "order_id" + ], + "localTableName": "public.order_shipping", + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order", - "deleteRule": "cascade" + "updateRule": "cascade" + }, + "order_shipping_shipping_method_id_foreign": { + "constraintName": "order_shipping_shipping_method_id_foreign", + "columnNames": [ + "shipping_method_id" + ], + "localTableName": "public.order_shipping", + "referencedColumnNames": [ + "id" + ], + "referencedTableName": "public.order_shipping_method", + "updateRule": "cascade" } } }, @@ -1845,7 +2297,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" } }, @@ -1854,7 +2306,9 @@ "indexes": [ { "keyName": "IDX_order_shipping_method_adjustment_shipping_method_id", - "columnNames": ["shipping_method_id"], + "columnNames": [ + "shipping_method_id" + ], "composite": false, "primary": false, "unique": false, @@ -1862,7 +2316,9 @@ }, { "keyName": "order_shipping_method_adjustment_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -1872,9 +2328,13 @@ "foreignKeys": { "order_shipping_method_adjustment_shipping_method_id_foreign": { "constraintName": "order_shipping_method_adjustment_shipping_method_id_foreign", - "columnNames": ["shipping_method_id"], + "columnNames": [ + "shipping_method_id" + ], "localTableName": "public.order_shipping_method_adjustment", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order_shipping_method", "deleteRule": "cascade", "updateRule": "cascade" @@ -1974,7 +2434,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": true, + "nullable": false, "mappedType": "text" } }, @@ -1983,7 +2443,9 @@ "indexes": [ { "keyName": "IDX_order_shipping_method_tax_line_shipping_method_id", - "columnNames": ["shipping_method_id"], + "columnNames": [ + "shipping_method_id" + ], "composite": false, "primary": false, "unique": false, @@ -1991,7 +2453,9 @@ }, { "keyName": "order_shipping_method_tax_line_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -2001,9 +2465,13 @@ "foreignKeys": { "order_shipping_method_tax_line_shipping_method_id_foreign": { "constraintName": "order_shipping_method_tax_line_shipping_method_id_foreign", - "columnNames": ["shipping_method_id"], + "columnNames": [ + "shipping_method_id" + ], "localTableName": "public.order_shipping_method_tax_line", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order_shipping_method", "deleteRule": "cascade", "updateRule": "cascade" @@ -2103,7 +2571,9 @@ "indexes": [ { "keyName": "IDX_order_transaction_order_id", - "columnNames": ["order_id"], + "columnNames": [ + "order_id" + ], "composite": false, "primary": false, "unique": false, @@ -2111,7 +2581,9 @@ }, { "keyName": "IDX_order_transaction_currency_code", - "columnNames": ["currency_code"], + "columnNames": [ + "currency_code" + ], "composite": false, "primary": false, "unique": false, @@ -2119,7 +2591,9 @@ }, { "keyName": "IDX_order_transaction_reference_id", - "columnNames": ["reference_id"], + "columnNames": [ + "reference_id" + ], "composite": false, "primary": false, "unique": false, @@ -2127,7 +2601,9 @@ }, { "keyName": "order_transaction_pkey", - "columnNames": ["id"], + "columnNames": [ + "id" + ], "composite": false, "primary": true, "unique": true @@ -2137,9 +2613,13 @@ "foreignKeys": { "order_transaction_order_id_foreign": { "constraintName": "order_transaction_order_id_foreign", - "columnNames": ["order_id"], + "columnNames": [ + "order_id" + ], "localTableName": "public.order_transaction", - "referencedColumnNames": ["id"], + "referencedColumnNames": [ + "id" + ], "referencedTableName": "public.order", "deleteRule": "cascade", "updateRule": "cascade" diff --git a/packages/modules/order/src/migrations/Migration20240219102530.ts b/packages/modules/order/src/migrations/Migration20240219102530.ts index 50b4440b44..fe23b9e2d4 100644 --- a/packages/modules/order/src/migrations/Migration20240219102530.ts +++ b/packages/modules/order/src/migrations/Migration20240219102530.ts @@ -30,6 +30,7 @@ export class Migration20240219102530 extends Migration { CREATE TABLE IF NOT EXISTS "order" ( "id" TEXT NOT NULL, "region_id" TEXT NULL, + "display_id" SERIAL, "customer_id" TEXT NULL, "version" INTEGER NOT NULL DEFAULT 1, "sales_channel_id" TEXT NULL, @@ -111,6 +112,11 @@ export class Migration20240219102530 extends Migration { "DROP NOT NULL" )} + CREATE INDEX IF NOT EXISTS "IDX_order_display_id" ON "order" ( + display_id + ) + WHERE deleted_at IS NOT NULL; + CREATE INDEX IF NOT EXISTS "IDX_order_region_id" ON "order" ( region_id ) diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index a357889909..b9352fdacc 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -28,6 +28,12 @@ type OptionalOrderProps = | "billing_address" | DAL.EntityDateColumns +const DisplayIdIndex = createPsqlIndexStatementHelper({ + tableName: "order", + columns: "display_id", + where: "deleted_at IS NOT NULL", +}) + const RegionIdIndex = createPsqlIndexStatementHelper({ tableName: "order", columns: "region_id", @@ -83,6 +89,10 @@ export default class Order { @PrimaryKey({ columnType: "text" }) id: string + @Property({ autoincrement: true, primary: false }) + @DisplayIdIndex.MikroORMIndex() + display_id: number + @Property({ columnType: "text", nullable: true,