diff --git a/Hoo.Service/Common/Extensions/MigrationExtensions.cs b/Hoo.Service/Common/Extensions/MigrationExtensions.cs new file mode 100644 index 0000000..863cbca --- /dev/null +++ b/Hoo.Service/Common/Extensions/MigrationExtensions.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; +using Hoo.Service.Data; + +namespace Hoo.Service.Common.Extensions; + +public static class MigrationExtensions +{ + public static void ApplyMigrations(this IApplicationBuilder app) + { + using IServiceScope scope = app.ApplicationServices.CreateScope(); + + using HooDbContext dbContext = scope.ServiceProvider.GetRequiredService(); + + dbContext.Database.Migrate(); + } +} diff --git a/Hoo.Service/Common/MochiLogMessageModel.cs b/Hoo.Service/Common/MochiLogMessageModel.cs index 87987aa..c077f94 100644 --- a/Hoo.Service/Common/MochiLogMessageModel.cs +++ b/Hoo.Service/Common/MochiLogMessageModel.cs @@ -1,4 +1,4 @@ -namespace Qilin.Service.Common +namespace Hoo.Service.Common { public class MochiLogMessageModel { diff --git a/Hoo.Service/Common/MochiLogger.cs b/Hoo.Service/Common/MochiLogger.cs index 25b7a30..b193674 100644 --- a/Hoo.Service/Common/MochiLogger.cs +++ b/Hoo.Service/Common/MochiLogger.cs @@ -1,4 +1,4 @@ -namespace Qilin.Service.Common +namespace Hoo.Service.Common { public class MochiLogger : ILogger { diff --git a/Hoo.Service/Common/MochiLoggerProvider.cs b/Hoo.Service/Common/MochiLoggerProvider.cs index 32918c8..4e303c4 100644 --- a/Hoo.Service/Common/MochiLoggerProvider.cs +++ b/Hoo.Service/Common/MochiLoggerProvider.cs @@ -1,4 +1,4 @@ -namespace Qilin.Service.Common +namespace Hoo.Service.Common { public class MochiLoggerProvider : ILoggerProvider { diff --git a/Hoo.Service/Controllers/FileController.cs b/Hoo.Service/Controllers/FileController.cs index 924a77f..143124c 100644 --- a/Hoo.Service/Controllers/FileController.cs +++ b/Hoo.Service/Controllers/FileController.cs @@ -1,9 +1,9 @@ -using Hoo.Service.Models; +using Hoo.Service.Common; +using Hoo.Service.Models; using Hoo.Service.Services; using Hoo.Service.Services.GoogleDrive; using Hoo.Service.Services.OneDrive; using Hoo.Service.Services.WebFiles; -using HooService.Common; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; diff --git a/Hoo.Service/Controllers/UtilsController.cs b/Hoo.Service/Controllers/UtilsController.cs index 715ed0f..432528f 100644 --- a/Hoo.Service/Controllers/UtilsController.cs +++ b/Hoo.Service/Controllers/UtilsController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; -namespace HooService.Controllers +namespace Hoo.Service.Controllers { [ApiController] public class UtilsController : ControllerBase diff --git a/Hoo.Service/Controllers/WebFileController.cs b/Hoo.Service/Controllers/WebFileController.cs index 39bf7e4..6ea65ba 100644 --- a/Hoo.Service/Controllers/WebFileController.cs +++ b/Hoo.Service/Controllers/WebFileController.cs @@ -1,9 +1,8 @@ using Hoo.Service.Models; using Hoo.Service.Services.WebFiles; using Microsoft.AspNetCore.Mvc; -using HooService.Common; -namespace HooService.Controllers +namespace Hoo.Service.Controllers { [ApiController] public class WebFileController : ControllerBase diff --git a/Hoo.Service/Hoo.Service.csproj b/Hoo.Service/Hoo.Service.csproj index daca742..c34faf2 100644 --- a/Hoo.Service/Hoo.Service.csproj +++ b/Hoo.Service/Hoo.Service.csproj @@ -17,6 +17,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Hoo.Service/Program.cs b/Hoo.Service/Program.cs index d519738..3a6f202 100644 --- a/Hoo.Service/Program.cs +++ b/Hoo.Service/Program.cs @@ -6,9 +6,9 @@ using Hoo.Service.Services.GoogleDrive; using Hoo.Service.Services.OneDrive; using Hoo.Service.Services.WebFiles; -using HooService.Common; using Microsoft.EntityFrameworkCore; -using Qilin.Service.Common; +using Hoo.Service.Common; +using Hoo.Service.Common.Extensions; var builder = WebApplication.CreateBuilder(args); @@ -27,9 +27,12 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); + +// builder.Services.AddDbContext(options => +// options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))); builder.Services.AddDbContext(options => - options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))); + options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -50,11 +53,12 @@ app.UseCors("AllowAllOrigins"); // Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ +// if (app.Environment.IsDevelopment()) +// { app.UseSwagger(); app.UseSwaggerUI(); -} + app.ApplyMigrations(); +// } // app.UseHttpsRedirection(); diff --git a/Hoo.Service/Services/HooFileProviderService.cs b/Hoo.Service/Services/HooFileProviderService.cs index 77fbb3d..901b88c 100644 --- a/Hoo.Service/Services/HooFileProviderService.cs +++ b/Hoo.Service/Services/HooFileProviderService.cs @@ -7,7 +7,7 @@ using Hoo.Service.Services.WebFiles; using Microsoft.Graph.Models.Security; -namespace HooService.Common +namespace Hoo.Service.Common { public class HooFileProviderService : IFileProviderService { diff --git a/Hoo.Service/Services/HooFileThumbnailProviderService.cs b/Hoo.Service/Services/HooFileThumbnailProviderService.cs index 488650d..6c32b28 100644 --- a/Hoo.Service/Services/HooFileThumbnailProviderService.cs +++ b/Hoo.Service/Services/HooFileThumbnailProviderService.cs @@ -6,7 +6,6 @@ using Hoo.Service.Services.GoogleDrive; using Hoo.Service.Services.OneDrive; using Hoo.Service.Services.WebFiles; -using HooService.Common; namespace Hoo.Service.Services { diff --git a/Hoo.Service/Services/IFileProviderService.cs b/Hoo.Service/Services/IFileProviderService.cs index 405bb43..1ea2a01 100644 --- a/Hoo.Service/Services/IFileProviderService.cs +++ b/Hoo.Service/Services/IFileProviderService.cs @@ -2,7 +2,7 @@ using Hoo.Service.Models; using Microsoft.AspNetCore.Mvc; -namespace HooService.Common +namespace Hoo.Service.Common { public interface IFileProviderService { diff --git a/Hoo.Service/Services/WebFiles/WebFileService.cs b/Hoo.Service/Services/WebFiles/WebFileService.cs index 11f54a8..96414ee 100644 --- a/Hoo.Service/Services/WebFiles/WebFileService.cs +++ b/Hoo.Service/Services/WebFiles/WebFileService.cs @@ -1,6 +1,5 @@ using Hoo.Service.Models; using Hoo.Service.Repository.WebFiles; -using HooService.Controllers; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; diff --git a/Hoo.Service/appsettings.json b/Hoo.Service/appsettings.json index dfe05da..a86b15d 100644 --- a/Hoo.Service/appsettings.json +++ b/Hoo.Service/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "DataSource=hoo.db" + "DefaultConnection": "Host=dosei;Username=gumi;Password=gumi;Database=hoo" }, "AllowedHosts": "*", "Logging": {