On Dec 26, 5:01 am, Emiliano Heyns <
Emiliano.He...@gmail.com> wrote:
> That would be annoying ;) No, the patch automatically moves ranks
> around so the desired spot falls free just before the new/updated
> story is saved. The user doesn't need to do anything.
Strictly speaking, the patch doesn't really enforce unique ranks, BTW.
There's no unique constraint on the database, and if you have 100
stories all ranked 1, this patch will not touch them. It's only when
you save a story that this patch does anything; it makes sure that no
other story has the rank the saving story has; everything with the
same rank or higher as the spry being saved simply gets its rank upped
by one. If the story being saved had a rank before, that gap is closed
during the save too (or ranks would soon grow out of control). Taking
to '100 stories with rank 1' as a baseline:
* save a new story with rank 5: you now have 100 stories with rank 1,
and one with rank 5
* save a new story with rank 4: you now have 100 stories with rank 1,
one with rank 4, and one with rank 5
* save story with rank 4, changing its rank to 5: you now have 100
stories with rank 1, one with rank 5, and one with rank 6
* save story with rank 6, changing its rank to 5: you now have 100
stories with rank 1, one with rank 5, and one with rank 6 (stories
with rank 5 and 6 have swapped ranks)
* save story with rank 1, changing its rank to 10: you now have 99
stories with rank 1, one with rank 5, one with rank 6, and one with
rank 10
* save story with rank 1, "changing" its rank 1: you now have 1 story
with rank 1, 98 stories with rank 2, one with rank 6, one with rank 7,
and one with rank 11
the patch doesn't compact the ranks, compacting is not something
easily achieved in bog-standard sql. Particular databases might have
stuff on board to help; MS SQL Server has CTEs which help you do this
with a single update statement, and PostgreSQL has something similar,
but all these are non-standard extenstions to SQL.
Emile