mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-04-22 11:36:38 +00:00
database and migrations
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user