Skip to content

Exclude __EFMigrationsLock from SQLite scaffolding#38169

Merged
roji merged 2 commits into
dotnet:mainfrom
TomasMoralesBarr:fix/sqlite-scaffold-excludes-migrations-lock-table
Apr 27, 2026
Merged

Exclude __EFMigrationsLock from SQLite scaffolding#38169
roji merged 2 commits into
dotnet:mainfrom
TomasMoralesBarr:fix/sqlite-scaffold-excludes-migrations-lock-table

Conversation

@TomasMoralesBarr
Copy link
Copy Markdown
Contributor

@TomasMoralesBarr TomasMoralesBarr commented Apr 27, 2026

Summary

Fixes #38148

When scaffolding a SQLite database that has had EF migrations applied, the __EFMigrationsLock table was incorrectly included in the scaffolded model. This table is EF-internal and should be excluded just like __EFMigrationsHistory.

Root Cause

SqliteDatabaseModelFactory.GetTables explicitly excluded __EFMigrationsHistory via HistoryRepository.DefaultTableName, but did not exclude __EFMigrationsLock, which is created by SqliteHistoryRepository to implement distributed locking during migrations on SQLite.

Changes

  • Added DefaultLockTableName public const to SqliteHistoryRepository to avoid hardcoding the table name in multiple places.
  • Added __EFMigrationsLock to the exclusion list in SqliteDatabaseModelFactory.GetTables.
  • Added a test in SqliteDatabaseModelFactoryTest to verify that EF-internal tables are not scaffolded.
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

- Add DefaultLockTableName public const to SqliteHistoryRepository
- Exclude __EFMigrationsLock in SqliteDatabaseModelFactory.GetTables
- Add test to verify EF-internal tables are not scaffolded

Fixes dotnet#38148
@TomasMoralesBarr TomasMoralesBarr requested a review from a team as a code owner April 27, 2026 02:55
Copilot AI review requested due to automatic review settings April 27, 2026 02:55
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 fixes SQLite reverse-engineering (scaffolding) to exclude EF-internal migrations infrastructure tables, specifically __EFMigrationsLock, matching the existing behavior for __EFMigrationsHistory (Fixes #38148).

Changes:

  • Exclude __EFMigrationsLock from SqliteDatabaseModelFactory.GetTables results.
  • Introduce a shared constant for the default lock table name in SqliteHistoryRepository.
  • Add a functional test verifying EF-internal tables aren’t scaffolded.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs Adds a regression test ensuring __EFMigrationsLock isn’t scaffolded.
src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs Updates the sqlite_master query exclusion list to filter out the lock table.
src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs Adds DefaultLockTableName constant and reuses it for LockTableName.

Comment thread src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs Outdated
Comment thread test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs Outdated
@TomasMoralesBarr
Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

- Move EF_internal_tables_are_not_scaffolded test to #region Table
Copy link
Copy Markdown
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM.

@roji roji enabled auto-merge (squash) April 27, 2026 08:57
@roji roji merged commit dc3a947 into dotnet:main Apr 27, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scaffolding SQLite Database generates model Efmigrationslock

3 participants