@strapi/data-transfer 4.18.1-experimental.0 → 4.19.0

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.
package/dist/index.mjs CHANGED
@@ -1550,9 +1550,10 @@ const createLinkQuery = (strapi2, trx) => {
1550
1550
  assignOrderColumns();
1551
1551
  const qb = connection.insert(payload).into(addSchema(joinTable.name));
1552
1552
  if (trx) {
1553
- qb.transacting(trx);
1553
+ await trx.transaction(async (nestedTrx) => {
1554
+ await qb.transacting(nestedTrx);
1555
+ });
1554
1556
  }
1555
- await qb;
1556
1557
  }
1557
1558
  };
1558
1559
  return { generateAll, generateAllForAttribute, insert };
@@ -1693,19 +1694,39 @@ const createConfigurationWriteStream = async (strapi2, transaction2) => {
1693
1694
  }
1694
1695
  });
1695
1696
  };
1696
- const createLinksWriteStream = (mapID, strapi2, transaction2) => {
1697
+ const isErrorWithCode = (error) => {
1698
+ return error && typeof error.code === "string";
1699
+ };
1700
+ const isForeignKeyConstraintError = (e) => {
1701
+ const MYSQL_FK_ERROR_CODES = ["1452", "1557", "1216", "1217", "1451"];
1702
+ const POSTGRES_FK_ERROR_CODE = "23503";
1703
+ const SQLITE_FK_ERROR_CODE = "SQLITE_CONSTRAINT_FOREIGNKEY";
1704
+ if (isErrorWithCode(e) && e.code) {
1705
+ return [SQLITE_FK_ERROR_CODE, POSTGRES_FK_ERROR_CODE, ...MYSQL_FK_ERROR_CODES].includes(e.code);
1706
+ }
1707
+ return e.message.toLowerCase().includes("foreign key constraint");
1708
+ };
1709
+ const createLinksWriteStream = (mapID, strapi2, transaction2, onWarning) => {
1697
1710
  return new Writable({
1698
1711
  objectMode: true,
1699
1712
  async write(link2, _encoding, callback) {
1700
1713
  await transaction2?.attach(async (trx) => {
1701
1714
  const { left, right } = link2;
1702
1715
  const query = createLinkQuery(strapi2, trx);
1703
- left.ref = mapID(left.type, left.ref) ?? left.ref;
1704
- right.ref = mapID(right.type, right.ref) ?? right.ref;
1716
+ const originalLeftRef = left.ref;
1717
+ const originalRightRef = right.ref;
1718
+ left.ref = mapID(left.type, originalLeftRef) ?? originalLeftRef;
1719
+ right.ref = mapID(right.type, originalRightRef) ?? originalRightRef;
1705
1720
  try {
1706
1721
  await query().insert(link2);
1707
1722
  } catch (e) {
1708
1723
  if (e instanceof Error) {
1724
+ if (isForeignKeyConstraintError(e)) {
1725
+ onWarning?.(
1726
+ `Skipping link ${left.type}:${originalLeftRef} -> ${right.type}:${originalRightRef} due to a foreign key constraint.`
1727
+ );
1728
+ return callback(null);
1729
+ }
1709
1730
  return callback(e);
1710
1731
  }
1711
1732
  return callback(
@@ -1808,6 +1829,7 @@ class LocalStrapiDestinationProvider {
1808
1829
  strapi;
1809
1830
  transaction;
1810
1831
  uploadsBackupDirectoryName;
1832
+ onWarning;
1811
1833
  /**
1812
1834
  * The entities mapper is used to map old entities to their new IDs
1813
1835
  */
@@ -1985,7 +2007,9 @@ class LocalStrapiDestinationProvider {
1985
2007
  async createAssetsWriteStream() {
1986
2008
  assertValidStrapi(this.strapi, "Not able to stream Assets");
1987
2009
  if (!this.#areAssetsIncluded()) {
1988
- throw new ProviderTransferError("Attempting to transfer assets when they are not included");
2010
+ throw new ProviderTransferError(
2011
+ "Attempting to transfer assets when `assets` is not set in restore options"
2012
+ );
1989
2013
  }
1990
2014
  const removeAssetsBackup = this.#removeAssetsBackup.bind(this);
1991
2015
  const strapi2 = this.strapi;
@@ -2091,7 +2115,7 @@ class LocalStrapiDestinationProvider {
2091
2115
  const { strategy } = this.options;
2092
2116
  const mapID = (uid, id) => this.#entitiesMapper[uid]?.[id];
2093
2117
  if (strategy === "restore") {
2094
- return createLinksWriteStream(mapID, this.strapi, this.transaction);
2118
+ return createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);
2095
2119
  }
2096
2120
  throw new ProviderValidationError(`Invalid strategy ${strategy}`, {
2097
2121
  check: "strategy",
@@ -3547,6 +3571,9 @@ const createPushController = handlerControllerFactory((proto) => ({
3547
3571
  autoDestroy: false,
3548
3572
  getStrapi: () => strapi
3549
3573
  });
3574
+ this.provider.onWarning = (message) => {
3575
+ strapi.log.warn(message);
3576
+ };
3550
3577
  return { transferID: this.transferID };
3551
3578
  },
3552
3579
  async status() {
@@ -4495,7 +4522,9 @@ const DEFAULT_IGNORED_CONTENT_TYPES = [
4495
4522
  "admin::api-token-permission",
4496
4523
  "admin::transfer-token",
4497
4524
  "admin::transfer-token-permission",
4498
- "admin::audit-log"
4525
+ "admin::audit-log",
4526
+ "plugin::content-releases.release",
4527
+ "plugin::content-releases.release-action"
4499
4528
  ];
4500
4529
  const abortTransfer = async ({
4501
4530
  engine,
@@ -4893,6 +4922,8 @@ const action$1 = async (opts) => {
4893
4922
  restore: parseRestoreFromOptions(engineOptions)
4894
4923
  };
4895
4924
  const destination = createLocalStrapiDestinationProvider$1(destinationOptions);
4925
+ destination.onWarning = (message) => console.warn(`
4926
+ ${chalk.yellow("warn")}: ${message}`);
4896
4927
  const engine2 = createTransferEngine$1(source, destination, engineOptions);
4897
4928
  engine2.diagnostics.onDiagnostic(formatDiagnostic("import"));
4898
4929
  const progress = engine2.progress.stream;