-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatabaseExtensions.cs
More file actions
107 lines (93 loc) · 4.53 KB
/
DatabaseExtensions.cs
File metadata and controls
107 lines (93 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Projects;
namespace Aspire.AppHost.Extensions;
public static class DatabaseExtensions
{
public static IResourceBuilder<SqlServerServerResource> AddDmsSqlServer(
this IDistributedApplicationBuilder builder,
IResourceBuilder<ParameterResource> password)
{
#pragma warning disable ASPIREPROXYENDPOINTS001
return builder.AddSqlServer("sql", password, 61749)
.WithDataVolume("dms-data")
.WithLifetime(ContainerLifetime.Persistent)
.WithEndpointProxySupport(false)
.WithImageTag("2022-latest");
#pragma warning restore ASPIREPROXYENDPOINTS001
}
public static DmsDatabaseResources AddDmsDatabases(
this IDistributedApplicationBuilder builder,
IResourceBuilder<SqlServerServerResource> sqlServer,
bool seedData = false)
{
var audit = sqlServer.AddDatabase("AuditDb");
var offlocStaging = sqlServer.AddDatabase("OfflocStagingDb");
var deliusStaging = sqlServer.AddDatabase("DeliusStagingDb");
var deliusRunningPicture = sqlServer.AddDatabase("DeliusRunningPictureDb");
var offlocRunningPicture = sqlServer.AddDatabase("OfflocRunningPictureDb");
var matching = sqlServer.AddDatabase("MatchingDb");
var cluster = sqlServer.AddDatabase("ClusterDb");
var auditSqlProj = builder.AddSqlProject<AuditDb>("Audit")
.WithReference(audit);
var offlocStagingSqlProj = builder.AddSqlProject<OfflocStagingDb>("OfflocStaging")
.WithReference(offlocStaging)
.WithSkipWhenDeployed();
var deliusStagingSqlProj = builder.AddSqlProject<DeliusStagingDb>("DeliusStaging")
.WithReference(deliusStaging)
.WithSkipWhenDeployed();
var deliusRunningPictureSqlProj = builder.AddSqlProject<DeliusRunningPictureDb>("DeliusRunningPicture")
.WithReference(deliusRunningPicture)
.WithSkipWhenDeployed();
var offlocRunningPictureSqlProj = builder.AddSqlProject<OfflocRunningPictureDb>("OfflocRunningPicture")
.WithReference(offlocRunningPicture)
.WithSkipWhenDeployed();
var matchingSqlProj = builder.AddSqlProject<MatchingDb>("Matching")
.WithReference(matching)
.WithConfigureDacDeployOptions(options => {
options.SetVariable("DeliusRunningPictureDb", "DeliusRunningPictureDb");
options.SetVariable("OfflocRunningPictureDb", "OfflocRunningPictureDb");
})
.WaitForCompletion(deliusRunningPictureSqlProj)
.WaitForCompletion(offlocRunningPictureSqlProj)
.WithSkipWhenDeployed();
var clusterSqlProj = builder.AddSqlProject<ClusterDb>("Cluster")
.WithReference(cluster)
.WithConfigureDacDeployOptions(options =>
{
options.SetVariable("MatchingDb", "MatchingDb");
options.SetVariable("DeliusRunningPictureDb", "DeliusRunningPictureDb");
options.SetVariable("OfflocRunningPictureDb", "OfflocRunningPictureDb");
options.SetVariable("PopulateReferenceTables", "True");
})
.WaitForCompletion(matchingSqlProj)
.WaitForCompletion(deliusRunningPictureSqlProj)
.WaitForCompletion(offlocRunningPictureSqlProj)
.WithSkipWhenDeployed();
if (seedData)
{
builder.AddProject<FakeDataSeeder>("FakeDataSeeder")
.WithReference(cluster)
.WaitForCompletion(clusterSqlProj);
}
return new DmsDatabaseResources(
new DmsDatabaseResource(audit, auditSqlProj),
new DmsDatabaseResource(offlocStaging, offlocStagingSqlProj),
new DmsDatabaseResource(deliusStaging, deliusStagingSqlProj),
new DmsDatabaseResource(deliusRunningPicture, deliusRunningPictureSqlProj),
new DmsDatabaseResource(offlocRunningPicture, offlocRunningPictureSqlProj),
new DmsDatabaseResource(matching, matchingSqlProj),
new DmsDatabaseResource(cluster, clusterSqlProj)
);
}
}
public record DmsDatabaseResources(
DmsDatabaseResource Audit,
DmsDatabaseResource OfflocStaging,
DmsDatabaseResource DeliusStaging,
DmsDatabaseResource DeliusRunningPicture,
DmsDatabaseResource OfflocRunningPicture,
DmsDatabaseResource Matching,
DmsDatabaseResource Cluster
);
public record DmsDatabaseResource(
IResourceBuilder<SqlServerDatabaseResource> DatabaseResource,
IResourceBuilder<SqlProjectResource> SqlProjectResource);