| | 1 | = !BluePrint: Deletion Cascades = |
| | 2 | [[TOC]] |
| | 3 | |
| | 4 | == Introduction == |
| | 5 | |
| | 6 | Deleting a record in Sahana Eden may require to update (or even delete) other records in other tables as well, in order to ensure the referential integrity of the database. |
| | 7 | |
| | 8 | Currently, this is controlled by the ondelete-setting of foreign key constraints: |
| | 9 | |
| | 10 | ||'''ondelete'''||'''Behavior'''|| |
| | 11 | ||RESTRICT||prevents the deletion of the referenced record as long as there is still at least one reference|| |
| | 12 | ||CASCADE||deletes the referencing record as well|| |
| | 13 | ||SET DEFAULT||changes the foreign key in the referencing record to its default value|| |
| | 14 | ||SET NULL||changes the foreign key in the referencing record to NULL|| |
| | 15 | |
| | 16 | Additionally, it is possible to define a custom ondelete-cascade for a table. |
| | 17 | |
| | 18 | == Description == |
| | 19 | |
| | 20 | The proposed change will allow a controlled override of the RESTRICT setting in 3 stages: |
| | 21 | |
| | 22 | - conditional restrict-override: automatically override a RESTRICT under certain conditions and perform predefined cascading methods |
| | 23 | - user confirmed restrict-override: requests user confirmation to override a RESTRICT (and perform pre-defined cascading methods) |
| | 24 | - user-defined conditional cascades: requests cascading methods from the user to override a RESTRICT |
| | 25 | |
| | 26 | == Requirements == |
| | 27 | |
| | 28 | The implementation of this BluePrint requires: |
| | 29 | |
| | 30 | - an "undelete" REST method to undelete records (and their original refences) |
| | 31 | - a framework to reconstruct for deleted records (both, for undelete and represent) |
| | 32 | - a conditional two-phase "delete" REST method which can present forms to the user |
| | 33 | - a cascading method "SKIP" which "soft-deletes" (archives) the referenced record but retains the reference |
| | 34 | - a user confirmation dialog when auto-deleting linktable-linked components |
| | 35 | |
| | 36 | == Use-Cases == |
| | 37 | |
| | 38 | - ''tbw'' |
| | 39 | |
| | 40 | == Design == |
| | 41 | |
| | 42 | === Conditional RESTRICT Override === |
| | 43 | |
| | 44 | This should implement a hook which can be called whenever resource.delete() finds a RESTRICT, and which returns an alternative action which can then be used to run through the normal cascade (where it turns RESTRICT again, the cascade would stop). |
| | 45 | |
| | 46 | === User-confirmed RESTRICT Override === |
| | 47 | |
| | 48 | This should implement a user dialog: |
| | 49 | |
| | 50 | - GET delete would return a list of records which have a RESTRICT for the current record |
| | 51 | - each item in the list explains the cascade action |
| | 52 | - the user can confirm the whole cascade or abort the attempt |
| | 53 | |
| | 54 | === User-defined Action upon RESTRICT Override === |
| | 55 | |
| | 56 | - GET delete would return a list of records which have a RESTRICT for the current record |
| | 57 | - each item in the list has a selector of possible cascade actions |
| | 58 | - the user can alter the cascade actions, confirm the whole cascade or abort the attempt |
| | 59 | |
| | 60 | == Implementation == |
| | 61 | |
| | 62 | - not started yet |
| | 63 | |
| | 64 | == References == |
| | 65 | |
| | 66 | ---- |
| | 67 | BluePrints |