-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating the position fails uniqueness constraint. #275
Comments
Hi @BookOfGreg, can you tell me if you're using the
Though @swanandp, I suppose it can't hurt to update in descending order anyway. I've tested it and all the tests pass still. What do you think? |
Agreed @brendon , though we should add this specific test case against it as a failing spec. |
@brendon I wasn't using that option but just chose to roll my own for now as I was only using a small subset of this gems functionality. I found that if you move things up the list, I needed it in Edit: My implementation: Edit2: |
Hi @BookOfGreg, it's not the default because it wasn't in the past and most people don't run a unique constraint on this column I think, though perhaps they should. I personally don't. Would you be keen to create a PR for us with tests for this change? Reordering in the correct direction is definitely fine, and we always For the tests, it could be as simple as running the sequential update tests with the unique constraints turned on but with |
Maybe this deserves to be a separate issue but the gem doesn't seem to be reordering with sequential_updates enabled, when running with sequential updates I'm still seeing this error containing my default order scope:
I'll be digging more into this in a couple days. |
That's interesting. Yes do some more digging. I'm wondering if the sequential updates thing will even be necessary if we make the database shuffle things in the correct order? |
Hi @BookOfGreg, how did you get on with this? |
Rolled my own, was much easier than using the gem unfortunately. |
All good :) I'll close this for now. |
Hi team,
Problem
insert_at
, and potentially other methods in this gem, generates SQL that breaks uniqueness constraints.Solution
insert_at
should order the sortable field highest first to avoid collisions.To Reproduce
Given this table (Server version: 10.1.22-MariaDB , Pretends to be MySQL 5.7.x)
And this matching ActiveRecord class
The insert_at generates the SQL:
With error:
I expected SQL of
The text was updated successfully, but these errors were encountered: