Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
/ ServerCommon Public archive

Commit

Permalink
[Database Migration] Validation database supports migration job. (#292)
Browse files Browse the repository at this point in the history
* Extend to validation database

* Delete default constructor of entities

* Update
  • Loading branch information
zhhyu authored May 6, 2019
1 parent a827b73 commit d6de585
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Infrastructure.Annotations;

namespace NuGet.Services.Validation
{
/// <summary>
/// This ValidationDbContextFactory is provided for running migrations in a flexible way as follows:
/// 1. Run migration using DbConnection; (For DatabaseMigrationTools with AAD token)
/// 2. Run migration using connection string;
/// 3. Run migration using default connection string ("Validation.SqlServer") in a web.config; (For command-line migration with integrated AAD/username+password)
/// </summary>
public class ValidationDbContextFactory : IDbContextFactory<ValidationEntitiesContext>
{
public static Func<ValidationEntitiesContext> ValidationEntitiesContextFactory;
public ValidationEntitiesContext Create()
{
var factory = ValidationEntitiesContextFactory;
return factory == null ? new ValidationEntitiesContext("Validation.SqlServer") : factory();
}
}

/// <summary>
/// The Entity Framework database context for validation entities.
/// </summary>
Expand Down Expand Up @@ -99,10 +117,6 @@ static ValidationEntitiesContext()
public IDbSet<PackageRevalidation> PackageRevalidations { get; set; }
public IDbSet<SymbolsServerRequest> SymbolsServerRequests { get; set; }

public ValidationEntitiesContext() : this("Validation.SqlServer")
{
}

public ValidationEntitiesContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace NuGet.Services.Validation
{
internal sealed class ValidationMigrationsConfiguration: DbMigrationsConfiguration<ValidationEntitiesContext>
public class ValidationMigrationsConfiguration: DbMigrationsConfiguration<ValidationEntitiesContext>
{
public ValidationMigrationsConfiguration()
{
Expand Down

0 comments on commit d6de585

Please sign in to comment.