public static void Apply(this Migration migration, DbModel dbModel) { foreach (var outputTableData in dbModel.OutputTableDatas) { migration.Apply(outputTableData); } }
public void Apply_ShouldNotCall_Migrate_WhenEqualsOrGreaterThan_ToVersion(string toVersion) { // Arrange _storage.Get <string>(SettingsVersionKey).Returns("1.30.10"); var migration = new Migration(_storage, toVersion); // Act migration.Apply(); // Assert migration.ReceivedMigrate.Should().BeFalse(); }
public void Apply_ShouldNotSet_SettingsVersion_WhenEqualsOrGreaterThan_ToVersion(string toVersion) { // Arrange _storage.Get <string>(SettingsVersionKey).Returns("1.30.10"); var migration = new Migration(_storage, toVersion); // Act migration.Apply(); // Assert _storage.DidNotReceive().Set(SettingsVersionKey, Arg.Any <string>()); }
public void Apply_ShouldCall_Migrate_WhenLessThan_ToVersion() { // Arrange _storage.Get <string>(SettingsVersionKey).Returns("1.30.7"); var migration = new Migration(_storage, "1.30.11"); // Act migration.Apply(); // Assert migration.ReceivedMigrate.Should().BeTrue(); }
public void Apply_ShouldSet_SettingsVersion_WhenLessThan_ToVersion() { // Arrange _storage.Get <string>(SettingsVersionKey).Returns("1.30.7"); var migration = new Migration(_storage, "1.30.11"); // Act migration.Apply(); // Assert _storage.Received().Set(SettingsVersionKey, "1.30.11"); }
/// <summary> /// ���������� �������� /// </summary> /// <param name="targetVersion">������ ����������� ��������</param> /// <param name="currentDatabaseVersion">������� ������ ��</param> public void ExecuteMigration(long targetVersion, long currentDatabaseVersion) { var migrationInfo = migrationAssembly.GetMigrationInfo(targetVersion); Migration migration = migrationAssembly.InstantiateMigration(migrationInfo, Provider); try { if (!migrationInfo.WithoutTransaction) { Provider.BeginTransaction(); } if (targetVersion <= currentDatabaseVersion) { Logger.MigrateDown(targetVersion, migration.Name); migration.Revert(); Provider.MigrationUnApplied(targetVersion, Key); } else { Logger.MigrateUp(targetVersion, migration.Name); migration.Apply(); Provider.MigrationApplied(targetVersion, Key); } if (!migrationInfo.WithoutTransaction) { Provider.Commit(); } } catch (Exception ex) { Logger.Exception(targetVersion, migration.Name, ex); if (!migrationInfo.WithoutTransaction) { // если изменения выполняются в транзакции, откатываем // изменения текущей миграции, которые успели выполниться Provider.Rollback(); Logger.RollingBack(currentDatabaseVersion); } throw; } }
public void Apply(Migration migration) { OutputTableDatas .ForEach(tableData => migration.Apply(tableData)); }
/// /// // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connection = $"{Configuration["CONNECTION_STRING"]}Database={Configuration["DATABASE_NAME"]};"; Migration.Apply(Configuration["CONNECTION_STRING"], Configuration["DATABASE_NAME"]); services.AddDbContext <MySqlContext>(options => options.UseMySql(connection)); services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddApiVersioning(); //Auth var signingConfigurations = new SigningConfiguration(); services.AddSingleton(signingConfigurations); var tokenConfigurations = new TokenConfiguration(); tokenConfigurations.Audience = "MyAudienceExample"; tokenConfigurations.Issuer = "MyIssuerExapmle"; tokenConfigurations.Seconds = 1200; services.AddSingleton(tokenConfigurations); services.AddAuthentication(authOptions => { authOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; authOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(bearerOptions => { var paramsValidation = bearerOptions.TokenValidationParameters; paramsValidation.IssuerSigningKey = signingConfigurations.Key; paramsValidation.ValidAudience = tokenConfigurations.Audience; paramsValidation.ValidIssuer = tokenConfigurations.Issuer; // Validates the signing of a received token paramsValidation.ValidateIssuerSigningKey = true; // Checks if a received token is still valid paramsValidation.ValidateLifetime = true; // Tolerance time for the expiration of a token (used in case // of time synchronization problems between different // computers involved in the communication process) paramsValidation.ClockSkew = TimeSpan.Zero; }); // Enables the use of the token as a means of // authorizing access to this project's resources services.AddAuthorization(auth => { auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser().Build()); }); //Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "RESTFul API .Net Core Repository Pattern Sample", Version = "v1" }); //Creating the button to inform the JWT Token c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "Please enter JWT with Bearer into field", Name = "Authorization", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", Enumerable.Empty <string> () }, }); // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); /* * Dependency Groups */ services.AddScoped <IPersonBusiness, PersonBusiness>(); services.AddScoped <IPersonRepository, PersonRepository>(); services.AddScoped <IBookBusiness, BookBusiness>(); services.AddScoped <IBookRepository, BookRepository>(); services.AddScoped <IUserBusiness, UserBusiness>(); services.AddScoped <IUserRepository, UserRepository>(); }