From: Matt S Trout Date: Mon, 18 Jan 2010 01:19:33 +0000 (+0000) Subject: Fix up foreign key from videos to announcements X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FApp-IdiotBox.git;a=commitdiff_plain;h=6c3eb3ebf271748e0fc86848f01137a1ce5f5f99 Fix up foreign key from videos to announcements All videos should be attached to an announcement from the same bucket, so make the schema enforce that. One could probably argue that this means that bucket_slug doesn't need to exist in the videos table but in my opinion one would be dead wrong :) - the bucket is an integral part of the video so while it's sort of duplication, it isn't denormalisation. --- diff --git a/share/sql/idiotbox-1.0-sqlite.sql b/share/sql/idiotbox-1.0-sqlite.sql index c9d24ae..d2f0d7a 100644 --- a/share/sql/idiotbox-1.0-sqlite.sql +++ b/share/sql/idiotbox-1.0-sqlite.sql @@ -15,6 +15,8 @@ CREATE TABLE videos ( name TEXT NOT NULL, author TEXT NOT NULL, details TEXT NOT NULL DEFAULT '', - announcement_id INTEGER REFERENCES announcements(id), - PRIMARY KEY (slug, bucket_slug) + announcement_id INTEGER NOT NULL, + PRIMARY KEY (slug, bucket_slug), + FOREIGN KEY (announcement_id, bucket_slug) + REFERENCES announcements(id, bucket_slug) );