Add Postgres support to Elsa.Server.Web

Introduced support for PostgreSQL in the Elsa Server configuration and updated the docker-compose to reflect the new database option. Adjusted the dependencies to include the EntityFrameworkCore PostgreSQL project reference.
This commit is contained in:
Sipke Schoorstra 2024-03-19 11:38:51 +01:00
parent 47d4d20606
commit 3140b72e15
5 changed files with 14 additions and 2 deletions

View file

@ -45,7 +45,7 @@ services:
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgrespw
POSTGRES_DB: elsa
POSTGRES_DB: postgres
ports:
- "5432:5432"
volumes:

View file

@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\modules\Elsa.EntityFrameworkCore.PostgreSql\Elsa.EntityFrameworkCore.PostgreSql.csproj" />
<ProjectReference Include="..\..\modules\Elsa.MassTransit.AzureServiceBus\Elsa.MassTransit.AzureServiceBus.csproj" />
<ProjectReference Include="..\Elsa\Elsa.csproj" />
<ProjectReference Include="..\..\common\Elsa.DropIns\Elsa.DropIns.csproj" />

View file

@ -24,6 +24,7 @@ using Proto.Persistence.SqlServer;
const bool useMongoDb = false;
const bool useSqlServer = false;
const bool usePostgres = false;
const bool useDapper = false;
const bool useProtoActor = false;
const bool useHangfire = false;
@ -39,6 +40,7 @@ var identitySection = configuration.GetSection("Identity");
var identityTokenSection = identitySection.GetSection("Tokens");
var sqliteConnectionString = configuration.GetConnectionString("Sqlite")!;
var sqlServerConnectionString = configuration.GetConnectionString("SqlServer")!;
var postgresConnectionString = configuration.GetConnectionString("PostgreSql")!;
var mongoDbConnectionString = configuration.GetConnectionString("MongoDb")!;
var azureServiceBusConnectionString = configuration.GetConnectionString("AzureServiceBus")!;
var rabbitMqConnectionString = configuration.GetConnectionString("RabbitMq")!;
@ -88,6 +90,8 @@ services
{
if (useSqlServer)
ef.UseSqlServer(sqlServerConnectionString!);
else if (usePostgres)
ef.UsePostgreSql(postgresConnectionString!);
else
ef.UseSqlite(sqliteConnectionString);
});
@ -110,6 +114,8 @@ services
{
if (useSqlServer)
ef.UseSqlServer(sqlServerConnectionString!);
else if (usePostgres)
ef.UsePostgreSql(postgresConnectionString!);
else
ef.UseSqlite(sqliteConnectionString);
});
@ -128,6 +134,8 @@ services
{
if (useSqlServer)
ef.UseSqlServer(sqlServerConnectionString!);
else if (usePostgres)
ef.UsePostgreSql(postgresConnectionString!);
else
ef.UseSqlite(sqliteConnectionString);
});
@ -207,6 +215,8 @@ services
{
if (useSqlServer)
ef.UseSqlServer(sqlServerConnectionString);
else if (usePostgres)
ef.UsePostgreSql(postgresConnectionString);
else
ef.UseSqlite(sqliteConnectionString);
});

View file

@ -15,6 +15,7 @@
"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",
"MongoDb": "mongodb://localhost:27017/elsa-workflows",
"AzureServiceBus": "",
"RabbitMq": "amqp://guest:guest@localhost:5672"

View file

@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using Elsa.Extensions;
using Elsa.Scheduling.Bookmarks;
using Elsa.Scheduling.Contracts;