< Summary

Information
Class: Elsa.Persistence.EFCore.PostgreSql.Services.PostgreSqlWorkflowReferenceQuery
Assembly: Elsa.Persistence.EFCore.PostgreSql
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.PostgreSql/Services/PostgreSqlWorkflowReferenceQuery.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 32
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
ExecuteAsync()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.PostgreSql/Services/PostgreSqlWorkflowReferenceQuery.cs

#LineLine coverage
 1using Elsa.Persistence.EFCore.Modules.Management;
 2using Elsa.Persistence.EFCore.PostgreSql.Helpers;
 3using Elsa.Workflows.Management;
 4using Elsa.Workflows.Management.Entities;
 5using Microsoft.EntityFrameworkCore;
 6
 7namespace Elsa.Persistence.EFCore.PostgreSql.Services;
 8
 9/// <summary>
 10/// Provides an implementation of <see cref="IWorkflowReferenceQuery"/> for querying PostgreSQL databases
 11/// to find all latest workflow definitions that reference a specific workflow definition.
 12/// </summary>
 013public class PostgreSqlWorkflowReferenceQuery(IDbContextFactory<ManagementElsaDbContext> dbContextFactory) : IWorkflowRe
 14{
 15    public async Task<IEnumerable<string>> ExecuteAsync(string workflowDefinitionId, CancellationToken cancellationToken
 16    {
 017        await using var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
 018        var tableName = dbContext.Model.FindEntityType(typeof(WorkflowDefinition))!.QuoteSchemaQualifiedTableName();
 19
 020        var sql = $"""
 021                   SELECT "DefinitionId", "TenantId" FROM {tableName} WHERE "IsLatest" = true AND EXISTS (
 022                   SELECT 1 FROM jsonb_array_elements("StringData"::jsonb->'activities') AS value
 023                   WHERE value->>'workflowDefinitionId' = @p0
 024                     AND value->'latestAvailablePublishedVersion' IS NOT NULL)
 025                   """;
 26
 027        return await dbContext.Set<WorkflowDefinition>()
 028            .FromSqlRaw(sql, workflowDefinitionId)
 029            .Select(x => x.DefinitionId)
 030            .ToListAsync(cancellationToken);
 031    }
 32}