Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database Migrator: Make database command timeout configurable #626

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IServiceCollection AddDatabase(this IServiceCollection services, A
case SQLSERVER:
dbContextOptions.UseSqlServer(options.ConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(SQLSERVER_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "AdminUi");
Expand All @@ -45,7 +45,7 @@ public static IServiceCollection AddDatabase(this IServiceCollection services, A
case POSTGRES:
dbContextOptions.UseNpgsql(options.ConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(POSTGRES_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "AdminUi");
Expand All @@ -63,6 +63,7 @@ public class DbOptions
{
public string Provider { get; set; } = null!;
public string ConnectionString { get; set; } = null!;
public int CommandTimeout { get; set; } = 20;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
3 changes: 3 additions & 0 deletions DatabaseMigrator/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public class SqlDatabaseConfiguration

[Required]
public string ConnectionString { get; set; } = null!;

[Range(1, int.MaxValue)]
public int CommandTimeout { get; set; } = 300;
}
9 changes: 9 additions & 0 deletions DatabaseMigrator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,54 +71,63 @@ static IHostBuilder CreateHostBuilder(string[] args)
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

Backbone.Modules.Devices.Infrastructure.Persistence.IServiceCollectionExtensions.AddDatabase(services, options =>
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.ConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

Backbone.Modules.Files.Infrastructure.Persistence.Database.IServiceCollectionExtensions.AddDatabase(services, options =>
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

Backbone.Modules.Messages.Infrastructure.Persistence.Database.IServiceCollectionExtensions.AddDatabase(services, options =>
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

Backbone.Modules.Quotas.Infrastructure.Persistence.Database.IServiceCollectionExtensions.AddDatabase(services, options =>
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

Backbone.Modules.Relationships.Infrastructure.Persistence.Database.IServiceCollectionExtensions.AddDatabase(services, options =>
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

Backbone.Modules.Synchronization.Infrastructure.Persistence.Database.IServiceCollectionExtensions.AddDatabase(services, options =>
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

Backbone.Modules.Tokens.Infrastructure.Persistence.Database.IServiceCollectionExtensions.AddDatabase(services, options =>
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

Backbone.AdminApi.Infrastructure.Persistence.IServiceCollectionExtensions.AddDatabase(services, options =>
{
options.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider;
options.ConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
options.CommandTimeout = parsedConfiguration.Infrastructure.SqlDatabase.CommandTimeout;
});

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void AddDatabase(this IServiceCollection services, Action<DbOption
case SQLSERVER:
dbContextOptions.UseSqlServer(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(SQLSERVER_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Challenges");
Expand All @@ -36,7 +36,7 @@ public static void AddDatabase(this IServiceCollection services, Action<DbOption
case POSTGRES:
dbContextOptions.UseNpgsql(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(POSTGRES_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Challenges");
Expand All @@ -54,6 +54,7 @@ public class DbOptions
{
public string Provider { get; set; } = null!;
public string DbConnectionString { get; set; } = null!;
public int CommandTimeout { get; set; } = 20;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void AddDatabase(this IServiceCollection services, Action<DbOption
case SQLSERVER:
dbContextOptions.UseSqlServer(options.ConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(SQLSERVER_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Devices");
Expand All @@ -38,7 +38,7 @@ public static void AddDatabase(this IServiceCollection services, Action<DbOption
case POSTGRES:
dbContextOptions.UseNpgsql(options.ConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(POSTGRES_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Devices");
Expand All @@ -47,6 +47,7 @@ public static void AddDatabase(this IServiceCollection services, Action<DbOption
default:
throw new Exception($"Unsupported database provider: {options.Provider}");
}

dbContextOptions.UseOpenIddict<
CustomOpenIddictEntityFrameworkCoreApplication,
CustomOpenIddictEntityFrameworkCoreAuthorization,
Expand All @@ -72,6 +73,7 @@ public class DbOptions
{
public string Provider { get; set; } = null!;
public string ConnectionString { get; set; } = null!;
public int CommandTimeout { get; set; } = 20;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case SQLSERVER:
dbContextOptions.UseSqlServer(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(SQLSERVER_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Files");
Expand All @@ -39,7 +39,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case POSTGRES:
dbContextOptions.UseNpgsql(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(POSTGRES_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Files");
Expand All @@ -58,6 +58,7 @@ public class DbOptions
{
public string Provider { get; set; } = null!;
public string DbConnectionString { get; set; } = null!;
public int CommandTimeout { get; set; } = 20;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case SQLSERVER:
dbContextOptions.UseSqlServer(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(SQLSERVER_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Messages");
Expand All @@ -38,7 +38,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case POSTGRES:
dbContextOptions.UseNpgsql(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(POSTGRES_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Messages");
Expand All @@ -55,6 +55,7 @@ public class DbOptions
{
public string Provider { get; set; } = null!;
public string DbConnectionString { get; set; } = null!;
public int CommandTimeout { get; set; } = 20;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case SQLSERVER:
dbContextOptions.UseSqlServer(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(SQLSERVER_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Quotas");
Expand All @@ -42,7 +42,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case POSTGRES:
dbContextOptions.UseNpgsql(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(POSTGRES_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Quotas");
Expand All @@ -67,6 +67,7 @@ public class DbOptions
{
public string Provider { get; set; } = null!;
public string DbConnectionString { get; set; } = null!;
public int CommandTimeout { get; set; } = 20;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case SQLSERVER:
dbContextOptions.UseSqlServer(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(SQLSERVER_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Relationships");
Expand All @@ -38,7 +38,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case POSTGRES:
dbContextOptions.UseNpgsql(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(POSTGRES_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Relationships");
Expand All @@ -54,6 +54,7 @@ public class DbOptions
{
public string Provider { get; set; } = null!;
public string DbConnectionString { get; set; } = null!;
public int CommandTimeout { get; set; } = 20;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case SQLSERVER:
dbContextOptions.UseSqlServer(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(SQLSERVER_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Synchronization");
Expand All @@ -39,7 +39,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
case POSTGRES:
dbContextOptions.UseNpgsql(options.DbConnectionString, sqlOptions =>
{
sqlOptions.CommandTimeout(20);
sqlOptions.CommandTimeout(options.CommandTimeout);
sqlOptions.MigrationsAssembly(POSTGRES_MIGRATIONS_ASSEMBLY);
sqlOptions.EnableRetryOnFailure(options.RetryOptions.MaxRetryCount, TimeSpan.FromSeconds(options.RetryOptions.MaxRetryDelayInSeconds), null);
sqlOptions.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "Synchronization");
Expand All @@ -57,6 +57,7 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio
public class DbOptions
{
public string Provider { get; set; } = null!;
public int CommandTimeout { get; set; } = 20;
public string DbConnectionString { get; set; } = null!;
public RetryOptions RetryOptions { get; set; } = new();
}
Expand Down
Loading