Skip to main content

Overview

NuGet.Services.CatalogValidation is a small shared library with a single well-defined responsibility: it defines the EF6 DbContext and code-first migration history for the CatalogValidation SQL database. The CatalogValidation database holds the same logical schema as the Validation database — validation sets, validator statuses, package signatures, certificate chains, scan results, and so on — but is a physically separate SQL Server instance used specifically for catalog-level validation workflows. The library extends ValidationEntitiesContext from NuGet.Services.Validation rather than duplicating entity or fluent-API configuration. The only override it adds is ConfigureBatchIdProperty, which activates the BatchId column on ValidatorStatuses. This column exists in the CatalogValidation database but is intentionally absent (ignored) in the main Validation database, reflecting a schema divergence between the two stores. The project ships as a multi-targeted library (net472 and netstandard2.1) so it can be referenced by both the full-.NET-Framework DatabaseMigrationTools executable and by any netstandard-compatible consumer. Its InitialSchema migration (timestamped 202512031702296) bootstraps all required tables, schemas, and indexes in a single operation, making it straightforward to provision a new CatalogValidation database from scratch.
The migration was introduced in December 2025 as the initial schema. AutomaticMigrationsEnabled is set to false, so all future schema changes must be expressed as explicit code-first migration classes added to this project.

Role in System

DatabaseMigrationTools (exe)
  └── CatalogValidationDbMigrationContext
        ├── CatalogValidationDbContextFactory   ← injectable factory
        ├── CatalogValidationEntitiesContext     ← EF DbContext (this library)
        └── CatalogValidationMigrationsConfiguration ← EF migration runner config

                └──► NuGet.Services.CatalogValidation  (this library)
                          ├── Entities/
                          │     ├── CatalogValidationEntitiesContext
                          │     └── CatalogValidationDbContextFactory
                          └── Migrations/
                                ├── CatalogValidationMigrationsConfiguration
                                └── 202512031702296_InitialSchema
At runtime the DatabaseMigrationTools job receives CatalogValidationDatabase as the MigrationTargetDatabase argument, resolves a CatalogValidationDbConfiguration connection string, and passes the resulting SqlConnection to CatalogValidationDbMigrationContext. That context wires up the factory delegate and creates a DbMigrator backed by CatalogValidationEntitiesContext to apply any pending EF migrations.

Schema parity with Validation DB

The CatalogValidation database contains the same tables as the main Validation database (dbo, signature, scan schemas). The entire schema is established through a single InitialSchema migration that creates all tables and indexes in one pass.

BatchId column activation

The only schema difference relative to the Validation database is the BatchId column on dbo.ValidatorStatuses. CatalogValidationEntitiesContext overrides ConfigureBatchIdProperty to configure and index this column instead of ignoring it as the base context does.

Dual factory pattern

CatalogValidationDbContextFactory exposes a static Func delegate (CatalogValidationEntitiesContextFactory) that DatabaseMigrationTools sets at startup. This lets the migration runner inject an authenticated SqlConnection without requiring a connection-string-based constructor path.

Migration timeout

CatalogValidationMigrationsConfiguration sets CommandTimeout to 30 minutes, accommodating the long-running DDL statements that may be required against large production tables.

Key Files and Classes

FileClass / TypePurpose
Entities/CatalogValidationEntitiesContext.csCatalogValidationEntitiesContextEF6 DbContext for the CatalogValidation database. Inherits all entity sets and fluent configuration from ValidationEntitiesContext; overrides ConfigureBatchIdProperty to map and index the BatchId column on ValidatorStatuses.
Entities/CatalogValidationEntitiesContext.csCatalogValidationDbContextFactoryIDbContextFactory<CatalogValidationEntitiesContext> implementation. Uses a static Func delegate so the migration runner can inject an externally-created, authenticated SqlConnection at startup.
Migrations/CatalogValidationMigrationsConfiguration.csCatalogValidationMigrationsConfigurationDbMigrationsConfiguration<CatalogValidationEntitiesContext>. Disables automatic migrations and sets a 30-minute command timeout.
Migrations/202512031702296_InitialSchema.csInitialSchemaThe sole EF migration. Creates all tables across the dbo, signature, and scan schemas, including all foreign keys and indexes, in a single Up() pass.
app.configLocal-only connection string (CatalogValidation.SqlServer) pointing to (localdb)\mssqllocaldb for running migrations from the command line during development.

Dependencies

NuGet Package References

PackagePurpose
EntityFrameworkEF6 DbContext, DbMigrationsConfiguration, DbMigration, and related migration infrastructure
Azure.CoreIncluded transitively via NuGet.Services.Validation; supports Azure SDK primitives
NuGet.VersioningIncluded transitively; used by entity types in the validation schema
System.Text.JsonIncluded transitively; used for serializing validation properties in the entity model

Internal Project References

ProjectPurpose
NuGet.Services.ValidationProvides ValidationEntitiesContext (the base DbContext), all entity classes (PackageValidationSet, ValidatorStatus, PackageSignature, etc.), and IValidationEntitiesContext

Notable Patterns and Implementation Details

Schema divergence via virtual override. ValidationEntitiesContext defines ConfigureBatchIdProperty as a virtual method that calls modelBuilder.Entity<ValidatorStatus>().Ignore(s => s.BatchId). CatalogValidationEntitiesContext overrides this method and explicitly does NOT call base, instead mapping and indexing the column. This is the only customization applied by this library to the inherited schema.
Single initial migration. All tables — across the dbo, signature, and scan database schemas — are created in a single InitialSchema migration rather than incremental migrations. This reflects that the CatalogValidation database is a new, purpose-built store rather than an evolved one.
No consumer other than DatabaseMigrationTools. As of the initial schema (December 2025), the only project that references this library is DatabaseMigrationTools. There is no runtime service (validator, orchestrator, or API) that reads from or writes to the CatalogValidation database yet — the library establishes the data layer in anticipation of future catalog validation workloads.
The app.config connection string (CatalogValidation.SqlServer) is used only when running EF migrations directly from the Package Manager Console or migrate.exe during development. In deployed environments, the connection string is supplied through CatalogValidationDbConfiguration resolved via JsonConfigurationJob.