From 148501a80ec11d8c1138880768a2e4cea08960f3 Mon Sep 17 00:00:00 2001 From: Simon Reid <94547286+reidst@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:26:14 -0600 Subject: [PATCH] Configure DB & Redis & add migration bundle --- .github/workflows/main_iseegreen.yml | 6 ++++++ Program.cs | 8 +++++++- appsettings.json | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main_iseegreen.yml b/.github/workflows/main_iseegreen.yml index ae6e523..1c197ed 100644 --- a/.github/workflows/main_iseegreen.yml +++ b/.github/workflows/main_iseegreen.yml @@ -28,6 +28,12 @@ jobs: - name: dotnet publish run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp + - name: Install .NET EF Core + run: dotnet tool install -g dotnet-ef --version 7.0.14 + + - name: Generate database migration bundle + run: dotnet ef migrations bundle --runtime linux-x64 -p DotNetCoreSqlDb/DotNetCoreSqlDb.csproj -o ${{env.DOTNET_ROOT}}/myapp/migrate + - name: Upload artifact for deployment job uses: actions/upload-artifact@v3 with: diff --git a/Program.cs b/Program.cs index 7069e8f..1148c13 100644 --- a/Program.cs +++ b/Program.cs @@ -7,7 +7,13 @@ // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddDbContext(options => - options.UseSqlite(builder.Configuration.GetConnectionString("ISeeGreenContextSQLite") ?? throw new InvalidOperationException("Connection string 'ISeeGreenContext' not found."))); + options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING") ?? throw new InvalidOperationException("Connection string 'AZURE_SQL_CONNECTIONSTRING' not found."))); + +builder.Services.AddStackExchangeRedisCache(options => +{ + options.Configuration = builder.Configuration["AZURE_REDIS_CONNECTIONSTRING"]; + options.InstanceName = "SampleInstance"; +}); builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = false) .AddEntityFrameworkStores(); diff --git a/appsettings.json b/appsettings.json index 9fd0cb3..c57fbc4 100644 --- a/appsettings.json +++ b/appsettings.json @@ -8,6 +8,6 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "ISeeGreenContextSQLite": "Data Source=ISG.db" + "AZURE_SQL_CONNECTIONSTRING": "Data Source=iseegreen-server.database.windows.net,1433;Initial Catalog=iseegreen-database;User ID=iseegreen-server-admin;Password=877GX404CJ8S7MS8$" } } \ No newline at end of file