Skip to content

Commit ddfd7e9

Browse files
author
Poorya
committed
parameterize postgres provider schema name
1 parent c182dce commit ddfd7e9

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

src/providers/WorkflowCore.Persistence.PostgreSQL/MigrationContextFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class MigrationContextFactory : IDesignTimeDbContextFactory<PostgresConte
77
{
88
public PostgresContext CreateDbContext(string[] args)
99
{
10-
return new PostgresContext(@"Server=127.0.0.1;Port=5432;Database=workflow;User Id=postgres;Password=password;");
10+
return new PostgresContext(@"Server=127.0.0.1;Port=5432;Database=workflow;User Id=postgres;Password=password;","wfc");
1111
}
1212
}
1313
}

src/providers/WorkflowCore.Persistence.PostgreSQL/PostgresContext.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ namespace WorkflowCore.Persistence.PostgreSQL
1212
public class PostgresContext : WorkflowDbContext
1313
{
1414
private readonly string _connectionString;
15+
private readonly string _schemaName;
1516

16-
public PostgresContext(string connectionString)
17+
public PostgresContext(string connectionString,string schemaName)
1718
:base()
1819
{
1920
_connectionString = connectionString;
21+
_schemaName = schemaName;
2022
}
2123

2224
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
@@ -27,37 +29,37 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2729

2830
protected override void ConfigureSubscriptionStorage(EntityTypeBuilder<PersistedSubscription> builder)
2931
{
30-
builder.ToTable("Subscription", "wfc");
32+
builder.ToTable("Subscription", _schemaName);
3133
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
3234
}
3335

3436
protected override void ConfigureWorkflowStorage(EntityTypeBuilder<PersistedWorkflow> builder)
3537
{
36-
builder.ToTable("Workflow", "wfc");
38+
builder.ToTable("Workflow", _schemaName);
3739
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
3840
}
3941

4042
protected override void ConfigureExecutionPointerStorage(EntityTypeBuilder<PersistedExecutionPointer> builder)
4143
{
42-
builder.ToTable("ExecutionPointer", "wfc");
44+
builder.ToTable("ExecutionPointer", _schemaName);
4345
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
4446
}
4547

4648
protected override void ConfigureExecutionErrorStorage(EntityTypeBuilder<PersistedExecutionError> builder)
4749
{
48-
builder.ToTable("ExecutionError", "wfc");
50+
builder.ToTable("ExecutionError", _schemaName);
4951
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
5052
}
5153

5254
protected override void ConfigureExetensionAttributeStorage(EntityTypeBuilder<PersistedExtensionAttribute> builder)
5355
{
54-
builder.ToTable("ExtensionAttribute", "wfc");
56+
builder.ToTable("ExtensionAttribute", _schemaName);
5557
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
5658
}
5759

5860
protected override void ConfigureEventStorage(EntityTypeBuilder<PersistedEvent> builder)
5961
{
60-
builder.ToTable("Event", "wfc");
62+
builder.ToTable("Event", _schemaName);
6163
builder.Property(x => x.PersistenceId).ValueGeneratedOnAdd();
6264
}
6365
}

src/providers/WorkflowCore.Persistence.PostgreSQL/PostgresContextFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ namespace WorkflowCore.Persistence.PostgreSQL
99
public class PostgresContextFactory : IWorkflowDbContextFactory
1010
{
1111
private readonly string _connectionString;
12+
private readonly string _schemaName;
1213

13-
public PostgresContextFactory(string connectionString)
14+
public PostgresContextFactory(string connectionString, string schemaName)
1415
{
1516
_connectionString = connectionString;
17+
_schemaName = schemaName;
1618
}
1719

1820
public WorkflowDbContext Build()
1921
{
20-
return new PostgresContext(_connectionString);
22+
return new PostgresContext(_connectionString,_schemaName);
2123
}
2224
}
2325
}

src/providers/WorkflowCore.Persistence.PostgreSQL/ServiceCollectionExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ namespace Microsoft.Extensions.DependencyInjection
1010
{
1111
public static class ServiceCollectionExtensions
1212
{
13-
public static WorkflowOptions UsePostgreSQL(this WorkflowOptions options, string connectionString, bool canCreateDB, bool canMigrateDB)
13+
public static WorkflowOptions UsePostgreSQL(this WorkflowOptions options,
14+
string connectionString, bool canCreateDB, bool canMigrateDB, string schemaName="wfc")
1415
{
15-
options.UsePersistence(sp => new EntityFrameworkPersistenceProvider(new PostgresContextFactory(connectionString), canCreateDB, canMigrateDB));
16+
options.UsePersistence(sp => new EntityFrameworkPersistenceProvider(new PostgresContextFactory(connectionString, schemaName), canCreateDB, canMigrateDB));
1617
return options;
1718
}
1819
}

test/WorkflowCore.Tests.PostgreSQL/PostgresPersistenceProviderFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PostgresPersistenceProviderFixture : BasePersistenceFixture
1919
public PostgresPersistenceProviderFixture(PostgresDockerSetup dockerSetup, ITestOutputHelper output)
2020
{
2121
output.WriteLine($"Connecting on {PostgresDockerSetup.ConnectionString}");
22-
_subject = new EntityFrameworkPersistenceProvider(new PostgresContextFactory(PostgresDockerSetup.ConnectionString), true, true);
22+
_subject = new EntityFrameworkPersistenceProvider(new PostgresContextFactory(PostgresDockerSetup.ConnectionString,"wfc"), true, true);
2323
_subject.EnsureStoreExists();
2424
}
2525
}

0 commit comments

Comments
 (0)