If I use DeleteRelationships with no
# spicedb
m
If I use DeleteRelationships with no filter, will it delete all relationships in my db?
v
No, at least one element in RelationshipFilter must be set.
m
hm, is there a filter I can set to simulate this behaviour? To rephrase, can I use DelRels to delete all relationships?
y
what's the use case?
m
I recently integrated authzed serverless into our backend for authz. We're still undergoing heavy development + testing, and we regularly refresh backend database (I know how that sounds, but it's the fastest way to iterate atm lol). While testing, we've ended up creating a lot of relationships in the authzed permission system that refer to object that don't exist anymore, or are simply incorrect. I want to "start fresh" by removing all of these relationships, so our authz db is in sync with our regular db every time the latter is reset. One solution is to create a new authz permission system, but that's time consuming, and a bit impractical, so I'd prefer to make a function that I can call to just clear up all the relationships.
y
what database backend are you using?
as a naive first pass, i'd probably just write a loop that iterates over all the definition types and calls
DeleteRelationships
for each type
it'll take a bit, but there's a flag that you can pass such that it gets backgrounded
m
Google Cloud SQL
y
so postgres?
m
yeah
y
a hack that we've used in the past, which i wouldn't unreservedly recommend but does seem to work, is to update every row with a small
deleted_xid
and let GC get rid of them
but i'd probably call the function
delete_relationships_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
or something
m
ahahah
fair enough, I figure I'll just delete it from the codebase once we're out of testing lol
thanks!
j
delete_relationships_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_OUT_OF_A_CANNON_INTO_THE_SUN
d
As a side note, if you have access to the postgres instance, my team has just turned around and truncated the table. Easy wipe.
j
be very careful doing this
it can cause problems
d
What problem? (I am not serverless so I dont know the difference, I just know that we havent ran into any problems yet)
j
if you have any existing traffic to the cluster
it will return inconsistent results
d
Ahhh yes yes, of course. The DB im talking about is strictly for dev and testing, so wiping it happens on a schedule about once a week at midnight. So no worries on our part. Thanks for the heads up though!
j
gotcha
241 Views