-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Optional RestartSequenceOperation.StartValue #26560
Comments
I intend to contribute a fix for this issue by:
Should I proceed with the implementation? |
@dmihaita Looks good. Go for it! |
I think there's a conceptual design issue here... There's no problem with allowing a null start value in RestartSequenceOperation; this represents an operation that occurs at some point in a migration. However, ISequence itself represents the state of the sequence in the model, at a given point in time; the start value of a sequence is always something - it can never be null. The attempt to work around this with InternalStartValue in #29346 also doesn't work: when I go to the sequence metadata and ask what its start value is, I should get the correct response corresponding to the reality in the database. With #29346 as it is, consider the following:
This can have various problematic consequences; for example, when we implement migration squashing (#2174), if you squash all the migrations together, the original start value of 5 disappears, and you're left with a sequence that has a null starting value (so 1). At the end of the day, the model cannot contain an operation that needs to occur in the database (such as "reset sequence"); operations can only be a result of comparing two model states (source and destination). So I think the only place where we can allow a sequence restart without a start value is if the user inserts that manually into a scaffolded migration. @dmihaita let me know if that makes sense - I'll also bring this to a quick team discussion to confirm the above. |
Thanks for the clarifications, now it is a little clearer (at the least the scope of the ISequence) |
@dmihaita we discussed this, and as written above, we don't think it makes sense to change the model/metadata in any way. In other words, this change should be restricted to RestartSequenceOperation and related APIs, but ISequence and related shouldn't change. |
Hello @roji, thank you for the update. |
You're right that when the start value is changed, EF generates a RestartSequenceOperation (/cc @bricelam); but that's still an actual model state change (the sequence's start value changed). The same isn't true of "just restart the sequence" - there's no sequence model state change. I don't think there's anything really to do about this - anything we try to introduce into the model here would again conflate state with operation, and cause bugs. I think it's reasonable to say that users have to manually trigger the restart in the scaffolded migration if they want to do this. |
@dmihaita is the above clear, and are you planning on updating this PR accordingly? |
My understanding is that this PR become obsolete, as there is nothing to be done without disrupting other functionalities. |
@dmihaita it's still possible to allow the operation to be used without specifying a start value; EF wouldn't ever generate such a migration operation (as a result of comparing two model states), but users could still specify that operation manually inside migrations. The value here isn't huge, but it's not zero either. |
In the beginning, sorry for being such a bother. I got it that this unit test should be removed, as per discussion above:
Should I revert the change to SequenceBuilder's method StartsAt also? (I changed the parameter from long to long?). |
Since EF shouldn't generate the new RestartSequenceOperation from a diff of two models (as above), the MigrationsTestBase tests aren't suitable for this. We have MigrationsSqlGeneratorTestBase where you can provide a migration operation directly and assert on the generated SQL - that should be suitable for this.
Yes, I think so. A sequence always has a starting value. |
I think the scope of this issue was covered with the latest commit.
|
A note coming out of implementing this for PG: DROP SEQUENCE IF EXISTS foo;
CREATE SEQUENCE foo START WITH 10;
SELECT nextval('foo'); -- 10
SELECT nextval('foo'); -- 11
ALTER SEQUENCE foo RESTART WITH 100;
SELECT nextval('foo'); -- 100, actual value changed
SELECT nextval('foo'); -- 101
ALTER SEQUENCE foo RESTART;
SELECT nextval('foo'); -- 10, schema start value did not change
SELECT nextval('foo'); -- 11
ALTER SEQUENCE foo START WITH 100;
SELECT nextval('foo'); -- 12, actual value did not change
ALTER SEQUENCE foo RESTART;
SELECT nextval('foo'); -- 100 In other words, So for PG, I'll need to do both: ALTER SEQUENCE foo START WITH x;
ALTER SEQUENCE foo RESTART; |
@bricelam What's the breaking change here? |
Hmm, just |
MSSQL, PostgreSQL and Firebird support "ALTER SEQUENCE {name} RESTART " without "WITH startValue" section
RestartSequenceOperation.StartValue requires definition of startValue:
efcore/src/EFCore.Relational/Migrations/Operations/RestartSequenceOperation.cs
Lines 27 to 30 in 252ece7
Why do not use Nullable<long> for this property?
The text was updated successfully, but these errors were encountered: