Skip to content
Merged
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
31 changes: 27 additions & 4 deletions deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
}
Expand Down Expand Up @@ -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]);
}
}
}
}

/**
* 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;
}
}