From 6349beb94956a7593822b9cc26e00717b4f7bada Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Mon, 22 Sep 2025 17:09:07 +0200 Subject: [PATCH 1/6] docs(cms): clarify unique constraint with draft publish --- docusaurus/docs/cms/backend-customization/models.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docusaurus/docs/cms/backend-customization/models.md b/docusaurus/docs/cms/backend-customization/models.md index c411878c45..1b70961fc6 100644 --- a/docusaurus/docs/cms/backend-customization/models.md +++ b/docusaurus/docs/cms/backend-customization/models.md @@ -186,10 +186,20 @@ Database validations and settings are custom options passed directly onto the `t | `defaultTo` | string | Sets the database `defaultTo`, typically used with `notNullable` | - | | `notNullable` | boolean | Sets the database `notNullable`, ensures that columns cannot be null | `false` | | `unsigned` | boolean | Only applies to number columns, removes the ability to go negative but doubles maximum length | `false` | -| `unique` | boolean | Enforces database level unique, caution when using with draft & publish feature | `false` | +| `unique` | boolean | Enforces database-level uniqueness on published entries. Draft saves skip the check when Draft & Publish is enabled, so duplicates fail only at publish time. | `false` | | `type` | string | Changes the database type, if `type` has arguments, you should pass them in `args` | - | | `args` | array | Arguments passed into the Knex.js function that changes things like `type` | `[]` | +:::caution Draft & Publish and `unique` +When [Draft & Publish](/cms/features/content-type-builder#draft-and-publish) is enabled, Strapi intentionally skips `unique` validations while an entry is saved as a draft. Duplicates therefore remain undetected until publication, at which point the database constraint triggers an error even though the UI previously displayed “Saved document” for the drafts. + +To avoid unexpected publication failures: + +- disable Draft & Publish on content-types that must stay globally unique, or +- add custom validation (e.g. lifecycle hooks or middleware) that checks for draft duplicates before saving, or +- rely on automatically generated unique identifiers such as a `uid` field and document editorial conventions. +::: + ```json title="./src/api/[api-name]/content-types/restaurant/schema.json" { From c3c19f4b696c8549e6c2c2448a29dbc8428b0305 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Mon, 22 Sep 2025 17:13:27 +0200 Subject: [PATCH 2/6] Fix wrong link --- docusaurus/docs/cms/backend-customization/models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/cms/backend-customization/models.md b/docusaurus/docs/cms/backend-customization/models.md index 1b70961fc6..3c2b6186e4 100644 --- a/docusaurus/docs/cms/backend-customization/models.md +++ b/docusaurus/docs/cms/backend-customization/models.md @@ -191,7 +191,7 @@ Database validations and settings are custom options passed directly onto the `t | `args` | array | Arguments passed into the Knex.js function that changes things like `type` | `[]` | :::caution Draft & Publish and `unique` -When [Draft & Publish](/cms/features/content-type-builder#draft-and-publish) is enabled, Strapi intentionally skips `unique` validations while an entry is saved as a draft. Duplicates therefore remain undetected until publication, at which point the database constraint triggers an error even though the UI previously displayed “Saved document” for the drafts. +When [Draft & Publish](/cms/features/draft-and-publish) is enabled, Strapi intentionally skips `unique` validations while an entry is saved as a draft. Duplicates therefore remain undetected until publication, at which point the database constraint triggers an error even though the UI previously displayed “Saved document” for the drafts. To avoid unexpected publication failures: From 71b85105bf23864555fb9b3a9936ab07f4680ffa Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Mon, 22 Sep 2025 17:13:53 +0200 Subject: [PATCH 3/6] Update docusaurus/docs/cms/backend-customization/models.md --- docusaurus/docs/cms/backend-customization/models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/cms/backend-customization/models.md b/docusaurus/docs/cms/backend-customization/models.md index 3c2b6186e4..b965831be5 100644 --- a/docusaurus/docs/cms/backend-customization/models.md +++ b/docusaurus/docs/cms/backend-customization/models.md @@ -195,7 +195,7 @@ When [Draft & Publish](/cms/features/draft-and-publish) is enabled, Strapi inten To avoid unexpected publication failures: -- disable Draft & Publish on content-types that must stay globally unique, or +- disable Draft & Publish on content-types that must stay globally unique, - add custom validation (e.g. lifecycle hooks or middleware) that checks for draft duplicates before saving, or - rely on automatically generated unique identifiers such as a `uid` field and document editorial conventions. ::: From db0b9a1405782c09b1c89bb6172d5957e6fcf52c Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Mon, 22 Sep 2025 17:14:10 +0200 Subject: [PATCH 4/6] Update docusaurus/docs/cms/backend-customization/models.md --- docusaurus/docs/cms/backend-customization/models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/cms/backend-customization/models.md b/docusaurus/docs/cms/backend-customization/models.md index b965831be5..ca04db79ee 100644 --- a/docusaurus/docs/cms/backend-customization/models.md +++ b/docusaurus/docs/cms/backend-customization/models.md @@ -196,7 +196,7 @@ When [Draft & Publish](/cms/features/draft-and-publish) is enabled, Strapi inten To avoid unexpected publication failures: - disable Draft & Publish on content-types that must stay globally unique, -- add custom validation (e.g. lifecycle hooks or middleware) that checks for draft duplicates before saving, or +- or add custom validation (e.g. lifecycle hooks or middleware) that checks for draft duplicates before saving, or - rely on automatically generated unique identifiers such as a `uid` field and document editorial conventions. ::: From 2914559f46de0b36d47c7e971a6a322fa6b9a53f Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Mon, 22 Sep 2025 17:14:25 +0200 Subject: [PATCH 5/6] Update docusaurus/docs/cms/backend-customization/models.md --- docusaurus/docs/cms/backend-customization/models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/cms/backend-customization/models.md b/docusaurus/docs/cms/backend-customization/models.md index ca04db79ee..f3cbb572c2 100644 --- a/docusaurus/docs/cms/backend-customization/models.md +++ b/docusaurus/docs/cms/backend-customization/models.md @@ -197,7 +197,7 @@ To avoid unexpected publication failures: - disable Draft & Publish on content-types that must stay globally unique, - or add custom validation (e.g. lifecycle hooks or middleware) that checks for draft duplicates before saving, or -- rely on automatically generated unique identifiers such as a `uid` field and document editorial conventions. +- or rely on automatically generated unique identifiers such as a `uid` field and document editorial conventions. ::: ```json title="./src/api/[api-name]/content-types/restaurant/schema.json" From 59967b42272491cd71c1239611a5993c971c08da Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Mon, 22 Sep 2025 17:14:40 +0200 Subject: [PATCH 6/6] Update docusaurus/docs/cms/backend-customization/models.md --- docusaurus/docs/cms/backend-customization/models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/cms/backend-customization/models.md b/docusaurus/docs/cms/backend-customization/models.md index f3cbb572c2..bb42117fde 100644 --- a/docusaurus/docs/cms/backend-customization/models.md +++ b/docusaurus/docs/cms/backend-customization/models.md @@ -196,7 +196,7 @@ When [Draft & Publish](/cms/features/draft-and-publish) is enabled, Strapi inten To avoid unexpected publication failures: - disable Draft & Publish on content-types that must stay globally unique, -- or add custom validation (e.g. lifecycle hooks or middleware) that checks for draft duplicates before saving, or +- or add custom validation (e.g. lifecycle hooks or middleware) that checks for draft duplicates before saving, - or rely on automatically generated unique identifiers such as a `uid` field and document editorial conventions. :::