Skip to content
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

Proposed fix for Optional RestartSequenceOperation.StartValue #26560 #29346

Merged
merged 6 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,6 @@ protected virtual void Generate(RenameTableOperation operation, IndentedStringBu
protected virtual void Generate(RestartSequenceOperation operation, IndentedStringBuilder builder)
{
builder.AppendLine(".RestartSequence(");

dmihaita marked this conversation as resolved.
Show resolved Hide resolved
using (builder.Indent())
{
builder
Expand All @@ -1805,14 +1804,17 @@ protected virtual void Generate(RestartSequenceOperation operation, IndentedStri
.Append(Code.Literal(operation.Schema));
}

builder
.AppendLine(",")
.Append("startValue: ")
.Append(Code.Literal(operation.StartValue))
.Append(")");
if (operation.StartValue.HasValue)
{
builder
.AppendLine(",")
.Append("startValue: ")
.Append(Code.Literal(operation.StartValue.Value));
}

Annotations(operation.GetAnnotations(), builder);
}
builder.Append(")");
dmihaita marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Migrations/MigrationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,12 +1233,12 @@ public MigrationBuilder(string? activeProvider)
/// See <see href="https://aka.ms/efcore-docs-migrations">Database migrations</see> for more information and examples.
/// </remarks>
/// <param name="name">The name of the sequence.</param>
/// <param name="startValue">The value at which the sequence will start, defaulting to 1.</param>
/// <param name="startValue">The value at which the sequence will start. If not specified, <see langword="null" />, the sequence numbering restarts based on the original CREATE SEQUENCE options.</param>
dmihaita marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="schema">The schema that contains the sequence, or <see langword="null" /> to use the default schema.</param>
/// <returns>A builder to allow annotations to be added to the operation.</returns>
public virtual OperationBuilder<RestartSequenceOperation> RestartSequence(
string name,
long startValue = 1L,
long? startValue = null,
string? schema = null)
{
Check.NotEmpty(name, nameof(name));
Expand Down
10 changes: 8 additions & 2 deletions src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,14 @@ protected virtual IUpdateSqlGenerator SqlGenerator
builder
.Append("ALTER SEQUENCE ")
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema))
.Append(" RESTART WITH ")
.Append(longTypeMapping.GenerateSqlLiteral(operation.StartValue))
.Append(" RESTART");
if (operation.StartValue.HasValue)
{
builder
.Append(" WITH ")
.Append(longTypeMapping.GenerateSqlLiteral(operation.StartValue.Value));
}
builder
dmihaita marked this conversation as resolved.
Show resolved Hide resolved
.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);

EndStatement(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class RestartSequenceOperation : MigrationOperation
public virtual string? Schema { get; set; }

/// <summary>
/// The value at which the sequence should re-start, defaulting to 1.
/// The value at which the sequence should re-start, of <see langword="null" /> if the start value should not be specified .
dmihaita marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public virtual long StartValue { get; set; } = 1L;
public virtual long? StartValue { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,14 @@ protected override void Generate(RenameSequenceOperation operation, IModel? mode
builder
.Append("ALTER SEQUENCE ")
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema))
.Append(" RESTART WITH ")
.Append(IntegerConstant(operation.StartValue))
.Append(" RESTART");
if (operation.StartValue.HasValue)
{
builder
.Append(" WITH ")
.Append(IntegerConstant(operation.StartValue.Value));
}
builder
dmihaita marked this conversation as resolved.
Show resolved Hide resolved
.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);

EndStatement(builder);
Expand Down