Skip to content

Commit

Permalink
The most significant changes in the code include updates to the versi…
Browse files Browse the repository at this point in the history
…ons of Dapper, xunit, and xunit.runner.visualstudio in the EasyDbMigratorTests.csproj file. The code has also been cleaned up by removing several instances of ReSharper disable comments, which suggests that the developer is no longer suppressing certain warnings. Additionally, the code readability has been improved by adding explicit argument names to several method calls in DbMigrator.cs. The class name in the HereThePostgreSQLServerScriptsCanBeFound.cs file has been corrected for accuracy. Lastly, a new .editorconfig file has been added to the project to configure coding style rules and conventions.

1. Updated the version of Dapper from 2.1.35 to 2.1.44 in EasyDbMigratorTests.csproj.
2. Updated the version of xunit from 2.7.0 to 2.7.1 in EasyDbMigratorTests.csproj.
3. Updated the version of xunit.runner.visualstudio from 2.5.7 to 2.5.8 in EasyDbMigratorTests.csproj.
4. Removed several instances of the ReSharper disable HeapView.ObjectAllocation comment in various files.
5. Added explicit argument names to several ArgumentNullException.ThrowIfNull calls in DbMigrator.cs.
6. Added explicit argument names to several _logger.Log calls in DbMigrator.cs.
7. Replaced several instances of the type HereThePostgreSqlServerScriptsCanBeFound with HereThePostgreSQLServerScriptsCanBeFound in PostgresServerIntegrationTests.cs.
8. Replaced several instances of creating a new List<string> and immediately assigning it to another variable with creating the list and assigning it directly to the desired variable in PostgresServerIntegrationTests.cs and SqlServerIntegrationTests.cs.
9. Removed the ReSharper disable once NotNullOrRequiredMemberIsNotInitialized comment in DbMigrationsRunRowSqlServer.cs.
10. Removed the ReSharper disable once HeapView.ClosureAllocation comment in LoggingTestExtensions.cs.
11. Modified DbMigratorTests.cs to remove comments that disable the HeapView.ClosureAllocation warning.
12. Modified MigrationConfigurationTests.cs to change the way inline data is provided to the test methods.
13. Modified ScriptTests.cs to change the way inline data is provided to the test methods.
14. Corrected the casing of the class name in HereThePostgreSQLServerScriptsCanBeFound.cs.
15. Added a new .editorconfig file to the project to configure coding style rules and conventions.
16. removed Rider files
  • Loading branch information
Retrodad0001 committed Apr 12, 2024
1 parent 79aa9a3 commit 17275ce
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 113 deletions.
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[*.cs]

# CA2254: Template should be a static expression
dotnet_diagnostic.CA2254.severity = warning

# IDE0305: Simplify collection initialization
dotnet_diagnostic.IDE0305.severity = none

# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = none

# IDE0028: Simplify collection initialization
dotnet_diagnostic.IDE0028.severity = none

# IDE0005: Using directive is unnecessary.
dotnet_diagnostic.IDE0005.severity = warning

# IDE0300: Simplify collection initialization
dotnet_diagnostic.IDE0300.severity = none

# IDE0270: Use coalesce expression
dotnet_diagnostic.IDE0270.severity = warning

# IDE0270: Use coalesce expression
dotnet_style_coalesce_expression = false

# IDE0079: Remove unnecessary suppression
dotnet_diagnostic.IDE0079.severity = warning
1 change: 1 addition & 0 deletions EasyDbMigrator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyDbMigratorTests", "Easy
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6F223ADD-7137-481D-A871-D44C9FF8DE15}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Help.txt = Help.txt
EndProjectSection
EndProject
Expand Down
4 changes: 0 additions & 4 deletions EasyDbMigrator/AssemblyResourceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public async Task<List<Script>> TryGetScriptsFromAssembly(Type typeOfClassWhereS
foreach (string filename in filenames)
{
await using Stream? stream = assembly?.GetManifestResourceStream(filename);
#pragma warning disable IDE0270
if (stream is null)
#pragma warning restore IDE0270
{
throw new InvalidOperationException(new StringBuilder()
.Append("steam cannot be null for resource name: ")
Expand All @@ -55,9 +53,7 @@ private static string[] TryGetManifestResourceNamesFromAssembly(Type typeOfClass
{
Assembly? assembly = Assembly.GetAssembly(typeOfClassWhereScriptsAreLocated);

#pragma warning disable IDE0270
if (assembly is null)
#pragma warning restore IDE0270
{
throw new InvalidOperationException(new StringBuilder().Append("assembly is null for custom-class: ")
.Append(typeOfClassWhereScriptsAreLocated)
Expand Down
8 changes: 0 additions & 8 deletions EasyDbMigrator/DatabaseConnectors/MicrosoftSqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public sealed class MicrosoftSqlConnector : IDatabaseConnector
public async Task<Result<bool>> TryDeleteDatabaseIfExistAsync(MigrationConfiguration migrationConfiguration
, CancellationToken cancellationToken)
{
// ReSharper disable once HeapView.ObjectAllocation
string query = $@"
IF EXISTS(SELECT * FROM master.sys.databases WHERE name='{migrationConfiguration.DatabaseName}')
BEGIN
Expand All @@ -56,7 +55,6 @@ ALTER DATABASE {migrationConfiguration.DatabaseName}
public async Task<Result<bool>> TrySetupDbMigrationsRunTableWhenNotExistAsync(MigrationConfiguration migrationConfiguration
, CancellationToken cancellationToken)
{
// ReSharper disable once HeapView.ObjectAllocation
string sqlScriptCreateMigrationTable = @$" USE {migrationConfiguration.DatabaseName}
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='DbMigrationsRun' AND xtype='U')
BEGIN
Expand Down Expand Up @@ -85,7 +83,6 @@ Version nvarchar(10) NOT NULL
/// <returns></returns>
public async Task<Result<bool>> TrySetupEmptyDataBaseWithDefaultSettingWhenThereIsNoDatabaseAsync(MigrationConfiguration migrationConfiguration, CancellationToken cancellationToken)
{
// ReSharper disable once HeapView.ObjectAllocation
string sqlScriptCreateDatabase = @$"
USE Master
IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = '{migrationConfiguration.DatabaseName}')
Expand All @@ -109,7 +106,6 @@ CREATE DATABASE {migrationConfiguration.DatabaseName}
/// <param name="executedDateTime"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
// ReSharper disable once HeapView.ClosureAllocation
public async Task<Result<RunMigrationResult>> RunDbMigrationScriptAsync(MigrationConfiguration migrationConfiguration
, Script script
, DateTimeOffset executedDateTime
Expand All @@ -128,7 +124,6 @@ public async Task<Result<RunMigrationResult>> RunDbMigrationScriptAsync(Migratio
await using SqlConnection connection = new(connectionString: migrationConfiguration.ConnectionString);
await connection.OpenAsync(cancellationToken: cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
// ReSharper disable once HeapView.ObjectAllocation
string checkIfScriptHasExecuted = $@"USE {migrationConfiguration.DatabaseName}
SELECT Id
FROM DbMigrationsRun
Expand All @@ -144,7 +139,6 @@ FROM DbMigrationsRun
}
string sqlFormattedDate = executedDateTime.ToString(format: "yyyy-MM-dd HH:mm:ss.fffffff zzz");
// ReSharper disable once HeapView.ObjectAllocation
string updateVersioningTableScript = $@"
USE {migrationConfiguration.DatabaseName}
INSERT INTO DbMigrationsRun (Executed, Filename, version)
Expand Down Expand Up @@ -187,15 +181,13 @@ INSERT INTO DbMigrationsRun (Executed, Filename, version)
{
return new Result<RunMigrationResult>(wasSuccessful: true
, value: RunMigrationResult.ExceptionWasThrownWhenScriptWasExecuted
// ReSharper disable once HeapView.ObjectAllocation
, exception: new ApplicationException(message: $"{ex} + {ex2.Message}"));
}
}

return new Result<RunMigrationResult>(wasSuccessful: true, value: RunMigrationResult.ExceptionWasThrownWhenScriptWasExecuted, exception: ex);
}
}
// ReSharper disable once HeapView.ClosureAllocation
private async Task<Result<bool>> TryExecuteSingleScriptAsync(string connectionString
, string scriptName
, string sqlScriptContent
Expand Down
8 changes: 0 additions & 8 deletions EasyDbMigrator/DatabaseConnectors/PostgreSqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public sealed class PostgreSqlConnector : IDatabaseConnector
public async Task<Result<bool>> TryDeleteDatabaseIfExistAsync(MigrationConfiguration migrationConfiguration
, CancellationToken cancellationToken)
{
// ReSharper disable once HeapView.ObjectAllocation
string query = $@"
DROP DATABASE IF EXISTS {migrationConfiguration.DatabaseName}
";
Expand Down Expand Up @@ -89,8 +88,6 @@ public async Task<Result<bool>> TrySetupEmptyDataBaseWithDefaultSettingWhenThere
return new Result<bool>(wasSuccessful: true);
}

// ReSharper disable once StringLiteralTypo
// ReSharper disable once HeapView.ObjectAllocation
string sqlScriptCreateDatabase = @$"
SELECT 'CREATE DATABASE {migrationConfiguration.DatabaseName}'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '{migrationConfiguration.DatabaseName}')
Expand All @@ -112,7 +109,6 @@ WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '{migrationConfigurati
/// <param name="executedDateTime"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
// ReSharper disable once HeapView.ClosureAllocation
public async Task<Result<RunMigrationResult>> RunDbMigrationScriptAsync(MigrationConfiguration migrationConfiguration
, Script script
, DateTimeOffset executedDateTime
Expand All @@ -132,7 +128,6 @@ public async Task<Result<RunMigrationResult>> RunDbMigrationScriptAsync(Migratio
await using NpgsqlConnection connection = new(connectionString: migrationConfiguration.ConnectionString);
await connection.OpenAsync(cancellationToken: cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
// ReSharper disable once HeapView.ObjectAllocation
string checkIfScriptHasExecuted = $@"
SELECT Id
FROM DbMigrationsRun
Expand All @@ -149,7 +144,6 @@ FROM DbMigrationsRun
}
string sqlFormattedDate = executedDateTime.ToString(format: "yyyy-MM-dd HH:mm:ss");
// ReSharper disable once HeapView.ObjectAllocation
string updateVersioningTableScript = $@"
INSERT INTO DbMigrationsRun (Executed, Filename, version)
Expand Down Expand Up @@ -190,7 +184,6 @@ INSERT INTO DbMigrationsRun (Executed, Filename, version)
{
return new Result<RunMigrationResult>(wasSuccessful: true
, value: RunMigrationResult.ExceptionWasThrownWhenScriptWasExecuted
// ReSharper disable once HeapView.ObjectAllocation
, exception: new ApplicationException(message: $"{ex} + {ex2.Message}"));
}
}
Expand All @@ -199,7 +192,6 @@ INSERT INTO DbMigrationsRun (Executed, Filename, version)
}
}

// ReSharper disable once HeapView.ClosureAllocation
private async Task<Result<bool>> TryExecuteSingleScriptAsync(string connectionString
, string scriptName
, string sqlScriptContent
Expand Down
Loading

0 comments on commit 17275ce

Please sign in to comment.