Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<UseProjectReferences>false</UseProjectReferences>
<UseProjectReferences>true</UseProjectReferences>
</PropertyGroup>
<PropertyGroup>
<Authors>Elsa Workflows Community</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<PropertyGroup>
<Description>Provides a UI for managing agents.</Description>
<PackageTags>elsa extension studio module agent ai llm semantic kernel</PackageTags>
<UseProjectReferences>true</UseProjectReferences>
</PropertyGroup>

<ItemGroup Label="Elsa" Condition="'$(UseProjectReferences)' == 'true'">
<ItemGroup Label="Elsa" Condition="$(UseProjectReferences) == true">
<ProjectReference Include="..\..\..\..\..\..\client\studio\src\modules\Elsa.Studio.Workflows\Elsa.Studio.Workflows.csproj" />
</ItemGroup>

<ItemGroup Label="Elsa" Condition="'$(UseProjectReferences)' != 'true'">
<ItemGroup Label="Elsa" Condition="$(UseProjectReferences) != true">
<PackageReference Include="Elsa.Studio.Workflows" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.Json;
using Elsa.Common.Entities;
using Elsa.Common.Models;
using Elsa.Persistence.Dapper.Extensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ public TDbContext CreateDbContext(string[] args)
var parser = new Parser(command);
var parseResult = parser.Parse(args);
var connectionString = parseResult.GetValueForOption(connectionStringOption) ?? "Data Source=local";
var serviceProvider = new ServiceCollection().BuildServiceProvider();
var services = new ServiceCollection();

ConfigureServices(services);
ConfigureBuilder(builder, connectionString);

var serviceProvider = services.BuildServiceProvider();
return (TDbContext)ActivatorUtilities.CreateInstance(serviceProvider, typeof(TDbContext), builder.Options);
}

protected virtual void ConfigureServices(IServiceCollection services)
{
// This method can be overridden to configure additional services if needed.
}

/// <summary>
/// Implement this to configure the <see cref="DbContextOptionsBuilder{TContext}"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Provides common Entity Framework Core types for implementing EF Core persistence of varipus ELsa modules.
</Description>
<PackageTags>elsa extension module persistence efcore</PackageTags>
<RootNamespace>Elsa.EFCore</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema
};

protected IServiceProvider ServiceProvider { get; }
private readonly ElsaDbContextOptions? elsaDbContextOptions;
private readonly ElsaDbContextOptions? _elsaDbContextOptions;
public string? TenantId { get; set; }

/// <summary>
Expand All @@ -41,10 +41,10 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema
protected ElsaDbContextBase(DbContextOptions options, IServiceProvider serviceProvider) : base(options)
{
ServiceProvider = serviceProvider;
elsaDbContextOptions = options.FindExtension<ElsaDbContextOptionsExtension>()?.Options;
_elsaDbContextOptions = options.FindExtension<ElsaDbContextOptionsExtension>()?.Options;

// ReSharper disable once VirtualMemberCallInConstructor
Schema = !string.IsNullOrWhiteSpace(elsaDbContextOptions?.SchemaName) ? elsaDbContextOptions.SchemaName : ElsaSchema;
Schema = !string.IsNullOrWhiteSpace(_elsaDbContextOptions?.SchemaName) ? _elsaDbContextOptions.SchemaName : ElsaSchema;

var tenantAccessor = serviceProvider.GetService<ITenantAccessor>();
var tenantId = tenantAccessor?.Tenant?.Id;
Expand All @@ -66,7 +66,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
if (!string.IsNullOrWhiteSpace(Schema))
modelBuilder.HasDefaultSchema(Schema);

var additionalConfigurations = elsaDbContextOptions?.GetModelConfigurations(this);
var additionalConfigurations = _elsaDbContextOptions?.GetModelConfigurations(this);

additionalConfigurations?.Invoke(modelBuilder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using Elsa.Persistence.EFCore.Modules.Management;
using Elsa.Persistence.EFCore.Modules.Runtime;
using Elsa.Persistence.EFCore.Modules.Tenants;
using Elsa.Persistence.EFCore.MySql.Handlers;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

Expand All @@ -33,6 +35,11 @@ public class TenantsDbContextFactories : MySqlDesignTimeDbContextFactory<Tenants

public class MySqlDesignTimeDbContextFactory<TDbContext> : DesignTimeDbContextFactoryBase<TDbContext> where TDbContext : DbContext
{
protected override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IEntityModelCreatingHandler, SetupForMySql>();
}

protected override void ConfigureBuilder(DbContextOptionsBuilder<TDbContext> builder, string connectionString)
{
builder.UseElsaMySql(GetType().Assembly, connectionString, serverVersion: ServerVersion.Parse("9.0.0"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Elsa.Workflows.Management.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Elsa.Persistence.EFCore.MySql.Handlers;

/// <summary>
/// Represents a class that handles entity model creation for SQLite databases.
/// </summary>
public class SetupForMySql : IEntityModelCreatingHandler
{
/// <inheritdoc />
public void Handle(ElsaDbContextBase dbContext, ModelBuilder modelBuilder, IMutableEntityType entityType)
{
if (!dbContext.Database.IsMySql())
return;

// Configure the WorkflowDefinition entity to use the PostgreSQL JSONB type for the StringData property:
if (entityType.ClrType == typeof(WorkflowDefinition))
{
modelBuilder
.Entity(entityType.Name)
.Property("StringData")
.HasColumnType("JSON");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading