diff --git a/Directory.Packages.props b/Directory.Packages.props index 29df7d6dd..9a867d348 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,168 +1,173 @@ - - true - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Elsa.sln b/Elsa.sln index 35db33303..d6247d663 100644 --- a/Elsa.sln +++ b/Elsa.sln @@ -126,6 +126,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docker", "docker", "{986E54 docker\ElsaServer.Dockerfile = docker\ElsaServer.Dockerfile docker\ElsaServerAndStudio.Dockerfile = docker\ElsaServerAndStudio.Dockerfile docker\ElsaStudio.Dockerfile = docker\ElsaStudio.Dockerfile + docker\docker-compose.yml = docker\docker-compose.yml + docker\docker-compose-datadog.yml = docker\docker-compose-datadog.yml + docker\ElsaServer-Datadog.Dockerfile = docker\ElsaServer-Datadog.Dockerfile EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elsa.Samples.AspNet.RunTaskIntegration", "samples\aspnet\Elsa.Samples.AspNet.RunTaskIntegration\Elsa.Samples.AspNet.RunTaskIntegration.csproj", "{51050209-EC2F-4DC7-8F46-07E22B7811CD}" @@ -312,6 +315,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "migrations", "migrations", ProjectSection(SolutionItems) = preProject migrations\efcore-3.1.sh = migrations\efcore-3.1.sh migrations\efcore-3.0.sh = migrations\efcore-3.0.sh + migrations\efcore-3.1-sql.sh = migrations\efcore-3.1-sql.sh EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Alterations.IntegrationTests", "test\integration\Elsa.Alterations.IntegrationTests\Elsa.Alterations.IntegrationTests.csproj", "{F50336DA-42D1-4DD1-A107-67AFEB8A33EE}" @@ -324,6 +328,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.KeyValues", "src\modul EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Workflows.Runtime.UnitTests", "test\unit\Elsa.Workflows.Runtime.UnitTests\Elsa.Workflows.Runtime.UnitTests.csproj", "{B0946844-DE0E-4C59-9391-C0EB649DBF4E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Server.LoadBalancer", "src\bundles\Elsa.Server.LoadBalancer\Elsa.Server.LoadBalancer.csproj", "{7C1E6DD9-C7DE-4686-AA73-D67A15D005A1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -792,6 +798,10 @@ Global {B0946844-DE0E-4C59-9391-C0EB649DBF4E}.Debug|Any CPU.Build.0 = Debug|Any CPU {B0946844-DE0E-4C59-9391-C0EB649DBF4E}.Release|Any CPU.ActiveCfg = Release|Any CPU {B0946844-DE0E-4C59-9391-C0EB649DBF4E}.Release|Any CPU.Build.0 = Release|Any CPU + {7C1E6DD9-C7DE-4686-AA73-D67A15D005A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C1E6DD9-C7DE-4686-AA73-D67A15D005A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C1E6DD9-C7DE-4686-AA73-D67A15D005A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C1E6DD9-C7DE-4686-AA73-D67A15D005A1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -932,6 +942,7 @@ Global {73BBB1E3-AEEC-44E8-83D7-6DD9CD687FE3} = {5BA4A8FA-F7F4-45B3-AEC8-8886D35AAC79} {086A7E2A-6CE7-41DA-927B-C033638060B1} = {56C2FFB8-EA54-45B5-A095-4A78142EB4B5} {B0946844-DE0E-4C59-9391-C0EB649DBF4E} = {18453B51-25EB-4317-A4B3-B10518252E92} + {7C1E6DD9-C7DE-4686-AA73-D67A15D005A1} = {F06B9573-DF68-4606-866C-A7546A10A05A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D4B5CEAA-7D70-4FCB-A68E-B03FBE5E0E5E} diff --git a/docker-compose.yml b/docker-compose.yml index 266587c9a..c27c2730e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: - "8600:8600" - "8600:8600/udp" command: "agent -server -bootstrap-expect 3 -ui -client 0.0.0.0" - + sqlserver: image: "mcr.microsoft.com/mssql/server:2019-latest" ports: @@ -38,18 +38,18 @@ services: ACCEPT_EULA: "Y" volumes: - c:\data\docker\sqlserver2019:/var/opt/mssql/data - + postgres: image: postgres:13.3-alpine container_name: elsa3-postgres environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgrespw - POSTGRES_DB: postgres + POSTGRES_USER: elsa + POSTGRES_PASSWORD: elsa + POSTGRES_DB: elsa ports: - "5432:5432" volumes: - - pgdata:/var/lib/postgresql/data + - pgdata-3:/var/lib/postgresql/data mongodb: image: mongo:latest @@ -57,7 +57,7 @@ services: - "127.0.0.1:27017:27017" volumes: - mongodb_data:/data/db - + mysql: image: arm64v8/mysql restart: always @@ -75,13 +75,13 @@ services: image: redis:latest ports: - "127.0.0.1:6379:6379" - + rabbitmq: image: "rabbitmq:3-management" ports: - "15672:15672" - "5672:5672" - + elasticsearch: image: "docker.elastic.co/elasticsearch/elasticsearch:8.5.0" environment: @@ -110,18 +110,18 @@ services: - "5601:5601" depends_on: - elasticsearch - + smtp4dev: image: rnwood/smtp4dev:3.1.3-ci20211206101 ports: - "4000:80" - "2525:25" - + networks: consul: volumes: mongodb_data: - pgdata: + pgdata-3: elasticsearch-data: driver: local \ No newline at end of file diff --git a/docker/ElsaServer-Datadog.Dockerfile b/docker/ElsaServer-Datadog.Dockerfile new file mode 100644 index 000000000..bd02ed1e8 --- /dev/null +++ b/docker/ElsaServer-Datadog.Dockerfile @@ -0,0 +1,58 @@ +# Version: 1 +# Description: Dockerfile for building and running Elsa Server + +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build +WORKDIR /source + +# Determine the architecture and download the appropriate version of the tracer +RUN ARCH=$(if [ "$(uname -m)" = "x86_64" ]; then echo "amd64"; elif [ "$(uname -m)" = "aarch64" ]; then echo "arm64"; else echo "amd64"; fi) \ + && TRACER_VERSION=$(curl -s https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest | grep tag_name | cut -d '"' -f 4 | cut -c2-) \ + && curl -Lo /tmp/datadog-dotnet-apm.deb https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm_${TRACER_VERSION}_${ARCH}.deb + +# copy sources. +COPY src/. ./src +COPY ./NuGet.Config ./ +COPY *.props ./ + +# restore packages. +RUN dotnet restore "./src/bundles/Elsa.Server.Web/Elsa.Server.Web.csproj" + +# build and publish (UseAppHost=false creates platform independent binaries). +WORKDIR /source/src/bundles/Elsa.Server.Web +RUN dotnet build "Elsa.Server.Web.csproj" -c Release -o /app/build +RUN dotnet publish "Elsa.Server.Web.csproj" -c Release -o /app/publish /p:UseAppHost=false --no-restore -f net8.0 + +# move binaries into smaller base image. +FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim AS base +WORKDIR /app +COPY --from=build /app/publish ./ + +# Install Python 3.11 +RUN apt-get update && apt-get install -y --no-install-recommends \ + python3.11 \ + python3.11-dev \ + libpython3.11 \ + python3-pip && \ + rm -rf /var/lib/apt/lists/* + +# Set PYTHONNET_PYDLL environment variable +ENV PYTHONNET_PYDLL /usr/lib/aarch64-linux-gnu/libpython3.11.so + +# Copy the tracer from build target +COPY --from=build /tmp/datadog-dotnet-apm.deb /tmp/datadog-dotnet-apm.deb +# Install the tracer +RUN mkdir -p /opt/datadog \ + && mkdir -p /var/log/datadog \ + && dpkg -i /tmp/datadog-dotnet-apm.deb \ + && rm /tmp/datadog-dotnet-apm.deb + +# Enable the tracer +ENV CORECLR_ENABLE_PROFILING=1 +ENV CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8} +ENV CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so +ENV DD_DOTNET_TRACER_HOME=/opt/datadog +ENV DD_INTEGRATIONS=/opt/datadog/integrations.json + +EXPOSE 8080/tcp +EXPOSE 443/tcp +ENTRYPOINT ["dotnet", "Elsa.Server.Web.dll"] diff --git a/docker/docker-compose-datadog.yml b/docker/docker-compose-datadog.yml new file mode 100644 index 000000000..36fb7952f --- /dev/null +++ b/docker/docker-compose-datadog.yml @@ -0,0 +1,89 @@ +version: '3.7' + +services: + postgres: + image: postgres:latest + command: -c 'max_connections=2000' + environment: + POSTGRES_USER: elsa + POSTGRES_PASSWORD: elsa + POSTGRES_DB: elsa + volumes: + - postgres-data:/var/lib/postgresql/data + ports: + - "5432:5432" + + cockroachdb: + image: cockroachdb/cockroach:v22.1.0 + command: start-single-node --insecure + ports: + - "26257:26257" # CockroachDB SQL port + - "8080:8080" # CockroachDB UI port + volumes: + - cockroachdb-data:/cockroach/cockroach-data + environment: + - COCKROACH_DATABASE=elsa + + rabbitmq: + image: "rabbitmq:3-management" + ports: + - "15672:15672" + - "5672:5672" + + redis: + image: redis:latest + ports: + - "127.0.0.1:6379:6379" + + elsa-server: + build: + context: ../. + dockerfile: ./docker/ElsaServer-Datadog.Dockerfile + depends_on: + - postgres + - rabbitmq + - redis + - datadog-agent + environment: + DD_AGENT_HOST: datadog-agent + ASPNETCORE_ENVIRONMENT: Development + PYTHONNET_PYDLL: /opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/bin/python3.11 + PYTHONNET_RUNTIME: coreclr + CONNECTIONSTRINGS__POSTGRESQL: "Server=postgres;Username=elsa;Database=elsa;Port=5432;Password=elsa;SSLMode=Prefer" + CONNECTIONSTRINGS__RABBITMQ: "amqp://guest:guest@rabbitmq:5672/" + CONNECTIONSTRINGS__REDIS: "redis:6379" + DISTRIBUTEDLOCKPROVIDER: "Postgres" + ports: + - "13000:8080" + + elsa-studio: + build: + context: ../. + dockerfile: ./docker/ElsaStudio-Datadog.Dockerfile + environment: + ASPNETCORE_ENVIRONMENT: Development + ELSASERVER__URL: "http://localhost:13000/elsa/api" + ports: + - "14000:8080" + + datadog-agent: + image: datadog/agent:7 + environment: + DD_API_KEY: "YOUR_API_KEY" + DD_SITE: "datadoghq.eu" + DD_LOGS_ENABLED: "true" + DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL: "true" + DD_APM_ENABLED: "true" + DD_APM_NON_LOCAL_TRAFFIC: "true" + DD_AC_INCLUDE: "name:postgres,name:rabbitmq,name:redis,name:elsa-server" + DD_AC_EXCLUDE: "name:datadog-agent" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /proc/:/host/proc/:ro + - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro + ports: + - "8126:8126" + +volumes: + postgres-data: + cockroachdb-data: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 000000000..a2a114dff --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,69 @@ +version: '3.7' + +services: + postgres: + image: postgres:latest + command: -c 'max_connections=2000' + environment: + POSTGRES_USER: elsa + POSTGRES_PASSWORD: elsa + POSTGRES_DB: elsa + volumes: + - postgres-data:/var/lib/postgresql/data + ports: + - "5432:5432" + + cockroachdb: + image: cockroachdb/cockroach:v22.1.0 + command: start-single-node --insecure + ports: + - "26257:26257" # CockroachDB SQL port + - "8080:8080" # CockroachDB UI port + volumes: + - cockroachdb-data:/cockroach/cockroach-data + environment: + - COCKROACH_DATABASE=elsa + + rabbitmq: + image: "rabbitmq:3-management" + ports: + - "15672:15672" + - "5672:5672" + + redis: + image: redis:latest + ports: + - "127.0.0.1:6379:6379" + + elsa-server: + build: + context: ../. + dockerfile: ./docker/ElsaServer.Dockerfile + depends_on: + - postgres + - rabbitmq + - redis + environment: + ASPNETCORE_ENVIRONMENT: Development + PYTHONNET_PYDLL: /opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/bin/python3.11 + PYTHONNET_RUNTIME: coreclr + CONNECTIONSTRINGS__POSTGRESQL: "Server=postgres;Username=elsa;Database=elsa;Port=5432;Password=elsa;SSLMode=Prefer" + CONNECTIONSTRINGS__RABBITMQ: "amqp://guest:guest@rabbitmq:5672/" + CONNECTIONSTRINGS__REDIS: "redis:6379" + DISTRIBUTEDLOCKPROVIDER: "Postgres" + ports: + - "13000:8080" + + elsa-studio: + build: + context: ../. + dockerfile: ./docker/ElsaStudio.Dockerfile + environment: + ASPNETCORE_ENVIRONMENT: Development + ELSASERVER__URL: "http://localhost:13000/elsa/api" + ports: + - "14000:8080" + +volumes: + postgres-data: + cockroachdb-data: diff --git a/migrations/efcore-3.1-sql.sh b/migrations/efcore-3.1-sql.sh new file mode 100755 index 000000000..f3414ad7f --- /dev/null +++ b/migrations/efcore-3.1-sql.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Define the modules to update +mods=("Alterations" "Runtime" "Management" "Identity") + +# Define the list of providers +providers=("MySql" "SqlServer" "Sqlite" "PostgreSql") + +# Loop through each module +for module in "${mods[@]}"; do + # Loop through each provider + for provider in "${providers[@]}"; do + providerPath="../src/modules/Elsa.EntityFrameworkCore.$provider" + sqlPath="$providerPath/Migrations/$module/v3.1.sql" + + echo "Generating SQL for $provider..." + echo "SQL path: $sqlPath" + dotnet ef migrations script -p "$providerPath" -c "$module"ElsaDbContext -o "$sqlPath" + + # Make the file writable: + chmod 777 "$sqlPath" + done +done diff --git a/src/bundles/Elsa.Server.Web/Activities/SlowActivity.cs b/src/bundles/Elsa.Server.Web/Activities/SlowActivity.cs new file mode 100644 index 000000000..49f25f6bd --- /dev/null +++ b/src/bundles/Elsa.Server.Web/Activities/SlowActivity.cs @@ -0,0 +1,37 @@ +using System.Reflection; +using Elsa.Extensions; +using Elsa.Workflows; +using Elsa.Workflows.Attributes; +using Elsa.Workflows.Contracts; +using Elsa.Workflows.Models; + +namespace Elsa.Server.Web.Activities; + +/// +/// Simulate an activity that takes a long time to complete. +/// +[Activity("Testing", "Testing", "Simulate an activity that takes a long time to complete.")] +public class SlowActivity : CodeActivity, IActivityPropertyDefaultValueProvider +{ + /// + /// The delay. + /// + [Input(Description = "The delay.", DefaultValueProvider = typeof(SlowActivity))] + public Input Delay { get; set; } = new(TimeSpan.FromSeconds(1)); + + /// + protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) + { + var delay = Delay.Get(context); + await Task.Delay(delay); + } + + object IActivityPropertyDefaultValueProvider.GetDefaultValue(PropertyInfo property) + { + return property.Name switch + { + nameof(Delay) => TimeSpan.FromSeconds(1), + _ => default + }; + } +} \ No newline at end of file diff --git a/src/bundles/Elsa.Server.Web/Elsa.Server.Web.csproj b/src/bundles/Elsa.Server.Web/Elsa.Server.Web.csproj index 8c904e790..e8e800fcd 100644 --- a/src/bundles/Elsa.Server.Web/Elsa.Server.Web.csproj +++ b/src/bundles/Elsa.Server.Web/Elsa.Server.Web.csproj @@ -45,6 +45,8 @@ + + diff --git a/src/bundles/Elsa.Server.Web/Endpoints/Api1/Get/Endpoint.cs b/src/bundles/Elsa.Server.Web/Endpoints/Api1/Get/Endpoint.cs new file mode 100644 index 000000000..5d727bb33 --- /dev/null +++ b/src/bundles/Elsa.Server.Web/Endpoints/Api1/Get/Endpoint.cs @@ -0,0 +1,33 @@ +using Elsa.Abstractions; +using Elsa.Workflows.Activities; +using Elsa.Workflows.Models; +using Elsa.Workflows.Runtime.Contracts; +using Elsa.Workflows.Runtime.Parameters; +using JetBrains.Annotations; + +namespace Elsa.Server.Web.Endpoints.Api1.Get; + +/// +/// Returns a message. +/// +[UsedImplicitly] +public class Get : ElsaEndpointWithoutRequest +{ + /// + public override void Configure() + { + Get("/api-1"); + AllowAnonymous(); + } + + /// + public override async Task HandleAsync(CancellationToken ct) + { + await Task.Delay(1000, ct); + var response = new + { + Message = "OK" + }; + await SendOkAsync(response, ct); + } +} \ No newline at end of file diff --git a/src/bundles/Elsa.Server.Web/Program.cs b/src/bundles/Elsa.Server.Web/Program.cs index 05b7613bb..b85561ab3 100644 --- a/src/bundles/Elsa.Server.Web/Program.cs +++ b/src/bundles/Elsa.Server.Web/Program.cs @@ -1,6 +1,7 @@ using System.Text.Encodings.Web; using Elsa.Alterations.Extensions; using Elsa.Alterations.MassTransit.Extensions; +using Elsa.Common.DistributedLocks.Noop; using Elsa.Dapper.Extensions; using Elsa.Dapper.Services; using Elsa.DropIns.Extensions; @@ -17,6 +18,11 @@ using Elsa.MongoDb.Modules.Management; using Elsa.MongoDb.Modules.Runtime; using Elsa.Server.Web; using Elsa.Workflows.Management.Compression; +using Elsa.Workflows.Management.Services; +using Elsa.Workflows.Runtime.Stores; +using Medallion.Threading.FileSystem; +using Medallion.Threading.Postgres; +using Medallion.Threading.Redis; using Microsoft.Data.Sqlite; using Microsoft.Extensions.Options; using Proto.Persistence.Sqlite; @@ -25,13 +31,16 @@ using Proto.Persistence.SqlServer; const bool useMongoDb = false; const bool useSqlServer = false; const bool usePostgres = false; +const bool useCockroachDb = false; const bool useDapper = false; const bool useProtoActor = false; const bool useHangfire = false; const bool useQuartz = true; const bool useMassTransit = true; -const bool useZipCompression = false; +const bool useZipCompression = true; const MassTransitBroker useMassTransitBroker = MassTransitBroker.Memory; +const bool runEFCoreMigrations = true; +const bool useMemoryStores = false; var builder = WebApplication.CreateBuilder(args); var services = builder.Services; @@ -41,9 +50,12 @@ var identityTokenSection = identitySection.GetSection("Tokens"); var sqliteConnectionString = configuration.GetConnectionString("Sqlite")!; var sqlServerConnectionString = configuration.GetConnectionString("SqlServer")!; var postgresConnectionString = configuration.GetConnectionString("PostgreSql")!; +var cockroachDbConnectionString = configuration.GetConnectionString("CockroachDb")!; var mongoDbConnectionString = configuration.GetConnectionString("MongoDb")!; var azureServiceBusConnectionString = configuration.GetConnectionString("AzureServiceBus")!; var rabbitMqConnectionString = configuration.GetConnectionString("RabbitMq")!; +var redisConnectionString = configuration.GetConnectionString("Redis")!; +var distributedLockProviderName = configuration["DistributedLockProvider"]; // Add Elsa services. services @@ -92,8 +104,12 @@ services ef.UseSqlServer(sqlServerConnectionString!); else if (usePostgres) ef.UsePostgreSql(postgresConnectionString!); + else if (useCockroachDb) + ef.UsePostgreSql(cockroachDbConnectionString!); else ef.UseSqlite(sqliteConnectionString); + + ef.RunMigrations = runEFCoreMigrations; }); identity.IdentityOptions = options => identitySection.Bind(options); @@ -116,12 +132,19 @@ services ef.UseSqlServer(sqlServerConnectionString!); else if (usePostgres) ef.UsePostgreSql(postgresConnectionString!); + else if (useCockroachDb) + ef.UsePostgreSql(cockroachDbConnectionString!); else ef.UseSqlite(sqliteConnectionString); + + ef.RunMigrations = runEFCoreMigrations; }); if (useZipCompression) management.SetCompressionAlgorithm(nameof(Zstd)); + + if (useMemoryStores) + management.UseWorkflowInstances(feature => feature.WorkflowInstanceStore = sp => sp.GetRequiredService()); }) .UseWorkflowRuntime(runtime => { @@ -136,8 +159,12 @@ services ef.UseSqlServer(sqlServerConnectionString!); else if (usePostgres) ef.UsePostgreSql(postgresConnectionString!); + else if (useCockroachDb) + ef.UsePostgreSql(cockroachDbConnectionString!); else ef.UseSqlite(sqliteConnectionString); + + ef.RunMigrations = runEFCoreMigrations; }); if (useProtoActor) @@ -158,6 +185,36 @@ services runtime.WorkflowInboxCleanupOptions = options => configuration.GetSection("Runtime:WorkflowInboxCleanup").Bind(options); runtime.WorkflowDispatcherOptions = options => configuration.GetSection("Runtime:WorkflowDispatcher").Bind(options); + + if (useMemoryStores) + { + runtime.ActivityExecutionLogStore = sp => sp.GetRequiredService(); + runtime.WorkflowExecutionLogStore = sp => sp.GetRequiredService(); + runtime.WorkflowInboxStore = sp => sp.GetRequiredService(); + } + + runtime.DistributedLockProvider = _ => + { + switch (distributedLockProviderName) + { + case "Postgres": + return new PostgresDistributedSynchronizationProvider(postgresConnectionString, options => + { + options.KeepaliveCadence(TimeSpan.FromMinutes(5)); + options.UseMultiplexing(); + }); + case "Redis": + { + var connectionMultiplexer = StackExchange.Redis.ConnectionMultiplexer.Connect(redisConnectionString); + var database = connectionMultiplexer.GetDatabase(); + return new RedisDistributedSynchronizationProvider(database); + } + case "Noop": + return new NoopDistributedSynchronizationProvider(); + default: + return new FileDistributedSynchronizationProvider(new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "App_Data", "locks"))); + } + }; }) .UseEnvironments(environments => environments.EnvironmentsOptions = options => configuration.GetSection("Environments").Bind(options)) .UseScheduling(scheduling => @@ -217,8 +274,12 @@ services ef.UseSqlServer(sqlServerConnectionString); else if (usePostgres) ef.UsePostgreSql(postgresConnectionString); + else if (useCockroachDb) + ef.UsePostgreSql(cockroachDbConnectionString!); else ef.UseSqlite(sqliteConnectionString); + + ef.RunMigrations = runEFCoreMigrations; }); } diff --git a/src/bundles/Elsa.Server.Web/appsettings.json b/src/bundles/Elsa.Server.Web/appsettings.json index c70ae9518..e635c88c8 100644 --- a/src/bundles/Elsa.Server.Web/appsettings.json +++ b/src/bundles/Elsa.Server.Web/appsettings.json @@ -15,10 +15,12 @@ "AllowedHosts": "*", "ConnectionStrings": { "Sqlite": "Data Source=App_Data/elsa.sqlite.db;Cache=Shared;", - "PostgreSql": "Server=localhost;Username=postgres;Database=elsa;Port=5432;Password=postgrespw;SSLMode=Prefer", + "PostgreSql": "Server=localhost;Username=elsa;Database=elsa;Port=5432;Password=elsa;SSLMode=Prefer;MaxPoolSize=2000;Timeout=60", + "CockroachDb": "Host=localhost;Port=26257;Database=elsa;SslMode=Disable;Username=root;IncludeErrorDetail=true", "MongoDb": "mongodb://localhost:27017/elsa-workflows", "AzureServiceBus": "", - "RabbitMq": "amqp://guest:guest@localhost:5672" + "RabbitMq": "amqp://guest:guest@localhost:5672", + "Redis": "localhost:6379,abortConnect=false" }, "Smtp": { "Host": "localhost", diff --git a/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedLock.cs b/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedLock.cs new file mode 100644 index 000000000..781aea108 --- /dev/null +++ b/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedLock.cs @@ -0,0 +1,36 @@ +using Medallion.Threading; + +namespace Elsa.Common.DistributedLocks.Noop; + +/// +/// Represents a Noop (No-Operation) implementation of the interface. +/// +public class NoopDistributedLock : IDistributedLock +{ + /// + public IDistributedSynchronizationHandle? TryAcquire(TimeSpan timeout = new TimeSpan(), CancellationToken cancellationToken = new CancellationToken()) + { + return new NoopDistributedSynchronizationHandle(); + } + + /// + public IDistributedSynchronizationHandle Acquire(TimeSpan? timeout = null, CancellationToken cancellationToken = new CancellationToken()) + { + return new NoopDistributedSynchronizationHandle(); + } + + /// + public ValueTask TryAcquireAsync(TimeSpan timeout = new TimeSpan(), CancellationToken cancellationToken = new CancellationToken()) + { + return new ValueTask(new NoopDistributedSynchronizationHandle()); + } + + /// + public ValueTask AcquireAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = new CancellationToken()) + { + return new ValueTask(new NoopDistributedSynchronizationHandle()); + } + + /// + public string Name => "Noop"; +} \ No newline at end of file diff --git a/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedSynchronizationHandle.cs b/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedSynchronizationHandle.cs new file mode 100644 index 000000000..eefd261d6 --- /dev/null +++ b/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedSynchronizationHandle.cs @@ -0,0 +1,24 @@ +using Medallion.Threading; + +namespace Elsa.Common.DistributedLocks.Noop; + +/// +/// Represents a Noop distributed synchronization handle. This handle is used in the NoopDistributedLock implementation +/// to provide a no-operation implementation of the IDistributedSynchronizationHandle interface. +/// +public class NoopDistributedSynchronizationHandle : IDistributedSynchronizationHandle +{ + /// + public void Dispose() + { + } + + /// + public ValueTask DisposeAsync() + { + return new ValueTask(); + } + + /// + public CancellationToken HandleLostToken { get; } +} \ No newline at end of file diff --git a/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedSynchronizationProvider.cs b/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedSynchronizationProvider.cs new file mode 100644 index 000000000..12dfd8208 --- /dev/null +++ b/src/modules/Elsa.Common/DistributedLocks/Noop/NoopDistributedSynchronizationProvider.cs @@ -0,0 +1,15 @@ +using Medallion.Threading; + +namespace Elsa.Common.DistributedLocks.Noop; + +/// +/// Represents a no-op implementation of the IDistributedLockProvider interface. +/// +public class NoopDistributedSynchronizationProvider : IDistributedLockProvider +{ + /// + public IDistributedLock CreateLock(string name) + { + return new NoopDistributedLock(); + } +} \ No newline at end of file diff --git a/src/modules/Elsa.Common/Elsa.Common.csproj b/src/modules/Elsa.Common/Elsa.Common.csproj index 75d83ee9f..d422efbdb 100644 --- a/src/modules/Elsa.Common/Elsa.Common.csproj +++ b/src/modules/Elsa.Common/Elsa.Common.csproj @@ -17,6 +17,7 @@ + diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Alterations/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Alterations/v3.1.sql new file mode 100755 index 000000000..90f43c60f --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Alterations/v3.1.sql @@ -0,0 +1,71 @@ +CREATE TABLE IF NOT EXISTS `__EFMigrationsHistory` ( + `MigrationId` varchar(150) CHARACTER SET utf8mb4 NOT NULL, + `ProductVersion` varchar(32) CHARACTER SET utf8mb4 NOT NULL, + CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) +) CHARACTER SET=utf8mb4; + +START TRANSACTION; + +ALTER DATABASE CHARACTER SET utf8mb4; + +CREATE TABLE `AlterationJobs` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `PlanId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowInstanceId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Status` int NOT NULL, + `CreatedAt` datetime(6) NOT NULL, + `StartedAt` datetime(6) NULL, + `CompletedAt` datetime(6) NULL, + `SerializedLog` longtext CHARACTER SET utf8mb4 NULL, + CONSTRAINT `PK_AlterationJobs` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE TABLE `AlterationPlans` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Status` int NOT NULL, + `CreatedAt` datetime(6) NOT NULL, + `StartedAt` datetime(6) NULL, + `CompletedAt` datetime(6) NULL, + `SerializedAlterations` longtext CHARACTER SET utf8mb4 NULL, + `SerializedWorkflowInstanceIds` longtext CHARACTER SET utf8mb4 NULL, + CONSTRAINT `PK_AlterationPlans` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE INDEX `IX_AlterationJob_CompletedAt` ON `AlterationJobs` (`CompletedAt`); + +CREATE INDEX `IX_AlterationJob_CreatedAt` ON `AlterationJobs` (`CreatedAt`); + +CREATE INDEX `IX_AlterationJob_PlanId` ON `AlterationJobs` (`PlanId`); + +CREATE INDEX `IX_AlterationJob_StartedAt` ON `AlterationJobs` (`StartedAt`); + +CREATE INDEX `IX_AlterationJob_Status` ON `AlterationJobs` (`Status`); + +CREATE INDEX `IX_AlterationJob_WorkflowInstanceId` ON `AlterationJobs` (`WorkflowInstanceId`); + +CREATE INDEX `IX_AlterationPlan_CompletedAt` ON `AlterationPlans` (`CompletedAt`); + +CREATE INDEX `IX_AlterationPlan_CreatedAt` ON `AlterationPlans` (`CreatedAt`); + +CREATE INDEX `IX_AlterationPlan_StartedAt` ON `AlterationPlans` (`StartedAt`); + +CREATE INDEX `IX_AlterationPlan_Status` ON `AlterationPlans` (`Status`); + +INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) +VALUES ('20231015122151_Initial', '7.0.14'); + +COMMIT; + +START TRANSACTION; + +ALTER TABLE `AlterationPlans` CHANGE `SerializedWorkflowInstanceIds` `SerializedWorkflowInstanceFilter` longtext NULL; + +ALTER TABLE `AlterationPlans` MODIFY COLUMN `Status` varchar(255) CHARACTER SET utf8mb4 NOT NULL; + +ALTER TABLE `AlterationJobs` MODIFY COLUMN `Status` varchar(255) CHARACTER SET utf8mb4 NOT NULL; + +INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) +VALUES ('20240312145108_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/v3.1.sql new file mode 100755 index 000000000..9f92600e5 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Identity/v3.1.sql @@ -0,0 +1,58 @@ +CREATE TABLE IF NOT EXISTS `__EFMigrationsHistory` ( + `MigrationId` varchar(150) CHARACTER SET utf8mb4 NOT NULL, + `ProductVersion` varchar(32) CHARACTER SET utf8mb4 NOT NULL, + CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) +) CHARACTER SET=utf8mb4; + +START TRANSACTION; + +ALTER DATABASE CHARACTER SET utf8mb4; + +CREATE TABLE `Applications` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ClientId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `HashedClientSecret` longtext CHARACTER SET utf8mb4 NOT NULL, + `HashedClientSecretSalt` longtext CHARACTER SET utf8mb4 NOT NULL, + `Name` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `HashedApiKey` longtext CHARACTER SET utf8mb4 NOT NULL, + `HashedApiKeySalt` longtext CHARACTER SET utf8mb4 NOT NULL, + `Roles` longtext CHARACTER SET utf8mb4 NOT NULL, + CONSTRAINT `PK_Applications` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE TABLE `Roles` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Name` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Permissions` longtext CHARACTER SET utf8mb4 NOT NULL, + CONSTRAINT `PK_Roles` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE TABLE `Users` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Name` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `HashedPassword` longtext CHARACTER SET utf8mb4 NOT NULL, + `HashedPasswordSalt` longtext CHARACTER SET utf8mb4 NOT NULL, + `Roles` longtext CHARACTER SET utf8mb4 NOT NULL, + CONSTRAINT `PK_Users` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE UNIQUE INDEX `IX_Application_ClientId` ON `Applications` (`ClientId`); + +CREATE UNIQUE INDEX `IX_Application_Name` ON `Applications` (`Name`); + +CREATE UNIQUE INDEX `IX_Role_Name` ON `Roles` (`Name`); + +CREATE UNIQUE INDEX `IX_User_Name` ON `Users` (`Name`); + +INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) +VALUES ('20231015122238_Initial', '7.0.14'); + +COMMIT; + +START TRANSACTION; + +INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) +VALUES ('20240312145212_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/v3.1.sql new file mode 100755 index 000000000..103614358 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Management/v3.1.sql @@ -0,0 +1,106 @@ +CREATE TABLE IF NOT EXISTS `__EFMigrationsHistory` ( + `MigrationId` varchar(150) CHARACTER SET utf8mb4 NOT NULL, + `ProductVersion` varchar(32) CHARACTER SET utf8mb4 NOT NULL, + CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) +) CHARACTER SET=utf8mb4; + +START TRANSACTION; + +ALTER DATABASE CHARACTER SET utf8mb4; + +CREATE TABLE `WorkflowDefinitions` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `DefinitionId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Name` varchar(255) CHARACTER SET utf8mb4 NULL, + `Description` longtext CHARACTER SET utf8mb4 NULL, + `ToolVersion` longtext CHARACTER SET utf8mb4 NULL, + `ProviderName` longtext CHARACTER SET utf8mb4 NULL, + `MaterializerName` longtext CHARACTER SET utf8mb4 NOT NULL, + `MaterializerContext` longtext CHARACTER SET utf8mb4 NULL, + `StringData` longtext CHARACTER SET utf8mb4 NULL, + `BinaryData` longblob NULL, + `IsReadonly` tinyint(1) NOT NULL, + `Data` longtext CHARACTER SET utf8mb4 NULL, + `UsableAsActivity` tinyint(1) NULL, + `CreatedAt` datetime(6) NOT NULL, + `Version` int NOT NULL, + `IsLatest` tinyint(1) NOT NULL, + `IsPublished` tinyint(1) NOT NULL, + CONSTRAINT `PK_WorkflowDefinitions` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE TABLE `WorkflowInstances` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `DefinitionId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `DefinitionVersionId` longtext CHARACTER SET utf8mb4 NOT NULL, + `Version` int NOT NULL, + `Status` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `SubStatus` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `CorrelationId` varchar(255) CHARACTER SET utf8mb4 NULL, + `Name` varchar(255) CHARACTER SET utf8mb4 NULL, + `IncidentCount` int NOT NULL, + `CreatedAt` datetime(6) NOT NULL, + `UpdatedAt` datetime(6) NOT NULL, + `FinishedAt` datetime(6) NULL, + `Data` longtext CHARACTER SET utf8mb4 NULL, + CONSTRAINT `PK_WorkflowInstances` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE UNIQUE INDEX `IX_WorkflowDefinition_DefinitionId_Version` ON `WorkflowDefinitions` (`DefinitionId`, `Version`); + +CREATE INDEX `IX_WorkflowDefinition_IsLatest` ON `WorkflowDefinitions` (`IsLatest`); + +CREATE INDEX `IX_WorkflowDefinition_IsPublished` ON `WorkflowDefinitions` (`IsPublished`); + +CREATE INDEX `IX_WorkflowDefinition_Name` ON `WorkflowDefinitions` (`Name`); + +CREATE INDEX `IX_WorkflowDefinition_UsableAsActivity` ON `WorkflowDefinitions` (`UsableAsActivity`); + +CREATE INDEX `IX_WorkflowDefinition_Version` ON `WorkflowDefinitions` (`Version`); + +CREATE INDEX `IX_WorkflowInstance_CorrelationId` ON `WorkflowInstances` (`CorrelationId`); + +CREATE INDEX `IX_WorkflowInstance_CreatedAt` ON `WorkflowInstances` (`CreatedAt`); + +CREATE INDEX `IX_WorkflowInstance_DefinitionId` ON `WorkflowInstances` (`DefinitionId`); + +CREATE INDEX `IX_WorkflowInstance_FinishedAt` ON `WorkflowInstances` (`FinishedAt`); + +CREATE INDEX `IX_WorkflowInstance_Name` ON `WorkflowInstances` (`Name`); + +CREATE INDEX `IX_WorkflowInstance_Status` ON `WorkflowInstances` (`Status`); + +CREATE INDEX `IX_WorkflowInstance_Status_DefinitionId` ON `WorkflowInstances` (`Status`, `DefinitionId`); + +CREATE INDEX `IX_WorkflowInstance_Status_SubStatus` ON `WorkflowInstances` (`Status`, `SubStatus`); + +CREATE INDEX `IX_WorkflowInstance_Status_SubStatus_DefinitionId_Version` ON `WorkflowInstances` (`Status`, `SubStatus`, `DefinitionId`, `Version`); + +CREATE INDEX `IX_WorkflowInstance_SubStatus` ON `WorkflowInstances` (`SubStatus`); + +CREATE INDEX `IX_WorkflowInstance_SubStatus_DefinitionId` ON `WorkflowInstances` (`SubStatus`, `DefinitionId`); + +CREATE INDEX `IX_WorkflowInstance_UpdatedAt` ON `WorkflowInstances` (`UpdatedAt`); + +INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) +VALUES ('20231015122223_Initial', '7.0.14'); + +COMMIT; + +START TRANSACTION; + +ALTER TABLE `WorkflowInstances` ADD `DataCompressionAlgorithm` longtext CHARACTER SET utf8mb4 NULL; + +ALTER TABLE `WorkflowInstances` ADD `IsSystem` tinyint(1) NOT NULL DEFAULT FALSE; + +ALTER TABLE `WorkflowDefinitions` ADD `IsSystem` tinyint(1) NOT NULL DEFAULT FALSE; + +CREATE INDEX `IX_WorkflowInstance_IsSystem` ON `WorkflowInstances` (`IsSystem`); + +CREATE INDEX `IX_WorkflowDefinition_IsSystem` ON `WorkflowDefinitions` (`IsSystem`); + +INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) +VALUES ('20240312145152_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/v3.1.sql new file mode 100755 index 000000000..1b709ea22 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/v3.1.sql @@ -0,0 +1,202 @@ +CREATE TABLE IF NOT EXISTS `__EFMigrationsHistory` ( + `MigrationId` varchar(150) CHARACTER SET utf8mb4 NOT NULL, + `ProductVersion` varchar(32) CHARACTER SET utf8mb4 NOT NULL, + CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) +) CHARACTER SET=utf8mb4; + +START TRANSACTION; + +ALTER DATABASE CHARACTER SET utf8mb4; + +CREATE TABLE `ActivityExecutionRecords` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowInstanceId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityNodeId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityType` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityTypeVersion` int NOT NULL, + `ActivityName` varchar(255) CHARACTER SET utf8mb4 NULL, + `StartedAt` datetime(6) NOT NULL, + `HasBookmarks` tinyint(1) NOT NULL, + `Status` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `CompletedAt` datetime(6) NULL, + `SerializedActivityState` longtext CHARACTER SET utf8mb4 NULL, + `SerializedException` longtext CHARACTER SET utf8mb4 NULL, + `SerializedOutputs` longtext CHARACTER SET utf8mb4 NULL, + `SerializedPayload` longtext CHARACTER SET utf8mb4 NULL, + CONSTRAINT `PK_ActivityExecutionRecords` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE TABLE `Bookmarks` ( + `BookmarkId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityTypeName` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Hash` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowInstanceId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityInstanceId` varchar(255) CHARACTER SET utf8mb4 NULL, + `CorrelationId` longtext CHARACTER SET utf8mb4 NULL, + `CreatedAt` datetime(6) NOT NULL, + `SerializedMetadata` longtext CHARACTER SET utf8mb4 NULL, + `SerializedPayload` longtext CHARACTER SET utf8mb4 NULL, + CONSTRAINT `PK_Bookmarks` PRIMARY KEY (`BookmarkId`) +) CHARACTER SET=utf8mb4; + +CREATE TABLE `Triggers` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowDefinitionId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowDefinitionVersionId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Name` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityId` longtext CHARACTER SET utf8mb4 NOT NULL, + `Hash` varchar(255) CHARACTER SET utf8mb4 NULL, + `SerializedPayload` longtext CHARACTER SET utf8mb4 NULL, + CONSTRAINT `PK_Triggers` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE TABLE `WorkflowExecutionLogRecords` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowDefinitionId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowDefinitionVersionId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowInstanceId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowVersion` int NOT NULL, + `ActivityInstanceId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ParentActivityInstanceId` varchar(255) CHARACTER SET utf8mb4 NULL, + `ActivityId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityType` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityTypeVersion` int NOT NULL, + `ActivityName` varchar(255) CHARACTER SET utf8mb4 NULL, + `ActivityNodeId` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Timestamp` datetime(6) NOT NULL, + `Sequence` bigint NOT NULL, + `EventName` varchar(255) CHARACTER SET utf8mb4 NULL, + `Message` longtext CHARACTER SET utf8mb4 NULL, + `Source` longtext CHARACTER SET utf8mb4 NULL, + `SerializedActivityState` longtext CHARACTER SET utf8mb4 NULL, + `SerializedPayload` longtext CHARACTER SET utf8mb4 NULL, + CONSTRAINT `PK_WorkflowExecutionLogRecords` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE TABLE `WorkflowInboxMessages` ( + `Id` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `ActivityTypeName` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `Hash` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `WorkflowInstanceId` varchar(255) CHARACTER SET utf8mb4 NULL, + `CorrelationId` varchar(255) CHARACTER SET utf8mb4 NULL, + `ActivityInstanceId` varchar(255) CHARACTER SET utf8mb4 NULL, + `CreatedAt` datetime(6) NOT NULL, + `ExpiresAt` datetime(6) NOT NULL, + `SerializedBookmarkPayload` longtext CHARACTER SET utf8mb4 NULL, + `SerializedInput` longtext CHARACTER SET utf8mb4 NULL, + CONSTRAINT `PK_WorkflowInboxMessages` PRIMARY KEY (`Id`) +) CHARACTER SET=utf8mb4; + +CREATE INDEX `IX_ActivityExecutionRecord_ActivityId` ON `ActivityExecutionRecords` (`ActivityId`); + +CREATE INDEX `IX_ActivityExecutionRecord_ActivityName` ON `ActivityExecutionRecords` (`ActivityName`); + +CREATE INDEX `IX_ActivityExecutionRecord_ActivityNodeId` ON `ActivityExecutionRecords` (`ActivityNodeId`); + +CREATE INDEX `IX_ActivityExecutionRecord_ActivityType` ON `ActivityExecutionRecords` (`ActivityType`); + +CREATE INDEX `IX_ActivityExecutionRecord_ActivityType_ActivityTypeVersion` ON `ActivityExecutionRecords` (`ActivityType`, `ActivityTypeVersion`); + +CREATE INDEX `IX_ActivityExecutionRecord_ActivityTypeVersion` ON `ActivityExecutionRecords` (`ActivityTypeVersion`); + +CREATE INDEX `IX_ActivityExecutionRecord_CompletedAt` ON `ActivityExecutionRecords` (`CompletedAt`); + +CREATE INDEX `IX_ActivityExecutionRecord_HasBookmarks` ON `ActivityExecutionRecords` (`HasBookmarks`); + +CREATE INDEX `IX_ActivityExecutionRecord_StartedAt` ON `ActivityExecutionRecords` (`StartedAt`); + +CREATE INDEX `IX_ActivityExecutionRecord_Status` ON `ActivityExecutionRecords` (`Status`); + +CREATE INDEX `IX_ActivityExecutionRecord_WorkflowInstanceId` ON `ActivityExecutionRecords` (`WorkflowInstanceId`); + +CREATE INDEX `IX_StoredBookmark_ActivityInstanceId` ON `Bookmarks` (`ActivityInstanceId`); + +CREATE INDEX `IX_StoredBookmark_ActivityTypeName` ON `Bookmarks` (`ActivityTypeName`); + +CREATE INDEX `IX_StoredBookmark_ActivityTypeName_Hash` ON `Bookmarks` (`ActivityTypeName`, `Hash`); + +CREATE INDEX `IX_StoredBookmark_ActivityTypeName_Hash_WorkflowInstanceId` ON `Bookmarks` (`ActivityTypeName`, `Hash`, `WorkflowInstanceId`); + +CREATE INDEX `IX_StoredBookmark_CreatedAt` ON `Bookmarks` (`CreatedAt`); + +CREATE INDEX `IX_StoredBookmark_Hash` ON `Bookmarks` (`Hash`); + +CREATE INDEX `IX_StoredBookmark_WorkflowInstanceId` ON `Bookmarks` (`WorkflowInstanceId`); + +CREATE INDEX `IX_StoredTrigger_Hash` ON `Triggers` (`Hash`); + +CREATE INDEX `IX_StoredTrigger_Name` ON `Triggers` (`Name`); + +CREATE INDEX `IX_StoredTrigger_WorkflowDefinitionId` ON `Triggers` (`WorkflowDefinitionId`); + +CREATE INDEX `IX_StoredTrigger_WorkflowDefinitionVersionId` ON `Triggers` (`WorkflowDefinitionVersionId`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_ActivityId` ON `WorkflowExecutionLogRecords` (`ActivityId`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_ActivityInstanceId` ON `WorkflowExecutionLogRecords` (`ActivityInstanceId`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_ActivityName` ON `WorkflowExecutionLogRecords` (`ActivityName`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_ActivityNodeId` ON `WorkflowExecutionLogRecords` (`ActivityNodeId`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_ActivityType` ON `WorkflowExecutionLogRecords` (`ActivityType`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_ActivityType_ActivityTypeVersion` ON `WorkflowExecutionLogRecords` (`ActivityType`, `ActivityTypeVersion`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_ActivityTypeVersion` ON `WorkflowExecutionLogRecords` (`ActivityTypeVersion`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_EventName` ON `WorkflowExecutionLogRecords` (`EventName`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_ParentActivityInstanceId` ON `WorkflowExecutionLogRecords` (`ParentActivityInstanceId`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_Sequence` ON `WorkflowExecutionLogRecords` (`Sequence`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_Timestamp` ON `WorkflowExecutionLogRecords` (`Timestamp`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_Timestamp_Sequence` ON `WorkflowExecutionLogRecords` (`Timestamp`, `Sequence`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_WorkflowDefinitionId` ON `WorkflowExecutionLogRecords` (`WorkflowDefinitionId`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_WorkflowDefinitionVersionId` ON `WorkflowExecutionLogRecords` (`WorkflowDefinitionVersionId`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_WorkflowInstanceId` ON `WorkflowExecutionLogRecords` (`WorkflowInstanceId`); + +CREATE INDEX `IX_WorkflowExecutionLogRecord_WorkflowVersion` ON `WorkflowExecutionLogRecords` (`WorkflowVersion`); + +CREATE INDEX `IX_WorkflowInboxMessage_ActivityInstanceId` ON `WorkflowInboxMessages` (`ActivityInstanceId`); + +CREATE INDEX `IX_WorkflowInboxMessage_ActivityTypeName` ON `WorkflowInboxMessages` (`ActivityTypeName`); + +CREATE INDEX `IX_WorkflowInboxMessage_CorrelationId` ON `WorkflowInboxMessages` (`CorrelationId`); + +CREATE INDEX `IX_WorkflowInboxMessage_CreatedAt` ON `WorkflowInboxMessages` (`CreatedAt`); + +CREATE INDEX `IX_WorkflowInboxMessage_ExpiresAt` ON `WorkflowInboxMessages` (`ExpiresAt`); + +CREATE INDEX `IX_WorkflowInboxMessage_Hash` ON `WorkflowInboxMessages` (`Hash`); + +CREATE INDEX `IX_WorkflowInboxMessage_WorkflowInstanceId` ON `WorkflowInboxMessages` (`WorkflowInstanceId`); + +INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) +VALUES ('20231024160940_Initial', '7.0.14'); + +COMMIT; + +START TRANSACTION; + +ALTER TABLE `ActivityExecutionRecords` ADD `SerializedActivityStateCompressionAlgorithm` longtext CHARACTER SET utf8mb4 NULL; + +ALTER TABLE `ActivityExecutionRecords` ADD `SerializedProperties` longtext CHARACTER SET utf8mb4 NULL; + +CREATE TABLE `KeyValuePairs` ( + `Key` varchar(255) CHARACTER SET utf8mb4 NOT NULL, + `SerializedValue` longtext CHARACTER SET utf8mb4 NOT NULL, + CONSTRAINT `PK_KeyValuePairs` PRIMARY KEY (`Key`) +) CHARACTER SET=utf8mb4; + +INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) +VALUES ('20240312145132_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Alterations/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Alterations/v3.1.sql new file mode 100755 index 000000000..20cf6570c --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Alterations/v3.1.sql @@ -0,0 +1,70 @@ + +CREATE TABLE IF NOT EXISTS "Elsa"."__EFMigrationsHistory" ( + "MigrationId" character varying(150) NOT NULL, + "ProductVersion" character varying(32) NOT NULL, + CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId") +); + +START TRANSACTION; + +CREATE TABLE "Elsa"."AlterationJobs" ( + "Id" text NOT NULL, + "PlanId" text NOT NULL, + "WorkflowInstanceId" text NOT NULL, + "Status" integer NOT NULL, + "CreatedAt" timestamp with time zone NOT NULL, + "StartedAt" timestamp with time zone NULL, + "CompletedAt" timestamp with time zone NULL, + "SerializedLog" text NULL, + CONSTRAINT "PK_AlterationJobs" PRIMARY KEY ("Id") +); + +CREATE TABLE "Elsa"."AlterationPlans" ( + "Id" text NOT NULL, + "Status" integer NOT NULL, + "CreatedAt" timestamp with time zone NOT NULL, + "StartedAt" timestamp with time zone NULL, + "CompletedAt" timestamp with time zone NULL, + "SerializedAlterations" text NULL, + "SerializedWorkflowInstanceIds" text NULL, + CONSTRAINT "PK_AlterationPlans" PRIMARY KEY ("Id") +); + +CREATE INDEX "IX_AlterationJob_CompletedAt" ON "Elsa"."AlterationJobs" ("CompletedAt"); + +CREATE INDEX "IX_AlterationJob_CreatedAt" ON "Elsa"."AlterationJobs" ("CreatedAt"); + +CREATE INDEX "IX_AlterationJob_PlanId" ON "Elsa"."AlterationJobs" ("PlanId"); + +CREATE INDEX "IX_AlterationJob_StartedAt" ON "Elsa"."AlterationJobs" ("StartedAt"); + +CREATE INDEX "IX_AlterationJob_Status" ON "Elsa"."AlterationJobs" ("Status"); + +CREATE INDEX "IX_AlterationJob_WorkflowInstanceId" ON "Elsa"."AlterationJobs" ("WorkflowInstanceId"); + +CREATE INDEX "IX_AlterationPlan_CompletedAt" ON "Elsa"."AlterationPlans" ("CompletedAt"); + +CREATE INDEX "IX_AlterationPlan_CreatedAt" ON "Elsa"."AlterationPlans" ("CreatedAt"); + +CREATE INDEX "IX_AlterationPlan_StartedAt" ON "Elsa"."AlterationPlans" ("StartedAt"); + +CREATE INDEX "IX_AlterationPlan_Status" ON "Elsa"."AlterationPlans" ("Status"); + +INSERT INTO "Elsa"."__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20231015122203_Initial', '7.0.14'); + +COMMIT; + +START TRANSACTION; + +ALTER TABLE "Elsa"."AlterationPlans" RENAME COLUMN "SerializedWorkflowInstanceIds" TO "SerializedWorkflowInstanceFilter"; + +ALTER TABLE "Elsa"."AlterationPlans" ALTER COLUMN "Status" TYPE text; + +ALTER TABLE "Elsa"."AlterationJobs" ALTER COLUMN "Status" TYPE text; + +INSERT INTO "Elsa"."__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20240312145127_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Identity/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Identity/v3.1.sql new file mode 100755 index 000000000..c604b536b --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Identity/v3.1.sql @@ -0,0 +1,59 @@ + +CREATE TABLE IF NOT EXISTS "Elsa"."__EFMigrationsHistory" ( + "MigrationId" character varying(150) NOT NULL, + "ProductVersion" character varying(32) NOT NULL, + CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId") +); + +START TRANSACTION; + +CREATE TABLE "Elsa"."Applications" ( + "Id" text NOT NULL, + "ClientId" text NOT NULL, + "HashedClientSecret" text NOT NULL, + "HashedClientSecretSalt" text NOT NULL, + "Name" text NOT NULL, + "HashedApiKey" text NOT NULL, + "HashedApiKeySalt" text NOT NULL, + "Roles" text NOT NULL, + CONSTRAINT "PK_Applications" PRIMARY KEY ("Id") +); + +COMMIT; + +CREATE TABLE "Elsa"."Roles" ( + "Id" text NOT NULL, + "Name" text NOT NULL, + "Permissions" text NOT NULL, + CONSTRAINT "PK_Roles" PRIMARY KEY ("Id") +); + +CREATE TABLE "Elsa"."Users" ( + "Id" text NOT NULL, + "Name" text NOT NULL, + "HashedPassword" text NOT NULL, + "HashedPasswordSalt" text NOT NULL, + "Roles" text NOT NULL, + CONSTRAINT "PK_Users" PRIMARY KEY ("Id") +); + +CREATE UNIQUE INDEX "IX_Application_ClientId" ON "Elsa"."Applications" ("ClientId"); + +CREATE UNIQUE INDEX "IX_Application_Name" ON "Elsa"."Applications" ("Name"); + +CREATE UNIQUE INDEX "IX_Role_Name" ON "Elsa"."Roles" ("Name"); + +CREATE UNIQUE INDEX "IX_User_Name" ON "Elsa"."Users" ("Name"); + +INSERT INTO "Elsa"."__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20231015122250_Initial', '7.0.14'); + +COMMIT; + +START TRANSACTION; + +INSERT INTO "Elsa"."__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20240312145226_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Management/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Management/v3.1.sql new file mode 100755 index 000000000..a44d13cfc --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Management/v3.1.sql @@ -0,0 +1,105 @@ + +CREATE TABLE IF NOT EXISTS "Elsa"."__EFMigrationsHistory" ( + "MigrationId" character varying(150) NOT NULL, + "ProductVersion" character varying(32) NOT NULL, + CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId") +); + +START TRANSACTION; + +CREATE TABLE "Elsa"."WorkflowDefinitions" ( + "Id" text NOT NULL, + "DefinitionId" text NOT NULL, + "Name" text NULL, + "Description" text NULL, + "ToolVersion" text NULL, + "ProviderName" text NULL, + "MaterializerName" text NOT NULL, + "MaterializerContext" text NULL, + "StringData" text NULL, + "BinaryData" bytea NULL, + "IsReadonly" boolean NOT NULL, + "Data" text NULL, + "UsableAsActivity" boolean NULL, + "CreatedAt" timestamp with time zone NOT NULL, + "Version" integer NOT NULL, + "IsLatest" boolean NOT NULL, + "IsPublished" boolean NOT NULL, + CONSTRAINT "PK_WorkflowDefinitions" PRIMARY KEY ("Id") +); + +CREATE TABLE "Elsa"."WorkflowInstances" ( + "Id" text NOT NULL, + "DefinitionId" text NOT NULL, + "DefinitionVersionId" text NOT NULL, + "Version" integer NOT NULL, + "Status" text NOT NULL, + "SubStatus" text NOT NULL, + "CorrelationId" text NULL, + "Name" text NULL, + "IncidentCount" integer NOT NULL, + "CreatedAt" timestamp with time zone NOT NULL, + "UpdatedAt" timestamp with time zone NOT NULL, + "FinishedAt" timestamp with time zone NULL, + "Data" text NULL, + CONSTRAINT "PK_WorkflowInstances" PRIMARY KEY ("Id") +); + +CREATE UNIQUE INDEX "IX_WorkflowDefinition_DefinitionId_Version" ON "Elsa"."WorkflowDefinitions" ("DefinitionId", "Version"); + +CREATE INDEX "IX_WorkflowDefinition_IsLatest" ON "Elsa"."WorkflowDefinitions" ("IsLatest"); + +CREATE INDEX "IX_WorkflowDefinition_IsPublished" ON "Elsa"."WorkflowDefinitions" ("IsPublished"); + +CREATE INDEX "IX_WorkflowDefinition_Name" ON "Elsa"."WorkflowDefinitions" ("Name"); + +CREATE INDEX "IX_WorkflowDefinition_UsableAsActivity" ON "Elsa"."WorkflowDefinitions" ("UsableAsActivity"); + +CREATE INDEX "IX_WorkflowDefinition_Version" ON "Elsa"."WorkflowDefinitions" ("Version"); + +CREATE INDEX "IX_WorkflowInstance_CorrelationId" ON "Elsa"."WorkflowInstances" ("CorrelationId"); + +CREATE INDEX "IX_WorkflowInstance_CreatedAt" ON "Elsa"."WorkflowInstances" ("CreatedAt"); + +CREATE INDEX "IX_WorkflowInstance_DefinitionId" ON "Elsa"."WorkflowInstances" ("DefinitionId"); + +CREATE INDEX "IX_WorkflowInstance_FinishedAt" ON "Elsa"."WorkflowInstances" ("FinishedAt"); + +CREATE INDEX "IX_WorkflowInstance_Name" ON "Elsa"."WorkflowInstances" ("Name"); + +CREATE INDEX "IX_WorkflowInstance_Status" ON "Elsa"."WorkflowInstances" ("Status"); + +CREATE INDEX "IX_WorkflowInstance_Status_DefinitionId" ON "Elsa"."WorkflowInstances" ("Status", "DefinitionId"); + +CREATE INDEX "IX_WorkflowInstance_Status_SubStatus" ON "Elsa"."WorkflowInstances" ("Status", "SubStatus"); + +CREATE INDEX "IX_WorkflowInstance_Status_SubStatus_DefinitionId_Version" ON "Elsa"."WorkflowInstances" ("Status", "SubStatus", "DefinitionId", "Version"); + +CREATE INDEX "IX_WorkflowInstance_SubStatus" ON "Elsa"."WorkflowInstances" ("SubStatus"); + +CREATE INDEX "IX_WorkflowInstance_SubStatus_DefinitionId" ON "Elsa"."WorkflowInstances" ("SubStatus", "DefinitionId"); + +CREATE INDEX "IX_WorkflowInstance_UpdatedAt" ON "Elsa"."WorkflowInstances" ("UpdatedAt"); + +INSERT INTO "Elsa"."__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20231015122234_Initial', '7.0.14'); + +COMMIT; + +START TRANSACTION; + +ALTER TABLE "Elsa"."WorkflowInstances" ADD "DataCompressionAlgorithm" text NULL; + +ALTER TABLE "Elsa"."WorkflowInstances" ADD "IsSystem" boolean NOT NULL DEFAULT FALSE; + +ALTER TABLE "Elsa"."WorkflowDefinitions" ADD "IsSystem" boolean NOT NULL DEFAULT FALSE; + +CREATE INDEX "IX_WorkflowInstance_IsSystem" ON "Elsa"."WorkflowInstances" ("IsSystem"); + +CREATE INDEX "IX_WorkflowDefinition_IsSystem" ON "Elsa"."WorkflowDefinitions" ("IsSystem"); + +INSERT INTO "Elsa"."__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20240312145207_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Runtime/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Runtime/v3.1.sql new file mode 100755 index 000000000..9a618c3f1 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Migrations/Runtime/v3.1.sql @@ -0,0 +1,200 @@ +CREATE TABLE IF NOT EXISTS "Elsa"."__EFMigrationsHistory" ( + "MigrationId" character varying(150) NOT NULL, + "ProductVersion" character varying(32) NOT NULL, + CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId") +); + +START TRANSACTION; + +CREATE TABLE "Elsa"."ActivityExecutionRecords" ( + "Id" text NOT NULL, + "WorkflowInstanceId" text NOT NULL, + "ActivityId" text NOT NULL, + "ActivityNodeId" text NOT NULL, + "ActivityType" text NOT NULL, + "ActivityTypeVersion" integer NOT NULL, + "ActivityName" text NULL, + "StartedAt" timestamp with time zone NOT NULL, + "HasBookmarks" boolean NOT NULL, + "Status" text NOT NULL, + "CompletedAt" timestamp with time zone NULL, + "SerializedActivityState" text NULL, + "SerializedException" text NULL, + "SerializedOutputs" text NULL, + "SerializedPayload" text NULL, + CONSTRAINT "PK_ActivityExecutionRecords" PRIMARY KEY ("Id") +); + +CREATE TABLE "Elsa"."Bookmarks" ( + "BookmarkId" text NOT NULL, + "ActivityTypeName" text NOT NULL, + "Hash" text NOT NULL, + "WorkflowInstanceId" text NOT NULL, + "ActivityInstanceId" text NULL, + "CorrelationId" text NULL, + "CreatedAt" timestamp with time zone NOT NULL, + "SerializedMetadata" text NULL, + "SerializedPayload" text NULL, + CONSTRAINT "PK_Bookmarks" PRIMARY KEY ("BookmarkId") +); + +CREATE TABLE "Elsa"."Triggers" ( + "Id" text NOT NULL, + "WorkflowDefinitionId" text NOT NULL, + "WorkflowDefinitionVersionId" text NOT NULL, + "Name" text NOT NULL, + "ActivityId" text NOT NULL, + "Hash" text NULL, + "SerializedPayload" text NULL, + CONSTRAINT "PK_Triggers" PRIMARY KEY ("Id") +); + +CREATE TABLE "Elsa"."WorkflowExecutionLogRecords" ( + "Id" text NOT NULL, + "WorkflowDefinitionId" text NOT NULL, + "WorkflowDefinitionVersionId" text NOT NULL, + "WorkflowInstanceId" text NOT NULL, + "WorkflowVersion" integer NOT NULL, + "ActivityInstanceId" text NOT NULL, + "ParentActivityInstanceId" text NULL, + "ActivityId" text NOT NULL, + "ActivityType" text NOT NULL, + "ActivityTypeVersion" integer NOT NULL, + "ActivityName" text NULL, + "ActivityNodeId" text NOT NULL, + "Timestamp" timestamp with time zone NOT NULL, + "Sequence" bigint NOT NULL, + "EventName" text NULL, + "Message" text NULL, + "Source" text NULL, + "SerializedActivityState" text NULL, + "SerializedPayload" text NULL, + CONSTRAINT "PK_WorkflowExecutionLogRecords" PRIMARY KEY ("Id") +); + +CREATE TABLE "Elsa"."WorkflowInboxMessages" ( + "Id" text NOT NULL, + "ActivityTypeName" text NOT NULL, + "Hash" text NOT NULL, + "WorkflowInstanceId" text NULL, + "CorrelationId" text NULL, + "ActivityInstanceId" text NULL, + "CreatedAt" timestamp with time zone NOT NULL, + "ExpiresAt" timestamp with time zone NOT NULL, + "SerializedBookmarkPayload" text NULL, + "SerializedInput" text NULL, + CONSTRAINT "PK_WorkflowInboxMessages" PRIMARY KEY ("Id") +); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityId" ON "Elsa"."ActivityExecutionRecords" ("ActivityId"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityName" ON "Elsa"."ActivityExecutionRecords" ("ActivityName"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityNodeId" ON "Elsa"."ActivityExecutionRecords" ("ActivityNodeId"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityType" ON "Elsa"."ActivityExecutionRecords" ("ActivityType"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityType_ActivityTypeVersion" ON "Elsa"."ActivityExecutionRecords" ("ActivityType", "ActivityTypeVersion"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityTypeVersion" ON "Elsa"."ActivityExecutionRecords" ("ActivityTypeVersion"); + +CREATE INDEX "IX_ActivityExecutionRecord_CompletedAt" ON "Elsa"."ActivityExecutionRecords" ("CompletedAt"); + +CREATE INDEX "IX_ActivityExecutionRecord_HasBookmarks" ON "Elsa"."ActivityExecutionRecords" ("HasBookmarks"); + +CREATE INDEX "IX_ActivityExecutionRecord_StartedAt" ON "Elsa"."ActivityExecutionRecords" ("StartedAt"); + +CREATE INDEX "IX_ActivityExecutionRecord_Status" ON "Elsa"."ActivityExecutionRecords" ("Status"); + +CREATE INDEX "IX_ActivityExecutionRecord_WorkflowInstanceId" ON "Elsa"."ActivityExecutionRecords" ("WorkflowInstanceId"); + +CREATE INDEX "IX_StoredBookmark_ActivityInstanceId" ON "Elsa"."Bookmarks" ("ActivityInstanceId"); + +CREATE INDEX "IX_StoredBookmark_ActivityTypeName" ON "Elsa"."Bookmarks" ("ActivityTypeName"); + +CREATE INDEX "IX_StoredBookmark_ActivityTypeName_Hash" ON "Elsa"."Bookmarks" ("ActivityTypeName", "Hash"); + +CREATE INDEX "IX_StoredBookmark_ActivityTypeName_Hash_WorkflowInstanceId" ON "Elsa"."Bookmarks" ("ActivityTypeName", "Hash", "WorkflowInstanceId"); + +CREATE INDEX "IX_StoredBookmark_CreatedAt" ON "Elsa"."Bookmarks" ("CreatedAt"); + +CREATE INDEX "IX_StoredBookmark_Hash" ON "Elsa"."Bookmarks" ("Hash"); + +CREATE INDEX "IX_StoredBookmark_WorkflowInstanceId" ON "Elsa"."Bookmarks" ("WorkflowInstanceId"); + +CREATE INDEX "IX_StoredTrigger_Hash" ON "Elsa"."Triggers" ("Hash"); + +CREATE INDEX "IX_StoredTrigger_Name" ON "Elsa"."Triggers" ("Name"); + +CREATE INDEX "IX_StoredTrigger_WorkflowDefinitionId" ON "Elsa"."Triggers" ("WorkflowDefinitionId"); + +CREATE INDEX "IX_StoredTrigger_WorkflowDefinitionVersionId" ON "Elsa"."Triggers" ("WorkflowDefinitionVersionId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityId" ON "Elsa"."WorkflowExecutionLogRecords" ("ActivityId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityInstanceId" ON "Elsa"."WorkflowExecutionLogRecords" ("ActivityInstanceId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityName" ON "Elsa"."WorkflowExecutionLogRecords" ("ActivityName"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityNodeId" ON "Elsa"."WorkflowExecutionLogRecords" ("ActivityNodeId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityType" ON "Elsa"."WorkflowExecutionLogRecords" ("ActivityType"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityType_ActivityTypeVersion" ON "Elsa"."WorkflowExecutionLogRecords" ("ActivityType", "ActivityTypeVersion"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityTypeVersion" ON "Elsa"."WorkflowExecutionLogRecords" ("ActivityTypeVersion"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_EventName" ON "Elsa"."WorkflowExecutionLogRecords" ("EventName"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ParentActivityInstanceId" ON "Elsa"."WorkflowExecutionLogRecords" ("ParentActivityInstanceId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_Sequence" ON "Elsa"."WorkflowExecutionLogRecords" ("Sequence"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_Timestamp" ON "Elsa"."WorkflowExecutionLogRecords" ("Timestamp"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_Timestamp_Sequence" ON "Elsa"."WorkflowExecutionLogRecords" ("Timestamp", "Sequence"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_WorkflowDefinitionId" ON "Elsa"."WorkflowExecutionLogRecords" ("WorkflowDefinitionId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_WorkflowDefinitionVersionId" ON "Elsa"."WorkflowExecutionLogRecords" ("WorkflowDefinitionVersionId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_WorkflowInstanceId" ON "Elsa"."WorkflowExecutionLogRecords" ("WorkflowInstanceId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_WorkflowVersion" ON "Elsa"."WorkflowExecutionLogRecords" ("WorkflowVersion"); + +CREATE INDEX "IX_WorkflowInboxMessage_ActivityInstanceId" ON "Elsa"."WorkflowInboxMessages" ("ActivityInstanceId"); + +CREATE INDEX "IX_WorkflowInboxMessage_ActivityTypeName" ON "Elsa"."WorkflowInboxMessages" ("ActivityTypeName"); + +CREATE INDEX "IX_WorkflowInboxMessage_CorrelationId" ON "Elsa"."WorkflowInboxMessages" ("CorrelationId"); + +CREATE INDEX "IX_WorkflowInboxMessage_CreatedAt" ON "Elsa"."WorkflowInboxMessages" ("CreatedAt"); + +CREATE INDEX "IX_WorkflowInboxMessage_ExpiresAt" ON "Elsa"."WorkflowInboxMessages" ("ExpiresAt"); + +CREATE INDEX "IX_WorkflowInboxMessage_Hash" ON "Elsa"."WorkflowInboxMessages" ("Hash"); + +CREATE INDEX "IX_WorkflowInboxMessage_WorkflowInstanceId" ON "Elsa"."WorkflowInboxMessages" ("WorkflowInstanceId"); + +INSERT INTO "Elsa"."__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20231024160952_Initial', '7.0.14'); + +COMMIT; + +START TRANSACTION; + +ALTER TABLE "Elsa"."ActivityExecutionRecords" ADD "SerializedActivityStateCompressionAlgorithm" text NULL; + +ALTER TABLE "Elsa"."ActivityExecutionRecords" ADD "SerializedProperties" text NULL; + +CREATE TABLE "Elsa"."KeyValuePairs" ( + "Key" text NOT NULL, + "SerializedValue" text NOT NULL, + CONSTRAINT "PK_KeyValuePairs" PRIMARY KEY ("Key") +); + +INSERT INTO "Elsa"."__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20240312145147_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Alterations/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Alterations/v3.1.sql new file mode 100755 index 000000000..0aa241fa2 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Alterations/v3.1.sql @@ -0,0 +1,114 @@ +IF OBJECT_ID(N'[Elsa].[__EFMigrationsHistory]') IS NULL +BEGIN + IF SCHEMA_ID(N'Elsa') IS NULL EXEC(N'CREATE SCHEMA [Elsa];'); + CREATE TABLE [Elsa].[__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) + ); +END; +GO + +BEGIN TRANSACTION; +GO + +IF SCHEMA_ID(N'Elsa') IS NULL EXEC(N'CREATE SCHEMA [Elsa];'); +GO + +CREATE TABLE [Elsa].[AlterationJobs] ( + [Id] nvarchar(450) NOT NULL, + [PlanId] nvarchar(450) NOT NULL, + [WorkflowInstanceId] nvarchar(450) NOT NULL, + [Status] int NOT NULL, + [CreatedAt] datetimeoffset NOT NULL, + [StartedAt] datetimeoffset NULL, + [CompletedAt] datetimeoffset NULL, + [SerializedLog] nvarchar(max) NULL, + CONSTRAINT [PK_AlterationJobs] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Elsa].[AlterationPlans] ( + [Id] nvarchar(450) NOT NULL, + [Status] int NOT NULL, + [CreatedAt] datetimeoffset NOT NULL, + [StartedAt] datetimeoffset NULL, + [CompletedAt] datetimeoffset NULL, + [SerializedAlterations] nvarchar(max) NULL, + [SerializedWorkflowInstanceIds] nvarchar(max) NULL, + CONSTRAINT [PK_AlterationPlans] PRIMARY KEY ([Id]) +); +GO + +CREATE INDEX [IX_AlterationJob_CompletedAt] ON [Elsa].[AlterationJobs] ([CompletedAt]); +GO + +CREATE INDEX [IX_AlterationJob_CreatedAt] ON [Elsa].[AlterationJobs] ([CreatedAt]); +GO + +CREATE INDEX [IX_AlterationJob_PlanId] ON [Elsa].[AlterationJobs] ([PlanId]); +GO + +CREATE INDEX [IX_AlterationJob_StartedAt] ON [Elsa].[AlterationJobs] ([StartedAt]); +GO + +CREATE INDEX [IX_AlterationJob_Status] ON [Elsa].[AlterationJobs] ([Status]); +GO + +CREATE INDEX [IX_AlterationJob_WorkflowInstanceId] ON [Elsa].[AlterationJobs] ([WorkflowInstanceId]); +GO + +CREATE INDEX [IX_AlterationPlan_CompletedAt] ON [Elsa].[AlterationPlans] ([CompletedAt]); +GO + +CREATE INDEX [IX_AlterationPlan_CreatedAt] ON [Elsa].[AlterationPlans] ([CreatedAt]); +GO + +CREATE INDEX [IX_AlterationPlan_StartedAt] ON [Elsa].[AlterationPlans] ([StartedAt]); +GO + +CREATE INDEX [IX_AlterationPlan_Status] ON [Elsa].[AlterationPlans] ([Status]); +GO + +INSERT INTO [Elsa].[__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'20231015122155_Initial', N'7.0.14'); +GO + +COMMIT; +GO + +BEGIN TRANSACTION; +GO + +EXEC sp_rename N'[Elsa].[AlterationPlans].[SerializedWorkflowInstanceIds]', N'SerializedWorkflowInstanceFilter', N'COLUMN'; +GO + +DROP INDEX [IX_AlterationPlan_Status] ON [Elsa].[AlterationPlans]; +DECLARE @var0 sysname; +SELECT @var0 = [d].[name] +FROM [sys].[default_constraints] [d] +INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] +WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Elsa].[AlterationPlans]') AND [c].[name] = N'Status'); +IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Elsa].[AlterationPlans] DROP CONSTRAINT [' + @var0 + '];'); +ALTER TABLE [Elsa].[AlterationPlans] ALTER COLUMN [Status] nvarchar(450) NOT NULL; +CREATE INDEX [IX_AlterationPlan_Status] ON [Elsa].[AlterationPlans] ([Status]); +GO + +DROP INDEX [IX_AlterationJob_Status] ON [Elsa].[AlterationJobs]; +DECLARE @var1 sysname; +SELECT @var1 = [d].[name] +FROM [sys].[default_constraints] [d] +INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] +WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Elsa].[AlterationJobs]') AND [c].[name] = N'Status'); +IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [Elsa].[AlterationJobs] DROP CONSTRAINT [' + @var1 + '];'); +ALTER TABLE [Elsa].[AlterationJobs] ALTER COLUMN [Status] nvarchar(450) NOT NULL; +CREATE INDEX [IX_AlterationJob_Status] ON [Elsa].[AlterationJobs] ([Status]); +GO + +INSERT INTO [Elsa].[__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'20240312145115_V3_1', N'7.0.14'); +GO + +COMMIT; +GO + diff --git a/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Identity/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Identity/v3.1.sql new file mode 100755 index 000000000..2f343e4be --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Identity/v3.1.sql @@ -0,0 +1,77 @@ +IF OBJECT_ID(N'[Elsa].[__EFMigrationsHistory]') IS NULL +BEGIN + IF SCHEMA_ID(N'Elsa') IS NULL EXEC(N'CREATE SCHEMA [Elsa];'); + CREATE TABLE [Elsa].[__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) + ); +END; +GO + +BEGIN TRANSACTION; +GO + +IF SCHEMA_ID(N'Elsa') IS NULL EXEC(N'CREATE SCHEMA [Elsa];'); +GO + +CREATE TABLE [Elsa].[Applications] ( + [Id] nvarchar(450) NOT NULL, + [ClientId] nvarchar(450) NOT NULL, + [HashedClientSecret] nvarchar(max) NOT NULL, + [HashedClientSecretSalt] nvarchar(max) NOT NULL, + [Name] nvarchar(450) NOT NULL, + [HashedApiKey] nvarchar(max) NOT NULL, + [HashedApiKeySalt] nvarchar(max) NOT NULL, + [Roles] nvarchar(max) NOT NULL, + CONSTRAINT [PK_Applications] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Elsa].[Roles] ( + [Id] nvarchar(450) NOT NULL, + [Name] nvarchar(450) NOT NULL, + [Permissions] nvarchar(max) NOT NULL, + CONSTRAINT [PK_Roles] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Elsa].[Users] ( + [Id] nvarchar(450) NOT NULL, + [Name] nvarchar(450) NOT NULL, + [HashedPassword] nvarchar(max) NOT NULL, + [HashedPasswordSalt] nvarchar(max) NOT NULL, + [Roles] nvarchar(max) NOT NULL, + CONSTRAINT [PK_Users] PRIMARY KEY ([Id]) +); +GO + +CREATE UNIQUE INDEX [IX_Application_ClientId] ON [Elsa].[Applications] ([ClientId]); +GO + +CREATE UNIQUE INDEX [IX_Application_Name] ON [Elsa].[Applications] ([Name]); +GO + +CREATE UNIQUE INDEX [IX_Role_Name] ON [Elsa].[Roles] ([Name]); +GO + +CREATE UNIQUE INDEX [IX_User_Name] ON [Elsa].[Users] ([Name]); +GO + +INSERT INTO [Elsa].[__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'20231015122242_Initial', N'7.0.14'); +GO + +COMMIT; +GO + +BEGIN TRANSACTION; +GO + +INSERT INTO [Elsa].[__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'20240312145217_V3_1', N'7.0.14'); +GO + +COMMIT; +GO + diff --git a/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Management/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Management/v3.1.sql new file mode 100755 index 000000000..21d259f82 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Management/v3.1.sql @@ -0,0 +1,143 @@ +IF OBJECT_ID(N'[Elsa].[__EFMigrationsHistory]') IS NULL +BEGIN + IF SCHEMA_ID(N'Elsa') IS NULL EXEC(N'CREATE SCHEMA [Elsa];'); + CREATE TABLE [Elsa].[__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) + ); +END; +GO + +BEGIN TRANSACTION; +GO + +IF SCHEMA_ID(N'Elsa') IS NULL EXEC(N'CREATE SCHEMA [Elsa];'); +GO + +CREATE TABLE [Elsa].[WorkflowDefinitions] ( + [Id] nvarchar(450) NOT NULL, + [DefinitionId] nvarchar(450) NOT NULL, + [Name] nvarchar(450) NULL, + [Description] nvarchar(max) NULL, + [ToolVersion] nvarchar(max) NULL, + [ProviderName] nvarchar(max) NULL, + [MaterializerName] nvarchar(max) NOT NULL, + [MaterializerContext] nvarchar(max) NULL, + [StringData] nvarchar(max) NULL, + [BinaryData] varbinary(max) NULL, + [IsReadonly] bit NOT NULL, + [Data] nvarchar(max) NULL, + [UsableAsActivity] bit NULL, + [CreatedAt] datetimeoffset NOT NULL, + [Version] int NOT NULL, + [IsLatest] bit NOT NULL, + [IsPublished] bit NOT NULL, + CONSTRAINT [PK_WorkflowDefinitions] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Elsa].[WorkflowInstances] ( + [Id] nvarchar(450) NOT NULL, + [DefinitionId] nvarchar(450) NOT NULL, + [DefinitionVersionId] nvarchar(max) NOT NULL, + [Version] int NOT NULL, + [Status] nvarchar(450) NOT NULL, + [SubStatus] nvarchar(450) NOT NULL, + [CorrelationId] nvarchar(450) NULL, + [Name] nvarchar(450) NULL, + [IncidentCount] int NOT NULL, + [CreatedAt] datetimeoffset NOT NULL, + [UpdatedAt] datetimeoffset NOT NULL, + [FinishedAt] datetimeoffset NULL, + [Data] nvarchar(max) NULL, + CONSTRAINT [PK_WorkflowInstances] PRIMARY KEY ([Id]) +); +GO + +CREATE UNIQUE INDEX [IX_WorkflowDefinition_DefinitionId_Version] ON [Elsa].[WorkflowDefinitions] ([DefinitionId], [Version]); +GO + +CREATE INDEX [IX_WorkflowDefinition_IsLatest] ON [Elsa].[WorkflowDefinitions] ([IsLatest]); +GO + +CREATE INDEX [IX_WorkflowDefinition_IsPublished] ON [Elsa].[WorkflowDefinitions] ([IsPublished]); +GO + +CREATE INDEX [IX_WorkflowDefinition_Name] ON [Elsa].[WorkflowDefinitions] ([Name]); +GO + +CREATE INDEX [IX_WorkflowDefinition_UsableAsActivity] ON [Elsa].[WorkflowDefinitions] ([UsableAsActivity]); +GO + +CREATE INDEX [IX_WorkflowDefinition_Version] ON [Elsa].[WorkflowDefinitions] ([Version]); +GO + +CREATE INDEX [IX_WorkflowInstance_CorrelationId] ON [Elsa].[WorkflowInstances] ([CorrelationId]); +GO + +CREATE INDEX [IX_WorkflowInstance_CreatedAt] ON [Elsa].[WorkflowInstances] ([CreatedAt]); +GO + +CREATE INDEX [IX_WorkflowInstance_DefinitionId] ON [Elsa].[WorkflowInstances] ([DefinitionId]); +GO + +CREATE INDEX [IX_WorkflowInstance_FinishedAt] ON [Elsa].[WorkflowInstances] ([FinishedAt]); +GO + +CREATE INDEX [IX_WorkflowInstance_Name] ON [Elsa].[WorkflowInstances] ([Name]); +GO + +CREATE INDEX [IX_WorkflowInstance_Status] ON [Elsa].[WorkflowInstances] ([Status]); +GO + +CREATE INDEX [IX_WorkflowInstance_Status_DefinitionId] ON [Elsa].[WorkflowInstances] ([Status], [DefinitionId]); +GO + +CREATE INDEX [IX_WorkflowInstance_Status_SubStatus] ON [Elsa].[WorkflowInstances] ([Status], [SubStatus]); +GO + +CREATE INDEX [IX_WorkflowInstance_Status_SubStatus_DefinitionId_Version] ON [Elsa].[WorkflowInstances] ([Status], [SubStatus], [DefinitionId], [Version]); +GO + +CREATE INDEX [IX_WorkflowInstance_SubStatus] ON [Elsa].[WorkflowInstances] ([SubStatus]); +GO + +CREATE INDEX [IX_WorkflowInstance_SubStatus_DefinitionId] ON [Elsa].[WorkflowInstances] ([SubStatus], [DefinitionId]); +GO + +CREATE INDEX [IX_WorkflowInstance_UpdatedAt] ON [Elsa].[WorkflowInstances] ([UpdatedAt]); +GO + +INSERT INTO [Elsa].[__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'20231015122227_Initial', N'7.0.14'); +GO + +COMMIT; +GO + +BEGIN TRANSACTION; +GO + +ALTER TABLE [Elsa].[WorkflowInstances] ADD [DataCompressionAlgorithm] nvarchar(max) NULL; +GO + +ALTER TABLE [Elsa].[WorkflowInstances] ADD [IsSystem] bit NOT NULL DEFAULT CAST(0 AS bit); +GO + +ALTER TABLE [Elsa].[WorkflowDefinitions] ADD [IsSystem] bit NOT NULL DEFAULT CAST(0 AS bit); +GO + +CREATE INDEX [IX_WorkflowInstance_IsSystem] ON [Elsa].[WorkflowInstances] ([IsSystem]); +GO + +CREATE INDEX [IX_WorkflowDefinition_IsSystem] ON [Elsa].[WorkflowDefinitions] ([IsSystem]); +GO + +INSERT INTO [Elsa].[__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'20240312145157_V3_1', N'7.0.14'); +GO + +COMMIT; +GO + diff --git a/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Runtime/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Runtime/v3.1.sql new file mode 100755 index 000000000..66c022a6d --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.SqlServer/Migrations/Runtime/v3.1.sql @@ -0,0 +1,267 @@ +IF OBJECT_ID(N'[Elsa].[__EFMigrationsHistory]') IS NULL +BEGIN + IF SCHEMA_ID(N'Elsa') IS NULL EXEC(N'CREATE SCHEMA [Elsa];'); + CREATE TABLE [Elsa].[__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) + ); +END; +GO + +BEGIN TRANSACTION; +GO + +IF SCHEMA_ID(N'Elsa') IS NULL EXEC(N'CREATE SCHEMA [Elsa];'); +GO + +CREATE TABLE [Elsa].[ActivityExecutionRecords] ( + [Id] nvarchar(450) NOT NULL, + [WorkflowInstanceId] nvarchar(450) NOT NULL, + [ActivityId] nvarchar(450) NOT NULL, + [ActivityNodeId] nvarchar(450) NOT NULL, + [ActivityType] nvarchar(450) NOT NULL, + [ActivityTypeVersion] int NOT NULL, + [ActivityName] nvarchar(450) NULL, + [StartedAt] datetimeoffset NOT NULL, + [HasBookmarks] bit NOT NULL, + [Status] nvarchar(450) NOT NULL, + [CompletedAt] datetimeoffset NULL, + [SerializedActivityState] nvarchar(max) NULL, + [SerializedException] nvarchar(max) NULL, + [SerializedOutputs] nvarchar(max) NULL, + [SerializedPayload] nvarchar(max) NULL, + CONSTRAINT [PK_ActivityExecutionRecords] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Elsa].[Bookmarks] ( + [BookmarkId] nvarchar(450) NOT NULL, + [ActivityTypeName] nvarchar(450) NOT NULL, + [Hash] nvarchar(450) NOT NULL, + [WorkflowInstanceId] nvarchar(450) NOT NULL, + [ActivityInstanceId] nvarchar(450) NULL, + [CorrelationId] nvarchar(max) NULL, + [CreatedAt] datetimeoffset NOT NULL, + [SerializedMetadata] nvarchar(max) NULL, + [SerializedPayload] nvarchar(max) NULL, + CONSTRAINT [PK_Bookmarks] PRIMARY KEY ([BookmarkId]) +); +GO + +CREATE TABLE [Elsa].[Triggers] ( + [Id] nvarchar(450) NOT NULL, + [WorkflowDefinitionId] nvarchar(450) NOT NULL, + [WorkflowDefinitionVersionId] nvarchar(450) NOT NULL, + [Name] nvarchar(450) NOT NULL, + [ActivityId] nvarchar(max) NOT NULL, + [Hash] nvarchar(450) NULL, + [SerializedPayload] nvarchar(max) NULL, + CONSTRAINT [PK_Triggers] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Elsa].[WorkflowExecutionLogRecords] ( + [Id] nvarchar(450) NOT NULL, + [WorkflowDefinitionId] nvarchar(450) NOT NULL, + [WorkflowDefinitionVersionId] nvarchar(450) NOT NULL, + [WorkflowInstanceId] nvarchar(450) NOT NULL, + [WorkflowVersion] int NOT NULL, + [ActivityInstanceId] nvarchar(450) NOT NULL, + [ParentActivityInstanceId] nvarchar(450) NULL, + [ActivityId] nvarchar(450) NOT NULL, + [ActivityType] nvarchar(450) NOT NULL, + [ActivityTypeVersion] int NOT NULL, + [ActivityName] nvarchar(450) NULL, + [ActivityNodeId] nvarchar(450) NOT NULL, + [Timestamp] datetimeoffset NOT NULL, + [Sequence] bigint NOT NULL, + [EventName] nvarchar(450) NULL, + [Message] nvarchar(max) NULL, + [Source] nvarchar(max) NULL, + [SerializedActivityState] nvarchar(max) NULL, + [SerializedPayload] nvarchar(max) NULL, + CONSTRAINT [PK_WorkflowExecutionLogRecords] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Elsa].[WorkflowInboxMessages] ( + [Id] nvarchar(450) NOT NULL, + [ActivityTypeName] nvarchar(450) NOT NULL, + [Hash] nvarchar(450) NOT NULL, + [WorkflowInstanceId] nvarchar(450) NULL, + [CorrelationId] nvarchar(450) NULL, + [ActivityInstanceId] nvarchar(450) NULL, + [CreatedAt] datetimeoffset NOT NULL, + [ExpiresAt] datetimeoffset NOT NULL, + [SerializedBookmarkPayload] nvarchar(max) NULL, + [SerializedInput] nvarchar(max) NULL, + CONSTRAINT [PK_WorkflowInboxMessages] PRIMARY KEY ([Id]) +); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_ActivityId] ON [Elsa].[ActivityExecutionRecords] ([ActivityId]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_ActivityName] ON [Elsa].[ActivityExecutionRecords] ([ActivityName]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_ActivityNodeId] ON [Elsa].[ActivityExecutionRecords] ([ActivityNodeId]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_ActivityType] ON [Elsa].[ActivityExecutionRecords] ([ActivityType]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_ActivityType_ActivityTypeVersion] ON [Elsa].[ActivityExecutionRecords] ([ActivityType], [ActivityTypeVersion]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_ActivityTypeVersion] ON [Elsa].[ActivityExecutionRecords] ([ActivityTypeVersion]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_CompletedAt] ON [Elsa].[ActivityExecutionRecords] ([CompletedAt]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_HasBookmarks] ON [Elsa].[ActivityExecutionRecords] ([HasBookmarks]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_StartedAt] ON [Elsa].[ActivityExecutionRecords] ([StartedAt]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_Status] ON [Elsa].[ActivityExecutionRecords] ([Status]); +GO + +CREATE INDEX [IX_ActivityExecutionRecord_WorkflowInstanceId] ON [Elsa].[ActivityExecutionRecords] ([WorkflowInstanceId]); +GO + +CREATE INDEX [IX_StoredBookmark_ActivityInstanceId] ON [Elsa].[Bookmarks] ([ActivityInstanceId]); +GO + +CREATE INDEX [IX_StoredBookmark_ActivityTypeName] ON [Elsa].[Bookmarks] ([ActivityTypeName]); +GO + +CREATE INDEX [IX_StoredBookmark_ActivityTypeName_Hash] ON [Elsa].[Bookmarks] ([ActivityTypeName], [Hash]); +GO + +CREATE INDEX [IX_StoredBookmark_ActivityTypeName_Hash_WorkflowInstanceId] ON [Elsa].[Bookmarks] ([ActivityTypeName], [Hash], [WorkflowInstanceId]); +GO + +CREATE INDEX [IX_StoredBookmark_CreatedAt] ON [Elsa].[Bookmarks] ([CreatedAt]); +GO + +CREATE INDEX [IX_StoredBookmark_Hash] ON [Elsa].[Bookmarks] ([Hash]); +GO + +CREATE INDEX [IX_StoredBookmark_WorkflowInstanceId] ON [Elsa].[Bookmarks] ([WorkflowInstanceId]); +GO + +CREATE INDEX [IX_StoredTrigger_Hash] ON [Elsa].[Triggers] ([Hash]); +GO + +CREATE INDEX [IX_StoredTrigger_Name] ON [Elsa].[Triggers] ([Name]); +GO + +CREATE INDEX [IX_StoredTrigger_WorkflowDefinitionId] ON [Elsa].[Triggers] ([WorkflowDefinitionId]); +GO + +CREATE INDEX [IX_StoredTrigger_WorkflowDefinitionVersionId] ON [Elsa].[Triggers] ([WorkflowDefinitionVersionId]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_ActivityId] ON [Elsa].[WorkflowExecutionLogRecords] ([ActivityId]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_ActivityInstanceId] ON [Elsa].[WorkflowExecutionLogRecords] ([ActivityInstanceId]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_ActivityName] ON [Elsa].[WorkflowExecutionLogRecords] ([ActivityName]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_ActivityNodeId] ON [Elsa].[WorkflowExecutionLogRecords] ([ActivityNodeId]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_ActivityType] ON [Elsa].[WorkflowExecutionLogRecords] ([ActivityType]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_ActivityType_ActivityTypeVersion] ON [Elsa].[WorkflowExecutionLogRecords] ([ActivityType], [ActivityTypeVersion]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_ActivityTypeVersion] ON [Elsa].[WorkflowExecutionLogRecords] ([ActivityTypeVersion]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_EventName] ON [Elsa].[WorkflowExecutionLogRecords] ([EventName]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_ParentActivityInstanceId] ON [Elsa].[WorkflowExecutionLogRecords] ([ParentActivityInstanceId]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_Sequence] ON [Elsa].[WorkflowExecutionLogRecords] ([Sequence]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_Timestamp] ON [Elsa].[WorkflowExecutionLogRecords] ([Timestamp]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_Timestamp_Sequence] ON [Elsa].[WorkflowExecutionLogRecords] ([Timestamp], [Sequence]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_WorkflowDefinitionId] ON [Elsa].[WorkflowExecutionLogRecords] ([WorkflowDefinitionId]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_WorkflowDefinitionVersionId] ON [Elsa].[WorkflowExecutionLogRecords] ([WorkflowDefinitionVersionId]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_WorkflowInstanceId] ON [Elsa].[WorkflowExecutionLogRecords] ([WorkflowInstanceId]); +GO + +CREATE INDEX [IX_WorkflowExecutionLogRecord_WorkflowVersion] ON [Elsa].[WorkflowExecutionLogRecords] ([WorkflowVersion]); +GO + +CREATE INDEX [IX_WorkflowInboxMessage_ActivityInstanceId] ON [Elsa].[WorkflowInboxMessages] ([ActivityInstanceId]); +GO + +CREATE INDEX [IX_WorkflowInboxMessage_ActivityTypeName] ON [Elsa].[WorkflowInboxMessages] ([ActivityTypeName]); +GO + +CREATE INDEX [IX_WorkflowInboxMessage_CorrelationId] ON [Elsa].[WorkflowInboxMessages] ([CorrelationId]); +GO + +CREATE INDEX [IX_WorkflowInboxMessage_CreatedAt] ON [Elsa].[WorkflowInboxMessages] ([CreatedAt]); +GO + +CREATE INDEX [IX_WorkflowInboxMessage_ExpiresAt] ON [Elsa].[WorkflowInboxMessages] ([ExpiresAt]); +GO + +CREATE INDEX [IX_WorkflowInboxMessage_Hash] ON [Elsa].[WorkflowInboxMessages] ([Hash]); +GO + +CREATE INDEX [IX_WorkflowInboxMessage_WorkflowInstanceId] ON [Elsa].[WorkflowInboxMessages] ([WorkflowInstanceId]); +GO + +INSERT INTO [Elsa].[__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'20231024160944_Initial', N'7.0.14'); +GO + +COMMIT; +GO + +BEGIN TRANSACTION; +GO + +ALTER TABLE [Elsa].[ActivityExecutionRecords] ADD [SerializedActivityStateCompressionAlgorithm] nvarchar(max) NULL; +GO + +ALTER TABLE [Elsa].[ActivityExecutionRecords] ADD [SerializedProperties] nvarchar(max) NULL; +GO + +CREATE TABLE [Elsa].[KeyValuePairs] ( + [Key] nvarchar(450) NOT NULL, + [SerializedValue] nvarchar(max) NOT NULL, + CONSTRAINT [PK_KeyValuePairs] PRIMARY KEY ([Key]) +); +GO + +INSERT INTO [Elsa].[__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'20240312145137_V3_1', N'7.0.14'); +GO + +COMMIT; +GO + diff --git a/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Alterations/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Alterations/v3.1.sql new file mode 100755 index 000000000..9cc9461e3 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Alterations/v3.1.sql @@ -0,0 +1,131 @@ +CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ( + "MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY, + "ProductVersion" TEXT NOT NULL +); + +BEGIN TRANSACTION; + +CREATE TABLE "AlterationJobs" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_AlterationJobs" PRIMARY KEY, + "PlanId" TEXT NOT NULL, + "WorkflowInstanceId" TEXT NOT NULL, + "Status" INTEGER NOT NULL, + "CreatedAt" TEXT NOT NULL, + "StartedAt" TEXT NULL, + "CompletedAt" TEXT NULL, + "SerializedLog" TEXT NULL +); + +CREATE TABLE "AlterationPlans" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_AlterationPlans" PRIMARY KEY, + "Status" INTEGER NOT NULL, + "CreatedAt" TEXT NOT NULL, + "StartedAt" TEXT NULL, + "CompletedAt" TEXT NULL, + "SerializedAlterations" TEXT NULL, + "SerializedWorkflowInstanceIds" TEXT NULL +); + +CREATE INDEX "IX_AlterationJob_CompletedAt" ON "AlterationJobs" ("CompletedAt"); + +CREATE INDEX "IX_AlterationJob_CreatedAt" ON "AlterationJobs" ("CreatedAt"); + +CREATE INDEX "IX_AlterationJob_PlanId" ON "AlterationJobs" ("PlanId"); + +CREATE INDEX "IX_AlterationJob_StartedAt" ON "AlterationJobs" ("StartedAt"); + +CREATE INDEX "IX_AlterationJob_Status" ON "AlterationJobs" ("Status"); + +CREATE INDEX "IX_AlterationJob_WorkflowInstanceId" ON "AlterationJobs" ("WorkflowInstanceId"); + +CREATE INDEX "IX_AlterationPlan_CompletedAt" ON "AlterationPlans" ("CompletedAt"); + +CREATE INDEX "IX_AlterationPlan_CreatedAt" ON "AlterationPlans" ("CreatedAt"); + +CREATE INDEX "IX_AlterationPlan_StartedAt" ON "AlterationPlans" ("StartedAt"); + +CREATE INDEX "IX_AlterationPlan_Status" ON "AlterationPlans" ("Status"); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20231015122159_Initial', '7.0.14'); + +COMMIT; + +BEGIN TRANSACTION; + +ALTER TABLE "AlterationPlans" RENAME COLUMN "SerializedWorkflowInstanceIds" TO "SerializedWorkflowInstanceFilter"; + +CREATE TABLE "ef_temp_AlterationPlans" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_AlterationPlans" PRIMARY KEY, + "CompletedAt" TEXT NULL, + "CreatedAt" TEXT NOT NULL, + "SerializedAlterations" TEXT NULL, + "SerializedWorkflowInstanceFilter" TEXT NULL, + "StartedAt" TEXT NULL, + "Status" TEXT NOT NULL +); + +INSERT INTO "ef_temp_AlterationPlans" ("Id", "CompletedAt", "CreatedAt", "SerializedAlterations", "SerializedWorkflowInstanceFilter", "StartedAt", "Status") +SELECT "Id", "CompletedAt", "CreatedAt", "SerializedAlterations", "SerializedWorkflowInstanceFilter", "StartedAt", "Status" +FROM "AlterationPlans"; + +CREATE TABLE "ef_temp_AlterationJobs" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_AlterationJobs" PRIMARY KEY, + "CompletedAt" TEXT NULL, + "CreatedAt" TEXT NOT NULL, + "PlanId" TEXT NOT NULL, + "SerializedLog" TEXT NULL, + "StartedAt" TEXT NULL, + "Status" TEXT NOT NULL, + "WorkflowInstanceId" TEXT NOT NULL +); + +INSERT INTO "ef_temp_AlterationJobs" ("Id", "CompletedAt", "CreatedAt", "PlanId", "SerializedLog", "StartedAt", "Status", "WorkflowInstanceId") +SELECT "Id", "CompletedAt", "CreatedAt", "PlanId", "SerializedLog", "StartedAt", "Status", "WorkflowInstanceId" +FROM "AlterationJobs"; + +COMMIT; + +PRAGMA foreign_keys = 0; + +BEGIN TRANSACTION; + +DROP TABLE "AlterationPlans"; + +ALTER TABLE "ef_temp_AlterationPlans" RENAME TO "AlterationPlans"; + +DROP TABLE "AlterationJobs"; + +ALTER TABLE "ef_temp_AlterationJobs" RENAME TO "AlterationJobs"; + +COMMIT; + +PRAGMA foreign_keys = 1; + +BEGIN TRANSACTION; + +CREATE INDEX "IX_AlterationPlan_CompletedAt" ON "AlterationPlans" ("CompletedAt"); + +CREATE INDEX "IX_AlterationPlan_CreatedAt" ON "AlterationPlans" ("CreatedAt"); + +CREATE INDEX "IX_AlterationPlan_StartedAt" ON "AlterationPlans" ("StartedAt"); + +CREATE INDEX "IX_AlterationPlan_Status" ON "AlterationPlans" ("Status"); + +CREATE INDEX "IX_AlterationJob_CompletedAt" ON "AlterationJobs" ("CompletedAt"); + +CREATE INDEX "IX_AlterationJob_CreatedAt" ON "AlterationJobs" ("CreatedAt"); + +CREATE INDEX "IX_AlterationJob_PlanId" ON "AlterationJobs" ("PlanId"); + +CREATE INDEX "IX_AlterationJob_StartedAt" ON "AlterationJobs" ("StartedAt"); + +CREATE INDEX "IX_AlterationJob_Status" ON "AlterationJobs" ("Status"); + +CREATE INDEX "IX_AlterationJob_WorkflowInstanceId" ON "AlterationJobs" ("WorkflowInstanceId"); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20240312145121_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Identity/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Identity/v3.1.sql new file mode 100755 index 000000000..c6118c85f --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Identity/v3.1.sql @@ -0,0 +1,52 @@ +CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ( + "MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY, + "ProductVersion" TEXT NOT NULL +); + +BEGIN TRANSACTION; + +CREATE TABLE "Applications" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_Applications" PRIMARY KEY, + "ClientId" TEXT NOT NULL, + "HashedClientSecret" TEXT NOT NULL, + "HashedClientSecretSalt" TEXT NOT NULL, + "Name" TEXT NOT NULL, + "HashedApiKey" TEXT NOT NULL, + "HashedApiKeySalt" TEXT NOT NULL, + "Roles" TEXT NOT NULL +); + +CREATE TABLE "Roles" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_Roles" PRIMARY KEY, + "Name" TEXT NOT NULL, + "Permissions" TEXT NOT NULL +); + +CREATE TABLE "Users" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_Users" PRIMARY KEY, + "Name" TEXT NOT NULL, + "HashedPassword" TEXT NOT NULL, + "HashedPasswordSalt" TEXT NOT NULL, + "Roles" TEXT NOT NULL +); + +CREATE UNIQUE INDEX "IX_Application_ClientId" ON "Applications" ("ClientId"); + +CREATE UNIQUE INDEX "IX_Application_Name" ON "Applications" ("Name"); + +CREATE UNIQUE INDEX "IX_Role_Name" ON "Roles" ("Name"); + +CREATE UNIQUE INDEX "IX_User_Name" ON "Users" ("Name"); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20231015122246_Initial', '7.0.14'); + +COMMIT; + +BEGIN TRANSACTION; + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20240312145221_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Management/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Management/v3.1.sql new file mode 100755 index 000000000..b12055d5c --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Management/v3.1.sql @@ -0,0 +1,101 @@ +CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ( + "MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY, + "ProductVersion" TEXT NOT NULL +); + +BEGIN TRANSACTION; + +CREATE TABLE "WorkflowDefinitions" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_WorkflowDefinitions" PRIMARY KEY, + "DefinitionId" TEXT NOT NULL, + "Name" TEXT NULL, + "Description" TEXT NULL, + "ToolVersion" TEXT NULL, + "ProviderName" TEXT NULL, + "MaterializerName" TEXT NOT NULL, + "MaterializerContext" TEXT NULL, + "StringData" TEXT NULL, + "BinaryData" BLOB NULL, + "IsReadonly" INTEGER NOT NULL, + "Data" TEXT NULL, + "UsableAsActivity" INTEGER NULL, + "CreatedAt" TEXT NOT NULL, + "Version" INTEGER NOT NULL, + "IsLatest" INTEGER NOT NULL, + "IsPublished" INTEGER NOT NULL +); + +CREATE TABLE "WorkflowInstances" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_WorkflowInstances" PRIMARY KEY, + "DefinitionId" TEXT NOT NULL, + "DefinitionVersionId" TEXT NOT NULL, + "Version" INTEGER NOT NULL, + "Status" TEXT NOT NULL, + "SubStatus" TEXT NOT NULL, + "CorrelationId" TEXT NULL, + "Name" TEXT NULL, + "IncidentCount" INTEGER NOT NULL, + "CreatedAt" TEXT NOT NULL, + "UpdatedAt" TEXT NOT NULL, + "FinishedAt" TEXT NULL, + "Data" TEXT NULL +); + +CREATE UNIQUE INDEX "IX_WorkflowDefinition_DefinitionId_Version" ON "WorkflowDefinitions" ("DefinitionId", "Version"); + +CREATE INDEX "IX_WorkflowDefinition_IsLatest" ON "WorkflowDefinitions" ("IsLatest"); + +CREATE INDEX "IX_WorkflowDefinition_IsPublished" ON "WorkflowDefinitions" ("IsPublished"); + +CREATE INDEX "IX_WorkflowDefinition_Name" ON "WorkflowDefinitions" ("Name"); + +CREATE INDEX "IX_WorkflowDefinition_UsableAsActivity" ON "WorkflowDefinitions" ("UsableAsActivity"); + +CREATE INDEX "IX_WorkflowDefinition_Version" ON "WorkflowDefinitions" ("Version"); + +CREATE INDEX "IX_WorkflowInstance_CorrelationId" ON "WorkflowInstances" ("CorrelationId"); + +CREATE INDEX "IX_WorkflowInstance_CreatedAt" ON "WorkflowInstances" ("CreatedAt"); + +CREATE INDEX "IX_WorkflowInstance_DefinitionId" ON "WorkflowInstances" ("DefinitionId"); + +CREATE INDEX "IX_WorkflowInstance_FinishedAt" ON "WorkflowInstances" ("FinishedAt"); + +CREATE INDEX "IX_WorkflowInstance_Name" ON "WorkflowInstances" ("Name"); + +CREATE INDEX "IX_WorkflowInstance_Status" ON "WorkflowInstances" ("Status"); + +CREATE INDEX "IX_WorkflowInstance_Status_DefinitionId" ON "WorkflowInstances" ("Status", "DefinitionId"); + +CREATE INDEX "IX_WorkflowInstance_Status_SubStatus" ON "WorkflowInstances" ("Status", "SubStatus"); + +CREATE INDEX "IX_WorkflowInstance_Status_SubStatus_DefinitionId_Version" ON "WorkflowInstances" ("Status", "SubStatus", "DefinitionId", "Version"); + +CREATE INDEX "IX_WorkflowInstance_SubStatus" ON "WorkflowInstances" ("SubStatus"); + +CREATE INDEX "IX_WorkflowInstance_SubStatus_DefinitionId" ON "WorkflowInstances" ("SubStatus", "DefinitionId"); + +CREATE INDEX "IX_WorkflowInstance_UpdatedAt" ON "WorkflowInstances" ("UpdatedAt"); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20231015122231_Initial', '7.0.14'); + +COMMIT; + +BEGIN TRANSACTION; + +ALTER TABLE "WorkflowInstances" ADD "DataCompressionAlgorithm" TEXT NULL; + +ALTER TABLE "WorkflowInstances" ADD "IsSystem" INTEGER NOT NULL DEFAULT 0; + +ALTER TABLE "WorkflowDefinitions" ADD "IsSystem" INTEGER NOT NULL DEFAULT 0; + +CREATE INDEX "IX_WorkflowInstance_IsSystem" ON "WorkflowInstances" ("IsSystem"); + +CREATE INDEX "IX_WorkflowDefinition_IsSystem" ON "WorkflowDefinitions" ("IsSystem"); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20240312145202_V3_1', '7.0.14'); + +COMMIT; + diff --git a/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Runtime/v3.1.sql b/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Runtime/v3.1.sql new file mode 100755 index 000000000..b56150711 --- /dev/null +++ b/src/modules/Elsa.EntityFrameworkCore.Sqlite/Migrations/Runtime/v3.1.sql @@ -0,0 +1,193 @@ +CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ( + "MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY, + "ProductVersion" TEXT NOT NULL +); + +BEGIN TRANSACTION; + +CREATE TABLE "ActivityExecutionRecords" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_ActivityExecutionRecords" PRIMARY KEY, + "WorkflowInstanceId" TEXT NOT NULL, + "ActivityId" TEXT NOT NULL, + "ActivityNodeId" TEXT NOT NULL, + "ActivityType" TEXT NOT NULL, + "ActivityTypeVersion" INTEGER NOT NULL, + "ActivityName" TEXT NULL, + "StartedAt" TEXT NOT NULL, + "HasBookmarks" INTEGER NOT NULL, + "Status" TEXT NOT NULL, + "CompletedAt" TEXT NULL, + "SerializedActivityState" TEXT NULL, + "SerializedException" TEXT NULL, + "SerializedOutputs" TEXT NULL, + "SerializedPayload" TEXT NULL +); + +CREATE TABLE "Bookmarks" ( + "BookmarkId" TEXT NOT NULL CONSTRAINT "PK_Bookmarks" PRIMARY KEY, + "ActivityTypeName" TEXT NOT NULL, + "Hash" TEXT NOT NULL, + "WorkflowInstanceId" TEXT NOT NULL, + "ActivityInstanceId" TEXT NULL, + "CorrelationId" TEXT NULL, + "CreatedAt" TEXT NOT NULL, + "SerializedMetadata" TEXT NULL, + "SerializedPayload" TEXT NULL +); + +CREATE TABLE "Triggers" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_Triggers" PRIMARY KEY, + "WorkflowDefinitionId" TEXT NOT NULL, + "WorkflowDefinitionVersionId" TEXT NOT NULL, + "Name" TEXT NOT NULL, + "ActivityId" TEXT NOT NULL, + "Hash" TEXT NULL, + "SerializedPayload" TEXT NULL +); + +CREATE TABLE "WorkflowExecutionLogRecords" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_WorkflowExecutionLogRecords" PRIMARY KEY, + "WorkflowDefinitionId" TEXT NOT NULL, + "WorkflowDefinitionVersionId" TEXT NOT NULL, + "WorkflowInstanceId" TEXT NOT NULL, + "WorkflowVersion" INTEGER NOT NULL, + "ActivityInstanceId" TEXT NOT NULL, + "ParentActivityInstanceId" TEXT NULL, + "ActivityId" TEXT NOT NULL, + "ActivityType" TEXT NOT NULL, + "ActivityTypeVersion" INTEGER NOT NULL, + "ActivityName" TEXT NULL, + "ActivityNodeId" TEXT NOT NULL, + "Timestamp" TEXT NOT NULL, + "Sequence" INTEGER NOT NULL, + "EventName" TEXT NULL, + "Message" TEXT NULL, + "Source" TEXT NULL, + "SerializedActivityState" TEXT NULL, + "SerializedPayload" TEXT NULL +); + +CREATE TABLE "WorkflowInboxMessages" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_WorkflowInboxMessages" PRIMARY KEY, + "ActivityTypeName" TEXT NOT NULL, + "Hash" TEXT NOT NULL, + "WorkflowInstanceId" TEXT NULL, + "CorrelationId" TEXT NULL, + "ActivityInstanceId" TEXT NULL, + "CreatedAt" TEXT NOT NULL, + "ExpiresAt" TEXT NOT NULL, + "SerializedBookmarkPayload" TEXT NULL, + "SerializedInput" TEXT NULL +); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityId" ON "ActivityExecutionRecords" ("ActivityId"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityName" ON "ActivityExecutionRecords" ("ActivityName"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityNodeId" ON "ActivityExecutionRecords" ("ActivityNodeId"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityType" ON "ActivityExecutionRecords" ("ActivityType"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityType_ActivityTypeVersion" ON "ActivityExecutionRecords" ("ActivityType", "ActivityTypeVersion"); + +CREATE INDEX "IX_ActivityExecutionRecord_ActivityTypeVersion" ON "ActivityExecutionRecords" ("ActivityTypeVersion"); + +CREATE INDEX "IX_ActivityExecutionRecord_CompletedAt" ON "ActivityExecutionRecords" ("CompletedAt"); + +CREATE INDEX "IX_ActivityExecutionRecord_HasBookmarks" ON "ActivityExecutionRecords" ("HasBookmarks"); + +CREATE INDEX "IX_ActivityExecutionRecord_StartedAt" ON "ActivityExecutionRecords" ("StartedAt"); + +CREATE INDEX "IX_ActivityExecutionRecord_Status" ON "ActivityExecutionRecords" ("Status"); + +CREATE INDEX "IX_ActivityExecutionRecord_WorkflowInstanceId" ON "ActivityExecutionRecords" ("WorkflowInstanceId"); + +CREATE INDEX "IX_StoredBookmark_ActivityInstanceId" ON "Bookmarks" ("ActivityInstanceId"); + +CREATE INDEX "IX_StoredBookmark_ActivityTypeName" ON "Bookmarks" ("ActivityTypeName"); + +CREATE INDEX "IX_StoredBookmark_ActivityTypeName_Hash" ON "Bookmarks" ("ActivityTypeName", "Hash"); + +CREATE INDEX "IX_StoredBookmark_ActivityTypeName_Hash_WorkflowInstanceId" ON "Bookmarks" ("ActivityTypeName", "Hash", "WorkflowInstanceId"); + +CREATE INDEX "IX_StoredBookmark_CreatedAt" ON "Bookmarks" ("CreatedAt"); + +CREATE INDEX "IX_StoredBookmark_Hash" ON "Bookmarks" ("Hash"); + +CREATE INDEX "IX_StoredBookmark_WorkflowInstanceId" ON "Bookmarks" ("WorkflowInstanceId"); + +CREATE INDEX "IX_StoredTrigger_Hash" ON "Triggers" ("Hash"); + +CREATE INDEX "IX_StoredTrigger_Name" ON "Triggers" ("Name"); + +CREATE INDEX "IX_StoredTrigger_WorkflowDefinitionId" ON "Triggers" ("WorkflowDefinitionId"); + +CREATE INDEX "IX_StoredTrigger_WorkflowDefinitionVersionId" ON "Triggers" ("WorkflowDefinitionVersionId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityId" ON "WorkflowExecutionLogRecords" ("ActivityId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityInstanceId" ON "WorkflowExecutionLogRecords" ("ActivityInstanceId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityName" ON "WorkflowExecutionLogRecords" ("ActivityName"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityNodeId" ON "WorkflowExecutionLogRecords" ("ActivityNodeId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityType" ON "WorkflowExecutionLogRecords" ("ActivityType"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityType_ActivityTypeVersion" ON "WorkflowExecutionLogRecords" ("ActivityType", "ActivityTypeVersion"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ActivityTypeVersion" ON "WorkflowExecutionLogRecords" ("ActivityTypeVersion"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_EventName" ON "WorkflowExecutionLogRecords" ("EventName"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_ParentActivityInstanceId" ON "WorkflowExecutionLogRecords" ("ParentActivityInstanceId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_Sequence" ON "WorkflowExecutionLogRecords" ("Sequence"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_Timestamp" ON "WorkflowExecutionLogRecords" ("Timestamp"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_Timestamp_Sequence" ON "WorkflowExecutionLogRecords" ("Timestamp", "Sequence"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_WorkflowDefinitionId" ON "WorkflowExecutionLogRecords" ("WorkflowDefinitionId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_WorkflowDefinitionVersionId" ON "WorkflowExecutionLogRecords" ("WorkflowDefinitionVersionId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_WorkflowInstanceId" ON "WorkflowExecutionLogRecords" ("WorkflowInstanceId"); + +CREATE INDEX "IX_WorkflowExecutionLogRecord_WorkflowVersion" ON "WorkflowExecutionLogRecords" ("WorkflowVersion"); + +CREATE INDEX "IX_WorkflowInboxMessage_ActivityInstanceId" ON "WorkflowInboxMessages" ("ActivityInstanceId"); + +CREATE INDEX "IX_WorkflowInboxMessage_ActivityTypeName" ON "WorkflowInboxMessages" ("ActivityTypeName"); + +CREATE INDEX "IX_WorkflowInboxMessage_CorrelationId" ON "WorkflowInboxMessages" ("CorrelationId"); + +CREATE INDEX "IX_WorkflowInboxMessage_CreatedAt" ON "WorkflowInboxMessages" ("CreatedAt"); + +CREATE INDEX "IX_WorkflowInboxMessage_ExpiresAt" ON "WorkflowInboxMessages" ("ExpiresAt"); + +CREATE INDEX "IX_WorkflowInboxMessage_Hash" ON "WorkflowInboxMessages" ("Hash"); + +CREATE INDEX "IX_WorkflowInboxMessage_WorkflowInstanceId" ON "WorkflowInboxMessages" ("WorkflowInstanceId"); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20231024160948_Initial', '7.0.14'); + +COMMIT; + +BEGIN TRANSACTION; + +ALTER TABLE "ActivityExecutionRecords" ADD "SerializedActivityStateCompressionAlgorithm" TEXT NULL; + +ALTER TABLE "ActivityExecutionRecords" ADD "SerializedProperties" TEXT NULL; + +CREATE TABLE "KeyValuePairs" ( + "Key" TEXT NOT NULL CONSTRAINT "PK_KeyValuePairs" PRIMARY KEY, + "SerializedValue" TEXT NOT NULL +); + +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('20240312145142_V3_1', '7.0.14'); + +COMMIT; +