Skip to content

Filter out full-text catalog operations from history table creation#38050

Open
roji wants to merge 2 commits intomainfrom
roji/filter-fulltext-from-history-table
Open

Filter out full-text catalog operations from history table creation#38050
roji wants to merge 2 commits intomainfrom
roji/filter-fulltext-from-history-table

Conversation

@roji
Copy link
Copy Markdown
Member

@roji roji commented Apr 4, 2026

  • The code builds and tests pass locally (also verified by our automated build checks)
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

PR #37652 added migration support for SQL Server full-text catalogs. Full-text catalogs are stored as database-level annotations (SqlServerAnnotationNames.FullTextCatalogs) on the model, and when the migration history table is created, the model differ generates an AlterDatabaseOperation that includes these annotations. The SQL generator then emits CREATE FULLTEXT CATALOG prematurely — before the actual migration runs — causing the later migration (which also creates the catalog) to fail.

This is the same problem that the Npgsql provider had with PostgreSQL extensions/enums, fixed in npgsql/efcore.pg#3713. The approach here mirrors that fix:

  • Override GetCreateCommands() in SqlServerHistoryRepository to strip FullTextCatalogs annotations from AlterDatabaseOperation before SQL generation
  • Make EnsureModel() protected (with [EntityFrameworkInternal]) in the base HistoryRepository so the SQL Server subclass can call it — avoiding the code duplication that the Npgsql provider had to resort to

This is a workaround for the proper fix tracked in #34991.

When the migration history table is created, the model differ generates
AlterDatabaseOperation with full-text catalog annotations. The SQL generator
then emits CREATE FULLTEXT CATALOG too early, causing the later actual
migration to fail.

Filter out SqlServerAnnotationNames.FullTextCatalogs from
AlterDatabaseOperation in SqlServerHistoryRepository.GetCreateCommands(),
following the same approach as npgsql/efcore.pg#3713.

This is a workaround for #34991.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roji roji requested a review from a team as a code owner April 4, 2026 17:15
Copilot AI review requested due to automatic review settings April 4, 2026 17:15
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

This PR prevents SQL Server full-text catalog DDL from being generated during migration history table creation, avoiding failures when the actual migration later creates the same catalogs. It does this by making the history-table mini-model accessible to providers and filtering out full-text catalog annotations before SQL generation.

Changes:

  • Exposes HistoryRepository.EnsureModel() as protected (internal API) so providers can reuse the history-table mini-model without duplicating logic.
  • Overrides SqlServerHistoryRepository.GetCreateCommands() to remove SqlServerAnnotationNames.FullTextCatalogs from any AlterDatabaseOperation before SQL generation.
  • Adds a SQL Server test intended to cover history-table creation when full-text catalogs are configured.

Reviewed changes

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

File Description
test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs Adds a regression test and test plumbing to configure a model with a full-text catalog.
src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs Filters FullTextCatalogs annotations out of AlterDatabaseOperation when generating history-table create commands.
src/EFCore.Relational/Migrations/HistoryRepository.cs Makes EnsureModel() protected (internal API) so provider subclasses can reuse the history-table mini-model.

- Make EnsureModel() protected virtual to fix API consistency test
- Replace configureModel approach with IConventionSetPlugin injection
  to properly test that the full-text catalog filtering override works
  when conventions add annotations to the history table's mini-model

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roji
Copy link
Copy Markdown
Member Author

roji commented Apr 4, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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.

SQL Server full-text search: Support creating full-text indexes and catalogs in migrations

3 participants