add triggers on source_files insert/delete

This commit is contained in:
Vincent Riquer 2013-02-26 11:22:53 +01:00
parent b1e35f038a
commit 0ce73ac805

View File

@ -23,4 +23,16 @@ CREATE TABLE destination_files (
CREATE INDEX sourcefiles_by_name ON source_files (filename,id); 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; COMMIT;