| 1 |
|
|---|
| 2 |
# This is a fix for InnoDB in MySQL >= 4.1.x |
|---|
| 3 |
# It "suspends judgement" for fkey relationships until are tables are set. |
|---|
| 4 |
SET FOREIGN_KEY_CHECKS = 0; |
|---|
| 5 |
|
|---|
| 6 |
#----------------------------------------------------------------------------- |
|---|
| 7 |
#-- ask_question |
|---|
| 8 |
#----------------------------------------------------------------------------- |
|---|
| 9 |
|
|---|
| 10 |
DROP TABLE IF EXISTS `ask_question`; |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
CREATE TABLE `ask_question` |
|---|
| 14 |
( |
|---|
| 15 |
`id` INTEGER NOT NULL AUTO_INCREMENT, |
|---|
| 16 |
`user_id` INTEGER, |
|---|
| 17 |
`title` TEXT, |
|---|
| 18 |
`stripped_title` TEXT, |
|---|
| 19 |
`body` TEXT, |
|---|
| 20 |
`html_body` TEXT, |
|---|
| 21 |
`interested_users` INTEGER default 0, |
|---|
| 22 |
`reports` INTEGER default 0, |
|---|
| 23 |
`created_at` DATETIME, |
|---|
| 24 |
`updated_at` DATETIME, |
|---|
| 25 |
PRIMARY KEY (`id`), |
|---|
| 26 |
INDEX `ask_question_FI_1` (`user_id`), |
|---|
| 27 |
CONSTRAINT `ask_question_FK_1` |
|---|
| 28 |
FOREIGN KEY (`user_id`) |
|---|
| 29 |
REFERENCES `ask_user` (`id`) |
|---|
| 30 |
)Type=InnoDB; |
|---|
| 31 |
|
|---|
| 32 |
#----------------------------------------------------------------------------- |
|---|
| 33 |
#-- ask_answer |
|---|
| 34 |
#----------------------------------------------------------------------------- |
|---|
| 35 |
|
|---|
| 36 |
DROP TABLE IF EXISTS `ask_answer`; |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
CREATE TABLE `ask_answer` |
|---|
| 40 |
( |
|---|
| 41 |
`id` INTEGER NOT NULL AUTO_INCREMENT, |
|---|
| 42 |
`question_id` INTEGER, |
|---|
| 43 |
`user_id` INTEGER, |
|---|
| 44 |
`body` TEXT, |
|---|
| 45 |
`html_body` TEXT, |
|---|
| 46 |
`relevancy_up` INTEGER default 0, |
|---|
| 47 |
`relevancy_down` INTEGER default 0, |
|---|
| 48 |
`reports` INTEGER default 0, |
|---|
| 49 |
`created_at` DATETIME, |
|---|
| 50 |
PRIMARY KEY (`id`), |
|---|
| 51 |
INDEX `ask_answer_FI_1` (`question_id`), |
|---|
| 52 |
CONSTRAINT `ask_answer_FK_1` |
|---|
| 53 |
FOREIGN KEY (`question_id`) |
|---|
| 54 |
REFERENCES `ask_question` (`id`) |
|---|
| 55 |
ON DELETE CASCADE, |
|---|
| 56 |
INDEX `ask_answer_FI_2` (`user_id`), |
|---|
| 57 |
CONSTRAINT `ask_answer_FK_2` |
|---|
| 58 |
FOREIGN KEY (`user_id`) |
|---|
| 59 |
REFERENCES `ask_user` (`id`) |
|---|
| 60 |
)Type=InnoDB; |
|---|
| 61 |
|
|---|
| 62 |
#----------------------------------------------------------------------------- |
|---|
| 63 |
#-- ask_user |
|---|
| 64 |
#----------------------------------------------------------------------------- |
|---|
| 65 |
|
|---|
| 66 |
DROP TABLE IF EXISTS `ask_user`; |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
CREATE TABLE `ask_user` |
|---|
| 70 |
( |
|---|
| 71 |
`id` INTEGER NOT NULL AUTO_INCREMENT, |
|---|
| 72 |
`nickname` VARCHAR(50), |
|---|
| 73 |
`first_name` VARCHAR(100), |
|---|
| 74 |
`last_name` VARCHAR(100), |
|---|
| 75 |
`email` VARCHAR(100), |
|---|
| 76 |
`sha1_password` VARCHAR(40), |
|---|
| 77 |
`salt` VARCHAR(32), |
|---|
| 78 |
`has_paypal` INTEGER default 0, |
|---|
| 79 |
`want_to_be_moderator` INTEGER default 0, |
|---|
| 80 |
`is_moderator` INTEGER default 0, |
|---|
| 81 |
`is_administrator` INTEGER default 0, |
|---|
| 82 |
`deletions` INTEGER default 0, |
|---|
| 83 |
`created_at` DATETIME, |
|---|
| 84 |
PRIMARY KEY (`id`) |
|---|
| 85 |
)Type=InnoDB; |
|---|
| 86 |
|
|---|
| 87 |
#----------------------------------------------------------------------------- |
|---|
| 88 |
#-- ask_interest |
|---|
| 89 |
#----------------------------------------------------------------------------- |
|---|
| 90 |
|
|---|
| 91 |
DROP TABLE IF EXISTS `ask_interest`; |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
CREATE TABLE `ask_interest` |
|---|
| 95 |
( |
|---|
| 96 |
`question_id` INTEGER NOT NULL, |
|---|
| 97 |
`user_id` INTEGER NOT NULL, |
|---|
| 98 |
`created_at` DATETIME, |
|---|
| 99 |
PRIMARY KEY (`question_id`,`user_id`), |
|---|
| 100 |
CONSTRAINT `ask_interest_FK_1` |
|---|
| 101 |
FOREIGN KEY (`question_id`) |
|---|
| 102 |
REFERENCES `ask_question` (`id`) |
|---|
| 103 |
ON DELETE CASCADE, |
|---|
| 104 |
INDEX `ask_interest_FI_2` (`user_id`), |
|---|
| 105 |
CONSTRAINT `ask_interest_FK_2` |
|---|
| 106 |
FOREIGN KEY (`user_id`) |
|---|
| 107 |
REFERENCES `ask_user` (`id`) |
|---|
| 108 |
)Type=InnoDB; |
|---|
| 109 |
|
|---|
| 110 |
#----------------------------------------------------------------------------- |
|---|
| 111 |
#-- ask_relevancy |
|---|
| 112 |
#----------------------------------------------------------------------------- |
|---|
| 113 |
|
|---|
| 114 |
DROP TABLE IF EXISTS `ask_relevancy`; |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
CREATE TABLE `ask_relevancy` |
|---|
| 118 |
( |
|---|
| 119 |
`answer_id` INTEGER NOT NULL, |
|---|
| 120 |
`user_id` INTEGER NOT NULL, |
|---|
| 121 |
`score` INTEGER, |
|---|
| 122 |
`created_at` DATETIME, |
|---|
| 123 |
PRIMARY KEY (`answer_id`,`user_id`), |
|---|
| 124 |
CONSTRAINT `ask_relevancy_FK_1` |
|---|
| 125 |
FOREIGN KEY (`answer_id`) |
|---|
| 126 |
REFERENCES `ask_answer` (`id`) |
|---|
| 127 |
ON DELETE CASCADE, |
|---|
| 128 |
INDEX `ask_relevancy_FI_2` (`user_id`), |
|---|
| 129 |
CONSTRAINT `ask_relevancy_FK_2` |
|---|
| 130 |
FOREIGN KEY (`user_id`) |
|---|
| 131 |
REFERENCES `ask_user` (`id`) |
|---|
| 132 |
)Type=InnoDB; |
|---|
| 133 |
|
|---|
| 134 |
#----------------------------------------------------------------------------- |
|---|
| 135 |
#-- ask_question_tag |
|---|
| 136 |
#----------------------------------------------------------------------------- |
|---|
| 137 |
|
|---|
| 138 |
DROP TABLE IF EXISTS `ask_question_tag`; |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
CREATE TABLE `ask_question_tag` |
|---|
| 142 |
( |
|---|
| 143 |
`question_id` INTEGER NOT NULL, |
|---|
| 144 |
`user_id` INTEGER NOT NULL, |
|---|
| 145 |
`created_at` DATETIME, |
|---|
| 146 |
`tag` VARCHAR(100), |
|---|
| 147 |
`normalized_tag` VARCHAR(100) NOT NULL, |
|---|
| 148 |
PRIMARY KEY (`question_id`,`user_id`,`normalized_tag`), |
|---|
| 149 |
KEY `normalized_tag_index`(`normalized_tag`), |
|---|
| 150 |
CONSTRAINT `ask_question_tag_FK_1` |
|---|
| 151 |
FOREIGN KEY (`question_id`) |
|---|
| 152 |
REFERENCES `ask_question` (`id`) |
|---|
| 153 |
ON DELETE CASCADE, |
|---|
| 154 |
INDEX `ask_question_tag_FI_2` (`user_id`), |
|---|
| 155 |
CONSTRAINT `ask_question_tag_FK_2` |
|---|
| 156 |
FOREIGN KEY (`user_id`) |
|---|
| 157 |
REFERENCES `ask_user` (`id`) |
|---|
| 158 |
)Type=InnoDB; |
|---|
| 159 |
|
|---|
| 160 |
#----------------------------------------------------------------------------- |
|---|
| 161 |
#-- ask_search_index |
|---|
| 162 |
#----------------------------------------------------------------------------- |
|---|
| 163 |
|
|---|
| 164 |
DROP TABLE IF EXISTS `ask_search_index`; |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
CREATE TABLE `ask_search_index` |
|---|
| 168 |
( |
|---|
| 169 |
`question_id` INTEGER, |
|---|
| 170 |
`word` VARCHAR(255), |
|---|
| 171 |
`weight` INTEGER, |
|---|
| 172 |
KEY `word_index`(`word`), |
|---|
| 173 |
INDEX `ask_search_index_FI_1` (`question_id`), |
|---|
| 174 |
CONSTRAINT `ask_search_index_FK_1` |
|---|
| 175 |
FOREIGN KEY (`question_id`) |
|---|
| 176 |
REFERENCES `ask_question` (`id`) |
|---|
| 177 |
ON DELETE CASCADE |
|---|
| 178 |
)Type=InnoDB; |
|---|
| 179 |
|
|---|
| 180 |
#----------------------------------------------------------------------------- |
|---|
| 181 |
#-- ask_report_question |
|---|
| 182 |
#----------------------------------------------------------------------------- |
|---|
| 183 |
|
|---|
| 184 |
DROP TABLE IF EXISTS `ask_report_question`; |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
CREATE TABLE `ask_report_question` |
|---|
| 188 |
( |
|---|
| 189 |
`question_id` INTEGER NOT NULL, |
|---|
| 190 |
`user_id` INTEGER NOT NULL, |
|---|
| 191 |
`created_at` DATETIME, |
|---|
| 192 |
PRIMARY KEY (`question_id`,`user_id`), |
|---|
| 193 |
CONSTRAINT `ask_report_question_FK_1` |
|---|
| 194 |
FOREIGN KEY (`question_id`) |
|---|
| 195 |
REFERENCES `ask_question` (`id`) |
|---|
| 196 |
ON DELETE CASCADE, |
|---|
| 197 |
INDEX `ask_report_question_FI_2` (`user_id`), |
|---|
| 198 |
CONSTRAINT `ask_report_question_FK_2` |
|---|
| 199 |
FOREIGN KEY (`user_id`) |
|---|
| 200 |
REFERENCES `ask_user` (`id`) |
|---|
| 201 |
)Type=InnoDB; |
|---|
| 202 |
|
|---|
| 203 |
#----------------------------------------------------------------------------- |
|---|
| 204 |
#-- ask_report_answer |
|---|
| 205 |
#----------------------------------------------------------------------------- |
|---|
| 206 |
|
|---|
| 207 |
DROP TABLE IF EXISTS `ask_report_answer`; |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
CREATE TABLE `ask_report_answer` |
|---|
| 211 |
( |
|---|
| 212 |
`answer_id` INTEGER NOT NULL, |
|---|
| 213 |
`user_id` INTEGER NOT NULL, |
|---|
| 214 |
`created_at` DATETIME, |
|---|
| 215 |
PRIMARY KEY (`answer_id`,`user_id`), |
|---|
| 216 |
CONSTRAINT `ask_report_answer_FK_1` |
|---|
| 217 |
FOREIGN KEY (`answer_id`) |
|---|
| 218 |
REFERENCES `ask_answer` (`id`) |
|---|
| 219 |
ON DELETE CASCADE, |
|---|
| 220 |
INDEX `ask_report_answer_FI_2` (`user_id`), |
|---|
| 221 |
CONSTRAINT `ask_report_answer_FK_2` |
|---|
| 222 |
FOREIGN KEY (`user_id`) |
|---|
| 223 |
REFERENCES `ask_user` (`id`) |
|---|
| 224 |
)Type=InnoDB; |
|---|
| 225 |
|
|---|
| 226 |
# This restores the fkey checks, after having unset them earlier |
|---|
| 227 |
SET FOREIGN_KEY_CHECKS = 1; |
|---|