Skip to content

Commit

Permalink
changed DbMigration connection to db
Browse files Browse the repository at this point in the history
  • Loading branch information
OlenaKostash committed Oct 24, 2024
1 parent e1c02e5 commit 1e80396
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/NBomber.Sinks.Timescale/DAL/DbMigrations .cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace NBomber.Sinks.Timescale.DAL;

internal class DbMigrations(string connectionString, ILogger logger)
internal class DbMigrations(NpgsqlConnection connection, ILogger logger)
{
public const int SinkSchemaVersion = 0;

Expand All @@ -31,7 +31,6 @@ private async Task<int> GetCurrendDbVersion()
{
try
{
using var connection = new NpgsqlConnection(connectionString);
var result = await connection.ExecuteQueryAsync<int>($@"SELECT ""{ColumnNames.Version}"" FROM {TableNames.SchemaVersionTable};");
var currentDbVersion = result.FirstOrDefault();
return currentDbVersion;
Expand All @@ -45,8 +44,6 @@ private async Task<int> GetCurrendDbVersion()

private async Task ApplyMigration(int version)
{
await using var connection = new NpgsqlConnection(connectionString);

switch (version)
{
case 0:
Expand Down
2 changes: 1 addition & 1 deletion src/NBomber.Sinks.Timescale/TimescaleDbSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task Init(IBaseContext context, IConfiguration infraConfig)

await _mainConnection.OpenAsync();

var migration = new DbMigrations(_config.ConnectionString, _logger);
var migration = new DbMigrations(_mainConnection, _logger);
await migration.Run();
}

Expand Down

0 comments on commit 1e80396

Please sign in to comment.