Skip to content

Commit 69de173

Browse files
author
Cephas Lin
committed
run migrations based on environment
1 parent 3a828dc commit 69de173

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Program.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
using Microsoft.EntityFrameworkCore;
2-
using Microsoft.Extensions.DependencyInjection;
32
using DotNetCoreSqlDb.Data;
43
var builder = WebApplication.CreateBuilder(args);
54

65
// Add database context and cache
7-
builder.Services.AddDbContext<MyDatabaseContext>(options =>
8-
options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING")));
9-
builder.Services.AddStackExchangeRedisCache(options =>
6+
if(builder.Environment.IsDevelopment())
107
{
11-
options.Configuration = builder.Configuration["AZURE_REDIS_CONNECTIONSTRING"];
12-
options.InstanceName = "SampleInstance";
13-
});
8+
builder.Services.AddDbContext<MyDatabaseContext>(options =>
9+
options.UseSqlServer(builder.Configuration.GetConnectionString("MyDbConnection")));
10+
builder.Services.AddDistributedMemoryCache();
11+
}
12+
else
13+
{
14+
builder.Services.AddDbContext<MyDatabaseContext>(options =>
15+
options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING")));
16+
builder.Services.AddStackExchangeRedisCache(options =>
17+
{
18+
options.Configuration = builder.Configuration["AZURE_REDIS_CONNECTIONSTRING"];
19+
options.InstanceName = "SampleInstance";
20+
});
21+
}
22+
1423

1524
// Add services to the container.
1625
builder.Services.AddControllersWithViews();

infra/resources.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ resource web 'Microsoft.Web/sites@2022-09-01' = {
252252
linuxFxVersion: 'DOTNETCORE|8.0' // Set to .NET 8 (LTS)
253253
vnetRouteAllEnabled: true // Route outbound traffic to the VNET
254254
ftpsState: 'Disabled'
255-
appCommandLine: './migrationsbundle && dotnet "DotNetCoreSqlDb.dll"'
255+
appCommandLine: './migrationsbundle -- --environment Production && dotnet "DotNetCoreSqlDb.dll"'
256256
}
257257
serverFarmId: appServicePlan.id
258258
httpsOnly: true

0 commit comments

Comments
 (0)