Skip to content

Use migration ID as scaffolded migration type name#37841

Merged
AndriySvyryd merged 5 commits intomainfrom
copilot/append-timestamp-to-migration-types
Mar 4, 2026
Merged

Use migration ID as scaffolded migration type name#37841
AndriySvyryd merged 5 commits intomainfrom
copilot/append-timestamp-to-migration-types

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 4, 2026

  • Modify MigrationsScaffolder.ScaffoldMigration to use migration ID as the type name
  • Add test in MigrationsScaffolderTest to verify the type name in scaffolded code
  • Fix OperationExecutorTest expected code templates to use migration ID-based type name
  • Fix HierarchyId MigrationTests expected code templates to use migration ID-based type name
  • Run all migration tests to verify no other failures (300/300 pass, 1215/1216 design tests pass — sole failure is unrelated SQL Server connectivity)
Original prompt

This section details on the original issue you should resolve

<issue_title>Append timestamp to scaffolded migration type names</issue_title>
<issue_description>When a new migration is added, EF currently scaffolds a .NET type with the name of the migration. This leads to a variety of issues around the name being problematic in C#:

  • The type name happens to be the same as a .NET type. A very frequent case is when users do dotnet ef migrations add DateTime.
  • The C# compiler now raises warnings when a type name could conflict with a future keyword (i.e. all-lowercase name), see #35938.

Migration files already have their creation timestamp prefixed to the name, so that migrations are properly sorted on the filesystem. We can simply append the same timestamp to the type name inside: public class DateTime_20250512080000 {...}.</issue_description>

Comments on the Issue (you are @copilot in this section)

@roji Tentatively proposing as a stretch goal in 10.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

When scaffolding a new migration, the type name now includes the
timestamp from the migration ID. For example, a migration named
"DateTime" will generate a type named "DateTime_20250512080000"
instead of just "DateTime", avoiding conflicts with .NET types
and potential C# keyword warnings.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Append timestamp to scaffolded migration type names Append timestamp to scaffolded migration type names Mar 4, 2026
Comment thread src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs Outdated
Comment thread src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs Outdated
Simplify by passing the migration ID directly as the type name
instead of constructing Name_Timestamp. The Code.Identifier()
call in the code generator handles making it a valid C# identifier.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates migration scaffolding to avoid generated migration type names colliding with BCL types / triggering compiler warnings by appending the migration timestamp (already present in the migration ID / file name) to the generated class name.

Changes:

  • Derive migrationTypeName by appending the timestamp portion of migrationId and pass it to GenerateMigration/GenerateMetadata.
  • Add a design-time test asserting the timestamped type name appears in both the migration and metadata output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs Appends migration ID timestamp to the generated migration type name when scaffolding.
test/EFCore.Design.Tests/Migrations/Design/MigrationScaffolderTest.cs Adds test coverage ensuring generated code contains the timestamped type name and the original [Migration] attribute.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs
Copilot AI changed the title Append timestamp to scaffolded migration type names Use migration ID as scaffolded migration type name Mar 4, 2026
Update expected type names in OperationExecutorTest and HierarchyId
MigrationTests to reflect migration ID being used as the type name
(prefixed with _ since IDs start with a digit).

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@AndriySvyryd AndriySvyryd marked this pull request as ready for review March 4, 2026 18:25
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner March 4, 2026 18:25
Copilot AI review requested due to automatic review settings March 4, 2026 18:25
@AndriySvyryd
Copy link
Copy Markdown
Member

@ErikEJ FYI

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


You can also share your feedback on Copilot code review. Take the survey.

Comment thread test/EFCore.Design.Tests/Migrations/Design/MigrationScaffolderTest.cs Outdated
…Test.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@AndriySvyryd AndriySvyryd enabled auto-merge (squash) March 4, 2026 21:19
@AndriySvyryd AndriySvyryd merged commit 9bad67c into main Mar 4, 2026
10 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/append-timestamp-to-migration-types branch March 4, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Append timestamp to scaffolded migration type names

4 participants