Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Feb 6, 2025
1 parent 12338b9 commit b807437
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/framework/Framework.DBAccess/CustomNpgsqlHistoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ public class CustomNpgsqlHistoryRepository(HistoryRepositoryDependencies depende
{
protected override string ExistsSql => $"SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = '{this.TableSchema}' AND table_name = '{this.TableName}');";

public override bool Exists()
{
return this.Dependencies.DatabaseCreator.Exists() &&
this.InterpretExistsResult(
this.Dependencies.RawSqlCommandBuilder
.Build(this.ExistsSql)
.ExecuteScalar(new RelationalCommandParameterObject(this.Dependencies.Connection, null, null, this.Dependencies.CurrentContext.Context, this.Dependencies.CommandLogger, CommandSource.Migrations)));
}
public override bool Exists() =>
this.Dependencies.DatabaseCreator.Exists() &&
this.InterpretExistsResult(
this.Dependencies.RawSqlCommandBuilder
.Build(this.ExistsSql)
.ExecuteScalar(new RelationalCommandParameterObject(this.Dependencies.Connection, null, null, this.Dependencies.CurrentContext.Context, this.Dependencies.CommandLogger, CommandSource.Migrations)));

public override async Task<bool> ExistsAsync(CancellationToken cancellationToken = new())
{
Expand All @@ -48,7 +46,10 @@ public override bool Exists()
return false;
}

var existsCommand = await this.Dependencies.RawSqlCommandBuilder.Build(this.ExistsSql).ExecuteScalarAsync(new RelationalCommandParameterObject(this.Dependencies.Connection, null, null, this.Dependencies.CurrentContext.Context, this.Dependencies.CommandLogger, CommandSource.Migrations), cancellationToken).ConfigureAwait(false);
var existsCommand = await this.Dependencies.RawSqlCommandBuilder
.Build(this.ExistsSql)
.ExecuteScalarAsync(new RelationalCommandParameterObject(this.Dependencies.Connection, null, null, this.Dependencies.CurrentContext.Context, this.Dependencies.CommandLogger, CommandSource.Migrations), cancellationToken)
.ConfigureAwait(false);
return this.InterpretExistsResult(existsCommand);
}

Expand Down Expand Up @@ -80,11 +81,14 @@ async Task<bool> IHistoryRepository.CreateIfNotExistsAsync(CancellationToken can

try
{
return await Dependencies.MigrationCommandExecutor.ExecuteNonQueryAsync(
GetCreateIfNotExistsCommands(), Dependencies.Connection, new MigrationExecutionState(),
commitTransaction: true,
cancellationToken: cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None)
!= 0;
return await Dependencies.MigrationCommandExecutor
.ExecuteNonQueryAsync(
GetCreateIfNotExistsCommands(),
Dependencies.Connection,
new MigrationExecutionState(),
commitTransaction: true,
cancellationToken: cancellationToken)
.ConfigureAwait(ConfigureAwaitOptions.None) != 0;
}
catch (PostgresException e) when (e.SqlState is PostgresErrorCodes.UniqueViolation
or PostgresErrorCodes.DuplicateTable
Expand All @@ -94,11 +98,14 @@ or PostgresErrorCodes.DuplicateTable
}
}

private IReadOnlyList<MigrationCommand> GetCreateIfNotExistsCommands()
=> Dependencies.MigrationsSqlGenerator.Generate([new SqlOperation
{
Sql = GetCreateIfNotExistsScript(),
SuppressTransaction = true
}]);
private IReadOnlyList<MigrationCommand> GetCreateIfNotExistsCommands() =>
Dependencies.MigrationsSqlGenerator.Generate(
[
new SqlOperation
{
Sql = GetCreateIfNotExistsScript(),
SuppressTransaction = true
}
]);
}
#pragma warning enable EF1001

Check warning on line 111 in src/framework/Framework.DBAccess/CustomNpgsqlHistoryRepository.cs

View workflow job for this annotation

GitHub Actions / Build, check and test services (9.0)

Expected 'disable' or 'restore'

Check warning on line 111 in src/framework/Framework.DBAccess/CustomNpgsqlHistoryRepository.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp, 9.0)

Expected 'disable' or 'restore'

0 comments on commit b807437

Please # to comment.