|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved. |
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.ComponentModel.DataAnnotations.Schema; |
5 | 6 | using System.Data.Common; |
6 | 7 | using System.Data.Entity; |
| 8 | +using System.Data.Entity.Infrastructure; |
7 | 9 | using System.Data.Entity.Infrastructure.Annotations; |
8 | 10 |
|
9 | 11 | namespace NuGet.Services.Validation |
10 | 12 | { |
| 13 | + /// <summary> |
| 14 | + /// This ValidationDbContextFactory is provided for running migrations in a flexible way as follows: |
| 15 | + /// 1. Run migration using DbConnection; (For DatabaseMigrationTools with AAD token) |
| 16 | + /// 2. Run migration using connection string; |
| 17 | + /// 3. Run migration using default connection string ("Validation.SqlServer") in a web.config; (For command-line migration with integrated AAD/username+password) |
| 18 | + /// </summary> |
| 19 | + public class ValidationDbContextFactory : IDbContextFactory<ValidationEntitiesContext> |
| 20 | + { |
| 21 | + public static Func<ValidationEntitiesContext> ValidationEntitiesContextFactory; |
| 22 | + public ValidationEntitiesContext Create() |
| 23 | + { |
| 24 | + var factory = ValidationEntitiesContextFactory; |
| 25 | + return factory == null ? new ValidationEntitiesContext("Validation.SqlServer") : factory(); |
| 26 | + } |
| 27 | + } |
| 28 | + |
11 | 29 | /// <summary> |
12 | 30 | /// The Entity Framework database context for validation entities. |
13 | 31 | /// </summary> |
@@ -99,10 +117,6 @@ static ValidationEntitiesContext() |
99 | 117 | public IDbSet<PackageRevalidation> PackageRevalidations { get; set; } |
100 | 118 | public IDbSet<SymbolsServerRequest> SymbolsServerRequests { get; set; } |
101 | 119 |
|
102 | | - public ValidationEntitiesContext() : this("Validation.SqlServer") |
103 | | - { |
104 | | - } |
105 | | - |
106 | 120 | public ValidationEntitiesContext(string nameOrConnectionString) : base(nameOrConnectionString) |
107 | 121 | { |
108 | 122 | } |
|
0 commit comments