Globinours/migrations/047_backfill_missing_animal_entries.sql

6 lines
462 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

INSERT INTO animal_movements(animal_id,kind,place,lieu,note,created_at)
SELECT a.id,'entry',COALESCE(NULLIF(trim(a.rescue_location_name),''),NULLIF(trim(a.rescue_address),'')),
'Entrée historique','Informations dentrée à compléter dans la fiche animale',
COALESCE(NULLIF(a.intake_date,'')||' 12:00:00',a.created_at,datetime('now'))
FROM animals a
WHERE NOT EXISTS(SELECT 1 FROM animal_movements m WHERE m.animal_id=a.id AND m.kind='entry');