FrancisG-Massey / Capstone2016

4 stars 0 forks source link

Only one active trap with number x at a time #203

Closed ZoeUdy closed 7 years ago

ZoeUdy commented 7 years ago

Please limit traps to only be able to have one active trap x at a time There can be multiple trap x if they are marked inactive

sam-hunt commented 7 years ago

This is trivial to do with a unique constraint in the db, and I've thought about this.

However what if the user creates two traps in the wrong order and wants to switch their numbers? While we don't support such a command at this stage, what if we wanted to? Seems to me to be something that wouldn't be terribly unusual.

They wouldn't be able to do two PUT requests to swap the numbers as this would violate the unique constraint. They'd either have to use a temporary number (what if that was being used by something else at the time?). Or we'd have to write a completely separate API function call to do it which wrapped the two UPDATE queries in a transaction.

Should we still just go ahead and add the unique constraint in the meantime, and categorise it as technical debt to sort out down the line?

ZoeUdy commented 7 years ago

I think, yes. Add the unique constraint, add this to technical debt. I think that is an edge case anyway, because most times they will be adding the traps while walking the line in linear order.

sam-hunt commented 7 years ago

Okay, I'll be be going all the way and enforcing NOT NULL on this column too then. Can be sorted out down the line.

Also after investigating, it seems like conditional unique constraints aren't a thing. Going to use a unique filtered index.