diff options
author | yorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b> | 2008-08-20 10:51:42 +0000 |
---|---|---|
committer | yorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b> | 2008-08-20 10:51:42 +0000 |
commit | cbd1e5abe69b7ad6e92b95142123e99f544b747e (patch) | |
tree | bcc7b5d9898b223a310c790f9a856e3318ad98dd | |
parent | 3dc8780c15985ff86699addff1f4dbe43c6be19a (diff) |
Fixed error when creating a new thread, changed type of threads_posts.num to smallint, and added (yet another) foreign key constraint to the threads table
git-svn-id: svn://vndb.org/vndb@100 1fe2e327-d9db-4752-bcf7-ef0cb4a1748b
-rw-r--r-- | lib/VNDB/Util/DB.pm | 2 | ||||
-rw-r--r-- | util/dump.sql | 3 | ||||
-rw-r--r-- | util/updates/update_1.22.sql | 6 |
3 files changed, 9 insertions, 2 deletions
diff --git a/lib/VNDB/Util/DB.pm b/lib/VNDB/Util/DB.pm index a309fec8..17ec18af 100644 --- a/lib/VNDB/Util/DB.pm +++ b/lib/VNDB/Util/DB.pm @@ -1477,7 +1477,7 @@ sub DBAddThread { # %options->{ title hidden locked tags } INSERT INTO threads (title, hidden, locked) VALUES (?, ?, ?) RETURNING id|, - $o{title}, $o{hidden}, $o{locked} + $o{title}, $o{hidden}?1:0, $o{locked}?1:0 )->{id}; $s->DBExec(q| diff --git a/util/dump.sql b/util/dump.sql index cca3eaee..cedd2518 100644 --- a/util/dump.sql +++ b/util/dump.sql @@ -149,7 +149,7 @@ CREATE TABLE threads ( -- threads_posts CREATE TABLE threads_posts ( tid integer NOT NULL DEFAULT 0, - num integer NOT NULL DEFAULT 0, + num smallint NOT NULL DEFAULT 0, uid integer NOT NULL DEFAULT 0, date bigint NOT NULL DEFAULT DATE_PART('epoch', NOW()), edited bigint NOT NULL DEFAULT 0, @@ -290,6 +290,7 @@ ALTER TABLE releases_vn ADD FOREIGN KEY (rid) REFERENCES releases_r ALTER TABLE releases_vn ADD FOREIGN KEY (vid) REFERENCES vn (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE rlists ADD FOREIGN KEY (uid) REFERENCES users (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE rlists ADD FOREIGN KEY (rid) REFERENCES releases (id) DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE threads ADD FOREIGN KEY (id, count) REFERENCES threads_posts (tid, num) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE threads_posts ADD FOREIGN KEY (tid) REFERENCES threads (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE threads_posts ADD FOREIGN KEY (uid) REFERENCES users (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE threads_tags ADD FOREIGN KEY (tid) REFERENCES threads (id) DEFERRABLE INITIALLY DEFERRED; diff --git a/util/updates/update_1.22.sql b/util/updates/update_1.22.sql index 96228955..e3729765 100644 --- a/util/updates/update_1.22.sql +++ b/util/updates/update_1.22.sql @@ -22,3 +22,9 @@ UPDATE changes c SET causedby = NULL OR NOT EXISTS(SELECT 1 FROM changes WHERE c.causedby = id); ALTER TABLE changes ADD FOREIGN KEY (causedby) REFERENCES changes (id) DEFERRABLE INITIALLY DEFERRED; + +-- another foreign key constraint: (threads.id, threads.count) -> (threads_posts.tid, threads_posts.num) +-- threads_posts converted to smallint as well +ALTER TABLE threads_posts ALTER COLUMN num TYPE smallint; +ALTER TABLE threads ADD FOREIGN KEY (id, count) REFERENCES threads_posts (tid, num) DEFERRABLE INITIALLY DEFERRED; + |