# `PhoenixKit.Migrations.Postgres.V51`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.87/lib/phoenix_kit/migrations/postgres/v51.ex#L1)

V51: Cart items unique constraint fix + User deletion FK constraints

## Part 1: Cart Items Unique Constraint
The original constraint only checked (cart_id, product_id), preventing
users from adding the same product with different options to their cart.

New constraint uses MD5 hash of selected_specs JSONB for efficient
unique checking across all option combinations.

## Part 2: User Deletion Foreign Key Constraints
Changes ON DELETE behavior for user-related tables to support GDPR
compliance - preserve financial/support records while allowing user deletion.

## Changes

- Drops existing idx_shop_cart_items_unique index
- Creates new unique index including MD5 hash of selected_specs
- orders.user_id: RESTRICT → SET NULL (preserve orders, anonymize user)
- billing_profiles.user_id: CASCADE → SET NULL (preserve for history)
- tickets.user_id: DELETE_ALL → SET NULL (preserve support history)
- orders.user_id: DROP NOT NULL constraint
- billing_profiles.user_id: DROP NOT NULL constraint
- tickets.user_id: DROP NOT NULL constraint

# `down`

# `up`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
