chore: sync changes from pg branch (#36556)
## Description Added the changes from move to pg script from the postgres branch to keep in sync. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Enhanced data transformation process for improved compatibility with Postgres. - Introduced mapping for `_class` field to `type` field. - **Bug Fixes** - Improved handling of asynchronous operations during MongoDB client instantiation. - **Refactor** - Clarified condition checks in data transformation logic for better readability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11100769096> > Commit: 46e043c998767acb456920f36459ae6f8968a267 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11100769096&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 30 Sep 2024 07:14:51 UTC <!-- end of auto-generated comment: Cypress test results --> /ok-to-test tags="@tag.Sanity"
This commit is contained in:
parent
85371bed71
commit
060cf92e55
|
|
@ -91,7 +91,7 @@ for await (const collectionName of sortedCollectionNames) {
|
||||||
if (isArchivedObject(doc)) {
|
if (isArchivedObject(doc)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
transformFields(doc);
|
transformFields(doc); // This now handles the _class to type transformation.
|
||||||
if (doc.policyMap == null) {
|
if (doc.policyMap == null) {
|
||||||
doc.policyMap = {};
|
doc.policyMap = {};
|
||||||
}
|
}
|
||||||
|
|
@ -147,16 +147,39 @@ function replacer(key, value) {
|
||||||
* Method to transform the data in the object to be compatible with Postgres.
|
* Method to transform the data in the object to be compatible with Postgres.
|
||||||
* Updates:
|
* Updates:
|
||||||
* 1. Changes the _id field to id, and removes the _id field.
|
* 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.
|
* @param {Document} obj - The object to transform.
|
||||||
* @returns {void} - No return value.
|
* @returns {void} - No return value.
|
||||||
*/
|
*/
|
||||||
function transformFields(obj) {
|
function transformFields(obj) {
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
if (key === "_id") { // Change the _id field to id
|
if (key === "_id") {
|
||||||
obj.id = obj._id.toString();
|
obj.id = obj._id.toString();
|
||||||
delete obj._id;
|
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]);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user