From 9892d1f7fdce0ef7b2d950f01082a0b84bb5df38 Mon Sep 17 00:00:00 2001 From: jgen Date: Sat, 22 Feb 2014 23:02:11 -0500 Subject: [PATCH] PostgreSQL does not support INDEX() inside the CREATE TABLE method. You must create the index as a separate query. Fortunately MySQL also support this way of doing things as well. --- ext/artists/main.php | 5 +---- ext/blocks/main.php | 4 ++-- ext/bookmarks/main.php | 2 +- ext/comment/main.php | 10 +++++----- ext/favorites/main.php | 2 +- ext/forum/main.php | 6 +++--- ext/notes/main.php | 10 +++++----- ext/numeric_score/main.php | 2 +- ext/pools/main.php | 2 -- ext/source_history/main.php | 2 +- ext/tag_history/main.php | 2 +- ext/tips/main.php | 1 - 12 files changed, 21 insertions(+), 27 deletions(-) diff --git a/ext/artists/main.php b/ext/artists/main.php index 984b12af..0e213bff 100644 --- a/ext/artists/main.php +++ b/ext/artists/main.php @@ -62,9 +62,9 @@ class Artists extends Extension { created DATETIME NOT NULL, updated DATETIME NOT NULL, notes TEXT, - INDEX(id), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE "); + $database->create_table("artist_members", " id SCORE_AIPK, artist_id INTEGER NOT NULL, @@ -72,7 +72,6 @@ class Artists extends Extension { name VARCHAR(255) NOT NULL, created DATETIME NOT NULL, updated DATETIME NOT NULL, - INDEX (id), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE "); @@ -83,7 +82,6 @@ class Artists extends Extension { created DATETIME, updated DATETIME, alias VARCHAR(255), - INDEX (id), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE "); @@ -94,7 +92,6 @@ class Artists extends Extension { created DATETIME NOT NULL, updated DATETIME NOT NULL, url VARCHAR(1000) NOT NULL, - INDEX (id), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE "); diff --git a/ext/blocks/main.php b/ext/blocks/main.php index afcda058..c80ce1af 100644 --- a/ext/blocks/main.php +++ b/ext/blocks/main.php @@ -17,9 +17,9 @@ class Blocks extends Extension { title VARCHAR(128) NOT NULL, area VARCHAR(16) NOT NULL, priority INTEGER NOT NULL, - content TEXT NOT NULL, - INDEX (pages) + content TEXT NOT NULL "); + $database->execute("CREATE INDEX blocks_pages_idx ON blocks(pages)", array()); $config->set_int("ext_blocks_version", 1); } } diff --git a/ext/bookmarks/main.php b/ext/bookmarks/main.php index 381ab7da..93661086 100644 --- a/ext/bookmarks/main.php +++ b/ext/bookmarks/main.php @@ -42,9 +42,9 @@ class Bookmarks extends Extension { owner_id INTEGER NOT NULL, url TEXT NOT NULL, title TEXT NOT NULL, - INDEX (owner_id), FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE "); + $database->execute("CREATE INDEX bookmark_owner_id_idx ON bookmark(owner_id)", array()); $config->set_int("ext_bookmarks_version", 1); } } diff --git a/ext/comment/main.php b/ext/comment/main.php index 1c472626..86421e24 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -80,12 +80,12 @@ class CommentList extends Extension { owner_ip SCORE_INET NOT NULL, posted DATETIME DEFAULT NULL, comment TEXT NOT NULL, - INDEX (image_id), - INDEX (owner_ip), - INDEX (posted), FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT "); + $database->execute("CREATE INDEX comments_image_id_idx ON comments(image_id)", array()); + $database->execute("CREATE INDEX comments_owner_id_idx ON comments(owner_id)", array()); + $database->execute("CREATE INDEX comments_posted_idx ON bookmark(posted)", array()); $config->set_int("ext_comments_version", 3); } @@ -97,9 +97,9 @@ class CommentList extends Extension { owner_id INTEGER NOT NULL, owner_ip CHAR(16) NOT NULL, posted DATETIME DEFAULT NULL, - comment TEXT NOT NULL, - INDEX (image_id) + comment TEXT NOT NULL "); + $database->execute("CREATE INDEX comments_image_id_idx ON comments(image_id)", array()); $config->set_int("ext_comments_version", 1); } diff --git a/ext/favorites/main.php b/ext/favorites/main.php index 6517377e..6b0f20cd 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -153,12 +153,12 @@ class Favorites extends Extension { image_id INTEGER NOT NULL, user_id INTEGER NOT NULL, created_at DATETIME NOT NULL, - INDEX(image_id), UNIQUE(image_id, user_id), FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE ) "); + $database->execute("CREATE INDEX user_favorites_image_id_idx ON user_favorites(image_id)", array()); $config->set_int("ext_favorites_version", 1); } diff --git a/ext/forum/main.php b/ext/forum/main.php index c820610f..0e18c9f3 100644 --- a/ext/forum/main.php +++ b/ext/forum/main.php @@ -29,20 +29,20 @@ class Forum extends Extension { user_id INTEGER NOT NULL, date DATETIME NOT NULL, uptodate DATETIME NOT NULL, - INDEX (date), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT "); - + $database->execute("CREATE INDEX forum_threads_date_idx ON forum_threads(date)", array()); + $database->create_table("forum_posts", " id SCORE_AIPK, thread_id INTEGER NOT NULL, user_id INTEGER NOT NULL, date DATETIME NOT NULL, message TEXT, - INDEX (date), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT, FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE "); + $database->execute("CREATE INDEX forum_posts_date_idx ON forum_posts(date)", array()); $config->set_int("forum_version", 2); $config->set_int("forumTitleSubString", 25); diff --git a/ext/notes/main.php b/ext/notes/main.php index f29a22e9..7f677cce 100644 --- a/ext/notes/main.php +++ b/ext/notes/main.php @@ -26,21 +26,21 @@ class Notes extends Extension { height INTEGER NOT NULL, width INTEGER NOT NULL, note TEXT NOT NULL, - INDEX (image_id), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE "); - + $database->execute("CREATE INDEX notes_image_id_idx ON notes(image_id)", array()); + $database->create_table("note_request", " id SCORE_AIPK, image_id INTEGER NOT NULL, user_id INTEGER NOT NULL, date DATETIME NOT NULL, - INDEX (image_id), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE "); - + $database->execute("CREATE INDEX note_request_image_id_idx ON note_request(image_id)", array()); + $database->create_table("note_histories", " id SCORE_AIPK, note_enable INTEGER NOT NULL, @@ -55,10 +55,10 @@ class Notes extends Extension { height INTEGER NOT NULL, width INTEGER NOT NULL, note TEXT NOT NULL, - INDEX (image_id), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE "); + $database->execute("CREATE INDEX note_histories_image_id_idx ON note_histories(image_id)", array()); $config->set_int("notesNotesPerPage", 20); $config->set_int("notesRequestsPerPage", 20); diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php index 2da74577..5ecaa95f 100644 --- a/ext/numeric_score/main.php +++ b/ext/numeric_score/main.php @@ -268,10 +268,10 @@ class NumericScore extends Extension { user_id INTEGER NOT NULL, score INTEGER NOT NULL, UNIQUE(image_id, user_id), - INDEX(image_id), FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE "); + $database->execute("CREATE INDEX numeric_score_votes_image_id_idx ON numeric_score_votes(image_id)", array()); $config->set_int("ext_numeric_score_version", 1); } if($config->get_int("ext_numeric_score_version") < 2) { diff --git a/ext/pools/main.php b/ext/pools/main.php index 6bcd8760..3114d170 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -35,7 +35,6 @@ class Pools extends Extension { description TEXT, date DATETIME NOT NULL, posts INTEGER NOT NULL DEFAULT 0, - INDEX (id), FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE "); $database->create_table("pool_images", " @@ -53,7 +52,6 @@ class Pools extends Extension { images TEXT, count INTEGER NOT NULL DEFAULT 0, date DATETIME NOT NULL, - INDEX (id), FOREIGN KEY (pool_id) REFERENCES pools(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE "); diff --git a/ext/source_history/main.php b/ext/source_history/main.php index 68d748de..cc4debfd 100644 --- a/ext/source_history/main.php +++ b/ext/source_history/main.php @@ -94,10 +94,10 @@ class Source_History extends Extension { user_ip SCORE_INET NOT NULL, source TEXT NOT NULL, date_set DATETIME NOT NULL, - INDEX(image_id), FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE "); + $database->execute("CREATE INDEX source_histories_image_id_idx ON source_histories(image_id)", array()); $config->set_int("ext_source_history_version", 3); } diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php index 583f7afe..fd62a41a 100644 --- a/ext/tag_history/main.php +++ b/ext/tag_history/main.php @@ -94,10 +94,10 @@ class Tag_History extends Extension { user_ip SCORE_INET NOT NULL, tags TEXT NOT NULL, date_set DATETIME NOT NULL, - INDEX(image_id), FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE "); + $database->execute("CREATE INDEX tag_histories_image_id_idx ON tag_histories(image_id)", array()); $config->set_int("ext_tag_history_version", 3); } diff --git a/ext/tips/main.php b/ext/tips/main.php index 41cc7823..d1c08929 100644 --- a/ext/tips/main.php +++ b/ext/tips/main.php @@ -18,7 +18,6 @@ class Tips extends Extension { enable SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, image TEXT NOT NULL, text TEXT NOT NULL, - INDEX (id) "); $database->execute("