Skip to content

Commit

Permalink
fix(database): adding/removing object(group) fields not working
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Apr 24, 2023
1 parent dae18ea commit 2b2f471
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion modules/database/src/adapters/utils/validateFieldChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ function validateSchemaFields(oldSchemaFields: Indexable, newSchemaFields: Index
if (!newType) return;
if (oldType === DataTypes.JSONB && newType === 'JSON') return;
if (isArray(oldType) && isArray(newType)) {
if (JSON.stringify(oldType[0]) !== JSON.stringify(newType[0]))
if (typeof oldType[0] === 'object') {
validateObject(oldType[0], newType[0]);
} else if (JSON.stringify(oldType[0]) !== JSON.stringify(newType[0]))
throw ConduitError.forbidden('Invalid schema types');
} else if (typeof oldType === 'object') {
validateObject(oldType, newType);
} else if (!isEqual(oldType, newType)) {
// TODO: Support schema field type migration
throw ConduitError.forbidden('Invalid schema types');
Expand All @@ -41,3 +45,11 @@ function validateSchemaFields(oldSchemaFields: Indexable, newSchemaFields: Index
});
return newSchemaFields;
}

function validateObject(oldType: any, newType: any) {
if (!oldType.hasOwnProperty('type') && !newType.hasOwnProperty('type')) {
validateSchemaFields(oldType, newType);
}
if (JSON.stringify(oldType[0]) !== JSON.stringify(newType[0]))
throw ConduitError.forbidden('Invalid schema types');
}

0 comments on commit 2b2f471

Please sign in to comment.