Update Dapper Migrations (#6520)

* Update workflow to check for patch version 3.3.3

Revised the GitHub Actions workflow to detect the correct patch branch, updating from version 3.3.2 to 3.3.3. This ensures compatibility with the latest release process.

* Refactor WebhooksFeature to streamline configuration.

Simplified the configuration of sinks, sources, and HTTP clients by using direct actions instead of service-level options. Updated Apply method to finalize configurations and added notification handlers for better extensibility. Improved code readability and maintainability by consolidating logic and removing unnecessary dependencies.

* Update base_version in GitHub Actions workflow

Bump the base_version from 3.3.2 to 3.3.4 in the packages workflow file. This ensures compatibility and uses the latest base version for package management.

* Update release branch check to target patch 3.3.4

Modified the GitHub Actions workflow to check for the `patch/3.3.4` branch instead of `patch/3.3.3` during release events. This ensures compatibility with the latest patch branch in the release process.

* Handle conversion of enumerables to arrays in ObjectConverter (#6508)

* Handle conversion of enumerables to arrays in ObjectConverter

Added functionality to convert enumerables to arrays when the target type is an array. The implementation ensures each item is properly cast to the target array's element type and then added to the resulting array.

* Add unit test for converting object array to double array

This commit introduces a new test ensuring the proper conversion of an object array of doubles to a double array. It verifies both the validity of the conversion and that the result is not null.

* Update base version to 3.3.5 in workflow configuration

Bump the `base_version` from 3.3.4 to 3.3.5 in the GitHub Actions workflow file. Adjust the matching branch reference to correspond with the updated version.

* Add V3.4 migration with schema updates and new column

Introduces Migration V3_4 to modify WorkflowInstances by adding the IsExecuting column. Updates Entity Framework migration to dynamically handle schema changes across tables. Ensures improved compatibility and extendability within the database layer.

* Refactor Dapper migration execution and update database schema. (#6519)

* Refactor migration execution and update database schema.

Replaced RunMigrationsHostedService with RunMigrationsStartupTask using IStartupTask for improved lifecycle management. Updated DapperMigrationsFeature to use the new startup task. Added a new "SerializedProperties" column to ActivityExecutionRecords and ensured proper schema adjustments during migrations.

* Add TenantId column to BookmarkQueueItems table

This commit introduces a nullable TenantId column to the BookmarkQueueItems table. The change ensures better multi-tenancy support by allowing tenant-specific data segregation.
This commit is contained in:
Sipke Schoorstra 2025-03-20 12:11:05 +01:00 committed by GitHub
parent ffe1a611d7
commit 9575cdeecf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 54 additions and 50 deletions

View file

@ -0,0 +1,24 @@
using System.Diagnostics.CodeAnalysis;
using FluentMigrator;
using JetBrains.Annotations;
namespace Elsa.Dapper.Migrations.Management;
/// <inheritdoc />
[Migration(10005, "Elsa:Management:V3.4")]
[PublicAPI]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class V3_4: Migration
{
/// <inheritdoc />
public override void Up()
{
Alter.Table("WorkflowInstances").AddColumn("IsExecuting").AsBoolean().NotNullable().WithDefaultValue(false);
}
/// <inheritdoc />
public override void Down()
{
Delete.Column("IsExecuting").FromTable("WorkflowInstances");
}
}

View file

@ -18,13 +18,14 @@ public class V3_3 : Migration
Alter.Table("Bookmarks").AddColumn("TenantId").AsString().Nullable();
Alter.Table("WorkflowExecutionLogRecords").AddColumn("TenantId").AsString().Nullable();
Alter.Table("ActivityExecutionRecords").AddColumn("TenantId").AsString().Nullable();
Alter.Table("ActivityExecutionRecords").AddColumn("SerializedProperties").AsString(MaxValue).Nullable();
Alter.Table("KeyValuePairs").AddColumn("TenantId").AsString().Nullable();
Rename.Column("Key").OnTable("KeyValuePairs").To("Id");
IfDatabase("SqlServer", "Oracle", "MySql", "Postgres")
.Create
.Table("BookmarkQueueItems")
.WithColumn("Id").AsString().PrimaryKey()
.WithColumn("TenantId").AsString().Nullable()
.WithColumn("WorkflowInstanceId").AsString().Nullable()
.WithColumn("CorrelationId").AsString().Nullable()
.WithColumn("BookmarkId").AsString().Nullable()
@ -38,6 +39,7 @@ public class V3_3 : Migration
.Create
.Table("BookmarkQueueItems")
.WithColumn("Id").AsString().PrimaryKey()
.WithColumn("TenantId").AsString().Nullable()
.WithColumn("WorkflowInstanceId").AsString().Nullable()
.WithColumn("CorrelationId").AsString().Nullable()
.WithColumn("BookmarkId").AsString().Nullable()
@ -55,6 +57,7 @@ public class V3_3 : Migration
Delete.Column("TenantId").FromTable("Bookmarks");
Delete.Column("TenantId").FromTable("WorkflowExecutionLogRecords");
Delete.Column("TenantId").FromTable("ActivityExecutionRecords");
Delete.Column("SerializedProperties").FromTable("ActivityExecutionRecords");
Delete.Column("TenantId").FromTable("KeyValuePairs");
Rename.Column("Id").OnTable("KeyValuePairs").To("Key");
Delete.Table("BookmarkQueueItems");

View file

@ -1,6 +1,7 @@
using Elsa.Dapper.Contracts;
using Elsa.Dapper.HostedServices;
using Elsa.Dapper.Migrations.Management;
using Elsa.Extensions;
using Elsa.Features.Abstractions;
using Elsa.Features.Services;
using FluentMigrator.Runner;
@ -11,13 +12,8 @@ namespace Elsa.Dapper.Features;
/// <summary>
/// Configures migrations.
/// </summary>
public class DapperMigrationsFeature : FeatureBase
public class DapperMigrationsFeature(IModule module) : FeatureBase(module)
{
/// <inheritdoc />
public DapperMigrationsFeature(IModule module) : base(module)
{
}
/// <summary>
/// Configures migrations to use SQLite.
/// </summary>
@ -48,11 +44,6 @@ public class DapperMigrationsFeature : FeatureBase
{
Services.AddFluentMigratorCore();
Services.ConfigureRunner(ConfigureRunner);
}
/// <inheritdoc />
public override void ConfigureHostedServices()
{
ConfigureHostedService<RunMigrationsHostedService>(-1);
Services.AddStartupTask<RunMigrationsStartupTask>();
}
}

View file

@ -1,33 +0,0 @@
using FluentMigrator.Runner;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Elsa.Dapper.HostedServices;
/// <summary>
/// Runs database migrations on startup.
/// </summary>
public class RunMigrationsHostedService : IHostedService
{
private readonly IServiceScopeFactory _scopeFactory;
/// <summary>
/// Initializes a new instance of the <see cref="RunMigrationsHostedService"/> class.
/// </summary>
public RunMigrationsHostedService(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
/// <inheritdoc />
public Task StartAsync(CancellationToken cancellationToken)
{
using var scope = _scopeFactory.CreateScope();
var runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
runner.MigrateUp();
return Task.CompletedTask;
}
/// <inheritdoc />
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}

View file

@ -0,0 +1,18 @@
using Elsa.Common;
using FluentMigrator.Runner;
using JetBrains.Annotations;
namespace Elsa.Dapper.HostedServices;
/// <summary>
/// Runs database migrations on startup.
/// </summary>
[UsedImplicitly]
public class RunMigrationsStartupTask(IMigrationRunner migrationRunner) : IStartupTask
{
public Task ExecuteAsync(CancellationToken cancellationToken)
{
migrationRunner.MigrateUp();
return Task.CompletedTask;
}
}

View file

@ -1,3 +1,4 @@
using Elsa.Extensions;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@ -19,22 +20,22 @@ namespace Elsa.EntityFrameworkCore.Sqlite.Migrations.Identity
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "Elsa");
name: _schema.Schema);
migrationBuilder.RenameTable(
name: "Users",
newName: "Users",
newSchema: "Elsa");
newSchema: _schema.Schema);
migrationBuilder.RenameTable(
name: "Roles",
newName: "Roles",
newSchema: "Elsa");
newSchema: _schema.Schema);
migrationBuilder.RenameTable(
name: "Applications",
newName: "Applications",
newSchema: "Elsa");
newSchema: _schema.Schema);
}
/// <inheritdoc />