b3612f5bec
- Strip /api prefix from all endpoint routes - Make Show.CityId nullable (no longer required FK) - Drop CityId FK constraint and alter column to NULL at startup via raw SQL - Add migration MakeCityIdNullable for schema consistency - Update Show DTOs to reflect nullable CityId Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using FastEndpoints;
|
|
using FastEndpoints.Swagger;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PyroFetes;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddDbContext<PyroFetesDbContext>(options =>
|
|
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
|
|
|
builder.Services.AddFastEndpoints();
|
|
builder.Services.SwaggerDocument();
|
|
|
|
var app = builder.Build();
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var db = scope.ServiceProvider.GetRequiredService<PyroFetesDbContext>();
|
|
db.Database.ExecuteSqlRaw("""
|
|
IF EXISTS (
|
|
SELECT 1 FROM sys.foreign_keys
|
|
WHERE name = 'FK_Shows_Cities_CityId' AND parent_object_id = OBJECT_ID('Shows')
|
|
)
|
|
ALTER TABLE Shows DROP CONSTRAINT FK_Shows_Cities_CityId
|
|
""");
|
|
db.Database.ExecuteSqlRaw("""
|
|
IF COL_LENGTH('Shows', 'CityId') IS NOT NULL
|
|
AND COLUMNPROPERTY(OBJECT_ID('Shows'), 'CityId', 'AllowsNull') = 0
|
|
ALTER TABLE Shows ALTER COLUMN CityId INT NULL
|
|
""");
|
|
}
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwaggerGen();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseFastEndpoints();
|
|
|
|
app.Run();
|
|
|