16 lines
1.3 KiB
SQL
16 lines
1.3 KiB
SQL
ALTER TABLE animals ADD COLUMN intake_type TEXT NOT NULL DEFAULT 'unknown'
|
||
CHECK (intake_type IN ('unknown','found','owner_surrender','transfer','born_in_care','return','seizure','other'));
|
||
ALTER TABLE animals ADD COLUMN intake_reason TEXT NOT NULL DEFAULT 'unknown'
|
||
CHECK (intake_reason IN ('unknown','stray_found','unwanted_litter','owner_health','owner_death','allergy','housing','financial','behavior','abandonment','danger','transfer','birth','other'));
|
||
ALTER TABLE animals ADD COLUMN depositor_contact_id INTEGER REFERENCES directory_contacts(id) ON DELETE SET NULL;
|
||
ALTER TABLE animals ADD COLUMN intake_circumstances TEXT;
|
||
CREATE INDEX idx_animals_intake_type ON animals(intake_type);
|
||
CREATE INDEX idx_animals_intake_reason ON animals(intake_reason);
|
||
CREATE INDEX idx_animals_depositor ON animals(depositor_contact_id);
|
||
|
||
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 d’entré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');
|