@strapi/core 5.31.0 → 5.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,28 @@
1
1
  /**
2
- * This migration is responsible for creating the draft counterpart for all the entries that were in a published state.
2
+ * Migration overview
3
+ * ===================
4
+ * 1. Create bare draft rows for every published entry, cloning only scalar fields (no relations/components yet).
5
+ * We do this with a single INSERT … SELECT per content type to avoid touching the document service for every single v4 entry.
3
6
  *
4
- * In v4, entries could either be in a draft or published state, but not both at the same time.
5
- * In v5, we introduced the concept of document, and an entry can be in a draft or published state.
7
+ * 2. Rewire all relations so the newly created drafts behave exactly like calling `documentService.discardDraft()`
8
+ * on every published entry:
9
+ * - Join-table relations (self, manyToMany, etc.) are copied in bulk.
10
+ * - Foreign keys (joinColumn relations) are updated so draft rows point to draft targets.
11
+ * - Component relations are copied while respecting the discard logic: each draft gets its own component instance,
12
+ * and the component’s relations (including nested components) are remapped to draft targets.
6
13
  *
7
- * This means the migration needs to create the draft counterpart if an entry was published.
14
+ * 3. Components are duplicated at the database layer (new component rows + join-table rows). We deliberately clone
15
+ * instead of sharing component IDs so that draft edits don’t mutate published data.
8
16
  *
9
- * This migration performs the following steps:
10
- * 1. Creates draft entries for all published entries, without it's components, dynamic zones or relations.
11
- * 2. Using the document service, discard those same drafts to copy its relations.
17
+ * Why we do it this way
18
+ * ----------------------
19
+ * Efficiency: calling the document service per entry would issue several queries per relation/component. The SQL
20
+ * batches mirror the service’s behavior but execute in O(content types × batches), so the migration scales to
21
+ * millions of entries.
22
+
23
+ * • Memory safety: any caches that track per-record information (component parent lookups, clone maps) are scoped to
24
+ * a single batch of 1,000 entries. Schema-level caches (component metadata, join table names) remain global because
25
+ * they’re tiny and reused.
12
26
  */
13
27
  import type { Database, Migration } from '@strapi/database';
14
28
  type DocumentVersion = {
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.d.ts","sourceRoot":"","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAI5D,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAqF3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,gBAAuB,GACxB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,oDAgCA;AA2DD,eAAO,MAAM,qBAAqB,EAAE,SAQnC,CAAC"}
1
+ {"version":3,"file":"5.0.0-discard-drafts.d.ts","sourceRoot":"","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAW5D,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AA8pE3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,gBAAuB,GACxB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,oDAgCA;AAED,eAAO,MAAM,qBAAqB,EAAE,SAQnC,CAAC"}