Skip to content
Merged

Dev #1121

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/src/services/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ const startTestMigration = async (req: Request): Promise<any> => {
region,
user_id,
is_sso,
isTest: true
});

await marketPlaceAppService?.createAppManifest({
Expand Down
15 changes: 13 additions & 2 deletions api/src/utils/content-type-creator.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,19 @@ const saveContent = async (ct: any, contentSave: string) => {
throw readError; // rethrow if it's not a "file not found" error
}
}
// Append new content to schemaData
schemaData.push(ct);
// Upsert by uid: replace an existing entry for this content type instead of
// blindly appending. schema.json is not cleared between runs (clearStaleEntries
// only wipes the entries/ subtree), so re-running against the same stack β€” e.g.
// a re-run test migration or a delta iteration β€” would otherwise accumulate
// duplicate content-type entries.
const existingIndex = Array.isArray(schemaData)
? schemaData.findIndex((existing: any) => existing?.uid === ct?.uid)
: -1;
if (existingIndex > -1) {
schemaData[existingIndex] = ct;
} else {
schemaData.push(ct);
}
// Write the updated schemaData back to schema.json
await fs.promises.writeFile(schemaFilePath, JSON.stringify(schemaData, null, 2));

Expand Down
8 changes: 5 additions & 3 deletions api/src/utils/field-attacher.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { shouldSkipContentTypeCreation } from "./content-type-checker.utils.js";
import { sanitizeProjectId, sanitizeStackId } from "./sanitize-path.utils.js";
import customLogger from "./custom-logger.utils.js";

export const fieldAttacher = async ({ projectId, orgId, destinationStackId, region, user_id, is_sso }: any) => {
export const fieldAttacher = async ({ projectId, orgId, destinationStackId, region, user_id, is_sso, isTest = false}: any) => {
const safeProjectId = sanitizeProjectId(projectId);
if (!safeProjectId) {
throw new Error("Invalid project identifier");
Expand Down Expand Up @@ -45,9 +45,11 @@ export const fieldAttacher = async ({ projectId, orgId, destinationStackId, regi
})
}

if (iteration === 1) {
// Always create the content type on a test migration (skip the iteration-based
// dedupe entirely) or on the first real iteration. The skip logic below only
// applies to delta iterations of a real migration.
if (isTest || iteration === 1) {
await contenTypeMaker({ contentType, destinationStackId: safeDestinationStackId, projectId: safeProjectId, newStack: projectData?.stackDetails?.isNewStack, keyMapper: projectData?.mapperKeys, region, user_id, is_sso })

}
else {
const shouldSkip = await shouldSkipContentTypeCreation(safeProjectId, contentType?.otherCmsUid, iteration);
Expand Down
Loading
Loading