]> git.openstreetmap.org Git - osqa.git/blob - forum/management/commands/create_extended_user.py
Make RequestHolder thread-safe
[osqa.git] / forum / management / commands / create_extended_user.py
1 from forum.base import get_database_engine
2
3 database_type = get_database_engine()
4
5 PG_MIGRATION_QUERY = """
6 SELECT id AS user_ptr_id, is_approved, email_isvalid, email_key, reputation, gravatar, gold, silver, bronze, questions_per_page, last_seen, real_name, website, location, date_of_birth, about, hide_ignored_questions, tag_filter_setting INTO forum_user FROM auth_user;
7
8 ALTER TABLE forum_user
9   ADD CONSTRAINT forum_user_pkey PRIMARY KEY(user_ptr_id);
10
11 ALTER TABLE forum_user
12   ADD CONSTRAINT forum_user_user_ptr_id_fkey FOREIGN KEY (user_ptr_id)
13       REFERENCES auth_user (id) MATCH SIMPLE
14       ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED;
15
16 ALTER TABLE forum_user
17   ADD CONSTRAINT forum_user_reputation_check CHECK (reputation >= 0);
18
19 ALTER TABLE auth_user DROP COLUMN is_approved;
20 ALTER TABLE auth_user DROP COLUMN email_isvalid;
21 ALTER TABLE auth_user DROP COLUMN email_key;
22 ALTER TABLE auth_user DROP COLUMN reputation;
23 ALTER TABLE auth_user DROP COLUMN gravatar;
24 ALTER TABLE auth_user DROP COLUMN gold;
25 ALTER TABLE auth_user DROP COLUMN silver;
26 ALTER TABLE auth_user DROP COLUMN bronze;
27 ALTER TABLE auth_user DROP COLUMN questions_per_page;
28 ALTER TABLE auth_user DROP COLUMN last_seen;
29 ALTER TABLE auth_user DROP COLUMN real_name;
30 ALTER TABLE auth_user DROP COLUMN website;
31 ALTER TABLE auth_user DROP COLUMN "location";
32 ALTER TABLE auth_user DROP COLUMN date_of_birth;
33 ALTER TABLE auth_user DROP COLUMN about;
34 ALTER TABLE auth_user DROP COLUMN hide_ignored_questions;
35 ALTER TABLE auth_user DROP COLUMN tag_filter_setting;
36
37 """
38
39 PG_FKEYS_QUERY = """
40
41 ALTER TABLE "public"."activity"
42 DROP CONSTRAINT "activity_user_id_fkey",
43 ADD CONSTRAINT "activity_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
44
45 ALTER TABLE "public"."answer"
46 DROP CONSTRAINT "answer_author_id_fkey",
47 ADD CONSTRAINT "answer_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
48 DROP CONSTRAINT "answer_deleted_by_id_fkey",
49 ADD CONSTRAINT "answer_deleted_by_id_fkey" FOREIGN KEY ("deleted_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
50 DROP CONSTRAINT "answer_last_edited_by_id_fkey",
51 ADD CONSTRAINT "answer_last_edited_by_id_fkey" FOREIGN KEY ("last_edited_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
52 DROP CONSTRAINT "answer_locked_by_id_fkey",
53 ADD CONSTRAINT "answer_locked_by_id_fkey" FOREIGN KEY ("locked_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
54
55 ALTER TABLE "public"."answer_revision"
56 DROP CONSTRAINT "answer_revision_author_id_fkey",
57 ADD CONSTRAINT "answer_revision_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
58
59 ALTER TABLE "public"."award"
60 DROP CONSTRAINT "award_user_id_fkey",
61 ADD CONSTRAINT "award_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
62
63 ALTER TABLE "public"."comment"
64 DROP CONSTRAINT "comment_user_id_fkey",
65 ADD CONSTRAINT "comment_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
66
67 ALTER TABLE "public"."favorite_question"
68 DROP CONSTRAINT "favorite_question_user_id_fkey",
69 ADD CONSTRAINT "favorite_question_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
70
71 ALTER TABLE "public"."flagged_item"
72 DROP CONSTRAINT "flagged_item_user_id_fkey",
73 ADD CONSTRAINT "flagged_item_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
74
75 ALTER TABLE "public"."forum_anonymousanswer"
76 DROP CONSTRAINT "forum_anonymousanswer_author_id_fkey",
77 ADD CONSTRAINT "forum_anonymousanswer_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
78
79 ALTER TABLE "public"."forum_anonymousquestion"
80 DROP CONSTRAINT "forum_anonymousquestion_author_id_fkey",
81 ADD CONSTRAINT "forum_anonymousquestion_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
82
83 ALTER TABLE "public"."forum_authkeyuserassociation"
84 DROP CONSTRAINT "forum_authkeyuserassociation_user_id_fkey",
85 ADD CONSTRAINT "forum_authkeyuserassociation_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
86
87 ALTER TABLE "public"."forum_markedtag"
88 DROP CONSTRAINT "forum_markedtag_user_id_fkey",
89 ADD CONSTRAINT "forum_markedtag_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
90
91 ALTER TABLE "public"."forum_questionsubscription"
92 DROP CONSTRAINT "forum_questionsubscription_user_id_fkey",
93 ADD CONSTRAINT "forum_questionsubscription_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
94
95 ALTER TABLE "public"."forum_subscriptionsettings"
96 DROP CONSTRAINT "forum_subscriptionsettings_user_id_fkey",
97 ADD CONSTRAINT "forum_subscriptionsettings_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
98
99 ALTER TABLE "public"."forum_validationhash"
100 DROP CONSTRAINT "forum_validationhash_user_id_fkey",
101 ADD CONSTRAINT "forum_validationhash_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
102
103 ALTER TABLE "public"."question"
104 DROP CONSTRAINT "question_author_id_fkey",
105 ADD CONSTRAINT "question_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
106 DROP CONSTRAINT "question_closed_by_id_fkey",
107 ADD CONSTRAINT "question_closed_by_id_fkey" FOREIGN KEY ("closed_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
108 DROP CONSTRAINT "question_deleted_by_id_fkey",
109 ADD CONSTRAINT "question_deleted_by_id_fkey" FOREIGN KEY ("deleted_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
110 DROP CONSTRAINT "question_last_activity_by_id_fkey",
111 ADD CONSTRAINT "question_last_activity_by_id_fkey" FOREIGN KEY ("last_activity_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
112 DROP CONSTRAINT "question_last_edited_by_id_fkey",
113 ADD CONSTRAINT "question_last_edited_by_id_fkey" FOREIGN KEY ("last_edited_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
114 DROP CONSTRAINT "question_locked_by_id_fkey",
115 ADD CONSTRAINT "question_locked_by_id_fkey" FOREIGN KEY ("locked_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
116
117 ALTER TABLE "public"."question_followed_by"
118 DROP CONSTRAINT "question_followed_by_user_id_fkey",
119 ADD CONSTRAINT "question_followed_by_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
120
121 ALTER TABLE "public"."question_revision"
122 DROP CONSTRAINT "question_revision_author_id_fkey",
123 ADD CONSTRAINT "question_revision_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
124
125 ALTER TABLE "public"."repute"
126 DROP CONSTRAINT "repute_user_id_fkey",
127 ADD CONSTRAINT "repute_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
128
129 ALTER TABLE "public"."tag"
130 DROP CONSTRAINT "tag_created_by_id_fkey",
131 ADD CONSTRAINT "tag_created_by_id_fkey" FOREIGN KEY ("created_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
132 DROP CONSTRAINT "tag_deleted_by_id_fkey",
133 ADD CONSTRAINT "tag_deleted_by_id_fkey" FOREIGN KEY ("deleted_by_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
134
135 ALTER TABLE "public"."vote"
136 DROP CONSTRAINT "vote_user_id_fkey",
137 ADD CONSTRAINT "vote_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."forum_user" (user_ptr_id) ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED;
138
139 """
140
141 MYSQL_MIGRATION_QUERY = """
142 CREATE TABLE `forum_user` (
143   `user_ptr_id` int(11) NOT NULL,
144   `is_approved` tinyint(1) NOT NULL,
145   `email_isvalid` tinyint(1) NOT NULL,
146   `email_key` varchar(32) DEFAULT NULL,
147   `reputation` int(10) unsigned NOT NULL,
148   `gravatar` varchar(32) NOT NULL,
149   `gold` smallint(6) NOT NULL,
150   `silver` smallint(6) NOT NULL,
151   `bronze` smallint(6) NOT NULL,
152   `questions_per_page` smallint(6) NOT NULL,
153   `last_seen` datetime NOT NULL,
154   `real_name` varchar(100) NOT NULL,
155   `website` varchar(200) NOT NULL,
156   `location` varchar(100) NOT NULL,
157   `date_of_birth` date DEFAULT NULL,
158   `about` longtext NOT NULL,
159   `hide_ignored_questions` tinyint(1) NOT NULL,
160   `tag_filter_setting` varchar(16) NOT NULL,
161   PRIMARY KEY (`user_ptr_id`),
162   CONSTRAINT `user_ptr_id_refs_id_71071d7` FOREIGN KEY (`user_ptr_id`) REFERENCES `auth_user` (`id`)
163 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
164 SELECT id AS user_ptr_id, is_approved, email_isvalid, email_key, reputation, gravatar, gold, silver, bronze, questions_per_page,
165         last_seen, real_name, website, location, date_of_birth, about, hide_ignored_questions, tag_filter_setting FROM auth_user;
166
167 ALTER TABLE `auth_user`
168 DROP COLUMN `is_approved`,
169 DROP COLUMN `email_isvalid`,
170 DROP COLUMN `email_key`,
171 DROP COLUMN `reputation`,
172 DROP COLUMN `gravatar`,
173 DROP COLUMN `gold`,
174 DROP COLUMN `silver`,
175 DROP COLUMN `bronze`,
176 DROP COLUMN `questions_per_page`,
177 DROP COLUMN `last_seen`,
178 DROP COLUMN `real_name`,
179 DROP COLUMN `website`,
180 DROP COLUMN `location`,
181 DROP COLUMN `date_of_birth`,
182 DROP COLUMN `about`,
183 DROP COLUMN `hide_ignored_questions`,
184 DROP COLUMN `tag_filter_setting`;
185
186 """
187
188 MYSQL_FKEYS_QUERY = """
189
190 ALTER TABLE `activity` DROP FOREIGN KEY `user_id_refs_id_47c8583f`;
191 ALTER TABLE `activity` ADD CONSTRAINT `user_id_refs_user_ptr_id_62ae9785` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
192
193 ALTER TABLE `answer` DROP FOREIGN KEY `author_id_refs_id_192b0170`;
194 ALTER TABLE `answer` ADD CONSTRAINT `author_id_refs_user_ptr_id_9681994` FOREIGN KEY (`author_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
195 ALTER TABLE `answer` DROP FOREIGN KEY `deleted_by_id_refs_id_192b0170`;
196 ALTER TABLE `answer` ADD CONSTRAINT `deleted_by_id_refs_user_ptr_id_9681994` FOREIGN KEY (`deleted_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
197 ALTER TABLE `answer` DROP FOREIGN KEY `last_edited_by_id_refs_id_192b0170`;
198 ALTER TABLE `answer` ADD CONSTRAINT `last_edited_by_id_refs_user_ptr_id_9681994` FOREIGN KEY (`last_edited_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
199 ALTER TABLE `answer` DROP FOREIGN KEY `locked_by_id_refs_id_192b0170`;
200 ALTER TABLE `answer` ADD CONSTRAINT `locked_by_id_refs_user_ptr_id_9681994` FOREIGN KEY (`locked_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
201
202 ALTER TABLE `answer_revision` DROP FOREIGN KEY `author_id_refs_id_3ccc055f`;
203 ALTER TABLE `answer_revision` ADD CONSTRAINT `author_id_refs_user_ptr_id_331f0123` FOREIGN KEY (`author_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
204
205 ALTER TABLE `award` DROP FOREIGN KEY `user_id_refs_id_2d83e9b6`;
206 ALTER TABLE `award` ADD CONSTRAINT `user_id_refs_user_ptr_id_1b2d0192` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
207
208 ALTER TABLE `comment` DROP FOREIGN KEY `user_id_refs_id_6be725e8`;
209 ALTER TABLE `comment` ADD CONSTRAINT `user_id_refs_user_ptr_id_1ac2320c` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
210
211 ALTER TABLE `favorite_question` DROP FOREIGN KEY `user_id_refs_id_52853822`;
212 ALTER TABLE `favorite_question` ADD CONSTRAINT `user_id_refs_user_ptr_id_3f419c1a` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
213
214 ALTER TABLE `flagged_item` DROP FOREIGN KEY `user_id_refs_id_35e3c608`;
215 ALTER TABLE `flagged_item` ADD CONSTRAINT `user_id_refs_user_ptr_id_1ce834d4` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
216
217 ALTER TABLE `forum_anonymousanswer` DROP FOREIGN KEY `author_id_refs_id_13fb542e`;
218 ALTER TABLE `forum_anonymousanswer` ADD CONSTRAINT `author_id_refs_user_ptr_id_6b5b476a` FOREIGN KEY (`author_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
219
220 ALTER TABLE `forum_anonymousquestion` DROP FOREIGN KEY `author_id_refs_id_7511a98a`;
221 ALTER TABLE `forum_anonymousquestion` ADD CONSTRAINT `author_id_refs_user_ptr_id_104edd52` FOREIGN KEY (`author_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
222
223 ALTER TABLE `forum_authkeyuserassociation` DROP FOREIGN KEY `user_id_refs_id_2c2a6b01`;
224 ALTER TABLE `forum_authkeyuserassociation` ADD CONSTRAINT `user_id_refs_user_ptr_id_3f0ec0c3` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
225
226 ALTER TABLE `forum_markedtag` DROP FOREIGN KEY `user_id_refs_id_23b833bd`;
227 ALTER TABLE `forum_markedtag` ADD CONSTRAINT `user_id_refs_user_ptr_id_5a13f081` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
228
229 ALTER TABLE `forum_questionsubscription` DROP FOREIGN KEY `user_id_refs_id_18e1489`;
230 ALTER TABLE `forum_questionsubscription` ADD CONSTRAINT `user_id_refs_user_ptr_id_521b19ad` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
231
232 ALTER TABLE `forum_subscriptionsettings` DROP FOREIGN KEY `user_id_refs_id_35edacb4`;
233 ALTER TABLE `forum_subscriptionsettings` ADD CONSTRAINT `user_id_refs_user_ptr_id_1bc4fc70` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
234
235 ALTER TABLE `forum_validationhash` DROP FOREIGN KEY `user_id_refs_id_2c2d214b`;
236 ALTER TABLE `forum_validationhash` ADD CONSTRAINT `user_id_refs_user_ptr_id_4e5b2d6f` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
237
238 ALTER TABLE `question` DROP FOREIGN KEY `author_id_refs_id_56e9d00c`;
239 ALTER TABLE `question` ADD CONSTRAINT `author_id_refs_user_ptr_id_60d41818` FOREIGN KEY (`author_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
240 ALTER TABLE `question` DROP FOREIGN KEY `closed_by_id_refs_id_56e9d00c`;
241 ALTER TABLE `question` ADD CONSTRAINT `closed_by_id_refs_user_ptr_id_60d41818` FOREIGN KEY (`closed_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
242 ALTER TABLE `question` DROP FOREIGN KEY `deleted_by_id_refs_id_56e9d00c`;
243 ALTER TABLE `question` ADD CONSTRAINT `deleted_by_id_refs_user_ptr_id_60d41818` FOREIGN KEY (`deleted_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
244 ALTER TABLE `question` DROP FOREIGN KEY `last_activity_by_id_refs_id_56e9d00c`;
245 ALTER TABLE `question` ADD CONSTRAINT `last_activity_by_id_refs_user_ptr_id_60d41818` FOREIGN KEY (`last_activity_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
246 ALTER TABLE `question` DROP FOREIGN KEY `last_edited_by_id_refs_id_56e9d00c`;
247 ALTER TABLE `question` ADD CONSTRAINT `last_edited_by_id_refs_user_ptr_id_60d41818` FOREIGN KEY (`last_edited_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
248 ALTER TABLE `question` DROP FOREIGN KEY `locked_by_id_refs_id_56e9d00c`;
249 ALTER TABLE `question` ADD CONSTRAINT `locked_by_id_refs_user_ptr_id_60d41818` FOREIGN KEY (`locked_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
250
251 ALTER TABLE `question_followed_by` DROP FOREIGN KEY `user_id_refs_id_6d30712d`;
252 ALTER TABLE `question_followed_by` ADD CONSTRAINT `user_id_refs_user_ptr_id_615e65af` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
253
254 ALTER TABLE `question_revision` DROP FOREIGN KEY `author_id_refs_id_4f88024f`;
255 ALTER TABLE `question_revision` ADD CONSTRAINT `author_id_refs_user_ptr_id_42e3d48d` FOREIGN KEY (`author_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
256
257 ALTER TABLE `repute` DROP FOREIGN KEY `user_id_refs_id_5a426cd`;
258 ALTER TABLE `repute` ADD CONSTRAINT `user_id_refs_user_ptr_id_5ea9540f` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
259
260 ALTER TABLE `tag` DROP FOREIGN KEY `created_by_id_refs_id_47205d6d`;
261 ALTER TABLE `tag` ADD CONSTRAINT `created_by_id_refs_user_ptr_id_417f3449` FOREIGN KEY (`created_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
262 ALTER TABLE `tag` DROP FOREIGN KEY `deleted_by_id_refs_id_47205d6d`;
263 ALTER TABLE `tag` ADD CONSTRAINT `deleted_by_id_refs_user_ptr_id_417f3449` FOREIGN KEY (`deleted_by_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
264
265 ALTER TABLE `vote` DROP FOREIGN KEY `user_id_refs_id_760a4df0`;
266 ALTER TABLE `vote` ADD CONSTRAINT `user_id_refs_user_ptr_id_18723e34` FOREIGN KEY (`user_id`) REFERENCES `forum_user` (`user_ptr_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
267
268 """
269
270 from django.core.management.base import NoArgsCommand
271 from django.db import connection, transaction
272 from django.conf import settings
273
274 class Command(NoArgsCommand):
275     def handle_noargs(self, **options):
276         if database_type.__contains__('postgresql'):
277             migration_query = PG_MIGRATION_QUERY
278             fkeys_query = PG_FKEYS_QUERY
279         elif database_type.__contains__('mysql'):
280             migration_query = MYSQL_MIGRATION_QUERY
281             fkeys_query = MYSQL_FKEYS_QUERY
282         else:
283             raise Exception("Database backend not suported by this migration command")
284
285         cursor = connection.cursor()
286         cursor.execute(migration_query)
287         cursor.execute(fkeys_query)
288         transaction.commit_unless_managed()