< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 112
Coverable lines: 112
Total lines: 166
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.PostgreSql/Migrations/Labels/20260913133325_PerTenantLabelUniqueness.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore.Migrations;
 2
 3#nullable disable
 4
 5namespace Elsa.Persistence.EFCore.PostgreSql.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            // Keep provider column type (text). HasMaxLength(255) is a model annotation only.
 29            // No silent dedupe. List leftover keys and abort; operators must resolve them before upgrading.
 030            migrationBuilder.Sql($"""
 031                DO $$
 032                DECLARE keys text;
 033                BEGIN
 034                    SELECT string_agg(format('(%s, %s)', "TenantId", "NormalizedName"), ', ')
 035                    INTO keys
 036                    FROM (
 037                        SELECT "TenantId", "NormalizedName"
 038                        FROM "{_schema.Schema}"."Labels"
 039                        GROUP BY "TenantId", "NormalizedName"
 040                        HAVING COUNT(*) > 1
 041                    ) d;
 042
 043                    IF keys IS NOT NULL THEN
 044                        RAISE EXCEPTION 'Cannot apply IX_Label_TenantId_NormalizedName. Operators must resolve leftover 
 045                    END IF;
 046                END $$;
 047                """);
 48
 049            migrationBuilder.CreateIndex(
 050                name: "IX_Label_TenantId_NormalizedName",
 051                schema: _schema.Schema,
 052                table: "Labels",
 053                columns: new[] { "TenantId", "NormalizedName" },
 054                unique: true);
 055        }
 56
 57        /// <inheritdoc />
 58        protected override void Down(MigrationBuilder migrationBuilder)
 59        {
 060            migrationBuilder.DropIndex(
 061                name: "IX_Label_TenantId_NormalizedName",
 062                schema: _schema.Schema,
 063                table: "Labels");
 064        }
 65    }
 66}

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.PostgreSql/Migrations/Labels/20260913133325_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;
 7using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
 8
 9#nullable disable
 10
 11namespace Elsa.Persistence.EFCore.PostgreSql.Migrations.Labels
 12{
 13    [DbContext(typeof(LabelsElsaDbContext))]
 14    [Migration("20260913133325_PerTenantLabelUniqueness")]
 15    partial class PerTenantLabelUniqueness
 16    {
 17        /// <inheritdoc />
 18        protected override void BuildTargetModel(ModelBuilder modelBuilder)
 19        {
 20#pragma warning disable 612, 618
 021            modelBuilder
 022                .HasDefaultSchema("Elsa")
 023                .HasAnnotation("ProductVersion", "9.0.17")
 024                .HasAnnotation("Relational:MaxIdentifierLength", 63);
 25
 026            NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
 27
 028            modelBuilder.Entity("Elsa.Labels.Entities.Label", b =>
 029                {
 030                    b.Property<string>("Id")
 031                        .HasColumnType("text");
 032
 033                    b.Property<string>("Color")
 034                        .HasColumnType("text");
 035
 036                    b.Property<string>("Description")
 037                        .HasColumnType("text");
 038
 039                    b.Property<string>("Name")
 040                        .IsRequired()
 041                        .HasMaxLength(255)
 042                        .HasColumnType("text");
 043
 044                    b.Property<string>("NormalizedName")
 045                        .IsRequired()
 046                        .HasMaxLength(255)
 047                        .HasColumnType("text");
 048
 049                    b.Property<string>("TenantId")
 050                        .HasColumnType("text");
 051
 052                    b.HasKey("Id");
 053
 054                    b.HasIndex("TenantId", "NormalizedName")
 055                        .IsUnique()
 056                        .HasDatabaseName("IX_Label_TenantId_NormalizedName");
 057
 058                    b.ToTable("Labels", "Elsa");
 059                });
 60
 061            modelBuilder.Entity("Elsa.Labels.Entities.WorkflowDefinitionLabel", b =>
 062                {
 063                    b.Property<string>("Id")
 064                        .HasColumnType("text");
 065
 066                    b.Property<string>("LabelId")
 067                        .IsRequired()
 068                        .HasColumnType("text");
 069
 070                    b.Property<string>("TenantId")
 071                        .HasColumnType("text");
 072
 073                    b.Property<string>("WorkflowDefinitionId")
 074                        .IsRequired()
 075                        .HasColumnType("text");
 076
 077                    b.Property<string>("WorkflowDefinitionVersionId")
 078                        .IsRequired()
 079                        .HasColumnType("text");
 080
 081                    b.HasKey("Id");
 082
 083                    b.HasIndex("LabelId")
 084                        .HasDatabaseName("WorkflowDefinitionLabel_LabelId");
 085
 086                    b.HasIndex("TenantId")
 087                        .HasDatabaseName("WorkflowDefinitionLabel_TenantId");
 088
 089                    b.HasIndex("WorkflowDefinitionId")
 090                        .HasDatabaseName("WorkflowDefinitionLabel_WorkflowDefinitionId");
 091
 092                    b.HasIndex("WorkflowDefinitionVersionId")
 093                        .HasDatabaseName("WorkflowDefinitionLabel_WorkflowDefinitionVersionId");
 094
 095                    b.ToTable("WorkflowDefinitionLabels", "Elsa");
 096                });
 97#pragma warning restore 612, 618
 098        }
 99    }
 100}