Skip to content

Commit

Permalink
feat: add support for configuring yuniql transaction mode
Browse files Browse the repository at this point in the history
This changes the default transaction mode from "session" to "version".
  • Loading branch information
Alxandr committed Mar 3, 2025
1 parent 0030d14 commit 2a1f1d6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Altinn.Authorization.ServiceDefaults.Npgsql.Migration;
using CommunityToolkit.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -72,7 +73,7 @@ private void MigrateDatabaseSync(string connectionString, ITraceService traceSer
config.Environment = options.Environment;
config.MetaSchemaName = options.MigrationsTable.Schema;
config.MetaTableName = options.MigrationsTable.Name;
config.TransactionMode = "session";
config.TransactionMode = GetTransactionMode(options.TransactionMode);
config.IsContinueAfterFailure = null;
config.IsRequiredClearedDraft = false;
config.IsForced = false;
Expand Down Expand Up @@ -150,6 +151,15 @@ Cancelling a running migration has the potential to corrupt the process.
}
}

private static string GetTransactionMode(YuniqlTransactionMode mode)
=> mode switch
{
YuniqlTransactionMode.None => TRANSACTION_MODE.NONE,
YuniqlTransactionMode.Version => TRANSACTION_MODE.VERSION,
YuniqlTransactionMode.Session => TRANSACTION_MODE.SESSION,
_ => ThrowHelper.ThrowArgumentOutOfRangeException<string>(nameof(mode)),
};

private Workspace ResolveWorkspace(YuniqlDatabaseMigratorOptions options)
{
if (options.WorkspaceFileProvider is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public sealed class YuniqlDatabaseMigratorOptions
/// </value>
public bool DisableTracing { get; set; }

/// <summary>
/// Gets or sets the transaction mode.
/// </summary>
public YuniqlTransactionMode TransactionMode { get; set; } = YuniqlTransactionMode.Version;

IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
if (string.IsNullOrEmpty(Environment))
Expand Down Expand Up @@ -81,3 +86,24 @@ public sealed class VersionTableOptions
/// </summary>
public string? Schema { get; set; }
}

/// <summary>
/// Yuniql transaction mode.
/// </summary>
public enum YuniqlTransactionMode
{
/// <summary>
/// No transaction will be used (transaction per statement).
/// </summary>
None,

/// <summary>
/// A transaction will be used for each version.
/// </summary>
Version,

/// <summary>
/// A transaction will be used for each session.
/// </summary>
Session,
}

0 comments on commit 2a1f1d6

Please sign in to comment.