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

Delete relationships in bulk #2032

Open
HugoSousa opened this issue Feb 14, 2025 · 0 comments
Open

Delete relationships in bulk #2032

HugoSousa opened this issue Feb 14, 2025 · 0 comments
Assignees
Labels
feature request New feature or request

Comments

@HugoSousa
Copy link

We have a scenario where we want to perform 2 delete operations:

  1. delete all relationships where team X is subject and
  2. delete all relationships where team X is entity

At the moment, we need to perform 2 'Delete Data' API calls to Permify. Something like:
POST /data/delete

{
  "tuple_filter": {
    "subject": {
      "type": "team",
      "ids": [
        "12345"
      ]
    }
  }
}

POST /data/delete

{
  "tuple_filter": {
    "entity": {
      "type": "team",
      "ids": [
        "12345"
      ]
    }
  }
}

We would like to convert this to a single API, to avoid consistency issues. For example, it could happen that the first API call succeeded and the second one failed, leading to an inconsistent state where data was partially deleted.
To note also that the way we're deleting relationships, by using tuple filter, would make it complicated to re-create the data that succeeded in the first API call - we would need additional API calls to fetch those relationships if we want to do that.

Describe the solution you'd like
It would be good if:
a) the "Delete data" endpoint could receive an array of tuple_filters / attribute_filters

{
  "tuple_filters": 
  [
    {
      "entity": 
	  {
	    "type": "team",
		"ids": ["12345"]
	  }
	},
	{
      "subject": 
	  {
	    "type": "team",
	    "ids": ["12345"]
	  }
	}
  ]
}

b) or the "Delete data" endpoint could receive an array of specific relationships to delete (with subject and entity identified)

{
  "relationships": 
  [
    {
	  "entity": 
	  {
	    "type": "team",
		"id": "12345"
	  },
	  "relation": "relation_type",
	  "subject": 
	  {
	    "type": "user",
	    "ids": ["67890"]
	  }
	}
  ]
}

Describe alternatives you've considered
We considered using data bundles where we could execute the 2 deletes in a single "Run Bundle" API call. However, we noticed that bundles work with specific relationships (with subject/entity ids) and not with tuple filter. So, we cannot do something like "delete all relationships where team X is subject" with a data bundle.

Another alternative we considered was the following:

  1. Read all relationships where team X is subject
  2. Read all relationships where team X is entity
  3. Create a bundle to delete all the relationships above
  4. Run bundle
  5. Delete bundle

This however implies having 5 API calls in something that could be done in one. It also feels like a waste to be creating a bundle that only serves a single purpose and cannot be reused.

@HugoSousa HugoSousa added the feature request New feature or request label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants