Skip to content

Commit da412e0

Browse files
Add CatalogValidationContext (#10624)
* Initial files * INitial files * Pushing solution * Removed unnecessary files * Removed more files * Removed more files * Removed more files * Properly changed gallery.sln * Polish * Removed more files * Fix nupkg package is not created * Added column * Updated entities * Moved everything to catalogvalidation * Add batchId * Revert unnecessary changes * Added batchid to validation entities (instead of catalogvalidation), made it optional, added indexing * Removed an unnecessary migration * Commenting out a check which doesn't apply * Fixed comment * Fixed tests * Proper migration schema * Clarified changes * Nit, testing pushed changes * Remove IsReducedVersionListsEnabled method Removed unimplemented method IsReducedVersionListsEnabled from FakeFeatureFlagService. * Remove IsReducedVersionListsEnabled method Removed the IsReducedVersionListsEnabled method. * Update comment for bug reference in Job.cs * Revert "Merge branch 'main' into lpar-validation-change" This reverts commit aacf762, reversing changes made to 72dde91. * Reverting unneccessary changes * Reverting more changes * Reverting * Fixing revert * Fixed code so that validationDB, table validatostatus doesn't have the batchID column * Latest nits --------- Co-authored-by: Lanaparezanin <[email protected]> Co-authored-by: Lanaparezanin <[email protected]>
1 parent aabb05b commit da412e0

21 files changed

Lines changed: 769 additions & 17 deletions

NuGet.Server.Common.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Validation.ScanAndSign.Core
132132
EndProject
133133
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Validation.Symbols.Core", "src\Validation.Symbols.Core\Validation.Symbols.Core.csproj", "{8A898F44-8174-49C2-BFB6-CD6C5328FCB3}"
134134
EndProject
135+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C2B79DF8-132E-49F3-A022-96F975BAB9B4}"
136+
EndProject
137+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Services.CatalogValidation", "src\NuGet.Services.CatalogValidation\NuGet.Services.CatalogValidation.csproj", "{7394C37E-7EA5-4366-B33E-4CFAC18A7FF5}"
138+
EndProject
135139
Global
136140
GlobalSection(SolutionConfigurationPlatforms) = preSolution
137141
Debug|Any CPU = Debug|Any CPU
@@ -350,6 +354,10 @@ Global
350354
{8A898F44-8174-49C2-BFB6-CD6C5328FCB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
351355
{8A898F44-8174-49C2-BFB6-CD6C5328FCB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
352356
{8A898F44-8174-49C2-BFB6-CD6C5328FCB3}.Release|Any CPU.Build.0 = Release|Any CPU
357+
{7394C37E-7EA5-4366-B33E-4CFAC18A7FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
358+
{7394C37E-7EA5-4366-B33E-4CFAC18A7FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
359+
{7394C37E-7EA5-4366-B33E-4CFAC18A7FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
360+
{7394C37E-7EA5-4366-B33E-4CFAC18A7FF5}.Release|Any CPU.Build.0 = Release|Any CPU
353361
EndGlobalSection
354362
GlobalSection(SolutionProperties) = preSolution
355363
HideSolutionNode = FALSE
@@ -412,6 +420,7 @@ Global
412420
{782464A0-3114-48F4-8F74-2534006C0445} = {70B97BE7-E189-4970-AB48-C766BFBA7783}
413421
{C125E644-362B-46C8-8346-4514A0480E95} = {70B97BE7-E189-4970-AB48-C766BFBA7783}
414422
{8A898F44-8174-49C2-BFB6-CD6C5328FCB3} = {70B97BE7-E189-4970-AB48-C766BFBA7783}
423+
{7394C37E-7EA5-4366-B33E-4CFAC18A7FF5} = {C2B79DF8-132E-49F3-A022-96F975BAB9B4}
415424
EndGlobalSection
416425
GlobalSection(ExtensibilityGlobals) = postSolution
417426
SolutionGuid = {AA413DB0-5475-4B5D-A3AF-6323DA8D538B}

NuGetGallery.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Services.Messaging",
9696
EndProject
9797
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Services.Validation", "src\NuGet.Services.Validation\NuGet.Services.Validation.csproj", "{14307F06-BDCC-4026-A7F9-09CD032D4B7B}"
9898
EndProject
99+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Services.CatalogValidation", "src\NuGet.Services.CatalogValidation\NuGet.Services.CatalogValidation.csproj", "{A5B7C8F3-2E4A-4F5B-8C1D-9E3F5A6B7C8D}"
100+
EndProject
99101
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Services.Validation.Issues", "src\NuGet.Services.Validation.Issues\NuGet.Services.Validation.Issues.csproj", "{31C526DC-C8BD-4863-B66F-2FB1C4E440D0}"
100102
EndProject
101103
Global
@@ -252,6 +254,10 @@ Global
252254
{14307F06-BDCC-4026-A7F9-09CD032D4B7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
253255
{14307F06-BDCC-4026-A7F9-09CD032D4B7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
254256
{14307F06-BDCC-4026-A7F9-09CD032D4B7B}.Release|Any CPU.Build.0 = Release|Any CPU
257+
{A5B7C8F3-2E4A-4F5B-8C1D-9E3F5A6B7C8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
258+
{A5B7C8F3-2E4A-4F5B-8C1D-9E3F5A6B7C8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
259+
{A5B7C8F3-2E4A-4F5B-8C1D-9E3F5A6B7C8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
260+
{A5B7C8F3-2E4A-4F5B-8C1D-9E3F5A6B7C8D}.Release|Any CPU.Build.0 = Release|Any CPU
255261
{31C526DC-C8BD-4863-B66F-2FB1C4E440D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
256262
{31C526DC-C8BD-4863-B66F-2FB1C4E440D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
257263
{31C526DC-C8BD-4863-B66F-2FB1C4E440D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -298,6 +304,7 @@ Global
298304
{178F8947-F521-4D0D-871B-CCD26393DBC7} = {285CA6BE-C2EE-4CBE-A647-5EFD45855E17}
299305
{259AF5A7-3928-4942-A1C7-850D845F5D4A} = {285CA6BE-C2EE-4CBE-A647-5EFD45855E17}
300306
{14307F06-BDCC-4026-A7F9-09CD032D4B7B} = {285CA6BE-C2EE-4CBE-A647-5EFD45855E17}
307+
{A5B7C8F3-2E4A-4F5B-8C1D-9E3F5A6B7C8D} = {285CA6BE-C2EE-4CBE-A647-5EFD45855E17}
301308
{31C526DC-C8BD-4863-B66F-2FB1C4E440D0} = {285CA6BE-C2EE-4CBE-A647-5EFD45855E17}
302309
EndGlobalSection
303310
GlobalSection(ExtensibilityGlobals) = postSolution

build.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Invoke-BuildStep 'Creating job packages from gallery solution' { `
108108
"src\DatabaseMigrationTools\DatabaseMigration.Gallery.nuspec",
109109
"src\DatabaseMigrationTools\DatabaseMigration.SupportRequest.nuspec",
110110
"src\DatabaseMigrationTools\DatabaseMigration.Validation.nuspec",
111+
"src\DatabaseMigrationTools\DatabaseMigration.CatalogValidation.nuspec",
111112
"src\GitHubVulnerabilities2Db\GitHubVulnerabilities2Db.nuspec",
112113
"src\GitHubVulnerabilities2v3\GitHubVulnerabilities2v3.nuspec",
113114
"src\GalleryTools\Gallery.GalleryTools.nuspec",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Data.Entity.Migrations;
6+
using System.Data.SqlClient;
7+
using NuGet.Services.DatabaseMigration;
8+
using NuGet.Services.CatalogValidation;
9+
using NuGet.Services.CatalogValidation.Entities;
10+
11+
namespace NuGetGallery.DatabaseMigrationTools
12+
{
13+
public class CatalogValidationDbMigrationContext : BaseDbMigrationContext
14+
{
15+
public CatalogValidationDbMigrationContext(SqlConnection sqlConnection)
16+
{
17+
SqlConnection = sqlConnection ?? throw new ArgumentNullException(nameof(sqlConnection));
18+
SqlConnectionAccessToken = sqlConnection.AccessToken;
19+
20+
CatalogValidationDbContextFactory.CatalogValidationEntitiesContextFactory = () =>
21+
{
22+
SetSqlConnectionAccessToken();
23+
return new CatalogValidationEntitiesContext(SqlConnection);
24+
};
25+
26+
var migrationsConfiguration = new CatalogValidationMigrationsConfiguration();
27+
GetDbMigrator = () => new DbMigrator(migrationsConfiguration, new CatalogValidationEntitiesContext(SqlConnection)); // ← Uses your new context
28+
}
29+
}
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<package >
3+
<metadata>
4+
<id>DatabaseMigration.CatalogValidation</id>
5+
<version>$version$</version>
6+
<title>DatabaseMigration.CatalogValidation</title>
7+
<authors>.NET Foundation</authors>
8+
<owners>.NET Foundation</owners>
9+
<description>DatabaseMigration.CatalogValidation</description>
10+
<copyright>Copyright .NET Foundation</copyright>
11+
</metadata>
12+
<files>
13+
<file src="bin\$configuration$\net472\*.*" target="bin"/>
14+
<file src="Scripts\PostDeploy.ps1" />
15+
</files>
16+
</package>

src/DatabaseMigrationTools/DatabaseMigrationTools.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ItemGroup>
1313
<ProjectReference Include="..\NuGet.Services.DatabaseMigration\NuGet.Services.DatabaseMigration.csproj" />
1414
<ProjectReference Include="..\NuGet.Services.Validation\NuGet.Services.Validation.csproj" />
15+
<ProjectReference Include="..\NuGet.Services.CatalogValidation\NuGet.Services.CatalogValidation.csproj" />
1516
<ProjectReference Include="..\NuGetGallery\NuGetGallery.csproj" />
1617
</ItemGroup>
1718
</Project>

src/DatabaseMigrationTools/MigrationContextFactory.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public class MigrationContextFactory : IMigrationContextFactory
3535
var sqlConnection = await serviceProvider.GetRequiredService<ISqlConnectionFactory<ValidationDbConfiguration>>().CreateAsync();
3636
return new ValidationDbMigrationContext(sqlConnection);
3737
}
38+
},
39+
{
40+
MigrationTargetDatabaseArgumentNames.CatalogValidationDatabase, async(IServiceProvider serviceProvider) =>
41+
{
42+
var sqlConnection = await serviceProvider.GetRequiredService<ISqlConnectionFactory<CatalogValidationDbConfiguration>>().CreateAsync();
43+
return new CatalogValidationDbMigrationContext(sqlConnection);
44+
}
3845
}
3946
};
4047

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGet.Jobs.Configuration
5+
{
6+
public class CatalogValidationDbConfiguration : IDbConfiguration
7+
{
8+
public string ConnectionString { get; set; }
9+
}
10+
}

src/NuGet.Jobs.Common/JsonConfigurationJob.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public abstract class JsonConfigurationJob : JobBase
3131
private const string StatisticsDbConfigurationSectionName = "StatisticsDb";
3232
private const string SupportRequestDbConfigurationSectionName = "SupportRequestDb";
3333
private const string ValidationDbConfigurationSectionName = "ValidationDb";
34+
private const string CatalogValidationDbConfigurationSectionName = "CatalogValidationDb";
3435
private const string ServiceBusConfigurationSectionName = "ServiceBus";
3536
private const string ValidationStorageConfigurationSectionName = "ValidationStorage";
3637
private const string FeatureFlagConfigurationSectionName = "FeatureFlags";
@@ -165,6 +166,7 @@ protected virtual void ConfigureDefaultJobServices(IServiceCollection services,
165166
services.Configure<StatisticsDbConfiguration>(configurationRoot.GetSection(StatisticsDbConfigurationSectionName));
166167
services.Configure<SupportRequestDbConfiguration>(configurationRoot.GetSection(SupportRequestDbConfigurationSectionName));
167168
services.Configure<ValidationDbConfiguration>(configurationRoot.GetSection(ValidationDbConfigurationSectionName));
169+
services.Configure<CatalogValidationDbConfiguration>(configurationRoot.GetSection(CatalogValidationDbConfigurationSectionName));
168170
services.Configure<ServiceBusConfiguration>(configurationRoot.GetSection(ServiceBusConfigurationSectionName));
169171
services.Configure<ValidationStorageConfiguration>(configurationRoot.GetSection(ValidationStorageConfigurationSectionName));
170172
services.ConfigureStorageMsi(configurationRoot);
@@ -178,6 +180,7 @@ protected virtual void ConfigureDefaultJobServices(IServiceCollection services,
178180
AddScopedSqlConnectionFactory<StatisticsDbConfiguration>(services);
179181
AddScopedSqlConnectionFactory<SupportRequestDbConfiguration>(services);
180182
AddScopedSqlConnectionFactory<ValidationDbConfiguration>(services);
183+
AddScopedSqlConnectionFactory<CatalogValidationDbConfiguration>(services);
181184
}
182185

183186
protected virtual void ConfigureDefaultAutofacServices(ContainerBuilder containerBuilder, IConfigurationRoot configurationRoot)
@@ -252,6 +255,7 @@ protected virtual void RegisterDatabases(IServiceProvider serviceProvider)
252255
RegisterDatabaseIfConfigured<StatisticsDbConfiguration>(serviceProvider, testDatabaseConnections);
253256
RegisterDatabaseIfConfigured<SupportRequestDbConfiguration>(serviceProvider, testDatabaseConnections);
254257
RegisterDatabaseIfConfigured<ValidationDbConfiguration>(serviceProvider, testDatabaseConnections);
258+
RegisterDatabaseIfConfigured<CatalogValidationDbConfiguration>(serviceProvider, testDatabaseConnections);
255259
}
256260
finally
257261
{
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.ComponentModel.DataAnnotations.Schema;
6+
using System.Data.Common;
7+
using System.Data.Entity;
8+
using System.Data.Entity.Infrastructure;
9+
using System.Data.Entity.Infrastructure.Annotations;
10+
using NuGet.Services.Validation;
11+
using NuGet.Services.Validation.Entities;
12+
13+
namespace NuGet.Services.CatalogValidation.Entities
14+
{
15+
/// <summary>
16+
/// DbContext factory for CatalogValidation migrations
17+
/// </summary>
18+
public class CatalogValidationDbContextFactory : IDbContextFactory<CatalogValidationEntitiesContext>
19+
{
20+
public static Func<CatalogValidationEntitiesContext> CatalogValidationEntitiesContextFactory;
21+
22+
public CatalogValidationEntitiesContext Create()
23+
{
24+
var factory = CatalogValidationEntitiesContextFactory;
25+
return factory == null ? new CatalogValidationEntitiesContext("CatalogValidation.SqlServer") : factory();
26+
}
27+
}
28+
29+
/// <summary>
30+
/// Entity Framework context for CatalogValidation database
31+
/// </summary>
32+
public class CatalogValidationEntitiesContext : ValidationEntitiesContext
33+
{
34+
private const string ValidatorStatusesBatchIdIndex = "IX_ValidatorStatuses_BatchId";
35+
36+
public CatalogValidationEntitiesContext(string nameOrConnectionString) : base(nameOrConnectionString)
37+
{
38+
}
39+
40+
public CatalogValidationEntitiesContext(DbConnection connection) : base(connection)
41+
{
42+
}
43+
44+
/// <summary>
45+
/// Configures the BatchId property for CatalogValidationDb.
46+
/// Overrides base implementation to configure the property instead of ignoring it.
47+
/// </summary>
48+
/// <param name="modelBuilder">The model builder.</param>
49+
protected override void ConfigureBatchIdProperty(DbModelBuilder modelBuilder)
50+
{
51+
// DO NOT call base - we're overriding the Ignore() behavior
52+
53+
// CatalogValidationDb HAS the BatchId column, so configure it
54+
modelBuilder.Entity<ValidatorStatus>()
55+
.Property(s => s.BatchId)
56+
.HasColumnName("BatchId")
57+
.HasMaxLength(20)
58+
.IsOptional()
59+
.HasColumnAnnotation(
60+
IndexAnnotation.AnnotationName,
61+
new IndexAnnotation(new IndexAttribute(ValidatorStatusesBatchIdIndex)));
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)