Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests for /metadata + fix relation deletion #8706

Merged
merged 11 commits into from
Nov 26, 2024

Conversation

ijreilly
Copy link
Collaborator

@ijreilly ijreilly commented Nov 24, 2024

In this PR

  1. Add integration tests for /metadata (master issue: Add metadata integration tests #8719)
  2. Fix relation deletion: index on "from" object was not deleted, impeding creation of a new relation between the same two objects A and B after relation between A and B was deleted

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds integration tests for the metadata API and fixes relation deletion issues, particularly around index cleanup when deleting relations between objects.

Key changes:

  • Added deleteIndexMetadata method in IndexMetadataService but missing corresponding database migration for index removal
  • Fixed relation deletion by adding cleanup of indexes on foreign key and deletedAt fields in RelationMetadataService
  • Added comprehensive integration test suite for custom object renaming with standard/custom relation handling
  • Created utility factories for GraphQL operations (queries/mutations) to support metadata API testing
  • Missing imports for APP_PORT and ACCESS_TOKEN in make-metadata-api-request.util.ts

11 file(s) reviewed, 16 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -98,6 +98,34 @@ export class IndexMetadataService {
);
}

async deleteIndexMetadata(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: deleteIndexMetadata removes the metadata record but doesn't create a migration to drop the actual database index. This will leave orphaned indexes in the database. Need to add a call to workspaceMigrationService to create a DROP INDEX migration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case the index is deleted by the relation deletion.
But it could be misleading for future users that deleteIndexMetadata does not actually deletes the index in db; although in most cases I expect it should be deleted by the original action (delete or rename a column, etc.).

Comment on lines 6 to 7
filter?: any;
paging?: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more specific type than any for filter and paging to ensure type safety

@Weiko Weiko self-requested a review November 24, 2024 16:05
@ijreilly ijreilly mentioned this pull request Nov 25, 2024
7 tasks
@ijreilly
Copy link
Collaborator Author

@Weiko fyi you probably know already but you can test the file directly with

yarn nx test:integration -- twenty/packages/twenty-server/test/integration/metadata/suites/object-metadata/rename-custom-object.integration-spec.ts

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great @ijreilly! Thanks for the fix on index deletion as well 👍

});

// Assert
const response = await makeMetadataAPIRequest(graphqlOperation);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Imho this is part of the act too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sorry ! thanks for spotting

);

if (!isDefined(deletedAtFieldMetadata)) {
throw new RelationMetadataException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to throw here? Not having a deletedAt column could be optional in the future. Wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are throwing if we don't find deletedAtFieldMetadata for the toObjectMetadata's object at relation creation. My idea was that if we don't find deletedAt (I don't know for which reason), we'll have a different index name than at creation and will not find it.
What I could do is store that check and throw in a util, so that we think of updating the code in both places and not just in create. or just remove that piece of code altogether. what do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I like your first idea, we can move to a util indeed. I understand better now so you can merge if you want and do that in a later PR @ijreilly

@ijreilly ijreilly merged commit 7bde200 into main Nov 26, 2024
19 checks passed
@ijreilly ijreilly deleted the tests-for-metadata branch November 26, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants