diff --git a/Dockerfile b/Dockerfile index c6ea7ff95..ec4fa4f11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,10 +20,11 @@ RUN mkdir -p /home/baget /home/baget/.nuget/NuGet &&\ useradd -d /home/baget -s /bin/bash -u 1000 -g baget baget &&\ chown -R baget:baget /home/baget /var/baget/ -ENV ASPNETCORE_ENVIRONMENT=Development \ +ENV ASPNETCORE_ENVIRONMENT=Production \ ApiKeyHash=658489D79E218D2474D049E8729198D86DB0A4AF43981686A31C7DCB02DC0900 \ Storage__Type=FileSystem \ Storage__Path=/var/baget/packages \ + Database__RunMigrations=true \ Database__Type=Sqlite \ Database__ConnectionString="Data Source=/var/baget/db/sqlite.db" \ Search__Type=Database diff --git a/src/BaGet.Core/Configuration/DatabaseOptions.cs b/src/BaGet.Core/Configuration/DatabaseOptions.cs index 570426c21..cc8be9111 100644 --- a/src/BaGet.Core/Configuration/DatabaseOptions.cs +++ b/src/BaGet.Core/Configuration/DatabaseOptions.cs @@ -2,6 +2,7 @@ { public class DatabaseOptions { + public bool RunMigrations { get; set; } public DatabaseType Type { get; set; } public string ConnectionString { get; set; } } diff --git a/src/BaGet/Startup.cs b/src/BaGet/Startup.cs index 047501717..24eb143e8 100644 --- a/src/BaGet/Startup.cs +++ b/src/BaGet/Startup.cs @@ -1,5 +1,6 @@ using System; using BaGet.Configurations; +using BaGet.Core.Configuration; using BaGet.Core.Entities; using BaGet.Extensions; using BaGet.Web.Extensions; @@ -8,6 +9,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; namespace BaGet { @@ -32,11 +34,15 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseDeveloperExceptionPage(); app.UseStatusCodePages(); + } - // Run migrations automatically in development mode. + // Run migrations if enabled + var databaseOptions = app.ApplicationServices.GetRequiredService>() + .Value + .Database; + if(databaseOptions.RunMigrations) { var scopeFactory = app.ApplicationServices .GetRequiredService(); - using (var scope = scopeFactory.CreateScope()) { scope.ServiceProvider diff --git a/src/BaGet/appsettings.json b/src/BaGet/appsettings.json index 8378b5000..396ac1341 100644 --- a/src/BaGet/appsettings.json +++ b/src/BaGet/appsettings.json @@ -2,6 +2,7 @@ "ApiKeyHash": "", "Database": { + "RunMigrations": true, "Type": "Sqlite", "ConnectionString": "Data Source=baget.db" },