Replies: 1 comment
-
This would be nice to have, and potentially something that could also be integrated with the Edgedb UI schema graph view? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So with recently added
delete source
target deletion policy, it now possible to easily define deletion policies that work both ways (source to target, target to source) and when something becomes easier we tend to use it more.I found myself now adding both ways links like:
and
plus using backlinks, of course.
All this makes a bit hard of tracking how the schema actually defined when it comes to deletion. Usually deleting data (especially linked) is not super easy to test, so it's always an afterthought.
And with all this the probablity of having an "oops" moment when all the references were deleted accidentaly increases.
But maybe we can do a static analysis of the schema and print these deletion policies in a more human friendly way? So even a tired by the end of the day person, can quickly look at the output and see if these rules make sense and schema is correct from the business logic perspective.
I could not find a Go syntax parser for EdgeQL, so just made a very quick PoC tool that uses old-school line parsing and some heuristics to build those rules. If I run it in the EdgeDB project directory (one with dbschema/*.esdl files) it produces output like this:
It's a very simple and primitive approach, doesn't cover all cases perhaps, will fail on more complex schemas and probably not even fully correct, but I just want to share the idea and hear the feedback. I think someone should have done something similar (for other DBs maybe), but I could not find quickly.
Here is a source code (in Go) for this hackish PoC: https://gist.github.com/divan/dd05b64ceea7541b9dc1a4b1aff09fca
Beta Was this translation helpful? Give feedback.
All reactions