Prefer to check the constraints in the manager level
ForeignKey is used widely in the SQL backend, and ForeignKey is normally coupled with ondelete parameter, typical values of ondelete include "CASCADE", "DELETE" and "RESTRICT".
If no value is given for this parameter, "RESTRICT" is default value which means the parent entry can not be deleted before the child entries are removed, or else the error "ERROR 1451" will be thrown when trying to remove the parent entry first.
*** In order to delete parent entity successfully, Keystone have done something in the driver layer, typically, remove the child at first and then remove the parent. It shows "RESTRICT" in table schema becomes useless in this case, and as Keystone has different backends besides MySQL, we should rely less on the DB itself to give us some error to learn something from the DB. so we can migrate the FK definition from "RESTRICT" to "CASCADE", this will also help to reduce database round trips.
The entities which have such behavior includes,
endpoint/service: Delete service will remove the referenced entries in endpoint at first (This is the existent logic, same below.)
request_
access_
user_group_
user_group_
project/domain: Delete domain will remove the referenced entries in project at first.
project/project: Delete project will remove the referenced entries in project at first.
The main changes here is the DB migration.
*** For those entities which not allow to remove the parent when it has children, it makes sense to define the FK with "RESTRICT" parameters, so the behavior will be consistent between Keystone manager and DB itself.
The entities which have such behavior includes,
endpoint/region: Delete region will raise "RegionDeletion
There is no changes needed here.
*** As to those entities which remove the parent without removing the children at first, this will prone to exceptions if no "CASCADE" is used, Keystone need to remove the children before removing the parent as well and also add "CASCADE" parameter to FK.
The entities which have such behavior includes,
federation_
project_
The main changes here is DB migration and some logic in the driver layer to hande with the reference.
Pending to be discussed, Should we move some logic from the driver layer to manager layer? both for existent and what is expected to be added in the future, saying, if we want to delete the domain we'd better to check the reference in the manager layer and delete the reference at first instead of doing it in each driver?
Blueprint information
- Status:
- Complete
- Approver:
- Steve Martinelli
- Priority:
- Low
- Drafter:
- Dave Chen
- Direction:
- Approved
- Assignee:
- Dave Chen
- Definition:
- Approved
- Series goal:
- None
- Implementation:
- Implemented
- Milestone target:
- None
- Started by
- Steve Martinelli
- Completed by
- Dave Chen
Related branches
Related bugs
Sprints
Whiteboard
Gerrit topic: https:/
Addressed by: https:/
Remove project association before removing endpoint group
Addressed by: https:/
Remove assigned protocol before removing IdP
Addressed by: https:/
Remove project association before removing endpoint group
Addressed by: https:/
Upgrade Foreign key in Endpoint with ondelete='CASCADE'