database and migrations

This commit is contained in:
Anton Martynenko
2025-10-28 11:07:07 +01:00
parent b9508137cb
commit f8d96ec40f
20 changed files with 471 additions and 1 deletions
+20
View File
@@ -2,9 +2,22 @@ using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using SatelliteProvider.DataAccess;
using SatelliteProvider.DataAccess.Repositories;
using SatelliteProvider.Common.Configs;
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.Configure<MapConfig>(builder.Configuration.GetSection("MapConfig"));
builder.Services.Configure<StorageConfig>(builder.Configuration.GetSection("StorageConfig"));
builder.Services.Configure<ProcessingConfig>(builder.Configuration.GetSection("ProcessingConfig"));
builder.Services.AddSingleton<ITileRepository>(sp => new TileRepository(connectionString));
builder.Services.AddSingleton<IRegionRepository>(sp => new RegionRepository(connectionString));
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
@@ -32,6 +45,13 @@ builder.Services.AddSwaggerGen(c =>
var app = builder.Build();
var logger = app.Services.GetRequiredService<ILogger<Program>>();
var migrator = new DatabaseMigrator(connectionString, logger as ILogger<DatabaseMigrator>);
if (!migrator.RunMigrations())
{
throw new Exception("Database migration failed. Application cannot start.");
}
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
@@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\SatelliteProvider.Common\SatelliteProvider.Common.csproj" />
<ProjectReference Include="..\SatelliteProvider.DataAccess\SatelliteProvider.DataAccess.csproj" />
</ItemGroup>
</Project>
@@ -4,5 +4,16 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=satelliteprovider;Username=postgres;Password=postgres"
},
"MapConfig": {
"Service": "GoogleMaps",
"ApiKey": "YOUR_API_KEY_HERE"
},
"StorageConfig": {
"TilesDirectory": "./tiles",
"ReadyDirectory": "./ready"
}
}
+17 -1
View File
@@ -5,5 +5,21 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=satelliteprovider;Username=postgres;Password=postgres"
},
"MapConfig": {
"Service": "GoogleMaps",
"ApiKey": "YOUR_API_KEY_HERE"
},
"StorageConfig": {
"TilesDirectory": "./tiles",
"ReadyDirectory": "./ready"
},
"ProcessingConfig": {
"MaxConcurrentDownloads": 4,
"DefaultZoomLevel": 20,
"QueueCapacity": 100
}
}