Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
89d67fe
Initial plan
Copilot Jan 16, 2026
7e82dd5
Implement block comment handling in SqlServerMigrationsSqlGenerator
Copilot Jan 16, 2026
4995896
Refactor block comment handling to combine with switch statement
Copilot Jan 16, 2026
672fa56
Add test for line comment containing block comment start before GO
Copilot Jan 16, 2026
eed1e58
Replace GO with go in test SQL and add multiline comment test
Copilot Jan 16, 2026
da14de3
Change back to foreach for character iteration
Copilot Jan 16, 2026
3549d96
Use enum for parsing state instead of multiple bool variables
Copilot Jan 16, 2026
d13bbd2
Add InBlockComment and Quoted states to enum and merge logic into switch
Copilot Jan 16, 2026
60a9d7c
Simplify GO recognition and reduce enum states
Copilot Jan 16, 2026
33399f6
Refactor to switch on state instead of character
Copilot Jan 16, 2026
45e8d6b
Process Maybe* states before main switch and use pattern matching
Copilot Jan 16, 2026
f1a29d3
Simplify Maybe* state handling and add additional tests
Copilot Jan 16, 2026
6c8af41
Refactor Maybe* state handling for better character processing
Copilot Jan 16, 2026
c037138
Remove unnecessary comment from state transition
Copilot Jan 16, 2026
181fdd0
Remove comment from state transition logic
Copilot Jan 16, 2026
b60e053
Remove unnecessary comments from state handling switch
Copilot Jan 16, 2026
00e6305
Update src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerato…
AndriySvyryd Jan 17, 2026
ee931ae
Refactor to use for loop with look-ahead and add escaped identifier s…
Copilot Jan 21, 2026
df1b23e
Rename Quoted to InQuotes and add comprehensive edge case tests
Copilot Jan 21, 2026
600e334
Enhance tests with multiline identifiers and unclosed delimiters
Copilot Jan 21, 2026
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 @@ -1388,6 +1388,15 @@ protected override void Generate(
builder.EndCommand();
}

private enum ParsingState
{
Normal,
InBlockComment,
InSquareBrackets,
InDoubleQuotes,
InQuotes
}

/// <summary>
/// Builds commands for the given <see cref="SqlOperation" /> by making calls on the given
/// <see cref="MigrationCommandListBuilder" />, and then terminates the final command.
Expand All @@ -1402,12 +1411,13 @@ protected override void Generate(SqlOperation operation, IModel? model, Migratio
.Replace("\\\r\n", "")
.Split(["\r\n", "\n"], StringSplitOptions.None);

var quoted = false;
var state = ParsingState.Normal;
var batchBuilder = new StringBuilder();
foreach (var line in preBatched)
{
var trimmed = line.TrimStart();
if (!quoted

if (state == ParsingState.Normal
&& trimmed.StartsWith("GO", StringComparison.OrdinalIgnoreCase)
&& (trimmed.Length == 2
|| char.IsWhiteSpace(trimmed[2])))
Expand All @@ -1427,31 +1437,34 @@ protected override void Generate(SqlOperation operation, IModel? model, Migratio
}
else
{
var commentStart = false;
foreach (var c in trimmed)
for (var i = 0; i < trimmed.Length; i++)
{
switch (c)
var c = trimmed[i];
var next = i + 1 < trimmed.Length ? trimmed[i + 1] : '\0';

if (state == ParsingState.Normal && c == '-' && next == '-')
{
case '\'':
quoted = !quoted;
commentStart = false;
break;
case '-':
if (!quoted)
{
if (commentStart)
{
goto LineEnd;
}
goto LineEnd;
}

commentStart = true;
}
state = state switch
{
ParsingState.Normal when c == '\'' => ParsingState.InQuotes,
ParsingState.Normal when c == '[' => ParsingState.InSquareBrackets,
ParsingState.Normal when c == '"' => ParsingState.InDoubleQuotes,
ParsingState.Normal when c == '/' && next == '*' => ConsumeAndReturn(ref i, ParsingState.InBlockComment),

break;
default:
commentStart = false;
break;
}
ParsingState.InQuotes when c == '\'' => ParsingState.Normal,

ParsingState.InSquareBrackets when c == ']' && next == ']' => ConsumeAndReturn(ref i, ParsingState.InSquareBrackets),
ParsingState.InSquareBrackets when c == ']' => ParsingState.Normal,

ParsingState.InDoubleQuotes when c == '"' => ParsingState.Normal,

ParsingState.InBlockComment when c == '*' && next == '/' => ConsumeAndReturn(ref i, ParsingState.Normal),

_ => state
};
}

LineEnd:
Expand All @@ -1461,6 +1474,12 @@ protected override void Generate(SqlOperation operation, IModel? model, Migratio

AppendBatch(batchBuilder.ToString());

ParsingState ConsumeAndReturn(ref int index, ParsingState newState)
{
index++;
return newState;
}

void AppendBatch(string batch)
{
if (!string.IsNullOrWhiteSpace(batch))
Expand Down
Loading