diff --git a/deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs b/deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs index de799d3b6af..efdae3404f5 100644 --- a/deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs +++ b/deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs @@ -91,7 +91,7 @@ for await (const collectionName of sortedCollectionNames) { if (isArchivedObject(doc)) { continue; } - transformFields(doc); + transformFields(doc); // This now handles the _class to type transformation. if (doc.policyMap == null) { doc.policyMap = {}; } @@ -147,16 +147,39 @@ function replacer(key, value) { * Method to transform the data in the object to be compatible with Postgres. * Updates: * 1. Changes the _id field to id, and removes the _id field. + * 2. Replaces the _class field with the appropriate type field. * @param {Document} obj - The object to transform. * @returns {void} - No return value. */ function transformFields(obj) { for (const key in obj) { - if (key === "_id") { // Change the _id field to id + if (key === "_id") { obj.id = obj._id.toString(); delete obj._id; - } else if (typeof obj[key] === "object") { + } else if (key === "_class") { + const type = mapClassToType(obj._class); + if (type) { + obj.type = type; // Add the type field + } + delete obj._class; // Remove the _class field + } else if (typeof obj[key] === "object" && obj[key] !== null) { transformFields(obj[key]); } } -} \ No newline at end of file +} + +/** + * Map the _class field to the appropriate type value. The DatasourceStorage class requires this check + * @param {string} _class - The _class field value. + * @returns {string|null} - The corresponding type value, or null if no match is found. + */ +function mapClassToType(_class) { + switch (_class) { + case "com.appsmith.external.models.DatasourceStructure$PrimaryKey": + return "primary key"; + case "com.appsmith.external.models.DatasourceStructure$ForeignKey": + return "foreign key"; + default: + return null; + } +}