{"version":3,"file":"schema.mjs","sources":["../../../server/src/services/schema.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, errors } from '@strapi/utils';\nimport { mapValues } from 'lodash';\n\nimport type { Schema } from '@strapi/types';\n\nimport createBuilder from './schema-builder';\nimport { createMigrationBuilder } from './migration-builder';\nimport type {\n  AttributeRenamesMapping,\n  RenameAttributeDefinition,\n  UnsupportedRename,\n} from './migration-builder';\nimport { finalizeSchemaMutation, rollbackSchemaMutation } from './schema-mutation';\nimport { getService } from '../utils';\nimport { isValidUidTarget } from '../utils/uid-target';\nimport { emitSchemaEvent } from '../utils/events';\nimport { validateUpdateSchema } from '../controllers/validation/schema';\nimport type { Schema as CTBSchema } from '../controllers/validation/schema';\nimport type { AttributeRenameMigrationMode } from '../config';\nimport {\n  assertCanConvertToSingleType,\n  assertCTBOwnedApplicationContentType,\n  assertValidDisplayName,\n  getRestrictRelationsTo,\n  isContentTypeVisible,\n} from './content-types';\nimport type { CoreContentStructureService } from './content-structure';\n\ntype ContentTypeKind = 'collectionType' | 'singleType';\n\nconst removeEmptyDefaultsOnUpdates = (schema: CTBSchema) => {\n  schema.components.forEach((component) => {\n    if (component.action === 'delete') {\n      return;\n    }\n\n    component.attributes.forEach((attribute) => {\n      if (attribute.action === 'update') {\n        const { properties } = attribute;\n\n        if ('default' in properties && properties.default === '') {\n          properties.default = undefined;\n        }\n      }\n    });\n  });\n\n  schema.contentTypes.forEach((contentType) => {\n    if (contentType.action === 'delete') {\n      return;\n    }\n\n    contentType.attributes.forEach((attribute) => {\n      if (attribute.action === 'update') {\n        const { properties } = attribute;\n\n        if ('default' in properties && properties.default === '') {\n          properties.default = undefined;\n        }\n      }\n    });\n  });\n};\n\nconst removeDeletedUIDTargetFieldsOnUpdates = (schema: CTBSchema) => {\n  schema.contentTypes.forEach((contentType) => {\n    if (contentType.action === 'delete') {\n      return;\n    }\n\n    contentType.attributes.forEach((attribute) => {\n      if (attribute.action === 'update') {\n        const { properties } = attribute;\n\n        if (\n          properties.type === 'uid' &&\n          properties.targetField &&\n          !contentType.attributes.some(\n            (attr) => attr.action !== 'delete' && attr.name === properties.targetField\n          )\n        ) {\n          properties.targetField = undefined;\n        }\n      }\n    });\n  });\n};\n\n/**\n * Composes the ordered rename hops of an updated type into an origin -> final\n * name map (`a -> b, b -> c` gives `a -> c`).\n */\nconst composeRenames = (hops: { oldName?: string; newName?: string }[]): Map<string, string> => {\n  const originByName = new Map<string, string>();\n\n  hops.forEach(({ oldName, newName }) => {\n    if (!oldName || !newName || oldName === newName) {\n      return;\n    }\n\n    const origin = originByName.get(oldName) ?? oldName;\n    originByName.delete(oldName);\n    originByName.set(newName, origin);\n  });\n\n  return new Map([...originByName].map(([name, origin]) => [origin, name]));\n};\n\n/**\n * Makes field conditions follow the renames of this save: a condition whose\n * `var` still names the origin of a rename is pointed at the field's final name.\n *\n * A `var` that names an attribute of the saved type is left alone: the caller\n * already rewrote it, or (in a swap) it cannot be told apart from one that was.\n */\nconst renameConditionVarsOnUpdates = (schema: CTBSchema) => {\n  type AttributeEntry = {\n    action?: string;\n    name?: string;\n    properties?: { conditions?: { visible?: Record<string, unknown> } };\n  };\n  type Entry = {\n    action?: string;\n    renames?: { oldName?: string; newName?: string }[];\n    attributes?: AttributeEntry[];\n  };\n\n  const entries = [\n    ...(schema.contentTypes as unknown as Entry[]),\n    ...(schema.components as unknown as Entry[]),\n  ];\n\n  entries.forEach((entry) => {\n    if (entry.action !== 'update' || !Array.isArray(entry.renames)) {\n      return;\n    }\n\n    const renames = composeRenames(entry.renames);\n    const savedAttributes = (entry.attributes ?? []).filter(\n      (attribute) => attribute.action !== 'delete'\n    );\n    const saved = new Set(savedAttributes.map((attribute) => attribute.name));\n\n    savedAttributes.forEach((attribute) => {\n      Object.values(attribute.properties?.conditions?.visible ?? {}).forEach((rule) => {\n        const fieldVar: unknown = Array.isArray(rule) ? rule[0] : undefined;\n\n        if (\n          typeof fieldVar !== 'object' ||\n          fieldVar === null ||\n          !('var' in fieldVar) ||\n          typeof fieldVar.var !== 'string' ||\n          saved.has(fieldVar.var)\n        ) {\n          return;\n        }\n\n        const finalName = renames.get(fieldVar.var);\n\n        if (finalName !== undefined && saved.has(finalName)) {\n          fieldVar.var = finalName;\n        }\n      });\n    });\n  });\n};\n\n/**\n * Keeps a uid field attached to its target when that target is renamed in this\n * save. A `targetField` that names a saved (non-deleted) attribute of the\n * payload is left alone: the caller already resolved it. When the renamed\n * target is not a string or text field (custom fields are resolved to their\n * underlying type), the uid is detached.\n */\nconst renameUIDTargetFieldsOnUpdates = (schema: CTBSchema) => {\n  schema.contentTypes.forEach((contentType) => {\n    if (contentType.action !== 'update' || !Array.isArray(contentType.renames)) {\n      return;\n    }\n\n    const finalNames = composeRenames(contentType.renames);\n    const savedAttributes = contentType.attributes.filter((attr) => attr.action !== 'delete');\n    const saved = new Set(savedAttributes.map((attr) => attr.name));\n\n    contentType.attributes.forEach((attribute) => {\n      if (attribute.action !== 'update') {\n        return;\n      }\n\n      const { properties } = attribute;\n\n      if (properties.type !== 'uid' || !properties.targetField) {\n        return;\n      }\n\n      const finalName = finalNames.get(properties.targetField);\n\n      if (!finalName || saved.has(properties.targetField)) {\n        return;\n      }\n\n      const target = savedAttributes.find((attr) => attr.name === finalName);\n\n      properties.targetField =\n        target && isValidUidTarget(target.properties) ? finalName : undefined;\n    });\n  });\n};\n\ninterface CollectedRename {\n  uid: string;\n  oldName: string;\n  newName: string;\n  newAttribute?: RenameAttributeDefinition;\n}\n\nconst getAttributeRenameMigrationMode = (): AttributeRenameMigrationMode => {\n  return strapi\n    .plugin('content-type-builder')\n    .config('renameMigrations.attributes', 'prompt-before-save');\n};\n\n/**\n * Collects attribute renames from the update-schema payload. The admin sends an\n * ordered `renames` array per updated content-type / component: the exact path\n * of rename hops the user performed (e.g. `a -> tmp`, `b -> a`, `tmp -> b` for a\n * swap). Order is preserved so the generated migration can replay each hop\n * verbatim — which is inherently collision-free because the Content-Type Builder\n * never allows two fields to share a name at any instant.\n */\nconst collectRenames = (schema: CTBSchema): CollectedRename[] => {\n  const renames: CollectedRename[] = [];\n\n  type RenameHop = { oldName?: string; newName?: string };\n  type AttributeEntry = { action?: string; name?: string; properties?: RenameAttributeDefinition };\n  type RenameAwareEntry = {\n    action?: string;\n    uid: string;\n    renames?: RenameHop[];\n    attributes?: AttributeEntry[];\n  };\n\n  const collectFrom = (entries: RenameAwareEntry[]) => {\n    entries\n      .filter((entry) => entry.action === 'update' && Array.isArray(entry.renames))\n      .forEach((entry) => {\n        // Only the last hop onto a name produces the field that carries the\n        // final definition: in `a -> b, b -> c, x -> b` the first `b` is `a`'s\n        // intermediate name and the final `b` is `x`'s field.\n        const lastHopByNewName = new Map<string, number>();\n        entry.renames!.forEach((hop, index) => {\n          if (hop.newName) {\n            lastHopByNewName.set(hop.newName, index);\n          }\n        });\n\n        entry.renames!.forEach((hop, index) => {\n          if (hop.oldName && hop.newName && hop.oldName !== hop.newName) {\n            // The definition the field ends up with in this save, so the builder\n            // can refuse hops that also change the field's storage (type,\n            // relation target, component…). Intermediate hops of a chain get no\n            // definition and are checked when the chain completes.\n            const newAttribute =\n              lastHopByNewName.get(hop.newName) === index\n                ? entry.attributes?.find(\n                    (attribute) => attribute.action !== 'delete' && attribute.name === hop.newName\n                  )?.properties\n                : undefined;\n\n            renames.push({\n              uid: entry.uid,\n              oldName: hop.oldName,\n              newName: hop.newName,\n              newAttribute,\n            });\n          }\n        });\n      });\n  };\n\n  collectFrom(schema.contentTypes as unknown as RenameAwareEntry[]);\n  collectFrom(schema.components as unknown as RenameAwareEntry[]);\n\n  return renames;\n};\n\n/**\n * Drops renames whose final name is not an attribute after this save (it was\n * deleted in the same save), so no store is pointed at a field that is gone.\n */\nconst keepSavedAttributes = (\n  schema: CTBSchema,\n  mapping: AttributeRenamesMapping\n): AttributeRenamesMapping => {\n  type Entry = { action?: string; uid: string; attributes?: { action?: string; name?: string }[] };\n  const entries = [\n    ...(schema.contentTypes as unknown as Entry[]),\n    ...(schema.components as unknown as Entry[]),\n  ];\n\n  const result: AttributeRenamesMapping = {};\n\n  for (const [uid, renames] of Object.entries(mapping)) {\n    const entry = entries.find((candidate) => candidate.uid === uid);\n    const saved = new Set(\n      (entry?.attributes ?? [])\n        .filter((attribute) => attribute.action !== 'delete' && attribute.name)\n        .map((attribute) => attribute.name as string)\n    );\n\n    for (const [origin, final] of Object.entries(renames)) {\n      if (saved.has(final)) {\n        result[uid] ??= {};\n        result[uid][origin] = final;\n      }\n    }\n  }\n\n  return result;\n};\n\nconst describeUnsupportedReason = (reason: UnsupportedRename['reason']): string => {\n  switch (reason) {\n    case 'type-changed':\n      return 'the field type, relation or component also changed';\n    case 'unsupported-type':\n      return 'the field type cannot be migrated (e.g. polymorphic relation)';\n    case 'attribute-not-found':\n      return 'the field is not in the current schema';\n    case 'target-occupied':\n      return 'the target field still exists in the current schema';\n    case 'model-not-found':\n    default:\n      return 'the type is not in the current schema';\n  }\n};\n\n/**\n * Generates a single data-preserving rename migration for the accepted renames\n * in this save. Must run before the server reloads, while `strapi.db.metadata`\n * still reflects the old (pre-rename) schema. Resolves to the written file's\n * path (so a failed save can remove it), or `null` when nothing was written.\n */\nconst generateRenameMigrations = async (schema: CTBSchema): Promise<string | null> => {\n  // In prompt modes the admin strips refused renames before sending the payload.\n  if (getAttributeRenameMigrationMode() === 'never') {\n    return null;\n  }\n\n  const renames = collectRenames(schema);\n  if (renames.length === 0) {\n    return null;\n  }\n\n  const migrationBuilder = createMigrationBuilder({ strapi });\n\n  for (const { uid, oldName, newName, newAttribute } of renames) {\n    migrationBuilder.addRenameAttribute(uid, { oldName, newName, newAttribute });\n  }\n\n  const attributeRenames = keepSavedAttributes(schema, migrationBuilder.attributeRenamesMapping());\n  if (Object.keys(attributeRenames).length > 0) {\n    migrationBuilder.addAttributeRenames(attributeRenames);\n  }\n\n  const unsupported = migrationBuilder.getUnsupported();\n  if (unsupported.length > 0) {\n    const fields = unsupported\n      .map((u) => `${u.uid}.${u.oldName} (${describeUnsupportedReason(u.reason)})`)\n      .join(', ');\n    strapi.log.warn(\n      `[content-type-builder] Could not generate a rename migration for ${unsupported.length} field(s): ${fields}. Data in these fields may not be preserved.`\n    );\n  }\n\n  if (migrationBuilder.hasChanges()) {\n    return migrationBuilder.writeFiles();\n  }\n\n  return null;\n};\n\n/**\n * Renames a single attribute on a content-type or component and generates the\n * data-preserving migration in one step. Used by the `strapi rename:field` CLI\n * command so scripted / non-UI workflows get the same behaviour as the admin.\n *\n * It reuses the regular `updateSchema` path (and therefore the same rename\n * resolver via `generateRenameMigrations`), so the migration is resolved against\n * the pre-reload `strapi.db.metadata` exactly like the admin save. The caller is\n * responsible for not reloading before this resolves (the CLI simply exits).\n *\n * Unlike the admin, there is no one to confirm a data-losing rename, so it\n * refuses before touching the schema when the rename cannot be migrated.\n */\nexport const renameAttribute = async (\n  uid: string,\n  oldName: string,\n  newName: string\n): Promise<void> => {\n  const { ApplicationError } = errors;\n\n  if (!oldName || !newName) {\n    throw new ApplicationError('Both an old and a new attribute name are required');\n  }\n\n  if (oldName === newName) {\n    throw new ApplicationError(`Cannot rename \"${oldName}\" to itself`);\n  }\n\n  if (getAttributeRenameMigrationMode() === 'never') {\n    throw new ApplicationError(\n      'Rename migrations are disabled (`renameMigrations.attributes: never`); rename the field in the Content-Type Builder instead'\n    );\n  }\n\n  const contentType = (strapi.contentTypes as Record<string, any>)[uid];\n  const component = (strapi.components as Record<string, any>)[uid];\n  const model = contentType ?? component;\n\n  if (!model) {\n    throw new ApplicationError(`No content-type or component found for uid \"${uid}\"`);\n  }\n\n  if (!model.attributes?.[oldName]) {\n    throw new ApplicationError(`Attribute \"${oldName}\" does not exist on \"${uid}\"`);\n  }\n\n  if (model.attributes?.[newName]) {\n    throw new ApplicationError(`Attribute \"${newName}\" already exists on \"${uid}\"`);\n  }\n\n  // Reuse the formatted, CTB-visible attributes (same shape the admin sends) so\n  // the schema edit matches an admin save and the renamed key is the only change.\n  const formattedSchema = await getSchema();\n  const isComponent = Boolean(component);\n  const entry = isComponent\n    ? (formattedSchema.components as Record<string, any>)[uid]\n    : (formattedSchema.contentTypes as Record<string, any>)[uid];\n\n  // Custom fields are exposed with their underlying type; the admin sends them\n  // back as `customField` so the schema file keeps them as custom fields.\n  const toPayloadProperties = (properties: Record<string, any>) =>\n    properties.customField ? { ...properties, type: 'customField' } : properties;\n\n  const attributes = entry.attributes.map(({ name, ...properties }: Record<string, any>) => ({\n    action: 'update',\n    name: name === oldName ? newName : name,\n    properties: toPayloadProperties(properties),\n  }));\n\n  // Dry run: the field keeps its definition, so only the rename itself can be\n  // refused (system attribute, unsupported relation, occupied target…).\n  const { name: _name, ...oldProperties } = entry.attributes.find(\n    (attribute: Record<string, any>) => attribute.name === oldName\n  ) ?? { name: oldName };\n  const probe = createMigrationBuilder({ strapi });\n  probe.addRenameAttribute(uid, {\n    oldName,\n    newName,\n    newAttribute: toPayloadProperties(oldProperties),\n  });\n\n  const refused = probe.getUnsupported();\n  if (refused.length > 0) {\n    throw new ApplicationError(\n      `Cannot rename \"${oldName}\" on \"${uid}\" without losing its data: ${refused\n        .map(({ reason }) => describeUnsupportedReason(reason))\n        .join(', ')}`\n    );\n  }\n\n  const renames = [{ oldName, newName }];\n\n  const payload = isComponent\n    ? {\n        contentTypes: [],\n        components: [\n          {\n            action: 'update',\n            uid,\n            category: model.category,\n            displayName: model.info?.displayName,\n            icon: model.info?.icon,\n            description: model.info?.description,\n            pluginOptions: model.pluginOptions,\n            renames,\n            attributes,\n          },\n        ],\n      }\n    : {\n        contentTypes: [\n          {\n            action: 'update',\n            uid,\n            kind: model.kind,\n            displayName: model.info?.displayName,\n            description: model.info?.description,\n            draftAndPublish: Boolean(model.options?.draftAndPublish),\n            options: model.options,\n            pluginOptions: model.pluginOptions,\n            renames,\n            attributes,\n          },\n        ],\n        components: [],\n      };\n\n  // Same checks as an admin save (name rules, reserved names, snake-case\n  // uniqueness: `fooBar` next to an existing `foo_bar` would share a column).\n  const { data } = await validateUpdateSchema({ data: payload });\n\n  await updateSchema(data as CTBSchema);\n};\n\nconst formatAttributes = (model: any) => {\n  const { getVisibleAttributes } = contentTypesUtils;\n\n  // only get attributes that can be seen in the CTB\n  return getVisibleAttributes(model).map((key) => {\n    return { ...formatAttribute(model.attributes[key]), name: key };\n  });\n};\n\nexport const formatAttribute = (attribute: Schema.Attribute.AnyAttribute & Record<string, any>) => {\n  if (attribute.type === 'relation') {\n    return {\n      ...attribute,\n      targetAttribute: attribute.inversedBy || attribute.mappedBy || null,\n      // Explicitly preserve conditions if they exist\n      ...(attribute.conditions && { conditions: attribute.conditions }),\n    };\n  }\n\n  return attribute;\n};\n\nexport const getSchema = async () => {\n  const contentTypes = mapValues(strapi.contentTypes, (contentType) => {\n    const {\n      uid,\n      options,\n      globalId,\n      pluginOptions,\n      kind,\n      modelName,\n      plugin,\n      collectionName,\n      info,\n      modelType,\n    } = contentType;\n\n    return {\n      uid,\n      modelName,\n      kind,\n      globalId,\n      options,\n      pluginOptions,\n      plugin,\n      collectionName,\n      info,\n      modelType,\n      attributes: formatAttributes(contentType),\n      visible: isContentTypeVisible(contentType),\n      restrictRelationsTo: getRestrictRelationsTo(contentType),\n    };\n  });\n\n  const components = mapValues(strapi.components, (component) => {\n    const { uid, globalId, modelName, collectionName, info, category, modelType } = component;\n\n    return {\n      uid,\n      modelName,\n      globalId,\n      modelType,\n      collectionName,\n      category,\n      info,\n      attributes: formatAttributes(component),\n    };\n  });\n\n  const coreContentStructure: CoreContentStructureService = strapi.get('content-structure');\n  const contentStructure = await coreContentStructure.getCleanedFile();\n\n  return {\n    contentStructure,\n    contentTypes,\n    components,\n    settings: {\n      renameMigrations: {\n        attributes: getAttributeRenameMigrationMode(),\n      },\n    },\n  };\n};\n\nexport const updateSchema = async (schema: CTBSchema) => {\n  const builder = createBuilder();\n  const apiHandler = getService('api-handler') as typeof import('./api-handler');\n\n  const { components, contentTypes, contentStructure } = schema;\n\n  // Reject protected/plugin deletes before builders, API backups, or folder reconciliation can\n  // mutate anything. This is the server-side invariant for crafted update requests.\n  contentTypes\n    .filter((contentType) => contentType.action === 'delete')\n    .forEach((contentType) => assertCTBOwnedApplicationContentType(contentType.uid));\n\n  // An update without `displayName` keeps the stored one; a create has none to fall back on.\n  for (const contentType of contentTypes) {\n    if (\n      contentType.action === 'create' ||\n      (contentType.action === 'update' && contentType.displayName !== undefined)\n    ) {\n      assertValidDisplayName(contentType.displayName);\n    }\n  }\n\n  // Same guard as the edit content-type route, run before anything is written.\n  for (const contentType of contentTypes) {\n    if (contentType.action === 'update' && contentType.kind === 'singleType') {\n      if (strapi.contentTypes[contentType.uid]?.kind === 'collectionType') {\n        await assertCanConvertToSingleType(contentType.uid);\n      }\n    }\n  }\n\n  // pre-process data\n  removeEmptyDefaultsOnUpdates(schema);\n  renameUIDTargetFieldsOnUpdates(schema);\n  removeDeletedUIDTargetFieldsOnUpdates(schema);\n  renameConditionVarsOnUpdates(schema);\n\n  const upsertedUids = new Map<string, ContentTypeKind>();\n  const deletedUids = new Set<string>();\n  const generatedApiNames: string[] = [];\n  const backedUpApiUids: string[] = [];\n  let schemaAlreadyRolledBack = false;\n  let migrationFilePath: string | null = null;\n  const APIsToDelete = contentTypes\n    .filter((contentType) => contentType.action === 'delete')\n    .map((contentType) => contentType.uid);\n\n  try {\n    for (const contentType of contentTypes) {\n      if (contentType.action === 'create') {\n        upsertedUids.set(contentType.uid, contentType.kind ?? 'collectionType');\n      } else if (contentType.action === 'update' && contentType.kind) {\n        // A kind switch in the same save must override the registry's stale kind,\n        // otherwise a folder assignment into the new section fails validation.\n        upsertedUids.set(contentType.uid, contentType.kind);\n      } else if (contentType.action === 'delete') {\n        deletedUids.add(contentType.uid);\n      }\n    }\n\n    // Validate folder references before anything is written. This will throw if invalid.\n    getService('content-structure').validateFromUpdate({\n      incomingStructure: contentStructure,\n      upsertedUids,\n      deletedUids,\n    });\n\n    // we pre create empty typesk\n    for (const contentType of contentTypes) {\n      if (contentType.action === 'create') {\n        builder.createContentType({\n          ...contentType,\n          attributes: {},\n        });\n      }\n    }\n\n    // we pre create empty types\n    for (const component of components) {\n      if (component.action === 'create') {\n        builder.createComponent({\n          ...component,\n          attributes: {},\n        });\n      }\n    }\n\n    for (const contentType of contentTypes) {\n      const { action, uid } = contentType;\n\n      if (action === 'create') {\n        builder.createContentTypeAttributes(\n          uid,\n          contentType.attributes.reduce((acc: any, attr: any) => {\n            acc[attr.name] = attr.properties;\n            return acc;\n          }, {})\n        );\n\n        if (!contentType.plugin) {\n          // Track before generation because a generator failure can leave a partial skeleton.\n          generatedApiNames.push(contentType.singularName);\n          await getService('content-types').generateAPI({\n            displayName: contentType!.displayName,\n            singularName: contentType!.singularName,\n            pluralName: contentType!.pluralName,\n            kind: contentType!.kind,\n          });\n        }\n      }\n\n      if (action === 'update') {\n        builder.editContentType({\n          ...contentType,\n          attributes: contentType.attributes.reduce((acc: any, attr: any) => {\n            if (attr.action === 'delete') {\n              return acc;\n            }\n\n            acc[attr.name] = attr.properties;\n            return acc;\n          }, {}),\n        });\n      }\n\n      if (action === 'delete') {\n        builder.deleteContentType(uid);\n        await apiHandler.backup(uid);\n        backedUpApiUids.push(uid);\n      }\n    }\n\n    for (const component of components) {\n      const { action, uid } = component;\n\n      if (action === 'create') {\n        builder.createComponentAttributes(\n          uid,\n          component.attributes.reduce((acc: any, attr: any) => {\n            acc[attr.name] = attr.properties;\n            return acc;\n          }, {})\n        );\n      }\n\n      if (action === 'update') {\n        builder.editComponent({\n          ...component,\n          attributes: component.attributes.reduce((acc: any, attr: any) => {\n            if (attr.action === 'delete') {\n              return acc;\n            }\n\n            acc[attr.name] = attr.properties;\n            return acc;\n          }, {}),\n        });\n      }\n\n      if (action === 'delete') {\n        builder.deleteComponent(uid);\n      }\n    }\n\n    // run sanity checks on the schema\n    // Relations target existing types\n    // Bidirectional relation have their counterpart in the schema\n    // Components target existing components\n    // Nested components target existing components\n    // Dynamic zones target existing components\n\n    // Generate rename migrations before reloading, while strapi.db.metadata still\n    // reflects the pre-rename schema (the controller triggers the reload after this).\n    migrationFilePath = await generateRenameMigrations(schema);\n\n    // The rows of renamed components are rewritten separately below, so that a failure\n    // before that point leaves them untouched while the catch restores the files.\n    const schemaFilesWritten = await builder.writeFiles({ renameComponentRows: false });\n\n    if (!schemaFilesWritten) {\n      schemaAlreadyRolledBack = true;\n      throw new errors.ApplicationError('Invalid schema edition');\n    }\n\n    for (const uid of APIsToDelete) {\n      await apiHandler.clear(uid, { preserveBackup: true });\n    }\n\n    // Rewrite the rows that store a renamed component uid, then commit the single folder\n    // file last: groups.json cannot be restored once written, and every preceding\n    // filesystem mutation can. The folder commit runs inside the row transaction, so if it\n    // fails the rows are rolled back and the catch restores the files: rows and files stay\n    // on the old uid. If the database COMMIT itself fails after groups.json is written,\n    // groups.json keeps the new folder layout; that is harmless, as unknown uids are\n    // dropped when groups.json is read.\n    await builder.renameComponentRows({\n      // Runs inside the row transaction: filesystem only, no database call in here (with\n      // a single-connection pool it would wait for the transaction forever).\n      beforeCommit: () =>\n        getService('content-structure').commitFromUpdate({\n          incomingStructure: contentStructure,\n          deletedUids,\n        }),\n    });\n  } catch (error) {\n    await rollbackSchemaMutation({\n      builder,\n      apiHandler,\n      backedUpApiUids,\n      generatedApiNames,\n      schemaAlreadyRolledBack,\n      migrationFilePath,\n    });\n\n    throw error;\n  }\n\n  // Backup cleanup is deliberately outside the compensating boundary: at this point all\n  // user-visible artifacts, including groups.json, have committed.\n  for (const error of await finalizeSchemaMutation({ apiHandler, backedUpApiUids })) {\n    strapi.log.error(error);\n  }\n\n  for (const contentType of contentTypes) {\n    if (contentType.action === 'delete') {\n      await emitSchemaEvent('content-type.delete', {\n        contentType: builder.contentTypes.get(contentType.uid),\n      });\n    }\n\n    if (contentType.action === 'update') {\n      await emitSchemaEvent('content-type.update', {\n        contentType: builder.contentTypes.get(contentType.uid),\n      });\n    }\n\n    if (contentType.action === 'create') {\n      await emitSchemaEvent('content-type.create', {\n        contentType: builder.contentTypes.get(contentType.uid),\n      });\n    }\n  }\n\n  for (const component of components) {\n    if (component.action === 'delete') {\n      await emitSchemaEvent('component.delete', {\n        component: builder.components.get(component.uid),\n      });\n    }\n\n    if (component.action === 'update') {\n      await emitSchemaEvent('component.update', {\n        component: builder.components.get(component.uid),\n      });\n    }\n\n    if (component.action === 'create') {\n      await emitSchemaEvent('component.create', {\n        component: builder.components.get(component.uid),\n      });\n    }\n  }\n};\n"],"names":["removeEmptyDefaultsOnUpdates","schema","components","forEach","component","action","attributes","attribute","properties","default","undefined","contentTypes","contentType","removeDeletedUIDTargetFieldsOnUpdates","type","targetField","some","attr","name","composeRenames","hops","originByName","Map","oldName","newName","origin","get","delete","set","map","renameConditionVarsOnUpdates","entries","entry","Array","isArray","renames","savedAttributes","filter","saved","Set","Object","values","conditions","visible","rule","fieldVar","var","has","finalName","renameUIDTargetFieldsOnUpdates","finalNames","target","find","isValidUidTarget","getAttributeRenameMigrationMode","strapi","plugin","config","collectRenames","collectFrom","lastHopByNewName","hop","index","newAttribute","push","uid","keepSavedAttributes","mapping","result","candidate","final","describeUnsupportedReason","reason","generateRenameMigrations","length","migrationBuilder","createMigrationBuilder","addRenameAttribute","attributeRenames","attributeRenamesMapping","keys","addAttributeRenames","unsupported","getUnsupported","fields","u","join","log","warn","hasChanges","writeFiles","renameAttribute","ApplicationError","errors","model","formattedSchema","getSchema","isComponent","Boolean","toPayloadProperties","customField","_name","oldProperties","probe","refused","payload","category","displayName","info","icon","description","pluginOptions","kind","draftAndPublish","options","data","validateUpdateSchema","updateSchema","formatAttributes","getVisibleAttributes","contentTypesUtils","key","formatAttribute","targetAttribute","inversedBy","mappedBy","mapValues","globalId","modelName","collectionName","modelType","isContentTypeVisible","restrictRelationsTo","getRestrictRelationsTo","coreContentStructure","contentStructure","getCleanedFile","settings","renameMigrations","builder","createBuilder","apiHandler","getService","assertCTBOwnedApplicationContentType","assertValidDisplayName","assertCanConvertToSingleType","upsertedUids","deletedUids","generatedApiNames","backedUpApiUids","schemaAlreadyRolledBack","migrationFilePath","APIsToDelete","add","validateFromUpdate","incomingStructure","createContentType","createComponent","createContentTypeAttributes","reduce","acc","singularName","generateAPI","pluralName","editContentType","deleteContentType","backup","createComponentAttributes","editComponent","deleteComponent","schemaFilesWritten","renameComponentRows","clear","preserveBackup","beforeCommit","commitFromUpdate","error","rollbackSchemaMutation","finalizeSchemaMutation","emitSchemaEvent"],"mappings":";;;;;;;;;;;AA8BA,MAAMA,+BAA+B,CAACC,MAAAA,GAAAA;AACpCA,IAAAA,MAAAA,CAAOC,UAAU,CAACC,OAAO,CAAC,CAACC,SAAAA,GAAAA;QACzB,IAAIA,SAAAA,CAAUC,MAAM,KAAK,QAAA,EAAU;AACjC,YAAA;AACF,QAAA;AAEAD,QAAAA,SAAAA,CAAUE,UAAU,CAACH,OAAO,CAAC,CAACI,SAAAA,GAAAA;YAC5B,IAAIA,SAAAA,CAAUF,MAAM,KAAK,QAAA,EAAU;gBACjC,MAAM,EAAEG,UAAU,EAAE,GAAGD,SAAAA;AAEvB,gBAAA,IAAI,SAAA,IAAaC,UAAAA,IAAcA,UAAAA,CAAWC,OAAO,KAAK,EAAA,EAAI;AACxDD,oBAAAA,UAAAA,CAAWC,OAAO,GAAGC,SAAAA;AACvB,gBAAA;AACF,YAAA;AACF,QAAA,CAAA,CAAA;AACF,IAAA,CAAA,CAAA;AAEAT,IAAAA,MAAAA,CAAOU,YAAY,CAACR,OAAO,CAAC,CAACS,WAAAA,GAAAA;QAC3B,IAAIA,WAAAA,CAAYP,MAAM,KAAK,QAAA,EAAU;AACnC,YAAA;AACF,QAAA;AAEAO,QAAAA,WAAAA,CAAYN,UAAU,CAACH,OAAO,CAAC,CAACI,SAAAA,GAAAA;YAC9B,IAAIA,SAAAA,CAAUF,MAAM,KAAK,QAAA,EAAU;gBACjC,MAAM,EAAEG,UAAU,EAAE,GAAGD,SAAAA;AAEvB,gBAAA,IAAI,SAAA,IAAaC,UAAAA,IAAcA,UAAAA,CAAWC,OAAO,KAAK,EAAA,EAAI;AACxDD,oBAAAA,UAAAA,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