@strapi/core 5.0.0-beta.15 → 5.0.0-beta.17

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.
@@ -10,11 +10,10 @@ type Knex = Parameters<Migration['up']>[0];
10
10
  * Versions with only a draft version will be ignored.
11
11
  * Only versions with a published version (which always have a draft version) will be discarded.
12
12
  */
13
- export declare function getBatchToDiscard({ db, trx, uid, isLocalized, batchSize, }: {
13
+ export declare function getBatchToDiscard({ db, trx, uid, batchSize, }: {
14
14
  db: Database;
15
15
  trx: Knex;
16
16
  uid: string;
17
- isLocalized: boolean;
18
17
  batchSize?: number;
19
18
  }): AsyncGenerator<DocumentVersion[], void, unknown>;
20
19
  /**
@@ -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":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAK5D,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;AAE3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,WAAW,EACX,SAAgB,GACjB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,oDA6BA;AA+CD;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,SASnC,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":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG5D,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;AAE3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,SAAgB,GACjB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,oDAuBA;AAiCD;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,SASnC,CAAC"}
@@ -5,17 +5,12 @@ async function* getBatchToDiscard({
5
5
  db,
6
6
  trx,
7
7
  uid,
8
- isLocalized,
9
8
  batchSize = 1e3
10
9
  }) {
11
10
  let offset = 0;
12
11
  let hasMore = true;
13
- const fields = ["id", "documentId"];
14
- if (isLocalized) {
15
- fields.push("locale");
16
- }
17
12
  while (hasMore) {
18
- const batch = await db.queryBuilder(uid).select(fields).where({ publishedAt: { $ne: null } }).limit(batchSize).offset(offset).orderBy("id").transacting(trx).execute();
13
+ const batch = await db.queryBuilder(uid).select(["id", "documentId", "locale"]).where({ publishedAt: { $ne: null } }).limit(batchSize).offset(offset).orderBy("id").transacting(trx).execute();
19
14
  if (batch.length < batchSize) {
20
15
  hasMore = false;
21
16
  }
@@ -32,18 +27,11 @@ const migrateUp = async (trx, db) => {
32
27
  const uid = meta.uid;
33
28
  const model = strapi.getModel(uid);
34
29
  const hasDP = strapiUtils.contentTypes.hasDraftAndPublish(model);
35
- const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType(model);
36
30
  if (!hasDP) {
37
31
  continue;
38
32
  }
39
- const discardDraft = async (entry) => {
40
- const params = { documentId: entry.documentId };
41
- if (isLocalized) {
42
- params.locale = entry.locale;
43
- }
44
- strapi.documents(uid).discardDraft(params);
45
- };
46
- for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid, isLocalized })) {
33
+ const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
34
+ for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
47
35
  await strapiUtils.async.map(batch, discardDraft, { concurrency: 10 });
48
36
  }
49
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.js","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { UID, Modules } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DiscardDraftParams<TSchemaUID extends UID.ContentType> =\n Modules.Documents.ServiceParams<TSchemaUID>['discardDraft'];\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n isLocalized,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n isLocalized: boolean;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n const fields = ['id', 'documentId'];\n\n if (isLocalized) {\n fields.push('locale');\n }\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(fields)\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\nconst migrateUp = async (trx: Knex, db: Database) => {\n for (const meta of db.metadata.values()) {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n\n const hasDP = contentTypes.hasDraftAndPublish(model);\n const isLocalized = strapi\n .plugin('i18n')\n .service('content-types')\n .isLocalizedContentType(model);\n\n if (!hasDP) {\n continue;\n }\n\n const discardDraft = async (entry: DocumentVersion) => {\n const params: DiscardDraftParams<typeof uid> = { documentId: entry.documentId };\n\n // Only add the locale param if the model is localized\n if (isLocalized) {\n params.locale = entry.locale;\n }\n\n strapi\n .documents(uid)\n // Discard draft by referencing the documentId (and locale if the model is localized)\n .discardDraft(params);\n };\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid, isLocalized })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\n/**\n * On V4 there was no concept of document, and an entry could be in a draft or published state.\n * But not both at the same time.\n *\n * On V5 we introduced the concept of document, and an entry can be in a draft or published state,\n * with the requirement that a document must always have a draft.\n *\n * This migration creates the document draft counterpart for all the entries that were in a published state.\n */\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n // TODO: Log to inform the user that the migration is running in the background\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["contentTypes","async"],"mappings":";;;AAgBA,gBAAuB,kBAAkB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAMG;AACD,MAAI,SAAS;AACb,MAAI,UAAU;AAER,QAAA,SAAS,CAAC,MAAM,YAAY;AAElC,MAAI,aAAa;AACf,WAAO,KAAK,QAAQ;AAAA,EACtB;AAEA,SAAO,SAAS;AAEd,UAAM,QAA2B,MAAM,GACpC,aAAa,GAAG,EAChB,OAAO,MAAM,EACb,MAAM,EAAE,aAAa,EAAE,KAAK,OAAQ,CAAA,EACpC,MAAM,SAAS,EACf,OAAO,MAAM,EACb,QAAQ,IAAI,EACZ,YAAY,GAAG,EACf,QAAQ;AAEP,QAAA,MAAM,SAAS,WAAW;AAClB,gBAAA;AAAA,IACZ;AAEU,cAAA;AACJ,UAAA;AAAA,EACR;AACF;AAEA,MAAM,YAAY,OAAO,KAAW,OAAiB;AACnD,aAAW,QAAQ,GAAG,SAAS,OAAA,GAAU;AACvC,UAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,UAAM,MAAM,KAAK;AACX,UAAA,QAAQ,OAAO,SAAS,GAAG;AAE3B,UAAA,QAAQA,YAAAA,aAAa,mBAAmB,KAAK;AAC7C,UAAA,cAAc,OACjB,OAAO,MAAM,EACb,QAAQ,eAAe,EACvB,uBAAuB,KAAK;AAE/B,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEM,UAAA,eAAe,OAAO,UAA2B;AACrD,YAAM,SAAyC,EAAE,YAAY,MAAM,WAAW;AAG9E,UAAI,aAAa;AACf,eAAO,SAAS,MAAM;AAAA,MACxB;AAEA,aACG,UAAU,GAAG,EAEb,aAAa,MAAM;AAAA,IAAA;AAOP,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,KAAK,KAAK,YAAY,CAAC,GAAG;AACpF,YAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;AAAA,EACF;AACF;AAWO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AAEV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;;;"}
1
+ {"version":3,"file":"5.0.0-discard-drafts.js","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\nconst migrateUp = async (trx: Knex, db: Database) => {\n for (const meta of db.metadata.values()) {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n continue;\n }\n\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(uid)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\n/**\n * On V4 there was no concept of document, and an entry could be in a draft or published state.\n * But not both at the same time.\n *\n * On V5 we introduced the concept of document, and an entry can be in a draft or published state,\n * with the requirement that a document must always have a draft.\n *\n * This migration creates the document draft counterpart for all the entries that were in a published state.\n */\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n // TODO: Log to inform the user that the migration is running in the background\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["contentTypes","async"],"mappings":";;;AAcA,gBAAuB,kBAAkB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAKG;AACD,MAAI,SAAS;AACb,MAAI,UAAU;AAEd,SAAO,SAAS;AAEd,UAAM,QAA2B,MAAM,GACpC,aAAa,GAAG,EAChB,OAAO,CAAC,MAAM,cAAc,QAAQ,CAAC,EACrC,MAAM,EAAE,aAAa,EAAE,KAAK,KAAO,EAAA,CAAC,EACpC,MAAM,SAAS,EACf,OAAO,MAAM,EACb,QAAQ,IAAI,EACZ,YAAY,GAAG,EACf,QAAQ;AAEP,QAAA,MAAM,SAAS,WAAW;AAClB,gBAAA;AAAA,IACZ;AAEU,cAAA;AACJ,UAAA;AAAA,EACR;AACF;AAEA,MAAM,YAAY,OAAO,KAAW,OAAiB;AACnD,aAAW,QAAQ,GAAG,SAAS,OAAA,GAAU;AACvC,UAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,UAAM,MAAM,KAAK;AACX,UAAA,QAAQ,OAAO,SAAS,GAAG;AAC3B,UAAA,QAAQA,YAAAA,aAAa,mBAAmB,KAAK;AACnD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,UAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAG,EAEb,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG;AACvE,YAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;AAAA,EACF;AACF;AAWO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AAEV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;;;"}
@@ -3,17 +3,12 @@ async function* getBatchToDiscard({
3
3
  db,
4
4
  trx,
5
5
  uid,
6
- isLocalized,
7
6
  batchSize = 1e3
8
7
  }) {
9
8
  let offset = 0;
10
9
  let hasMore = true;
11
- const fields = ["id", "documentId"];
12
- if (isLocalized) {
13
- fields.push("locale");
14
- }
15
10
  while (hasMore) {
16
- const batch = await db.queryBuilder(uid).select(fields).where({ publishedAt: { $ne: null } }).limit(batchSize).offset(offset).orderBy("id").transacting(trx).execute();
11
+ const batch = await db.queryBuilder(uid).select(["id", "documentId", "locale"]).where({ publishedAt: { $ne: null } }).limit(batchSize).offset(offset).orderBy("id").transacting(trx).execute();
17
12
  if (batch.length < batchSize) {
18
13
  hasMore = false;
19
14
  }
@@ -30,18 +25,11 @@ const migrateUp = async (trx, db) => {
30
25
  const uid = meta.uid;
31
26
  const model = strapi.getModel(uid);
32
27
  const hasDP = contentTypes.hasDraftAndPublish(model);
33
- const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType(model);
34
28
  if (!hasDP) {
35
29
  continue;
36
30
  }
37
- const discardDraft = async (entry) => {
38
- const params = { documentId: entry.documentId };
39
- if (isLocalized) {
40
- params.locale = entry.locale;
41
- }
42
- strapi.documents(uid).discardDraft(params);
43
- };
44
- for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid, isLocalized })) {
31
+ const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
32
+ for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
45
33
  await async.map(batch, discardDraft, { concurrency: 10 });
46
34
  }
47
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.mjs","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { UID, Modules } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DiscardDraftParams<TSchemaUID extends UID.ContentType> =\n Modules.Documents.ServiceParams<TSchemaUID>['discardDraft'];\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n isLocalized,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n isLocalized: boolean;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n const fields = ['id', 'documentId'];\n\n if (isLocalized) {\n fields.push('locale');\n }\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(fields)\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\nconst migrateUp = async (trx: Knex, db: Database) => {\n for (const meta of db.metadata.values()) {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n\n const hasDP = contentTypes.hasDraftAndPublish(model);\n const isLocalized = strapi\n .plugin('i18n')\n .service('content-types')\n .isLocalizedContentType(model);\n\n if (!hasDP) {\n continue;\n }\n\n const discardDraft = async (entry: DocumentVersion) => {\n const params: DiscardDraftParams<typeof uid> = { documentId: entry.documentId };\n\n // Only add the locale param if the model is localized\n if (isLocalized) {\n params.locale = entry.locale;\n }\n\n strapi\n .documents(uid)\n // Discard draft by referencing the documentId (and locale if the model is localized)\n .discardDraft(params);\n };\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid, isLocalized })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\n/**\n * On V4 there was no concept of document, and an entry could be in a draft or published state.\n * But not both at the same time.\n *\n * On V5 we introduced the concept of document, and an entry can be in a draft or published state,\n * with the requirement that a document must always have a draft.\n *\n * This migration creates the document draft counterpart for all the entries that were in a published state.\n */\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n // TODO: Log to inform the user that the migration is running in the background\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":[],"mappings":";AAgBA,gBAAuB,kBAAkB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAMG;AACD,MAAI,SAAS;AACb,MAAI,UAAU;AAER,QAAA,SAAS,CAAC,MAAM,YAAY;AAElC,MAAI,aAAa;AACf,WAAO,KAAK,QAAQ;AAAA,EACtB;AAEA,SAAO,SAAS;AAEd,UAAM,QAA2B,MAAM,GACpC,aAAa,GAAG,EAChB,OAAO,MAAM,EACb,MAAM,EAAE,aAAa,EAAE,KAAK,OAAQ,CAAA,EACpC,MAAM,SAAS,EACf,OAAO,MAAM,EACb,QAAQ,IAAI,EACZ,YAAY,GAAG,EACf,QAAQ;AAEP,QAAA,MAAM,SAAS,WAAW;AAClB,gBAAA;AAAA,IACZ;AAEU,cAAA;AACJ,UAAA;AAAA,EACR;AACF;AAEA,MAAM,YAAY,OAAO,KAAW,OAAiB;AACnD,aAAW,QAAQ,GAAG,SAAS,OAAA,GAAU;AACvC,UAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,UAAM,MAAM,KAAK;AACX,UAAA,QAAQ,OAAO,SAAS,GAAG;AAE3B,UAAA,QAAQ,aAAa,mBAAmB,KAAK;AAC7C,UAAA,cAAc,OACjB,OAAO,MAAM,EACb,QAAQ,eAAe,EACvB,uBAAuB,KAAK;AAE/B,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEM,UAAA,eAAe,OAAO,UAA2B;AACrD,YAAM,SAAyC,EAAE,YAAY,MAAM,WAAW;AAG9E,UAAI,aAAa;AACf,eAAO,SAAS,MAAM;AAAA,MACxB;AAEA,aACG,UAAU,GAAG,EAEb,aAAa,MAAM;AAAA,IAAA;AAOP,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,KAAK,KAAK,YAAY,CAAC,GAAG;AACpF,YAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;AAAA,EACF;AACF;AAWO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AAEV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;"}
1
+ {"version":3,"file":"5.0.0-discard-drafts.mjs","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\nconst migrateUp = async (trx: Knex, db: Database) => {\n for (const meta of db.metadata.values()) {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n continue;\n }\n\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(uid)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\n/**\n * On V4 there was no concept of document, and an entry could be in a draft or published state.\n * But not both at the same time.\n *\n * On V5 we introduced the concept of document, and an entry can be in a draft or published state,\n * with the requirement that a document must always have a draft.\n *\n * This migration creates the document draft counterpart for all the entries that were in a published state.\n */\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n // TODO: Log to inform the user that the migration is running in the background\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":[],"mappings":";AAcA,gBAAuB,kBAAkB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAKG;AACD,MAAI,SAAS;AACb,MAAI,UAAU;AAEd,SAAO,SAAS;AAEd,UAAM,QAA2B,MAAM,GACpC,aAAa,GAAG,EAChB,OAAO,CAAC,MAAM,cAAc,QAAQ,CAAC,EACrC,MAAM,EAAE,aAAa,EAAE,KAAK,KAAO,EAAA,CAAC,EACpC,MAAM,SAAS,EACf,OAAO,MAAM,EACb,QAAQ,IAAI,EACZ,YAAY,GAAG,EACf,QAAQ;AAEP,QAAA,MAAM,SAAS,WAAW;AAClB,gBAAA;AAAA,IACZ;AAEU,cAAA;AACJ,UAAA;AAAA,EACR;AACF;AAEA,MAAM,YAAY,OAAO,KAAW,OAAiB;AACnD,aAAW,QAAQ,GAAG,SAAS,OAAA,GAAU;AACvC,UAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,UAAM,MAAM,KAAK;AACX,UAAA,QAAQ,OAAO,SAAS,GAAG;AAC3B,UAAA,QAAQ,aAAa,mBAAmB,KAAK;AACnD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,UAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAG,EAEb,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG;AACvE,YAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;AAAA,EACF;AACF;AAWO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AAEV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;"}
@@ -1,4 +1,4 @@
1
- import type { Schema } from '@strapi/types';
1
+ import { Schema } from '@strapi/types';
2
2
  interface Input {
3
3
  oldContentTypes: Record<string, Schema.ContentType>;
4
4
  contentTypes: Record<string, Schema.ContentType>;
@@ -1 +1 @@
1
- {"version":3,"file":"draft-publish.d.ts","sourceRoot":"","sources":["../../src/migrations/draft-publish.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,MAAM,EAAE,MAAM,eAAe,CAAC;AAMrD,UAAU,KAAK;IACb,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;CAClD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,qBAAqB,sCAA6C,KAAK,kBAmD5E,CAAC;AAEF,QAAA,MAAM,sBAAsB,sCAA6C,KAAK,kBAqB7E,CAAC;AAEF,OAAO,EAAE,qBAAqB,IAAI,MAAM,EAAE,sBAAsB,IAAI,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"draft-publish.d.ts","sourceRoot":"","sources":["../../src/migrations/draft-publish.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIvC,UAAU,KAAK;IACb,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;CAClD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,qBAAqB,sCAA6C,KAAK,kBAoC5E,CAAC;AAEF,QAAA,MAAM,sBAAsB,sCAA6C,KAAK,kBAqB7E,CAAC;AAEF,OAAO,EAAE,qBAAqB,IAAI,MAAM,EAAE,sBAAsB,IAAI,OAAO,EAAE,CAAC"}
@@ -13,16 +13,9 @@ const enableDraftAndPublish = async ({ oldContentTypes, contentTypes }) => {
13
13
  }
14
14
  const oldContentType = oldContentTypes[uid];
15
15
  const contentType = contentTypes[uid];
16
- const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType(contentType);
17
16
  if (!strapiUtils.contentTypes.hasDraftAndPublish(oldContentType) && strapiUtils.contentTypes.hasDraftAndPublish(contentType)) {
18
- const discardDraft = async (entry) => {
19
- const params = { documentId: entry.documentId };
20
- if (isLocalized) {
21
- params.locale = entry.locale;
22
- }
23
- return strapi.documents(uid).discardDraft(params);
24
- };
25
- for await (const batch of _5_0_0DiscardDrafts.getBatchToDiscard({ db: strapi.db, trx, uid, isLocalized })) {
17
+ const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
18
+ for await (const batch of _5_0_0DiscardDrafts.getBatchToDiscard({ db: strapi.db, trx, uid })) {
26
19
  await strapiUtils.async.map(batch, discardDraft, { concurrency: 10 });
27
20
  }
28
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"draft-publish.js","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, async } from '@strapi/utils';\nimport type { Modules, Schema } from '@strapi/types';\n\nimport { getBatchToDiscard } from './database/5.0.0-discard-drafts';\n\ntype DiscardDraftParams = Modules.Documents.ServiceParams['discardDraft'];\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n const isLocalized = strapi\n .plugin('i18n')\n .service('content-types')\n .isLocalizedContentType(contentType);\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const discardDraft = async (entry: { documentId: string; locale: string }) => {\n const params: DiscardDraftParams = { documentId: entry.documentId };\n\n // Only add the locale param if the old content-type is localized\n if (isLocalized) {\n params.locale = entry.locale;\n }\n\n return (\n strapi\n .documents(uid as any)\n // Discard draft by referencing the documentId (and locale if the model is localized)\n .discardDraft(params)\n );\n };\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid, isLocalized })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n }\n });\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypesUtils","getBatchToDiscard","async"],"mappings":";;;;AAoBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiB,mBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAGA,SAAO,OAAO,GAAG,YAAY,OAAO,QAAQ;AAC1C,eAAW,OAAO,cAAc;AAC1B,UAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,MACF;AAEM,YAAA,iBAAiB,gBAAgB,GAAG;AACpC,YAAA,cAAc,aAAa,GAAG;AAE9B,YAAA,cAAc,OACjB,OAAO,MAAM,EACb,QAAQ,eAAe,EACvB,uBAAuB,WAAW;AAInC,UAAA,CAACA,yBAAkB,mBAAmB,cAAc,KACpDA,yBAAkB,mBAAmB,WAAW,GAChD;AACM,cAAA,eAAe,OAAO,UAAkD;AAC5E,gBAAM,SAA6B,EAAE,YAAY,MAAM,WAAW;AAGlE,cAAI,aAAa;AACf,mBAAO,SAAS,MAAM;AAAA,UACxB;AAEA,iBACE,OACG,UAAU,GAAU,EAEpB,aAAa,MAAM;AAAA,QAAA;AAQT,yBAAA,SAASC,sCAAkB,EAAE,IAAI,OAAO,IAAI,KAAK,KAAK,YAAY,CAAC,GAAG;AACrF,gBAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AACH;AAEA,MAAM,yBAAyB,OAAO,EAAE,iBAAiB,mBAA0B;AACjF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAEA,aAAW,OAAO,cAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAc,aAAa,GAAG;AAIlC,QAAAF,YAAAA,aAAkB,mBAAmB,cAAc,KACnD,CAACA,yBAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;;;"}
1
+ {"version":3,"file":"draft-publish.js","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, async } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\nimport { getBatchToDiscard } from './database/5.0.0-discard-drafts';\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const discardDraft = async (entry: { documentId: string; locale: string }) =>\n strapi\n .documents(uid as any)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n }\n });\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypesUtils","getBatchToDiscard","async"],"mappings":";;;;AAkBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiB,mBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAGA,SAAO,OAAO,GAAG,YAAY,OAAO,QAAQ;AAC1C,eAAW,OAAO,cAAc;AAC1B,UAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,MACF;AAEM,YAAA,iBAAiB,gBAAgB,GAAG;AACpC,YAAA,cAAc,aAAa,GAAG;AAIlC,UAAA,CAACA,yBAAkB,mBAAmB,cAAc,KACpDA,yBAAkB,mBAAmB,WAAW,GAChD;AACA,cAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAU,EAEpB,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,yBAAA,SAASC,sCAAkB,EAAE,IAAI,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG;AACxE,gBAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AACH;AAEA,MAAM,yBAAyB,OAAO,EAAE,iBAAiB,mBAA0B;AACjF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAEA,aAAW,OAAO,cAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAc,aAAa,GAAG;AAIlC,QAAAF,YAAAA,aAAkB,mBAAmB,cAAc,KACnD,CAACA,yBAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;;;"}
@@ -11,16 +11,9 @@ const enableDraftAndPublish = async ({ oldContentTypes, contentTypes: contentTyp
11
11
  }
12
12
  const oldContentType = oldContentTypes[uid];
13
13
  const contentType = contentTypes$1[uid];
14
- const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType(contentType);
15
14
  if (!contentTypes.hasDraftAndPublish(oldContentType) && contentTypes.hasDraftAndPublish(contentType)) {
16
- const discardDraft = async (entry) => {
17
- const params = { documentId: entry.documentId };
18
- if (isLocalized) {
19
- params.locale = entry.locale;
20
- }
21
- return strapi.documents(uid).discardDraft(params);
22
- };
23
- for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid, isLocalized })) {
15
+ const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
16
+ for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid })) {
24
17
  await async.map(batch, discardDraft, { concurrency: 10 });
25
18
  }
26
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"draft-publish.mjs","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, async } from '@strapi/utils';\nimport type { Modules, Schema } from '@strapi/types';\n\nimport { getBatchToDiscard } from './database/5.0.0-discard-drafts';\n\ntype DiscardDraftParams = Modules.Documents.ServiceParams['discardDraft'];\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n const isLocalized = strapi\n .plugin('i18n')\n .service('content-types')\n .isLocalizedContentType(contentType);\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const discardDraft = async (entry: { documentId: string; locale: string }) => {\n const params: DiscardDraftParams = { documentId: entry.documentId };\n\n // Only add the locale param if the old content-type is localized\n if (isLocalized) {\n params.locale = entry.locale;\n }\n\n return (\n strapi\n .documents(uid as any)\n // Discard draft by referencing the documentId (and locale if the model is localized)\n .discardDraft(params)\n );\n };\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid, isLocalized })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n }\n });\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypes","contentTypesUtils"],"mappings":";;AAoBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiBA,cAAAA,qBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAGA,SAAO,OAAO,GAAG,YAAY,OAAO,QAAQ;AAC1C,eAAW,OAAOA,gBAAc;AAC1B,UAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,MACF;AAEM,YAAA,iBAAiB,gBAAgB,GAAG;AACpC,YAAA,cAAcA,eAAa,GAAG;AAE9B,YAAA,cAAc,OACjB,OAAO,MAAM,EACb,QAAQ,eAAe,EACvB,uBAAuB,WAAW;AAInC,UAAA,CAACC,aAAkB,mBAAmB,cAAc,KACpDA,aAAkB,mBAAmB,WAAW,GAChD;AACM,cAAA,eAAe,OAAO,UAAkD;AAC5E,gBAAM,SAA6B,EAAE,YAAY,MAAM,WAAW;AAGlE,cAAI,aAAa;AACf,mBAAO,SAAS,MAAM;AAAA,UACxB;AAEA,iBACE,OACG,UAAU,GAAU,EAEpB,aAAa,MAAM;AAAA,QAAA;AAQT,yBAAA,SAAS,kBAAkB,EAAE,IAAI,OAAO,IAAI,KAAK,KAAK,YAAY,CAAC,GAAG;AACrF,gBAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AACH;AAEA,MAAM,yBAAyB,OAAO,EAAE,iBAAiBD,cAAAA,qBAA0B;AACjF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAEA,aAAW,OAAOA,gBAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAcA,eAAa,GAAG;AAIlC,QAAAC,aAAkB,mBAAmB,cAAc,KACnD,CAACA,aAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"draft-publish.mjs","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, async } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\nimport { getBatchToDiscard } from './database/5.0.0-discard-drafts';\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const discardDraft = async (entry: { documentId: string; locale: string }) =>\n strapi\n .documents(uid as any)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n }\n });\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypes","contentTypesUtils"],"mappings":";;AAkBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiBA,cAAAA,qBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAGA,SAAO,OAAO,GAAG,YAAY,OAAO,QAAQ;AAC1C,eAAW,OAAOA,gBAAc;AAC1B,UAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,MACF;AAEM,YAAA,iBAAiB,gBAAgB,GAAG;AACpC,YAAA,cAAcA,eAAa,GAAG;AAIlC,UAAA,CAACC,aAAkB,mBAAmB,cAAc,KACpDA,aAAkB,mBAAmB,WAAW,GAChD;AACA,cAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAU,EAEpB,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,yBAAA,SAAS,kBAAkB,EAAE,IAAI,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG;AACxE,gBAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AACH;AAEA,MAAM,yBAAyB,OAAO,EAAE,iBAAiBD,cAAAA,qBAA0B;AACjF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAEA,aAAW,OAAOA,gBAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAcA,eAAa,GAAG;AAIlC,QAAAC,aAAkB,mBAAmB,cAAc,KACnD,CAACA,aAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/core",
3
- "version": "5.0.0-beta.15",
3
+ "version": "5.0.0-beta.17",
4
4
  "description": "Core of Strapi",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -55,16 +55,16 @@
55
55
  "@koa/cors": "5.0.0",
56
56
  "@koa/router": "12.0.1",
57
57
  "@paralleldrive/cuid2": "2.2.2",
58
- "@strapi/admin": "5.0.0-beta.15",
59
- "@strapi/database": "5.0.0-beta.15",
60
- "@strapi/generate-new": "5.0.0-beta.15",
61
- "@strapi/generators": "5.0.0-beta.15",
62
- "@strapi/logger": "5.0.0-beta.15",
58
+ "@strapi/admin": "5.0.0-beta.17",
59
+ "@strapi/database": "5.0.0-beta.17",
60
+ "@strapi/generate-new": "5.0.0-beta.17",
61
+ "@strapi/generators": "5.0.0-beta.17",
62
+ "@strapi/logger": "5.0.0-beta.17",
63
63
  "@strapi/pack-up": "5.0.0",
64
- "@strapi/permissions": "5.0.0-beta.15",
65
- "@strapi/types": "5.0.0-beta.15",
66
- "@strapi/typescript-utils": "5.0.0-beta.15",
67
- "@strapi/utils": "5.0.0-beta.15",
64
+ "@strapi/permissions": "5.0.0-beta.17",
65
+ "@strapi/types": "5.0.0-beta.17",
66
+ "@strapi/typescript-utils": "5.0.0-beta.17",
67
+ "@strapi/utils": "5.0.0-beta.17",
68
68
  "bcryptjs": "2.4.3",
69
69
  "boxen": "5.1.2",
70
70
  "chalk": "4.1.2",
@@ -126,13 +126,13 @@
126
126
  "@types/node": "18.19.24",
127
127
  "@types/node-schedule": "2.1.0",
128
128
  "@types/statuses": "2.0.1",
129
- "eslint-config-custom": "5.0.0-beta.15",
129
+ "eslint-config-custom": "5.0.0-beta.17",
130
130
  "supertest": "6.3.3",
131
- "tsconfig": "5.0.0-beta.15"
131
+ "tsconfig": "5.0.0-beta.17"
132
132
  },
133
133
  "engines": {
134
134
  "node": ">=18.0.0 <=20.x.x",
135
135
  "npm": ">=6.0.0"
136
136
  },
137
- "gitHead": "bdee57a0571da734d9a1c4b5c35b3bbdb26fda8b"
137
+ "gitHead": "d0b51fbf84decc447d0be264128c9d1f35b3a60f"
138
138
  }