Rank 2: Process
Does appwrite enforce data integrity?
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 2: Process
Does appwrite enforce data integrity?
From what I've seen in your use case the department will be assigned to the value.
But, When you'll fetch the User -> departments (one-to-many for example) you won't get the non-existing one.
So to summarize
department after it was created then of the three will happened
So as far of data integrity it looks pretty solid to me.
Most of the magic is going in this method
https://github.com/utopia-php/database/blob/main/src/Database/Database.php#L2552
Rank 2: Process
Yeah, it looks good, functions can be used to validate actions with orphan rows
Moderator
Never saw here any problems related to data integrity related, so I think that should not be a problem
Moderator
Could happen, yes, and in any platform/database too, but really unlikely
Rank 2: Process
Thanks for your answers, it would be nice if the appwrite crud methods/requests have an an optional param to check if relations are orphans, for example if I create/update a record, it can optionally check the relational ids to check if they exists. That should reduce the code developers must write if avoiding orphans is a requirement.
Rank 2: Process
Or maybe make DB FK optional when creating a relationship in a collection
Rank 2: Process
[SOLVED] relationships mariadb
Rank 2: Process
I have made a feature request:
https://github.com/appwrite/appwrite/issues/5662
Moderator
@nev-21 I don't understand at all such feature, what's the difference with relationships?
Rank 2: Process
Current relationships are created with soft-foreign-keys, the feature request is about to optionally use mariadb foreign-keys, and optionally have a query param in requests that checks orphans
Moderator
And what's the advantage/feature you get by using it?
Rank 2: Process
In my opinion, it applies only when avoiding orphans is a requirement, if having orphans is not a problem the default behaviour of appwrite will be ok.
I think the advantages is to avoid making repetitive checks with functions for every model that should not have orphans
Rank 2: Process
I was reading this question: https://stackoverflow.com/questions/83147/whats-wrong-with-foreign-keys
Moderator
Appwrite relationships have the possibility to make in-delete cascading if needed, so what's the difference?
Moderator
Also you can set relationships to a null value, or restrict
Rank 2: Process
Yeah I think that is good
Rank 2: Process
but that is not the problem, I was talking about orphan rows:
When assigning an employee to a departement, but before press save, other authorized user delete the department. That employee will belong to a non-existing department.
Rank 2: Process
so to avoid that, DB FK can be used, or a param in request that check for orphans when an action is needed
Moderator
Probably it will throw an error or apply the defined action (for example deleting), but not tried
Rank 2: Process
Yeah I didn't realize, but I think still exist the possibility of a hidden bug (that maybe is critical for the bussines logic) for example: all employees that have an assigned department, can have access to special data(or files), If I forgot check orphans, an employee (with orphan) still have access.
Rank 2: Process
It will not throw an exception
Moderator
I'm going to check, but probably appwrite checks that by default
Rank 2: Process
cause the assigned department is simple the id
Rank 2: Process
please