Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

4.2 KB
Raw Blame
---
title: "Product Edit data models"
sidebarTitle: "Data models"
description: "Fields, enums, indexes, and relations of the ProductChange and ProductChangeAction models."
---

The Product Edit module, resolved with `MercurModules.PRODUCT_EDIT` (`"product_edit"`), owns two data models: `ProductChange` and `ProductChangeAction`. Both are defined in `packages/core/src/modules/product-edit/models`. Every model also gets `created_at`, `updated_at`, and `deleted_at` from Medusa.

## ProductChange

A single reviewable edit to one product. Table `product_change`, id prefix `prodch`.

| Field | Type | Description |
| --- | --- | --- |
| `id` | `text` | Primary key, prefixed `prodch` |
| `product_id` | `text` | The product the change targets |
| `status` | `enum` | A `ProductChangeStatus` value. Default `pending` |
| `internal_note` | `text`, nullable | Note for operators |
| `external_note` | `text`, nullable | Note shown to the seller. Holds the message of a revision request |
| `created_by` | `text`, nullable | Actor who staged the change: a seller id from vendor routes, a user id from admin routes |
| `confirmed_by` | `text`, nullable | Actor who confirmed the change |
| `confirmed_at` | `dateTime`, nullable | When the change was confirmed |
| `declined_by` | `text`, nullable | Actor who declined the change |
| `declined_at` | `dateTime`, nullable | When the change was declined |
| `declined_reason` | `text`, nullable | Reason given on decline |
| `canceled_by` | `text`, nullable | Actor who canceled the change |
| `canceled_at` | `dateTime`, nullable | When the change was canceled |
| `requires_action_by` | `text`, nullable | Reserved. No workflow writes it |
| `requires_action_at` | `dateTime`, nullable | Reserved. No workflow writes it |
| `requires_action_reason` | `text`, nullable | Reserved. No workflow writes it |
| `metadata` | `json`, nullable | Custom key-value data |

Relations:

- **`actions`**: has many `ProductChangeAction`. The model cascades deletes to its actions

Indexes on `status`, on `product_id`, and on `(product_id, status)`, all excluding soft-deleted rows.

## ProductChangeAction

A single typed operation inside a change. Table `product_change_action`, id prefix `prodchact`.

| Field | Type | Description |
| --- | --- | --- |
| `id` | `text` | Primary key, prefixed `prodchact` |
| `product_id` | `text` | The product the action targets |
| `product_change_id` | `text`, nullable | The parent change. The foreign key is `ON DELETE SET NULL` |
| `ordering` | `autoincrement` | Insertion order across all actions |
| `action` | `text` | A `ProductChangeActionType` value |
| `details` | `json` | The operation payload. Default `{}` |
| `reference` | `text`, nullable | Free-form type of a related record. Not set by Mercur |
| `reference_id` | `text`, nullable | Free-form id of a related record. Not set by Mercur |
| `internal_note` | `text`, nullable | Note for operators |
| `applied` | `boolean` | `true` once the action is written to the product. Default `false` |

Relations:

- **`product_change`**: belongs to `ProductChange`, nullable

Indexes on `product_change_id`, `product_id`, `(reference, reference_id)`, and `ordering`, all excluding soft-deleted rows.

## ProductChangeStatus

The values of `ProductChange.status`, exported from `@mercurjs/types`:

| Value | Meaning |
| --- | --- |
| `pending` | Waiting for review |
| `confirmed` | Approved and applied, or recorded as an audit change |
| `declined` | Rejected by an operator |
| `canceled` | Withdrawn before review |

## ProductChangeActionType

The values of `ProductChangeAction.action`, exported from `@mercurjs/types`:

| Value | Applied on confirm |
| --- | --- |
| `UPDATE` | Yes |
| `STATUS_CHANGE` | Yes |
| `VARIANT_ADD` | Yes |
| `VARIANT_UPDATE` | Yes |
| `VARIANT_REMOVE` | Yes |
| `ATTRIBUTE_ADD` | Yes |
| `ATTRIBUTE_UPDATE` | Yes |
| `ATTRIBUTE_REMOVE` | Yes |
| `PRODUCT_DELETE` | Yes |
| `PRODUCT_ADD` | No, audit only |
| `CHANGE_REQUESTED` | No, audit only |

The `details` shape for each type is listed in [Change actions](/platform/product-edit/concepts/change-actions#action-types). The matching DTOs are `ProductChangeDTO` and `ProductChangeActionDTO`, and the create inputs are `CreateProductChangeDTO` and `CreateProductChangeActionDTO`, all from `@mercurjs/types`.