Files
xamxam/app/migrations/applied/013_fix_csv_column_shift.sql
Pontoporeia 3f87d71e38 Fix: CSV importer and imported data
- pad rows, distinguish empty year, better error diagnostics
- derive year from identifier when year column is empty
- fix remaining 18 theses: Installation/Performance (slash→dash) orientation alias
- csv importer: use column-name-based header detection instead of hardcoded positions
2026-05-07 12:35:31 +02:00

31 lines
1.3 KiB
SQL

-- Fix theses that were imported with column-shifted CSV data.
-- Orientation names ended up in synopsis, finality names in context_note,
-- and keywords in remarks. Move them to the correct FK columns.
-- 1. Fix orientation_id from synopsis
UPDATE theses SET
orientation_id = (SELECT o.id FROM orientations o WHERE LOWER(o.name) = LOWER(theses.synopsis)),
synopsis = NULL
WHERE orientation_id IS NULL
AND synopsis IS NOT NULL
AND synopsis != ''
AND EXISTS (SELECT 1 FROM orientations o WHERE LOWER(o.name) = LOWER(theses.synopsis));
-- 2. Fix finality_id from context_note
UPDATE theses SET
finality_id = (SELECT ft.id FROM finality_types ft WHERE LOWER(ft.name) = LOWER(theses.context_note)),
context_note = NULL
WHERE finality_id IS NULL
AND context_note IS NOT NULL
AND context_note != ''
AND EXISTS (SELECT 1 FROM finality_types ft WHERE LOWER(ft.name) = LOWER(theses.context_note));
-- 3. Fix AP program from synopsis (if any synopsis values match AP names — edge case)
UPDATE theses SET
ap_program_id = (SELECT ap.id FROM ap_programs ap WHERE LOWER(ap.name) = LOWER(theses.synopsis)),
synopsis = NULL
WHERE ap_program_id IS NULL
AND synopsis IS NOT NULL
AND synopsis != ''
AND EXISTS (SELECT 1 FROM ap_programs ap WHERE LOWER(ap.name) = LOWER(theses.synopsis));