From 3f5eed25f4a5f2d3248f28aa0ee5495a91eec628 Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Tue, 24 Mar 2026 16:21:57 +0200 Subject: [PATCH] fix(geoportal): DROP enrichment views before recreate (column change) PostgreSQL CREATE OR REPLACE VIEW fails when column structure changes. Now drops views first, then recreates them. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/app/api/geoportal/setup-enrichment-views/route.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/api/geoportal/setup-enrichment-views/route.ts b/src/app/api/geoportal/setup-enrichment-views/route.ts index f18b946..5229eea 100644 --- a/src/app/api/geoportal/setup-enrichment-views/route.ts +++ b/src/app/api/geoportal/setup-enrichment-views/route.ts @@ -82,11 +82,13 @@ export async function GET() { } } -/** POST — create enrichment views (idempotent) */ +/** POST — create enrichment views (idempotent, drops first if structure changed) */ export async function POST() { const results: string[] = []; try { for (const v of VIEWS) { + // DROP first — CREATE OR REPLACE fails when columns change + await prisma.$executeRawUnsafe(`DROP VIEW IF EXISTS ${v.name} CASCADE`); await prisma.$executeRawUnsafe(v.sql); results.push(`${v.name} OK`); }