diff --git a/Elsa.sln b/Elsa.sln index 376a59761..48812db79 100644 --- a/Elsa.sln +++ b/Elsa.sln @@ -200,6 +200,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.AspNet.HttpEnd EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Environments", "src\modules\Elsa.Environments\Elsa.Environments.csproj", "{B5CDF747-8066-40D5-9BAE-CBE397BC9B51}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.EntityFrameworkCore.MySql", "src\modules\Elsa.EntityFrameworkCore.MySql\Elsa.EntityFrameworkCore.MySql.csproj", "{8DC74562-1F06-4AFA-8308-8A779E8812A3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -510,6 +512,10 @@ Global {B5CDF747-8066-40D5-9BAE-CBE397BC9B51}.Debug|Any CPU.Build.0 = Debug|Any CPU {B5CDF747-8066-40D5-9BAE-CBE397BC9B51}.Release|Any CPU.ActiveCfg = Release|Any CPU {B5CDF747-8066-40D5-9BAE-CBE397BC9B51}.Release|Any CPU.Build.0 = Release|Any CPU + {8DC74562-1F06-4AFA-8308-8A779E8812A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8DC74562-1F06-4AFA-8308-8A779E8812A3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8DC74562-1F06-4AFA-8308-8A779E8812A3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8DC74562-1F06-4AFA-8308-8A779E8812A3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {155227F0-A33B-40AA-A4B4-06F813EB921B} = {61017E64-6D00-49CB-9E81-5002DC8F7D5F} @@ -599,5 +605,6 @@ Global {3212A999-4AC4-4911-9AA4-92AB906BCB5E} = {56C2FFB8-EA54-45B5-A095-4A78142EB4B5} {165ACC9D-B67C-4B49-A818-ECFD247C899C} = {56C2FFB8-EA54-45B5-A095-4A78142EB4B5} {B5CDF747-8066-40D5-9BAE-CBE397BC9B51} = {5BA4A8FA-F7F4-45B3-AEC8-8886D35AAC79} + {8DC74562-1F06-4AFA-8308-8A779E8812A3} = {5BA4A8FA-F7F4-45B3-AEC8-8886D35AAC79} EndGlobalSection EndGlobal diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Abstractions/MySqlDesignTimeDbContextFactoryBase.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Abstractions/MySqlDesignTimeDbContextFactoryBase.cs new file mode 100644 index 000000000..ed5ac8506 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Abstractions/MySqlDesignTimeDbContextFactoryBase.cs @@ -0,0 +1,18 @@ +using Elsa.EntityFrameworkCore.Extensions; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; + +namespace Elsa.EntityFrameworkCore.MySql.Abstractions; + +public abstract class MySqlDesignTimeDbContextFactoryBase : IDesignTimeDbContextFactory where TDbContext : DbContext +{ + public TDbContext CreateDbContext(string[] args) + { + var connectionString = args.Any() ? args[0] : "Data Source=local"; + + var builder = new DbContextOptionsBuilder(); + builder.UseElsaMySql(connectionString); + + return (TDbContext)Activator.CreateInstance(typeof(TDbContext), builder.Options)!; + } +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Elsa.EntityFrameworkCore.MySql.csproj b/src/modules/Elsa.EntityFrameworkCore.MySql/Elsa.EntityFrameworkCore.MySql.csproj new file mode 100644 index 000000000..c4f4354fa --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Elsa.EntityFrameworkCore.MySql.csproj @@ -0,0 +1,26 @@ + + + + + + + net6.0;net7.0 + + Provides MySql implementation and migrations for various modules. + + elsa module persistence efcore mysql + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Extensions/DbContextOptionsBuilderExtensions.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Extensions/DbContextOptionsBuilderExtensions.cs new file mode 100644 index 000000000..2c82ee235 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Extensions/DbContextOptionsBuilderExtensions.cs @@ -0,0 +1,21 @@ +using Elsa.EntityFrameworkCore.Common; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Pomelo.EntityFrameworkCore.MySql.Infrastructure; + +// ReSharper disable once CheckNamespace +namespace Elsa.EntityFrameworkCore.Extensions; + +public static class DbContextOptionsBuilderExtensions +{ + public static DbContextOptionsBuilder UseElsaMySql(this DbContextOptionsBuilder builder, string connectionString, Action? configure = default) => + builder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), db => + { + db + .MigrationsAssembly(typeof(DbContextOptionsBuilderExtensions).Assembly.GetName().Name) + .MigrationsHistoryTable(ElsaDbContextBase.MigrationsHistoryTable, ElsaDbContextBase.ElsaSchema) + .SchemaBehavior(MySqlSchemaBehavior.Ignore); + + configure?.Invoke(db); + }); +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/FodyWeavers.xml b/src/modules/Elsa.EntityFrameworkCore.MySql/FodyWeavers.xml new file mode 100644 index 000000000..ac6b5b292 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/20230517105414_Initial.Designer.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/20230517105414_Initial.Designer.cs new file mode 100644 index 000000000..8f8f88ac3 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/20230517105414_Initial.Designer.cs @@ -0,0 +1,128 @@ +// +using Elsa.EntityFrameworkCore.Modules.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Identity +{ + [DbContext(typeof(IdentityElsaDbContext))] + [Migration("20230517105414_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Elsa") + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Elsa.Identity.Entities.Application", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("HashedApiKey") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HashedApiKeySalt") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HashedClientSecret") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HashedClientSecretSalt") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Roles") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("Roles"); + + b.HasKey("Id"); + + b.HasIndex("ClientId") + .IsUnique() + .HasDatabaseName("IX_Application_ClientId"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("IX_Application_Name"); + + b.ToTable("Applications", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Identity.Entities.Role", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Permissions") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("Permissions"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("IX_Role_Name"); + + b.ToTable("Roles", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Identity.Entities.User", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("HashedPassword") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HashedPasswordSalt") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Roles") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("Roles"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("IX_User_Name"); + + b.ToTable("Users", "Elsa"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/20230517105414_Initial.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/20230517105414_Initial.cs new file mode 100644 index 000000000..b60aad112 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/20230517105414_Initial.cs @@ -0,0 +1,132 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Identity +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "Elsa"); + + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Applications", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ClientId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + HashedClientSecret = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + HashedClientSecretSalt = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + HashedApiKey = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + HashedApiKeySalt = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Roles = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Applications", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Roles", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Permissions = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Roles", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Users", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + HashedPassword = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + HashedPasswordSalt = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Roles = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_Application_ClientId", + schema: "Elsa", + table: "Applications", + column: "ClientId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Application_Name", + schema: "Elsa", + table: "Applications", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Role_Name", + schema: "Elsa", + table: "Roles", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_User_Name", + schema: "Elsa", + table: "Users", + column: "Name", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Applications", + schema: "Elsa"); + + migrationBuilder.DropTable( + name: "Roles", + schema: "Elsa"); + + migrationBuilder.DropTable( + name: "Users", + schema: "Elsa"); + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/IdentityElsaDbContextModelSnapshot.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/IdentityElsaDbContextModelSnapshot.cs new file mode 100644 index 000000000..44a2940fa --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/IdentityElsaDbContextModelSnapshot.cs @@ -0,0 +1,125 @@ +// +using Elsa.EntityFrameworkCore.Modules.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Identity +{ + [DbContext(typeof(IdentityElsaDbContext))] + partial class IdentityElsaDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Elsa") + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Elsa.Identity.Entities.Application", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("HashedApiKey") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HashedApiKeySalt") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HashedClientSecret") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HashedClientSecretSalt") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Roles") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("Roles"); + + b.HasKey("Id"); + + b.HasIndex("ClientId") + .IsUnique() + .HasDatabaseName("IX_Application_ClientId"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("IX_Application_Name"); + + b.ToTable("Applications", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Identity.Entities.Role", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Permissions") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("Permissions"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("IX_Role_Name"); + + b.ToTable("Roles", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Identity.Entities.User", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("HashedPassword") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("HashedPasswordSalt") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Roles") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("Roles"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("IX_User_Name"); + + b.ToTable("Users", "Elsa"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/20230517105302_Initial.Designer.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/20230517105302_Initial.Designer.cs new file mode 100644 index 000000000..cad5c0ac3 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/20230517105302_Initial.Designer.cs @@ -0,0 +1,82 @@ +// +using Elsa.EntityFrameworkCore.Modules.Labels; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Labels +{ + [DbContext(typeof(LabelsElsaDbContext))] + [Migration("20230517105302_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Elsa") + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Elsa.Labels.Entities.Label", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Color") + .HasColumnType("longtext"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NormalizedName") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Labels", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Labels.Entities.WorkflowDefinitionLabel", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("LabelId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowDefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowDefinitionVersionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("LabelId") + .HasDatabaseName("WorkflowDefinitionLabel_LabelId"); + + b.HasIndex("WorkflowDefinitionId") + .HasDatabaseName("WorkflowDefinitionLabel_WorkflowDefinitionId"); + + b.HasIndex("WorkflowDefinitionVersionId") + .HasDatabaseName("WorkflowDefinitionLabel_WorkflowDefinitionVersionId"); + + b.ToTable("WorkflowDefinitionLabels", "Elsa"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/20230517105302_Initial.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/20230517105302_Initial.cs new file mode 100644 index 000000000..f67fa7af7 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/20230517105302_Initial.cs @@ -0,0 +1,92 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Labels +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "Elsa"); + + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Labels", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + NormalizedName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Color = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Labels", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "WorkflowDefinitionLabels", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + WorkflowDefinitionId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + WorkflowDefinitionVersionId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + LabelId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_WorkflowDefinitionLabels", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "WorkflowDefinitionLabel_LabelId", + schema: "Elsa", + table: "WorkflowDefinitionLabels", + column: "LabelId"); + + migrationBuilder.CreateIndex( + name: "WorkflowDefinitionLabel_WorkflowDefinitionId", + schema: "Elsa", + table: "WorkflowDefinitionLabels", + column: "WorkflowDefinitionId"); + + migrationBuilder.CreateIndex( + name: "WorkflowDefinitionLabel_WorkflowDefinitionVersionId", + schema: "Elsa", + table: "WorkflowDefinitionLabels", + column: "WorkflowDefinitionVersionId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Labels", + schema: "Elsa"); + + migrationBuilder.DropTable( + name: "WorkflowDefinitionLabels", + schema: "Elsa"); + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/LabelsElsaDbContextModelSnapshot.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/LabelsElsaDbContextModelSnapshot.cs new file mode 100644 index 000000000..e27b03b14 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Labels/LabelsElsaDbContextModelSnapshot.cs @@ -0,0 +1,79 @@ +// +using Elsa.EntityFrameworkCore.Modules.Labels; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Labels +{ + [DbContext(typeof(LabelsElsaDbContext))] + partial class LabelsElsaDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Elsa") + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Elsa.Labels.Entities.Label", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Color") + .HasColumnType("longtext"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NormalizedName") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Labels", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Labels.Entities.WorkflowDefinitionLabel", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("LabelId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowDefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowDefinitionVersionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("LabelId") + .HasDatabaseName("WorkflowDefinitionLabel_LabelId"); + + b.HasIndex("WorkflowDefinitionId") + .HasDatabaseName("WorkflowDefinitionLabel_WorkflowDefinitionId"); + + b.HasIndex("WorkflowDefinitionVersionId") + .HasDatabaseName("WorkflowDefinitionLabel_WorkflowDefinitionVersionId"); + + b.ToTable("WorkflowDefinitionLabels", "Elsa"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/20230517105323_Initial.Designer.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/20230517105323_Initial.Designer.cs new file mode 100644 index 000000000..feb484d41 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/20230517105323_Initial.Designer.cs @@ -0,0 +1,187 @@ +// +using System; +using Elsa.EntityFrameworkCore.Modules.Management; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Management +{ + [DbContext(typeof(ManagementElsaDbContext))] + [Migration("20230517105323_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Elsa") + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Elsa.Workflows.Management.Entities.WorkflowDefinition", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("BinaryData") + .HasColumnType("longblob"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("DefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("IsLatest") + .HasColumnType("tinyint(1)"); + + b.Property("IsPublished") + .HasColumnType("tinyint(1)"); + + b.Property("MaterializerContext") + .HasColumnType("longtext"); + + b.Property("MaterializerName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .HasColumnType("varchar(255)"); + + b.Property("StringData") + .HasColumnType("longtext"); + + b.Property("UsableAsActivity") + .HasColumnType("tinyint(1)"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IsLatest") + .HasDatabaseName("IX_WorkflowDefinition_IsLatest"); + + b.HasIndex("IsPublished") + .HasDatabaseName("IX_WorkflowDefinition_IsPublished"); + + b.HasIndex("Name") + .HasDatabaseName("IX_WorkflowDefinition_Name"); + + b.HasIndex("Version") + .HasDatabaseName("IX_WorkflowDefinition_Version"); + + b.HasIndex("DefinitionId", "Version") + .IsUnique() + .HasDatabaseName("IX_WorkflowDefinition_DefinitionId_Version"); + + b.ToTable("WorkflowDefinitions", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Workflows.Management.Entities.WorkflowInstance", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("CancelledAt") + .HasColumnType("datetime(6)"); + + b.Property("CorrelationId") + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("DefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("DefinitionVersionId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("FaultedAt") + .HasColumnType("datetime(6)"); + + b.Property("FinishedAt") + .HasColumnType("datetime(6)"); + + b.Property("LastExecutedAt") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .HasColumnType("varchar(255)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("SubStatus") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CorrelationId") + .HasDatabaseName("IX_WorkflowInstance_CorrelationId"); + + b.HasIndex("CreatedAt") + .HasDatabaseName("IX_WorkflowInstance_CreatedAt"); + + b.HasIndex("DefinitionId") + .HasDatabaseName("IX_WorkflowInstance_DefinitionId"); + + b.HasIndex("FaultedAt") + .HasDatabaseName("IX_WorkflowInstance_FaultedAt"); + + b.HasIndex("FinishedAt") + .HasDatabaseName("IX_WorkflowInstance_FinishedAt"); + + b.HasIndex("LastExecutedAt") + .HasDatabaseName("IX_WorkflowInstance_LastExecutedAt"); + + b.HasIndex("Name") + .HasDatabaseName("IX_WorkflowInstance_Name"); + + b.HasIndex("Status") + .HasDatabaseName("IX_WorkflowInstance_Status"); + + b.HasIndex("SubStatus") + .HasDatabaseName("IX_WorkflowInstance_SubStatus"); + + b.HasIndex("Status", "DefinitionId") + .HasDatabaseName("IX_WorkflowInstance_Status_DefinitionId"); + + b.HasIndex("Status", "SubStatus") + .HasDatabaseName("IX_WorkflowInstance_Status_SubStatus"); + + b.HasIndex("SubStatus", "DefinitionId") + .HasDatabaseName("IX_WorkflowInstance_SubStatus_DefinitionId"); + + b.HasIndex("Status", "SubStatus", "DefinitionId", "Version") + .HasDatabaseName("IX_WorkflowInstance_Status_SubStatus_DefinitionId_Version"); + + b.ToTable("WorkflowInstances", "Elsa"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/20230517105323_Initial.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/20230517105323_Initial.cs new file mode 100644 index 000000000..26876d61d --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/20230517105323_Initial.cs @@ -0,0 +1,210 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Management +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "Elsa"); + + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "WorkflowDefinitions", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DefinitionId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + MaterializerName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + MaterializerContext = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + StringData = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + BinaryData = table.Column(type: "longblob", nullable: true), + UsableAsActivity = table.Column(type: "tinyint(1)", nullable: true), + Data = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + Version = table.Column(type: "int", nullable: false), + IsLatest = table.Column(type: "tinyint(1)", nullable: false), + IsPublished = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WorkflowDefinitions", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "WorkflowInstances", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DefinitionId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DefinitionVersionId = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Version = table.Column(type: "int", nullable: false), + Status = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + SubStatus = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CorrelationId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + LastExecutedAt = table.Column(type: "datetime(6)", nullable: true), + FinishedAt = table.Column(type: "datetime(6)", nullable: true), + CancelledAt = table.Column(type: "datetime(6)", nullable: true), + FaultedAt = table.Column(type: "datetime(6)", nullable: true), + Data = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_WorkflowInstances", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowDefinition_DefinitionId_Version", + schema: "Elsa", + table: "WorkflowDefinitions", + columns: new[] { "DefinitionId", "Version" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowDefinition_IsLatest", + schema: "Elsa", + table: "WorkflowDefinitions", + column: "IsLatest"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowDefinition_IsPublished", + schema: "Elsa", + table: "WorkflowDefinitions", + column: "IsPublished"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowDefinition_Name", + schema: "Elsa", + table: "WorkflowDefinitions", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowDefinition_Version", + schema: "Elsa", + table: "WorkflowDefinitions", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_CorrelationId", + schema: "Elsa", + table: "WorkflowInstances", + column: "CorrelationId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_CreatedAt", + schema: "Elsa", + table: "WorkflowInstances", + column: "CreatedAt"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_DefinitionId", + schema: "Elsa", + table: "WorkflowInstances", + column: "DefinitionId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_FaultedAt", + schema: "Elsa", + table: "WorkflowInstances", + column: "FaultedAt"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_FinishedAt", + schema: "Elsa", + table: "WorkflowInstances", + column: "FinishedAt"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_LastExecutedAt", + schema: "Elsa", + table: "WorkflowInstances", + column: "LastExecutedAt"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_Name", + schema: "Elsa", + table: "WorkflowInstances", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_Status", + schema: "Elsa", + table: "WorkflowInstances", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_Status_DefinitionId", + schema: "Elsa", + table: "WorkflowInstances", + columns: new[] { "Status", "DefinitionId" }); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_Status_SubStatus", + schema: "Elsa", + table: "WorkflowInstances", + columns: new[] { "Status", "SubStatus" }); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_Status_SubStatus_DefinitionId_Version", + schema: "Elsa", + table: "WorkflowInstances", + columns: new[] { "Status", "SubStatus", "DefinitionId", "Version" }); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_SubStatus", + schema: "Elsa", + table: "WorkflowInstances", + column: "SubStatus"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowInstance_SubStatus_DefinitionId", + schema: "Elsa", + table: "WorkflowInstances", + columns: new[] { "SubStatus", "DefinitionId" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "WorkflowDefinitions", + schema: "Elsa"); + + migrationBuilder.DropTable( + name: "WorkflowInstances", + schema: "Elsa"); + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/ManagementElsaDbContextModelSnapshot.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/ManagementElsaDbContextModelSnapshot.cs new file mode 100644 index 000000000..8dded3906 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/ManagementElsaDbContextModelSnapshot.cs @@ -0,0 +1,184 @@ +// +using System; +using Elsa.EntityFrameworkCore.Modules.Management; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Management +{ + [DbContext(typeof(ManagementElsaDbContext))] + partial class ManagementElsaDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Elsa") + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Elsa.Workflows.Management.Entities.WorkflowDefinition", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("BinaryData") + .HasColumnType("longblob"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("DefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("IsLatest") + .HasColumnType("tinyint(1)"); + + b.Property("IsPublished") + .HasColumnType("tinyint(1)"); + + b.Property("MaterializerContext") + .HasColumnType("longtext"); + + b.Property("MaterializerName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .HasColumnType("varchar(255)"); + + b.Property("StringData") + .HasColumnType("longtext"); + + b.Property("UsableAsActivity") + .HasColumnType("tinyint(1)"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IsLatest") + .HasDatabaseName("IX_WorkflowDefinition_IsLatest"); + + b.HasIndex("IsPublished") + .HasDatabaseName("IX_WorkflowDefinition_IsPublished"); + + b.HasIndex("Name") + .HasDatabaseName("IX_WorkflowDefinition_Name"); + + b.HasIndex("Version") + .HasDatabaseName("IX_WorkflowDefinition_Version"); + + b.HasIndex("DefinitionId", "Version") + .IsUnique() + .HasDatabaseName("IX_WorkflowDefinition_DefinitionId_Version"); + + b.ToTable("WorkflowDefinitions", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Workflows.Management.Entities.WorkflowInstance", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("CancelledAt") + .HasColumnType("datetime(6)"); + + b.Property("CorrelationId") + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("DefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("DefinitionVersionId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("FaultedAt") + .HasColumnType("datetime(6)"); + + b.Property("FinishedAt") + .HasColumnType("datetime(6)"); + + b.Property("LastExecutedAt") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .HasColumnType("varchar(255)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("SubStatus") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CorrelationId") + .HasDatabaseName("IX_WorkflowInstance_CorrelationId"); + + b.HasIndex("CreatedAt") + .HasDatabaseName("IX_WorkflowInstance_CreatedAt"); + + b.HasIndex("DefinitionId") + .HasDatabaseName("IX_WorkflowInstance_DefinitionId"); + + b.HasIndex("FaultedAt") + .HasDatabaseName("IX_WorkflowInstance_FaultedAt"); + + b.HasIndex("FinishedAt") + .HasDatabaseName("IX_WorkflowInstance_FinishedAt"); + + b.HasIndex("LastExecutedAt") + .HasDatabaseName("IX_WorkflowInstance_LastExecutedAt"); + + b.HasIndex("Name") + .HasDatabaseName("IX_WorkflowInstance_Name"); + + b.HasIndex("Status") + .HasDatabaseName("IX_WorkflowInstance_Status"); + + b.HasIndex("SubStatus") + .HasDatabaseName("IX_WorkflowInstance_SubStatus"); + + b.HasIndex("Status", "DefinitionId") + .HasDatabaseName("IX_WorkflowInstance_Status_DefinitionId"); + + b.HasIndex("Status", "SubStatus") + .HasDatabaseName("IX_WorkflowInstance_Status_SubStatus"); + + b.HasIndex("SubStatus", "DefinitionId") + .HasDatabaseName("IX_WorkflowInstance_SubStatus_DefinitionId"); + + b.HasIndex("Status", "SubStatus", "DefinitionId", "Version") + .HasDatabaseName("IX_WorkflowInstance_Status_SubStatus_DefinitionId_Version"); + + b.ToTable("WorkflowInstances", "Elsa"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/20230517105351_Initial.Designer.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/20230517105351_Initial.Designer.cs new file mode 100644 index 000000000..369636d37 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/20230517105351_Initial.Designer.cs @@ -0,0 +1,246 @@ +// +using System; +using Elsa.EntityFrameworkCore.Modules.Runtime; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Runtime +{ + [DbContext(typeof(RuntimeElsaDbContext))] + [Migration("20230517105351_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Elsa") + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Elsa.Workflows.Core.State.WorkflowState", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("CorrelationId") + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("DefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("DefinitionVersion") + .HasColumnType("int"); + + b.Property("Status") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("SubStatus") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("CorrelationId") + .HasDatabaseName("IX_WorkflowState_CorrelationId"); + + b.HasIndex("CreatedAt") + .HasDatabaseName("IX_WorkflowState_CreatedAt"); + + b.HasIndex("DefinitionId") + .HasDatabaseName("IX_WorkflowState_DefinitionId"); + + b.HasIndex("UpdatedAt") + .HasDatabaseName("IX_WorkflowState_UpdatedAt"); + + b.HasIndex("Status", "DefinitionId") + .HasDatabaseName("IX_WorkflowState_Status_DefinitionId"); + + b.HasIndex("Status", "SubStatus") + .HasDatabaseName("IX_WorkflowState_Status_SubStatus"); + + b.HasIndex("Status", "SubStatus", "DefinitionId", "DefinitionVersion") + .HasDatabaseName("IX_WorkflowState_Status_SubStatus_DefinitionId_DefinitionVersion"); + + b.ToTable("WorkflowStates", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Workflows.Runtime.Entities.StoredBookmark", b => + { + b.Property("BookmarkId") + .HasColumnType("varchar(255)"); + + b.Property("ActivityTypeName") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("CorrelationId") + .HasColumnType("longtext"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("Hash") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowInstanceId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("BookmarkId"); + + b.HasIndex(new[] { "ActivityTypeName" }, "IX_StoredBookmark_ActivityTypeName"); + + b.HasIndex(new[] { "ActivityTypeName", "Hash" }, "IX_StoredBookmark_ActivityTypeName_Hash"); + + b.HasIndex(new[] { "ActivityTypeName", "Hash", "WorkflowInstanceId" }, "IX_StoredBookmark_ActivityTypeName_Hash_WorkflowInstanceId"); + + b.HasIndex(new[] { "Hash" }, "IX_StoredBookmark_Hash"); + + b.HasIndex(new[] { "WorkflowInstanceId" }, "IX_StoredBookmark_WorkflowInstanceId"); + + b.ToTable("Bookmarks", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Workflows.Runtime.Entities.StoredTrigger", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ActivityId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("Hash") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowDefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("Hash") + .HasDatabaseName("IX_StoredTrigger_Hash"); + + b.HasIndex("Name") + .HasDatabaseName("IX_StoredTrigger_Name"); + + b.HasIndex("WorkflowDefinitionId") + .HasDatabaseName("IX_StoredTrigger_WorkflowDefinitionId"); + + b.ToTable("WorkflowTriggers", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Workflows.Runtime.Entities.WorkflowExecutionLogRecord", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ActivityData") + .HasColumnType("longtext"); + + b.Property("ActivityId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("ActivityInstanceId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("ActivityType") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("EventName") + .HasColumnType("varchar(255)"); + + b.Property("Message") + .HasColumnType("longtext"); + + b.Property("NodeId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ParentActivityInstanceId") + .HasColumnType("varchar(255)"); + + b.Property("PayloadData") + .HasColumnType("longtext"); + + b.Property("Source") + .HasColumnType("longtext"); + + b.Property("Timestamp") + .HasColumnType("datetime(6)"); + + b.Property("WorkflowDefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowInstanceId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowVersion") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ActivityId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_ActivityId"); + + b.HasIndex("ActivityInstanceId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_ActivityInstanceId"); + + b.HasIndex("ActivityType") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_ActivityType"); + + b.HasIndex("EventName") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_EventName"); + + b.HasIndex("ParentActivityInstanceId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_ParentActivityInstanceId"); + + b.HasIndex("Timestamp") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_Timestamp"); + + b.HasIndex("WorkflowDefinitionId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_WorkflowDefinitionId"); + + b.HasIndex("WorkflowInstanceId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_WorkflowInstanceId"); + + b.HasIndex("WorkflowVersion") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_WorkflowVersion"); + + b.ToTable("WorkflowExecutionLogRecords", "Elsa"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/20230517105351_Initial.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/20230517105351_Initial.cs new file mode 100644 index 000000000..0c4d21dec --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/20230517105351_Initial.cs @@ -0,0 +1,300 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Runtime +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "Elsa"); + + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Bookmarks", + schema: "Elsa", + columns: table => new + { + BookmarkId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ActivityTypeName = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Hash = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + WorkflowInstanceId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CorrelationId = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Data = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Bookmarks", x => x.BookmarkId); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "WorkflowExecutionLogRecords", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + WorkflowDefinitionId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + WorkflowInstanceId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + WorkflowVersion = table.Column(type: "int", nullable: false), + ActivityInstanceId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ParentActivityInstanceId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ActivityId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ActivityType = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + NodeId = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Timestamp = table.Column(type: "datetime(6)", nullable: false), + EventName = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Message = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Source = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ActivityData = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + PayloadData = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_WorkflowExecutionLogRecords", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "WorkflowStates", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DefinitionId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DefinitionVersion = table.Column(type: "int", nullable: false), + CorrelationId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Status = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + SubStatus = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + Data = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + UpdatedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WorkflowStates", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "WorkflowTriggers", + schema: "Elsa", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + WorkflowDefinitionId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ActivityId = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Hash = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Data = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_WorkflowTriggers", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_StoredBookmark_ActivityTypeName", + schema: "Elsa", + table: "Bookmarks", + column: "ActivityTypeName"); + + migrationBuilder.CreateIndex( + name: "IX_StoredBookmark_ActivityTypeName_Hash", + schema: "Elsa", + table: "Bookmarks", + columns: new[] { "ActivityTypeName", "Hash" }); + + migrationBuilder.CreateIndex( + name: "IX_StoredBookmark_ActivityTypeName_Hash_WorkflowInstanceId", + schema: "Elsa", + table: "Bookmarks", + columns: new[] { "ActivityTypeName", "Hash", "WorkflowInstanceId" }); + + migrationBuilder.CreateIndex( + name: "IX_StoredBookmark_Hash", + schema: "Elsa", + table: "Bookmarks", + column: "Hash"); + + migrationBuilder.CreateIndex( + name: "IX_StoredBookmark_WorkflowInstanceId", + schema: "Elsa", + table: "Bookmarks", + column: "WorkflowInstanceId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_ActivityId", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "ActivityId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_ActivityInstanceId", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "ActivityInstanceId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_ActivityType", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "ActivityType"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_EventName", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "EventName"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_ParentActivityInstanceId", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "ParentActivityInstanceId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_Timestamp", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "Timestamp"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_WorkflowDefinitionId", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "WorkflowDefinitionId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_WorkflowInstanceId", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "WorkflowInstanceId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowExecutionLogRecord_WorkflowVersion", + schema: "Elsa", + table: "WorkflowExecutionLogRecords", + column: "WorkflowVersion"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowState_CorrelationId", + schema: "Elsa", + table: "WorkflowStates", + column: "CorrelationId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowState_CreatedAt", + schema: "Elsa", + table: "WorkflowStates", + column: "CreatedAt"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowState_DefinitionId", + schema: "Elsa", + table: "WorkflowStates", + column: "DefinitionId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowState_Status_DefinitionId", + schema: "Elsa", + table: "WorkflowStates", + columns: new[] { "Status", "DefinitionId" }); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowState_Status_SubStatus", + schema: "Elsa", + table: "WorkflowStates", + columns: new[] { "Status", "SubStatus" }); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowState_Status_SubStatus_DefinitionId_DefinitionVersion", + schema: "Elsa", + table: "WorkflowStates", + columns: new[] { "Status", "SubStatus", "DefinitionId", "DefinitionVersion" }); + + migrationBuilder.CreateIndex( + name: "IX_WorkflowState_UpdatedAt", + schema: "Elsa", + table: "WorkflowStates", + column: "UpdatedAt"); + + migrationBuilder.CreateIndex( + name: "IX_StoredTrigger_Hash", + schema: "Elsa", + table: "WorkflowTriggers", + column: "Hash"); + + migrationBuilder.CreateIndex( + name: "IX_StoredTrigger_Name", + schema: "Elsa", + table: "WorkflowTriggers", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_StoredTrigger_WorkflowDefinitionId", + schema: "Elsa", + table: "WorkflowTriggers", + column: "WorkflowDefinitionId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Bookmarks", + schema: "Elsa"); + + migrationBuilder.DropTable( + name: "WorkflowExecutionLogRecords", + schema: "Elsa"); + + migrationBuilder.DropTable( + name: "WorkflowStates", + schema: "Elsa"); + + migrationBuilder.DropTable( + name: "WorkflowTriggers", + schema: "Elsa"); + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/RuntimeElsaDbContextModelSnapshot.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/RuntimeElsaDbContextModelSnapshot.cs new file mode 100644 index 000000000..b240b98bd --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/RuntimeElsaDbContextModelSnapshot.cs @@ -0,0 +1,243 @@ +// +using System; +using Elsa.EntityFrameworkCore.Modules.Runtime; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Elsa.EntityFrameworkCore.MySql.Migrations.Runtime +{ + [DbContext(typeof(RuntimeElsaDbContext))] + partial class RuntimeElsaDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Elsa") + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Elsa.Workflows.Core.State.WorkflowState", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("CorrelationId") + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("DefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("DefinitionVersion") + .HasColumnType("int"); + + b.Property("Status") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("SubStatus") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("CorrelationId") + .HasDatabaseName("IX_WorkflowState_CorrelationId"); + + b.HasIndex("CreatedAt") + .HasDatabaseName("IX_WorkflowState_CreatedAt"); + + b.HasIndex("DefinitionId") + .HasDatabaseName("IX_WorkflowState_DefinitionId"); + + b.HasIndex("UpdatedAt") + .HasDatabaseName("IX_WorkflowState_UpdatedAt"); + + b.HasIndex("Status", "DefinitionId") + .HasDatabaseName("IX_WorkflowState_Status_DefinitionId"); + + b.HasIndex("Status", "SubStatus") + .HasDatabaseName("IX_WorkflowState_Status_SubStatus"); + + b.HasIndex("Status", "SubStatus", "DefinitionId", "DefinitionVersion") + .HasDatabaseName("IX_WorkflowState_Status_SubStatus_DefinitionId_DefinitionVersion"); + + b.ToTable("WorkflowStates", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Workflows.Runtime.Entities.StoredBookmark", b => + { + b.Property("BookmarkId") + .HasColumnType("varchar(255)"); + + b.Property("ActivityTypeName") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("CorrelationId") + .HasColumnType("longtext"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("Hash") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowInstanceId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("BookmarkId"); + + b.HasIndex(new[] { "ActivityTypeName" }, "IX_StoredBookmark_ActivityTypeName"); + + b.HasIndex(new[] { "ActivityTypeName", "Hash" }, "IX_StoredBookmark_ActivityTypeName_Hash"); + + b.HasIndex(new[] { "ActivityTypeName", "Hash", "WorkflowInstanceId" }, "IX_StoredBookmark_ActivityTypeName_Hash_WorkflowInstanceId"); + + b.HasIndex(new[] { "Hash" }, "IX_StoredBookmark_Hash"); + + b.HasIndex(new[] { "WorkflowInstanceId" }, "IX_StoredBookmark_WorkflowInstanceId"); + + b.ToTable("Bookmarks", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Workflows.Runtime.Entities.StoredTrigger", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ActivityId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("Hash") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowDefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("Hash") + .HasDatabaseName("IX_StoredTrigger_Hash"); + + b.HasIndex("Name") + .HasDatabaseName("IX_StoredTrigger_Name"); + + b.HasIndex("WorkflowDefinitionId") + .HasDatabaseName("IX_StoredTrigger_WorkflowDefinitionId"); + + b.ToTable("WorkflowTriggers", "Elsa"); + }); + + modelBuilder.Entity("Elsa.Workflows.Runtime.Entities.WorkflowExecutionLogRecord", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ActivityData") + .HasColumnType("longtext"); + + b.Property("ActivityId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("ActivityInstanceId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("ActivityType") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("EventName") + .HasColumnType("varchar(255)"); + + b.Property("Message") + .HasColumnType("longtext"); + + b.Property("NodeId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ParentActivityInstanceId") + .HasColumnType("varchar(255)"); + + b.Property("PayloadData") + .HasColumnType("longtext"); + + b.Property("Source") + .HasColumnType("longtext"); + + b.Property("Timestamp") + .HasColumnType("datetime(6)"); + + b.Property("WorkflowDefinitionId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowInstanceId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkflowVersion") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ActivityId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_ActivityId"); + + b.HasIndex("ActivityInstanceId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_ActivityInstanceId"); + + b.HasIndex("ActivityType") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_ActivityType"); + + b.HasIndex("EventName") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_EventName"); + + b.HasIndex("ParentActivityInstanceId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_ParentActivityInstanceId"); + + b.HasIndex("Timestamp") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_Timestamp"); + + b.HasIndex("WorkflowDefinitionId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_WorkflowDefinitionId"); + + b.HasIndex("WorkflowInstanceId") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_WorkflowInstanceId"); + + b.HasIndex("WorkflowVersion") + .HasDatabaseName("IX_WorkflowExecutionLogRecord_WorkflowVersion"); + + b.ToTable("WorkflowExecutionLogRecords", "Elsa"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Identity/DesignTimeDbContextFactory.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Identity/DesignTimeDbContextFactory.cs new file mode 100644 index 000000000..9fdfbde8a --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Identity/DesignTimeDbContextFactory.cs @@ -0,0 +1,13 @@ +using Elsa.EntityFrameworkCore.Modules.Identity; +using Elsa.EntityFrameworkCore.MySql.Abstractions; +using JetBrains.Annotations; + +namespace Elsa.EntityFrameworkCore.MySql.Modules.Identity; + +/// +/// The design-time factory for the . +/// +[PublicAPI] +public class DesignTimeIdentityDbContextFactory : MySqlDesignTimeDbContextFactoryBase +{ +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Identity/Extensions.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Identity/Extensions.cs new file mode 100644 index 000000000..37eb99c4a --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Identity/Extensions.cs @@ -0,0 +1,19 @@ +using Elsa.EntityFrameworkCore.Modules.Identity; + +// ReSharper disable once CheckNamespace +namespace Elsa.EntityFrameworkCore.Extensions; + +public static partial class Extensions +{ + /// + /// Configures the feature with MySql persistence providers. + /// + /// The feature to configure. + /// The connection string to use. + /// The configured feature. + public static EFCoreIdentityPersistenceFeature UseMySql(this EFCoreIdentityPersistenceFeature feature, string connectionString) + { + feature.DbContextOptionsBuilder = (_, db) => db.UseElsaMySql(connectionString); + return feature; + } +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Labels/DesignTimeDbContextFactory.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Labels/DesignTimeDbContextFactory.cs new file mode 100644 index 000000000..9bf00713f --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Labels/DesignTimeDbContextFactory.cs @@ -0,0 +1,9 @@ +using Elsa.EntityFrameworkCore.Modules.Labels; +using Elsa.EntityFrameworkCore.MySql.Abstractions; + +namespace Elsa.EntityFrameworkCore.MySql.Modules.Labels; + +// ReSharper disable once UnusedType.Global +public class DesignTimeDbContextFactory : MySqlDesignTimeDbContextFactoryBase +{ +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Labels/Extensions.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Labels/Extensions.cs new file mode 100644 index 000000000..49f8bb17c --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Labels/Extensions.cs @@ -0,0 +1,13 @@ +using Elsa.EntityFrameworkCore.Modules.Labels; + +// ReSharper disable once CheckNamespace +namespace Elsa.EntityFrameworkCore.Extensions; + +public static partial class Extensions +{ + public static EFCoreLabelPersistenceFeature UseMySql(this EFCoreLabelPersistenceFeature feature, string connectionString) + { + feature.DbContextOptionsBuilder = (_, db) => db.UseElsaMySql(connectionString); + return feature; + } +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Management/DesignTimeDbContextFactory.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Management/DesignTimeDbContextFactory.cs new file mode 100644 index 000000000..c70ebf0a7 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Management/DesignTimeDbContextFactory.cs @@ -0,0 +1,9 @@ +using Elsa.EntityFrameworkCore.Modules.Management; +using Elsa.EntityFrameworkCore.MySql.Abstractions; + +namespace Elsa.EntityFrameworkCore.MySql.Modules.Management; + +// ReSharper disable once UnusedType.Global +public class DesignTimeDbContextFactory : MySqlDesignTimeDbContextFactoryBase +{ +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Management/Extensions.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Management/Extensions.cs new file mode 100644 index 000000000..6af28a920 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Management/Extensions.cs @@ -0,0 +1,30 @@ +using Elsa.EntityFrameworkCore.Modules.Management; +using JetBrains.Annotations; + +// ReSharper disable once CheckNamespace +namespace Elsa.EntityFrameworkCore.Extensions; + +/// +/// Extends EF Core features. +/// +[PublicAPI] +public static partial class Extensions +{ + public static EFCoreWorkflowDefinitionPersistenceFeature UseMySql(this EFCoreWorkflowDefinitionPersistenceFeature feature, string connectionString) + { + feature.DbContextOptionsBuilder = (_, db) => db.UseElsaMySql(connectionString); + return feature; + } + + public static EFCoreWorkflowInstancePersistenceFeature UseMySql(this EFCoreWorkflowInstancePersistenceFeature feature, string connectionString) + { + feature.DbContextOptionsBuilder = (_, db) => db.UseElsaMySql(connectionString); + return feature; + } + + public static EFCoreWorkflowManagementPersistenceFeature UseMySql(this EFCoreWorkflowManagementPersistenceFeature feature, string connectionString) + { + feature.DbContextOptionsBuilder = (_, db) => db.UseElsaMySql(connectionString); + return feature; + } +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Runtime/DesignTimeDbContextFactory.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Runtime/DesignTimeDbContextFactory.cs new file mode 100644 index 000000000..4eac3d09a --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Runtime/DesignTimeDbContextFactory.cs @@ -0,0 +1,9 @@ +using Elsa.EntityFrameworkCore.Modules.Runtime; +using Elsa.EntityFrameworkCore.MySql.Abstractions; + +namespace Elsa.EntityFrameworkCore.MySql.Modules.Runtime; + +// ReSharper disable once UnusedType.Global +public class DesignTimeRuntimeDbContextFactory : MySqlDesignTimeDbContextFactoryBase +{ +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Runtime/Extensions.cs b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Runtime/Extensions.cs new file mode 100644 index 000000000..c73fca49c --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Modules/Runtime/Extensions.cs @@ -0,0 +1,19 @@ +using Elsa.EntityFrameworkCore.Modules.Runtime; + +// ReSharper disable once CheckNamespace +namespace Elsa.EntityFrameworkCore.Extensions; + +public static partial class Extensions +{ + public static EFCoreDefaultWorkflowRuntimePersistenceFeature UseMySql(this EFCoreDefaultWorkflowRuntimePersistenceFeature feature, string connectionString) + { + feature.DbContextOptionsBuilder = (_, db) => db.UseElsaMySql(connectionString); + return feature; + } + + public static EFCoreExecutionLogRecordPersistenceFeature UseMySql(this EFCoreExecutionLogRecordPersistenceFeature feature, string connectionString) + { + feature.DbContextOptionsBuilder = (_, db) => db.UseElsaMySql(connectionString); + return feature; + } +} \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/generate-migrations.cmd b/src/modules/Elsa.EntityFrameworkCore.MySql/generate-migrations.cmd new file mode 100644 index 000000000..bfef70185 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/generate-migrations.cmd @@ -0,0 +1,5 @@ +dotnet ef migrations add Initial -c ActivityDefinitionsElsaDbContext -o Migrations/ActivityDefinitions +dotnet ef migrations add Initial -c LabelsElsaDbContext -o Migrations/Labels +dotnet ef migrations add Initial -c ManagementElsaDbContext -o Migrations/Management +dotnet ef migrations add Initial -c RuntimeElsaDbContext -o Migrations/Runtime +dotnet ef migrations add Initial -c IdentityElsaDbContext -o Migrations/Identity \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/generate-migrations.sh b/src/modules/Elsa.EntityFrameworkCore.MySql/generate-migrations.sh new file mode 100644 index 000000000..bfef70185 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/generate-migrations.sh @@ -0,0 +1,5 @@ +dotnet ef migrations add Initial -c ActivityDefinitionsElsaDbContext -o Migrations/ActivityDefinitions +dotnet ef migrations add Initial -c LabelsElsaDbContext -o Migrations/Labels +dotnet ef migrations add Initial -c ManagementElsaDbContext -o Migrations/Management +dotnet ef migrations add Initial -c RuntimeElsaDbContext -o Migrations/Runtime +dotnet ef migrations add Initial -c IdentityElsaDbContext -o Migrations/Identity \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/FlowSwitch.cs b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/FlowSwitch.cs index 2c7cc628e..85b16d486 100644 --- a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/FlowSwitch.cs +++ b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/FlowSwitch.cs @@ -1,5 +1,3 @@ -using System.Runtime.CompilerServices; -using System.Text.Json.Serialization; using Elsa.Expressions; using Elsa.Expressions.Contracts; using Elsa.Expressions.Models; @@ -9,6 +7,8 @@ using Elsa.Workflows.Core.Activities.Flowchart.Models; using Elsa.Workflows.Core.Attributes; using Elsa.Workflows.Core.Models; using JetBrains.Annotations; +using System.Runtime.CompilerServices; +using System.Text.Json.Serialization; namespace Elsa.Workflows.Core.Activities.Flowchart.Activities; @@ -33,17 +33,29 @@ public class FlowSwitch : Activity [Input(UIHint = "flow-switch-editor")] public ICollection Cases { get; set; } = new List(); + /// + /// The switch mode determines whether the first match should be scheduled, or all matches. + /// + [Input(Description = "The switch mode determines whether the first match should be scheduled, or all matches.")] + public Input Mode { get; set; } = new(SwitchMode.MatchFirst); + /// protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) { - var matchingCase = await FindMatchingCaseAsync(context.ExpressionExecutionContext); - var outcome = matchingCase?.Label ?? "Default"; + var matchingCases = await FindMatchingCasesAsync(context.ExpressionExecutionContext); + var hasAnyMatches = matchingCases.Any(); - await context.CompleteActivityAsync(new Outcomes(outcome)); + var mode = context.Get(Mode); + var results = mode == SwitchMode.MatchFirst ? hasAnyMatches ? new[] { matchingCases.First() } : Array.Empty() : matchingCases.ToArray(); + + var outcomes = hasAnyMatches ? results.Select(r => r.Label).ToArray() : new[] { "Default" }; + + await context.CompleteActivityAsync(new Outcomes(outcomes)); } - private async Task FindMatchingCaseAsync(ExpressionExecutionContext context) + private async Task> FindMatchingCasesAsync(ExpressionExecutionContext context) { + var matchingCases = new List(); var expressionEvaluator = context.GetRequiredService(); foreach (var switchCase in Cases) @@ -51,10 +63,12 @@ public class FlowSwitch : Activity var result = await expressionEvaluator.EvaluateAsync(switchCase.Condition, context); if (result == true) - return switchCase; + { + matchingCases.Add(switchCase); + } } - return null; + return matchingCases; } } diff --git a/src/modules/Elsa.Workflows.Core/Activities/Switch.cs b/src/modules/Elsa.Workflows.Core/Activities/Switch.cs index 0fde014f2..f776f814f 100644 --- a/src/modules/Elsa.Workflows.Core/Activities/Switch.cs +++ b/src/modules/Elsa.Workflows.Core/Activities/Switch.cs @@ -50,6 +50,12 @@ public class Switch : Activity )] public ICollection Cases { get; set; } = new List(); + /// + /// The switch mode determines whether the first match should be scheduled, or all matches. + /// + [Input(Description = "The switch mode determines whether the first match should be scheduled, or all matches.")] + public Input Mode { get; set; } = new(SwitchMode.MatchFirst); + /// /// The default activity to schedule when no case matches. /// @@ -59,19 +65,28 @@ public class Switch : Activity protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) { context.Set(Output, Expression); - var matchingCase = await FindMatchingCaseAsync(context.ExpressionExecutionContext); + var matchingCases = await FindMatchingCasesAsync(context.ExpressionExecutionContext); + var hasAnyMatches = matchingCases.Any(); - if (matchingCase != null) + var mode = context.Get(Mode); + var results = mode == SwitchMode.MatchFirst ? hasAnyMatches ? new[] { matchingCases.First() } : Array.Empty() : matchingCases.ToArray(); + + if (hasAnyMatches) { - await context.ScheduleActivityAsync(matchingCase.Activity, OnChildActivityCompletedAsync); + foreach (var result in results) + { + await context.ScheduleActivityAsync(result.Activity, OnChildActivityCompletedAsync); + } + return; } await context.ScheduleActivityAsync(Default, OnChildActivityCompletedAsync); } - private async Task FindMatchingCaseAsync(ExpressionExecutionContext context) + private async Task> FindMatchingCasesAsync(ExpressionExecutionContext context) { + var matchingCases = new List(); var expressionEvaluator = context.GetRequiredService(); foreach (var switchCase in Cases) @@ -79,10 +94,12 @@ public class Switch : Activity var result = await expressionEvaluator.EvaluateAsync(switchCase.Condition, context); if (result == true) - return switchCase; + { + matchingCases.Add(switchCase); + } } - return null; + return matchingCases; } private async ValueTask OnChildActivityCompletedAsync(ActivityExecutionContext context, ActivityExecutionContext childContext) diff --git a/src/modules/Elsa.Workflows.Core/Models/SwitchMode.cs b/src/modules/Elsa.Workflows.Core/Models/SwitchMode.cs new file mode 100644 index 000000000..f25aa3cf9 --- /dev/null +++ b/src/modules/Elsa.Workflows.Core/Models/SwitchMode.cs @@ -0,0 +1,15 @@ +namespace Elsa.Workflows.Core.Models +{ + public enum SwitchMode + { + /// + /// Yields the outcome of the first condition evaluating to true. + /// + MatchFirst, + + /// + /// Yields the outcome of all conditions evaluating to true. + /// + MatchAny + } +} diff --git a/src/modules/Elsa.Workflows.Core/Notifications/WorkflowExecuted.cs b/src/modules/Elsa.Workflows.Core/Notifications/WorkflowExecuted.cs index 8f7e9b39a..016a6784a 100644 --- a/src/modules/Elsa.Workflows.Core/Notifications/WorkflowExecuted.cs +++ b/src/modules/Elsa.Workflows.Core/Notifications/WorkflowExecuted.cs @@ -7,4 +7,4 @@ namespace Elsa.Workflows.Core.Notifications; /// /// A domain event that is published everytime a burst of execution completes. /// -public record WorkflowExecuted(Workflow Workflow, WorkflowState WorkflowState) : INotification; \ No newline at end of file +public record WorkflowExecuted(Workflow Workflow, WorkflowState WorkflowState, WorkflowExecutionContext WorkflowExecutionContext) : INotification; \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/Notifications/WorkflowExecuting.cs b/src/modules/Elsa.Workflows.Core/Notifications/WorkflowExecuting.cs index 645b8c17e..ae3168508 100644 --- a/src/modules/Elsa.Workflows.Core/Notifications/WorkflowExecuting.cs +++ b/src/modules/Elsa.Workflows.Core/Notifications/WorkflowExecuting.cs @@ -6,4 +6,4 @@ namespace Elsa.Workflows.Core.Notifications; /// /// A domain event that is published before a burst of execution begins. /// -public record WorkflowExecuting(Workflow Workflow) : INotification; \ No newline at end of file +public record WorkflowExecuting(Workflow Workflow, WorkflowExecutionContext WorkflowExecutionContext) : INotification; \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/Services/WorkflowRunner.cs b/src/modules/Elsa.Workflows.Core/Services/WorkflowRunner.cs index a8e4b1966..deaf4cb97 100644 --- a/src/modules/Elsa.Workflows.Core/Services/WorkflowRunner.cs +++ b/src/modules/Elsa.Workflows.Core/Services/WorkflowRunner.cs @@ -165,7 +165,7 @@ public class WorkflowRunner : IWorkflowRunner var cancellationToken = workflowExecutionContext.CancellationToken; // Publish domain event. - await _eventPublisher.PublishAsync(new WorkflowExecuting(workflow), cancellationToken); + await _eventPublisher.PublishAsync(new WorkflowExecuting(workflow, workflowExecutionContext), cancellationToken); // Transition into the Running state. workflowExecutionContext.TransitionTo(WorkflowSubStatus.Executing); @@ -182,7 +182,7 @@ public class WorkflowRunner : IWorkflowRunner var result = workflow.ResultVariable?.Get(workflowExecutionContext.MemoryRegister); // Publish domain event. - await _eventPublisher.PublishAsync(new WorkflowExecuted(workflow, workflowState), cancellationToken); + await _eventPublisher.PublishAsync(new WorkflowExecuted(workflow, workflowState, workflowExecutionContext), cancellationToken); // Return workflow execution result containing state + bookmarks. return new RunWorkflowResult(workflowState, workflowExecutionContext.Workflow, result);