From 0ce73ac805efedf9bf586c843402399e1e683f65 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 26 Feb 2013 11:22:53 +0100 Subject: [PATCH] add triggers on source_files insert/delete --- share/schema.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/share/schema.sql b/share/schema.sql index 5b854ca..89ca5bf 100644 --- a/share/schema.sql +++ b/share/schema.sql @@ -23,4 +23,16 @@ CREATE TABLE destination_files ( CREATE INDEX sourcefiles_by_name ON source_files (filename,id); +CREATE TRIGGER create_destinations AFTER INSERT ON source_files +BEGIN + INSERT INTO destination_files (source_file_id,destination_id) + SELECT source_files.id,destinations.id FROM source_files + INNER JOIN destinations + WHERE source_files.id=new.id; +END; +CREATE TRIGGER delete_destinations_files AFTER DELETE ON source_files +BEGIN + UPDATE destination_files SET source_file_id=NULL WHERE source_file_id=old.id; +END; + COMMIT;