|
1
|
import { model } from "@medusajs/framework/utils" |
|
2
|
|
|
3
|
export const LayoutConfiguration = model |
|
4
|
.define("layout_configuration", { |
|
5
|
id: model.id({ prefix: "lyconf" }).primaryKey(), |
|
6
|
zone: model.text().searchable(), |
|
7
|
user_id: model.text().nullable(), |
|
8
|
is_system_default: model.boolean().default(false), |
|
9
|
configuration: model.json(), |
|
10
|
}) |
|
11
|
.indexes([ |
|
12
|
{ |
|
13
|
on: ["zone", "user_id"], |
|
14
|
unique: true, |
|
15
|
}, |
|
16
|
// Enforce at most one system default per zone. The `(zone, user_id)` unique |
|
17
|
// index can't guarantee this because system defaults have `user_id = null` |
|
18
|
// and Postgres treats NULLs as distinct, so it would allow duplicates. This |
|
19
|
// partial unique index also serves the system-default lookup by zone. |
|
20
|
{ |
|
21
|
on: ["zone"], |
|
22
|
unique: true, |
|
23
|
where: "is_system_default = true", |
|
24
|
}, |
|
25
|
]) |