Remove /api prefix from all routes and fix CityId FK constraint
- 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>
This commit is contained in:
@@ -13,6 +13,23 @@ 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();
|
||||
|
||||
Reference in New Issue
Block a user