developmentseed / developmentseed/osm-teams
Need to move validation logic into PostgreSQL trigger
- Dominant language
- JavaScript
- Stars
- 29
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
`removeModerator` will probably not work correctly if 2+ requests are interleaved, because the `delete` and the `select` are not atomic:
https://github.com/developmentseed/osm-teams/blob/master/app/lib/team.js#L281-L285
I reviewed the PostgreSQL docs, and I think the correct thing to do is move this business logic, e.g. "cannot remove osmId because there must be at least one moderator", out of the model and into a database trigger:
Caused by #141
Relates to #155
^ Same issue comes up in `removeOwner`
see also:
https://karolgalanciak.com/blog/2016/05/06/when-validation-is-not-enough-postgresql-triggers-for-data-integrity/
/cc @kamicut
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with app/lib/team.js#L281-L285 and the corresponding removeOwner path, then review the linked PostgreSQL trigger article and documentation. Done means the “at least one moderator” rule remains enforced atomically for removeModerator and removeOwner, including interleaved requests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, postgresql
- Domain
- backend, databases
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100