-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
253 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using NBomber.Contracts.Stats; | ||
using NBomber.Sinks.Timescale.DAL; | ||
|
||
namespace NBomber.Sinks.Timescale.Contracts; | ||
|
||
internal class NodeInfoDbRecord | ||
{ | ||
[Column(ColumnNames.Time)] public DateTime Time { get; set; } | ||
[Column(ColumnNames.SessionId)] public string SessionId { get; set; } | ||
[Column(ColumnNames.CurrentOperation)] public OperationType CurrentOperation { get; set; } | ||
[Column(ColumnNames.TestSuite)] public string TestSuite { get; set; } | ||
[Column(ColumnNames.TestName)] public string TestName { get; set; } | ||
[Column(ColumnNames.Metadata)] public string Metadata{ get; set; } | ||
[Column(ColumnNames.NodeInfo)] public string NodeInfo { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using Npgsql; | ||
using RepoDb; | ||
using ILogger = Serilog.ILogger; | ||
|
||
namespace NBomber.Sinks.Timescale.DAL; | ||
|
||
internal class DbMigrations(string connectionString, ILogger logger) | ||
{ | ||
public const int SinkSchemaVersion = 0; | ||
|
||
public async Task Run() | ||
{ | ||
var currentDbVersion = await GetCurrendDbVersion(); | ||
|
||
if (currentDbVersion > SinkSchemaVersion) | ||
{ | ||
var errMessage = $@"Your NBomber.Sinks.Timescale schema version: '{SinkSchemaVersion}' is not compatible with DB schema version: '{currentDbVersion}'"; | ||
logger.Error(errMessage); | ||
throw new PlatformNotSupportedException(errMessage); | ||
} | ||
else if (currentDbVersion < SinkSchemaVersion) | ||
{ | ||
for (var v = currentDbVersion + 1; v <= SinkSchemaVersion; v++) | ||
{ | ||
await ApplyMigration(v); | ||
} | ||
} | ||
} | ||
|
||
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; | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.Error(ex, ex.Message); | ||
return -1; | ||
} | ||
} | ||
|
||
private async Task ApplyMigration(int version) | ||
{ | ||
await using var connection = new NpgsqlConnection(connectionString); | ||
|
||
switch (version) | ||
{ | ||
case 0: | ||
await connection.ExecuteNonQueryAsync( | ||
SqlQueries.CreateStepStatsTable | ||
+ SqlQueries.CreateSessionsTable | ||
+ SqlQueries.CreateDbSchemaVersion); | ||
|
||
await connection.ExecuteNonQueryAsync($@" | ||
INSERT INTO {TableNames.SchemaVersionTable} (""{ColumnNames.Version}"") | ||
VALUES ({version}) | ||
;"); | ||
|
||
logger.Debug("Created initial tables"); | ||
break; | ||
|
||
//case 1: | ||
// await connection.ExecuteNonQueryAsync($@" | ||
// ALTER TABLE {SqlQueries.StepStatsTable} | ||
// ADD COLUMN IF NOT EXISTS {ColumnNames.TestCulomn} TEXT | ||
// ; | ||
|
||
// WITH updated AS ( | ||
// UPDATE {SqlQueries.DbSchemaVersion} | ||
// SET ""{ColumnNames.Version}"" = {version} | ||
// RETURNING * | ||
// ) | ||
// INSERT INTO {SqlQueries.DbSchemaVersion} (""{ColumnNames.Version}"") | ||
// SELECT 1 | ||
// WHERE NOT EXISTS (SELECT * FROM updated);"); | ||
// break; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.