elsa-workflows / elsa-workflows/elsa-core

[BUG] Unable to Separate Workflow Definitions and Instances in Different Databases with Elsa 3

Open
#6,027 1 comment 0 reactions 0 assignees View on GitHub
bug triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

**Description**:
I'm using Elsa 3 and trying to store workflow definitions and workflow instances in separate SQL Server databases. However, regardless of the separate configuration for both, only the connection string specified for workflow instances is being used for both workflows (instances and definitions). I suspect the issue is related to using a single DbContext for both workflow definitions and workflow instances.

**Current Configuration**:
I am configuring Elsa using the following connection strings:

`
var instanceConnectionString = "Data Source=.;Initial Catalog=elsa_instances;User ID=sa;Password=123;multipleactiveresultsets=True;Enlist=false;Application Name=Instances;Encrypt=false;";
var definitaionConnectionString = "Data Source=.;Initial Catalog=elsa_definitions;User ID=sa;Password=123;multipleactiveresultsets=True;Enlist=false;Application Name=Definitions;Encrypt=false;";

builder.Services.AddElsa(elsa =>
{

elsa.UseWorkflowManagement(management =>
{
management.UseWorkflowInstances(m => m.UseEntityFrameworkCore(ef => ef.UseSqlServer(instanceConnectionString )));
management.UseWorkflowDefinitions(m => m.UseEntityFrameworkCore(ef => ef.UseSqlServer(definitaionConnectionString )));
})})

`

However, both workflows (instances and definitions) seem to be using only the first connection string (instanceConnectionString).

**Investigation**:
After reviewing the code, I noticed that both workflow definitions and workflow instances are part of the same DbContext in
ManagementElsaDbContext
Since both workflow instances and definitions share the same DbContext, they also share the same database connection.

**Expected Behavior**:
I expected Elsa to use separate connection strings for workflow instances and workflow definitions, as specified in the configuration:

Workflow Instances should use instanceConnectionString and store data in one database.
Workflow Definitions should use definitaionConnectionString and store data in a different database.
**Proposed Solution**:
I believe that separating the DbContext for workflow instances and definitions into two separate classes would solve this issue. For example:

WorkflowInstanceDbContext for workflow instances.
WorkflowDefinitionDbContext for workflow definitions.

**Environment**:
Elsa Version: 3.x
Database Provider: SQL Server
ASP.NET Core Version: 7.0
Additional Context:
This issue could potentially arise because the current setup assumes that both instances and definitions are handled in the same DbContext, which causes connection string conflicts. If there's a way to register them separately without needing different DbContext classes, that would be ideal.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.