< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 108
Coverable lines: 108
Total lines: 159
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: .ctor(...)100%210%
File 1: Up(...)100%210%
File 1: Down(...)100%210%
File 2: BuildTargetModel(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Sqlite/Migrations/Labels/20260913133258_PerTenantLabelUniqueness.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore.Migrations;
 2
 3#nullable disable
 4
 5namespace Elsa.Persistence.EFCore.Sqlite.Migrations.Labels
 6{
 7    /// <inheritdoc />
 8    public partial class PerTenantLabelUniqueness : Migration
 9    {
 10        private readonly Elsa.Persistence.EFCore.IElsaDbContextSchema _schema;
 11
 12        /// <inheritdoc />
 013        public PerTenantLabelUniqueness(Elsa.Persistence.EFCore.IElsaDbContextSchema schema)
 14        {
 015            _schema = schema;
 016        }
 17
 18        /// <inheritdoc />
 19        protected override void Up(MigrationBuilder migrationBuilder)
 20        {
 21            // Default tenant is "" (not null). Stamp leftover nulls so the unique index covers them.
 022            migrationBuilder.Sql($"""
 023                UPDATE "{_schema.Schema}"."Labels"
 024                SET "TenantId" = ''
 025                WHERE "TenantId" IS NULL;
 026                """);
 27
 28            // No silent dedupe. List leftover keys and abort; operators must resolve them before upgrading.
 029            migrationBuilder.Sql($"""
 030                SELECT RAISE(ABORT, 'Cannot apply IX_Label_TenantId_NormalizedName. Operators must resolve leftover (Ten
 031                    (SELECT group_concat('(' || IFNULL("TenantId", '') || ', ' || "NormalizedName" || ')', ', ')
 032                     FROM (
 033                         SELECT "TenantId", "NormalizedName"
 034                         FROM "{_schema.Schema}"."Labels"
 035                         GROUP BY "TenantId", "NormalizedName"
 036                         HAVING COUNT(*) > 1
 037                     )))
 038                WHERE EXISTS (
 039                    SELECT 1
 040                    FROM "{_schema.Schema}"."Labels"
 041                    GROUP BY "TenantId", "NormalizedName"
 042                    HAVING COUNT(*) > 1
 043                );
 044                """);
 45
 046            migrationBuilder.CreateIndex(
 047                name: "IX_Label_TenantId_NormalizedName",
 048                schema: _schema.Schema,
 049                table: "Labels",
 050                columns: new[] { "TenantId", "NormalizedName" },
 051                unique: true);
 052        }
 53
 54        /// <inheritdoc />
 55        protected override void Down(MigrationBuilder migrationBuilder)
 56        {
 057            migrationBuilder.DropIndex(
 058                name: "IX_Label_TenantId_NormalizedName",
 059                schema: _schema.Schema,
 060                table: "Labels");
 061        }
 62    }
 63}

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Sqlite/Migrations/Labels/20260913133258_PerTenantLabelUniqueness.Designer.cs

#LineLine coverage
 1// <auto-generated />
 2using Elsa.Persistence.EFCore.Modules.Labels;
 3using Microsoft.EntityFrameworkCore;
 4using Microsoft.EntityFrameworkCore.Infrastructure;
 5using Microsoft.EntityFrameworkCore.Migrations;
 6using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
 7
 8#nullable disable
 9
 10namespace Elsa.Persistence.EFCore.Sqlite.Migrations.Labels
 11{
 12    [DbContext(typeof(LabelsElsaDbContext))]
 13    [Migration("20260913133258_PerTenantLabelUniqueness")]
 14    partial class PerTenantLabelUniqueness
 15    {
 16        /// <inheritdoc />
 17        protected override void BuildTargetModel(ModelBuilder modelBuilder)
 18        {
 19#pragma warning disable 612, 618
 020            modelBuilder
 021                .HasDefaultSchema("Elsa")
 022                .HasAnnotation("ProductVersion", "9.0.17");
 23
 024            modelBuilder.Entity("Elsa.Labels.Entities.Label", b =>
 025                {
 026                    b.Property<string>("Id")
 027                        .HasColumnType("TEXT");
 028
 029                    b.Property<string>("Color")
 030                        .HasColumnType("TEXT");
 031
 032                    b.Property<string>("Description")
 033                        .HasColumnType("TEXT");
 034
 035                    b.Property<string>("Name")
 036                        .IsRequired()
 037                        .HasMaxLength(255)
 038                        .HasColumnType("TEXT");
 039
 040                    b.Property<string>("NormalizedName")
 041                        .IsRequired()
 042                        .HasMaxLength(255)
 043                        .HasColumnType("TEXT");
 044
 045                    b.Property<string>("TenantId")
 046                        .HasColumnType("TEXT");
 047
 048                    b.HasKey("Id");
 049
 050                    b.HasIndex("TenantId", "NormalizedName")
 051                        .IsUnique()
 052                        .HasDatabaseName("IX_Label_TenantId_NormalizedName");
 053
 054                    b.ToTable("Labels", "Elsa");
 055                });
 56
 057            modelBuilder.Entity("Elsa.Labels.Entities.WorkflowDefinitionLabel", b =>
 058                {
 059                    b.Property<string>("Id")
 060                        .HasColumnType("TEXT");
 061
 062                    b.Property<string>("LabelId")
 063                        .IsRequired()
 064                        .HasColumnType("TEXT");
 065
 066                    b.Property<string>("TenantId")
 067                        .HasColumnType("TEXT");
 068
 069                    b.Property<string>("WorkflowDefinitionId")
 070                        .IsRequired()
 071                        .HasColumnType("TEXT");
 072
 073                    b.Property<string>("WorkflowDefinitionVersionId")
 074                        .IsRequired()
 075                        .HasColumnType("TEXT");
 076
 077                    b.HasKey("Id");
 078
 079                    b.HasIndex("LabelId")
 080                        .HasDatabaseName("WorkflowDefinitionLabel_LabelId");
 081
 082                    b.HasIndex("TenantId")
 083                        .HasDatabaseName("WorkflowDefinitionLabel_TenantId");
 084
 085                    b.HasIndex("WorkflowDefinitionId")
 086                        .HasDatabaseName("WorkflowDefinitionLabel_WorkflowDefinitionId");
 087
 088                    b.HasIndex("WorkflowDefinitionVersionId")
 089                        .HasDatabaseName("WorkflowDefinitionLabel_WorkflowDefinitionVersionId");
 090
 091                    b.ToTable("WorkflowDefinitionLabels", "Elsa");
 092                });
 93#pragma warning restore 612, 618
 094        }
 95    }
 96}