summaryrefslogtreecommitdiffstats
path: root/sql_scripts/cnprog_new_install_2009_04_09.sql
blob: f4424852c740369d273cab1730043473518cf2f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
USE cnprog;


/************ Update: Tables ***************/

/******************** Add Table: activity ************************/

/* Build Table Structure */
CREATE TABLE activity
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	activity_type SMALLINT NOT NULL,
	active_at DATETIME NOT NULL,
	content_type_id INTEGER NOT NULL,
	object_id INTEGER UNSIGNED NOT NULL,
	is_auditted TINYINT NULL DEFAULT 0
) ENGINE=MyISAM AUTO_INCREMENT=103 DEFAULT CHARSET=latin1;

/* Table Items: activity */

/* Add Indexes for: activity */
CREATE INDEX activity_content_type_id ON activity (content_type_id);
CREATE INDEX activity_user_id ON activity (user_id);

/******************** Add Table: answer ************************/

/* Build Table Structure */
CREATE TABLE answer
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	question_id INTEGER NOT NULL,
	author_id INTEGER NOT NULL,
	added_at DATETIME NOT NULL,
	wiki TINYINT NOT NULL,
	wikified_at DATETIME NULL,
	accepted TINYINT NOT NULL,
	deleted TINYINT NOT NULL,
	deleted_by_id INTEGER NULL,
	locked TINYINT NOT NULL,
	locked_by_id INTEGER NULL,
	locked_at DATETIME NULL,
	score INTEGER NOT NULL,
	comment_count INTEGER UNSIGNED NOT NULL,
	offensive_flag_count SMALLINT NOT NULL,
	last_edited_at DATETIME NULL,
	last_edited_by_id INTEGER NULL,
	html LONGTEXT NOT NULL,
	vote_up_count INTEGER NOT NULL,
	vote_down_count INTEGER NOT NULL,
	accepted_at DATETIME NULL
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8;

/* Table Items: answer */

/* Add Indexes for: answer */
CREATE INDEX answer_author_id ON answer (author_id);
CREATE INDEX answer_deleted_by_id ON answer (deleted_by_id);
CREATE INDEX answer_last_edited_by_id ON answer (last_edited_by_id);
CREATE INDEX answer_locked_by_id ON answer (locked_by_id);
CREATE INDEX answer_question_id ON answer (question_id);

/******************** Add Table: answer_revision ************************/

/* Build Table Structure */
CREATE TABLE answer_revision
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	answer_id INTEGER NOT NULL,
	revision INTEGER UNSIGNED NOT NULL,
	author_id INTEGER NOT NULL,
	revised_at DATETIME NOT NULL,
	summary TEXT NOT NULL,
	`text` LONGTEXT NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

/* Table Items: answer_revision */

/* Add Indexes for: answer_revision */
CREATE INDEX answer_revision_answer_id ON answer_revision (answer_id);
CREATE INDEX answer_revision_author_id ON answer_revision (author_id);

/******************** Add Table: auth_group ************************/

/* Build Table Structure */
CREATE TABLE auth_group
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name VARCHAR(80) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/* Table Items: auth_group */

/* Add Indexes for: auth_group */
CREATE UNIQUE INDEX name ON auth_group (name);

/******************** Add Table: auth_group_permissions ************************/

/* Build Table Structure */
CREATE TABLE auth_group_permissions
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	group_id INTEGER NOT NULL,
	permission_id INTEGER NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/* Table Items: auth_group_permissions */

/* Add Indexes for: auth_group_permissions */
CREATE UNIQUE INDEX group_id ON auth_group_permissions (group_id, permission_id);
CREATE INDEX permission_id_refs_id_5886d21f ON auth_group_permissions (permission_id);

/******************** Add Table: auth_message ************************/

/* Build Table Structure */
CREATE TABLE auth_message
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	message LONGTEXT NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8;

/* Table Items: auth_message */

/* Add Indexes for: auth_message */
CREATE INDEX auth_message_user_id ON auth_message (user_id);

/******************** Add Table: auth_permission ************************/

/* Build Table Structure */
CREATE TABLE auth_permission
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name VARCHAR(50) NOT NULL,
	content_type_id INTEGER NOT NULL,
	codename VARCHAR(100) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8;

/* Table Items: auth_permission */

/* Add Indexes for: auth_permission */
CREATE INDEX auth_permission_content_type_id ON auth_permission (content_type_id);
CREATE UNIQUE INDEX content_type_id ON auth_permission (content_type_id, codename);

/******************** Add Table: auth_user ************************/

/* Build Table Structure */
CREATE TABLE auth_user
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	username VARCHAR(30) NOT NULL,
	first_name VARCHAR(30) NOT NULL,
	last_name VARCHAR(30) NOT NULL,
	email VARCHAR(75) NOT NULL,
	password VARCHAR(128) NOT NULL,
	is_staff TINYINT NOT NULL,
	is_active TINYINT NOT NULL,
	is_superuser TINYINT NOT NULL,
	last_login DATETIME NOT NULL,
	date_joined DATETIME NOT NULL,
	gold SMALLINT NOT NULL DEFAULT 0,
	silver SMALLINT UNSIGNED NOT NULL DEFAULT 0,
	bronze SMALLINT UNSIGNED NOT NULL DEFAULT 0,
	reputation INTEGER UNSIGNED NULL DEFAULT 1,
	gravatar VARCHAR(128) NULL,
	questions_per_page SMALLINT UNSIGNED NULL DEFAULT 10,
	last_seen DATETIME NULL,
	real_name VARCHAR(100) NULL,
	website VARCHAR(200) NULL,
	location VARCHAR(100) NULL,
	date_of_birth DATETIME NULL,
	about TEXT NULL
) ENGINE=InnoDB AUTO_INCREMENT=104 DEFAULT CHARSET=utf8;

/* Table Items: auth_user */

/* Add Indexes for: auth_user */
CREATE UNIQUE INDEX username ON auth_user (username);

/******************** Add Table: auth_user_groups ************************/

/* Build Table Structure */
CREATE TABLE auth_user_groups
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	group_id INTEGER NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/* Table Items: auth_user_groups */

/* Add Indexes for: auth_user_groups */
CREATE INDEX group_id_refs_id_f116770 ON auth_user_groups (group_id);
CREATE UNIQUE INDEX user_id ON auth_user_groups (user_id, group_id);

/******************** Add Table: auth_user_user_permissions ************************/

/* Build Table Structure */
CREATE TABLE auth_user_user_permissions
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	permission_id INTEGER NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/* Table Items: auth_user_user_permissions */

/* Add Indexes for: auth_user_user_permissions */
CREATE INDEX permission_id_refs_id_67e79cb ON auth_user_user_permissions (permission_id);
CREATE UNIQUE INDEX user_id ON auth_user_user_permissions (user_id, permission_id);

/******************** Add Table: award ************************/

/* Build Table Structure */
CREATE TABLE award
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	badge_id INTEGER NOT NULL,
	awarded_at DATETIME NOT NULL,
	notified TINYINT NOT NULL,
	content_type_id INTEGER NULL,
	object_id INTEGER NULL
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;

/* Table Items: award */

/* Add Indexes for: award */
CREATE INDEX award_badge_id ON award (badge_id);
CREATE INDEX award_user_id ON award (user_id);

/******************** Add Table: badge ************************/

/* Build Table Structure */
CREATE TABLE badge
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name VARCHAR(50) NOT NULL,
	`type` SMALLINT NOT NULL,
	slug VARCHAR(50) NOT NULL,
	description TEXT NOT NULL,
	multiple TINYINT NOT NULL,
	awarded_count INTEGER UNSIGNED NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8;

/* Table Items: badge */

/* Add Indexes for: badge */
CREATE INDEX badge_slug ON badge (slug);
CREATE UNIQUE INDEX name ON badge (name, `type`);

/******************** Add Table: book ************************/

/* Build Table Structure */
CREATE TABLE book
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	title VARCHAR(255) NOT NULL,
	short_name VARCHAR(255) NOT NULL,
	author VARCHAR(255) NOT NULL,
	user_id INTEGER NULL,
	price DECIMAL(10, 2) NULL,
	pages SMALLINT NULL,
	published_at DATE NOT NULL,
	publication VARCHAR(255) NOT NULL,
	cover_img VARCHAR(255) NULL,
	tagnames VARCHAR(125) NULL,
	added_at DATETIME NOT NULL,
	last_edited_at DATETIME NOT NULL
) TYPE=InnoDB;

/* Table Items: book */

/* Add Indexes for: book */
CREATE UNIQUE INDEX book_short_name_Idx ON book (short_name);
CREATE INDEX fk_books_auth_user ON book (user_id);

/******************** Add Table: book_author_info ************************/

/* Build Table Structure */
CREATE TABLE book_author_info
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	blog_url VARCHAR(255) NULL,
	user_id INTEGER NOT NULL,
	added_at DATETIME NOT NULL,
	last_edited_at DATETIME NOT NULL,
	book_id INTEGER NOT NULL
) TYPE=InnoDB;

/* Table Items: book_author_info */

/* Add Indexes for: book_author_info */
CREATE INDEX fk_book_author_info_auth_user ON book_author_info (user_id);
CREATE INDEX fk_book_author_info_book ON book_author_info (book_id);

/******************** Add Table: book_author_rss ************************/

/* Build Table Structure */
CREATE TABLE book_author_rss
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	title VARCHAR(255) NOT NULL,
	url VARCHAR(255) NOT NULL,
	rss_created_at DATETIME NOT NULL,
	user_id INTEGER NOT NULL,
	added_at DATETIME NOT NULL,
	book_id INTEGER NOT NULL
) TYPE=InnoDB;

/* Table Items: book_author_rss */

/* Add Indexes for: book_author_rss */
CREATE INDEX fk_book_author_rss_auth_user ON book_author_rss (user_id);
CREATE INDEX fk_book_author_rss_book ON book_author_rss (book_id);

/******************** Add Table: book_question ************************/

/* Build Table Structure */
CREATE TABLE book_question
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	book_id INTEGER NOT NULL,
	question_id INTEGER NOT NULL
) TYPE=InnoDB;

/* Table Items: book_question */

/* Add Indexes for: book_question */
CREATE INDEX fk_book_question_book ON book_question (book_id);
CREATE INDEX fk_book_question_question ON book_question (question_id);

/******************** Add Table: `comment` ************************/

/* Build Table Structure */
CREATE TABLE `comment`
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	content_type_id INTEGER NOT NULL,
	object_id INTEGER UNSIGNED NOT NULL,
	user_id INTEGER NOT NULL,
	`comment` TEXT NOT NULL,
	added_at DATETIME NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;

/* Table Items: `comment` */

/* Add Indexes for: comment */
CREATE INDEX comment_content_type_id ON `comment` (content_type_id);
CREATE INDEX comment_user_id ON `comment` (user_id);
CREATE INDEX content_type_id ON `comment` (content_type_id, object_id, user_id);

/******************** Add Table: django_admin_log ************************/

/* Build Table Structure */
CREATE TABLE django_admin_log
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	action_time DATETIME NOT NULL,
	user_id INTEGER NOT NULL,
	content_type_id INTEGER NULL,
	object_id LONGTEXT NULL,
	object_repr VARCHAR(200) NOT NULL,
	action_flag SMALLINT UNSIGNED NOT NULL,
	change_message LONGTEXT NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

/* Table Items: django_admin_log */

/* Add Indexes for: django_admin_log */
CREATE INDEX django_admin_log_content_type_id ON django_admin_log (content_type_id);
CREATE INDEX django_admin_log_user_id ON django_admin_log (user_id);

/******************** Add Table: django_authopenid_association ************************/

/* Build Table Structure */
CREATE TABLE django_authopenid_association
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	server_url LONGTEXT NOT NULL,
	handle VARCHAR(255) NOT NULL,
	secret LONGTEXT NOT NULL,
	issued INTEGER NOT NULL,
	lifetime INTEGER NOT NULL,
	assoc_type LONGTEXT NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

/******************** Add Table: django_authopenid_nonce ************************/

/* Build Table Structure */
CREATE TABLE django_authopenid_nonce
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	server_url VARCHAR(255) NOT NULL,
	`timestamp` INTEGER NOT NULL,
	salt VARCHAR(40) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;

/******************** Add Table: django_authopenid_userassociation ************************/

/* Build Table Structure */
CREATE TABLE django_authopenid_userassociation
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	openid_url VARCHAR(255) NOT NULL,
	user_id INTEGER NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

/* Table Items: django_authopenid_userassociation */

/* Add Indexes for: django_authopenid_userassociation */
CREATE UNIQUE INDEX user_id ON django_authopenid_userassociation (user_id);

/******************** Add Table: django_authopenid_userpasswordqueue ************************/

/* Build Table Structure */
CREATE TABLE django_authopenid_userpasswordqueue
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	new_password VARCHAR(30) NOT NULL,
	confirm_key VARCHAR(40) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/* Table Items: django_authopenid_userpasswordqueue */

/* Add Indexes for: django_authopenid_userpasswordqueue */
CREATE UNIQUE INDEX user_id ON django_authopenid_userpasswordqueue (user_id);

/******************** Add Table: django_content_type ************************/

/* Build Table Structure */
CREATE TABLE django_content_type
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name VARCHAR(100) NOT NULL,
	app_label VARCHAR(100) NOT NULL,
	model VARCHAR(100) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8;

/* Table Items: django_content_type */

/* Add Indexes for: django_content_type */
CREATE UNIQUE INDEX app_label ON django_content_type (app_label, model);

/******************** Add Table: django_session ************************/

/* Build Table Structure */
CREATE TABLE django_session
(
	session_key VARCHAR(40) NOT NULL,
	session_data LONGTEXT NOT NULL,
	expire_date DATETIME NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/* Table Items: django_session */
ALTER TABLE django_session ADD CONSTRAINT pkdjango_session
	PRIMARY KEY (session_key);

/******************** Add Table: django_site ************************/

/* Build Table Structure */
CREATE TABLE django_site
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	domain VARCHAR(100) NOT NULL,
	name VARCHAR(50) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

/******************** Add Table: favorite_question ************************/

/* Build Table Structure */
CREATE TABLE favorite_question
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	question_id INTEGER NOT NULL,
	user_id INTEGER NOT NULL,
	added_at DATETIME NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

/* Table Items: favorite_question */

/* Add Indexes for: favorite_question */
CREATE INDEX favorite_question_question_id ON favorite_question (question_id);
CREATE INDEX favorite_question_user_id ON favorite_question (user_id);

/******************** Add Table: flagged_item ************************/

/* Build Table Structure */
CREATE TABLE flagged_item
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	content_type_id INTEGER NOT NULL,
	object_id INTEGER UNSIGNED NOT NULL,
	user_id INTEGER NOT NULL,
	flagged_at DATETIME NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

/* Table Items: flagged_item */

/* Add Indexes for: flagged_item */
CREATE UNIQUE INDEX content_type_id ON flagged_item (content_type_id, object_id, user_id);
CREATE INDEX flagged_item_content_type_id ON flagged_item (content_type_id);
CREATE INDEX flagged_item_user_id ON flagged_item (user_id);

/******************** Add Table: question ************************/

/* Build Table Structure */
CREATE TABLE question
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	title TEXT NOT NULL,
	author_id INTEGER NOT NULL,
	added_at DATETIME NOT NULL,
	wiki TINYINT NOT NULL,
	wikified_at DATETIME NULL,
	answer_accepted TINYINT NOT NULL,
	closed TINYINT NOT NULL,
	closed_by_id INTEGER NULL,
	closed_at DATETIME NULL,
	close_reason SMALLINT NULL,
	deleted TINYINT NOT NULL,
	deleted_at DATETIME NULL,
	deleted_by_id INTEGER NULL,
	locked TINYINT NOT NULL,
	locked_by_id INTEGER NULL,
	locked_at DATETIME NULL,
	score INTEGER NOT NULL,
	answer_count INTEGER UNSIGNED NOT NULL,
	comment_count INTEGER UNSIGNED NOT NULL,
	view_count INTEGER UNSIGNED NOT NULL,
	offensive_flag_count SMALLINT NOT NULL,
	favourite_count INTEGER UNSIGNED NOT NULL,
	last_edited_at DATETIME NULL,
	last_edited_by_id INTEGER NULL,
	last_activity_at DATETIME NOT NULL,
	last_activity_by_id INTEGER NOT NULL,
	tagnames VARCHAR(125) NOT NULL,
	summary VARCHAR(180) NOT NULL,
	html LONGTEXT NOT NULL,
	vote_up_count INTEGER NOT NULL,
	vote_down_count INTEGER NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;

/* Table Items: question */

/* Add Indexes for: question */
CREATE INDEX question_author_id ON question (author_id);
CREATE INDEX question_closed_by_id ON question (closed_by_id);
CREATE INDEX question_deleted_by_id ON question (deleted_by_id);
CREATE INDEX question_last_activity_by_id ON question (last_activity_by_id);
CREATE INDEX question_last_edited_by_id ON question (last_edited_by_id);
CREATE INDEX question_locked_by_id ON question (locked_by_id);

/******************** Add Table: question_revision ************************/

/* Build Table Structure */
CREATE TABLE question_revision
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	question_id INTEGER NOT NULL,
	revision INTEGER UNSIGNED NOT NULL,
	title TEXT NOT NULL,
	author_id INTEGER NOT NULL,
	revised_at DATETIME NOT NULL,
	tagnames VARCHAR(125) NOT NULL,
	summary TEXT NOT NULL,
	`text` LONGTEXT NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

/* Table Items: question_revision */

/* Add Indexes for: question_revision */
CREATE INDEX question_revision_author_id ON question_revision (author_id);
CREATE INDEX question_revision_question_id ON question_revision (question_id);

/******************** Add Table: question_tags ************************/

/* Build Table Structure */
CREATE TABLE question_tags
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	question_id INTEGER NOT NULL,
	tag_id INTEGER NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;

/* Table Items: question_tags */

/* Add Indexes for: question_tags */
CREATE UNIQUE INDEX question_id ON question_tags (question_id, tag_id);
CREATE INDEX tag_id_refs_id_43fcb953 ON question_tags (tag_id);

/******************** Add Table: repute ************************/

/* Build Table Structure */
CREATE TABLE repute
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	positive SMALLINT NOT NULL,
	negative SMALLINT NOT NULL,
	question_id INTEGER NOT NULL,
	reputed_at DATETIME NOT NULL,
	reputation_type SMALLINT NOT NULL,
	reputation INTEGER NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;

/* Table Items: repute */

/* Add Indexes for: repute */
CREATE INDEX repute_question_id ON repute (question_id);
CREATE INDEX repute_user_id ON repute (user_id);

/******************** Add Table: tag ************************/

/* Build Table Structure */
CREATE TABLE tag
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name VARCHAR(255) NOT NULL,
	created_by_id INTEGER NOT NULL,
	used_count INTEGER UNSIGNED NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8;

/* Table Items: tag */

/* Add Indexes for: tag */
CREATE UNIQUE INDEX name ON tag (name);
CREATE INDEX tag_created_by_id ON tag (created_by_id);

/******************** Add Table: user_badge ************************/

/* Build Table Structure */
CREATE TABLE user_badge
(
	id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	badge_id INTEGER NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/* Table Items: user_badge */

/* Add Indexes for: user_badge */
CREATE INDEX fk_user_badge_auth_user ON user_badge (user_id);
CREATE INDEX fk_user_badge_badge ON user_badge (badge_id);

/******************** Add Table: user_favorite_questions ************************/

/* Build Table Structure */
CREATE TABLE user_favorite_questions
(
	id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	user_id INTEGER NOT NULL,
	question_id INTEGER NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/* Table Items: user_favorite_questions */

/* Add Indexes for: user_favorite_questions */
CREATE INDEX fk_user_favorite_questions_auth_user ON user_favorite_questions (user_id);
CREATE INDEX fk_user_favorite_questions_question ON user_favorite_questions (question_id);

/******************** Add Table: vote ************************/

/* Build Table Structure */
CREATE TABLE vote
(
	id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
	content_type_id INTEGER NOT NULL,
	object_id INTEGER UNSIGNED NOT NULL,
	user_id INTEGER NOT NULL,
	vote SMALLINT NOT NULL,
	voted_at DATETIME NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

/* Table Items: vote */

/* Add Indexes for: vote */
CREATE UNIQUE INDEX content_type_id ON vote (content_type_id, object_id, user_id);
CREATE INDEX vote_content_type_id ON vote (content_type_id);
CREATE INDEX vote_user_id ON vote (user_id);


/************ Add Foreign Keys to Database ***************/
/*-----------------------------------------------------------
Warning: Versions of MySQL prior to 4.1.2 require indexes on all columns involved in a foreign key. The following indexes may be required: 
fk_auth_group_permissions_auth_group may require an index on table: auth_group_permissions, column: group_id
fk_auth_user_groups_auth_user may require an index on table: auth_user_groups, column: user_id
fk_auth_user_user_permissions_auth_user may require an index on table: auth_user_user_permissions, column: user_id
fk_question_tags_question may require an index on table: question_tags, column: question_id
-----------------------------------------------------------
*/

/************ Foreign Key: fk_activity_auth_user ***************/
ALTER TABLE activity ADD CONSTRAINT fk_activity_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: deleted_by_id_refs_id_192b0170 ***************/
ALTER TABLE answer ADD CONSTRAINT deleted_by_id_refs_id_192b0170
	FOREIGN KEY (deleted_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_answer_auth_user ***************/
ALTER TABLE answer ADD CONSTRAINT fk_answer_auth_user
	FOREIGN KEY (author_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_answer_question ***************/
ALTER TABLE answer ADD CONSTRAINT fk_answer_question
	FOREIGN KEY (question_id) REFERENCES question (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: last_edited_by_id_refs_id_192b0170 ***************/
ALTER TABLE answer ADD CONSTRAINT last_edited_by_id_refs_id_192b0170
	FOREIGN KEY (last_edited_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: locked_by_id_refs_id_192b0170 ***************/
ALTER TABLE answer ADD CONSTRAINT locked_by_id_refs_id_192b0170
	FOREIGN KEY (locked_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_answer_revision_auth_user ***************/
ALTER TABLE answer_revision ADD CONSTRAINT fk_answer_revision_auth_user
	FOREIGN KEY (author_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_auth_group_permissions_auth_group ***************/
ALTER TABLE auth_group_permissions ADD CONSTRAINT fk_auth_group_permissions_auth_group
	FOREIGN KEY (group_id) REFERENCES auth_group (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_auth_group_permissions_auth_permission ***************/
ALTER TABLE auth_group_permissions ADD CONSTRAINT fk_auth_group_permissions_auth_permission
	FOREIGN KEY (permission_id) REFERENCES auth_permission (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_auth_message_auth_user ***************/
ALTER TABLE auth_message ADD CONSTRAINT fk_auth_message_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_auth_permission_django_content_type ***************/
ALTER TABLE auth_permission ADD CONSTRAINT fk_auth_permission_django_content_type
	FOREIGN KEY (content_type_id) REFERENCES django_content_type (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_auth_user_groups_auth_group ***************/
ALTER TABLE auth_user_groups ADD CONSTRAINT fk_auth_user_groups_auth_group
	FOREIGN KEY (group_id) REFERENCES auth_group (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_auth_user_groups_auth_user ***************/
ALTER TABLE auth_user_groups ADD CONSTRAINT fk_auth_user_groups_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_auth_user_user_permissions_auth_permission ***************/
ALTER TABLE auth_user_user_permissions ADD CONSTRAINT fk_auth_user_user_permissions_auth_permission
	FOREIGN KEY (permission_id) REFERENCES auth_permission (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_auth_user_user_permissions_auth_user ***************/
ALTER TABLE auth_user_user_permissions ADD CONSTRAINT fk_auth_user_user_permissions_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_award_auth_user ***************/
ALTER TABLE award ADD CONSTRAINT fk_award_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_award_badge ***************/
ALTER TABLE award ADD CONSTRAINT fk_award_badge
	FOREIGN KEY (badge_id) REFERENCES badge (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_books_auth_user ***************/
ALTER TABLE book ADD CONSTRAINT fk_books_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_book_author_info_auth_user ***************/
ALTER TABLE book_author_info ADD CONSTRAINT fk_book_author_info_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_book_author_info_book ***************/
ALTER TABLE book_author_info ADD CONSTRAINT fk_book_author_info_book
	FOREIGN KEY (book_id) REFERENCES book (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_book_author_rss_auth_user ***************/
ALTER TABLE book_author_rss ADD CONSTRAINT fk_book_author_rss_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_book_author_rss_book ***************/
ALTER TABLE book_author_rss ADD CONSTRAINT fk_book_author_rss_book
	FOREIGN KEY (book_id) REFERENCES book (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_book_question_book ***************/
ALTER TABLE book_question ADD CONSTRAINT fk_book_question_book
	FOREIGN KEY (book_id) REFERENCES book (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_book_question_question ***************/
ALTER TABLE book_question ADD CONSTRAINT fk_book_question_question
	FOREIGN KEY (question_id) REFERENCES question (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_comment_auth_user ***************/
ALTER TABLE `comment` ADD CONSTRAINT fk_comment_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_comment_django_content_type ***************/
ALTER TABLE `comment` ADD CONSTRAINT fk_comment_django_content_type
	FOREIGN KEY (content_type_id) REFERENCES django_content_type (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_django_admin_log_auth_user ***************/
ALTER TABLE django_admin_log ADD CONSTRAINT fk_django_admin_log_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_django_admin_log_django_content_type ***************/
ALTER TABLE django_admin_log ADD CONSTRAINT fk_django_admin_log_django_content_type
	FOREIGN KEY (content_type_id) REFERENCES django_content_type (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_django_authopenid_userassociation_auth_user ***************/
ALTER TABLE django_authopenid_userassociation ADD CONSTRAINT fk_django_authopenid_userassociation_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_django_authopenid_userpasswordqueue_auth_user ***************/
ALTER TABLE django_authopenid_userpasswordqueue ADD CONSTRAINT fk_django_authopenid_userpasswordqueue_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_favorite_question_auth_user ***************/
ALTER TABLE favorite_question ADD CONSTRAINT fk_favorite_question_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_favorite_question_question ***************/
ALTER TABLE favorite_question ADD CONSTRAINT fk_favorite_question_question
	FOREIGN KEY (question_id) REFERENCES question (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_flagged_item_auth_user ***************/
ALTER TABLE flagged_item ADD CONSTRAINT fk_flagged_item_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_flagged_item_django_content_type ***************/
ALTER TABLE flagged_item ADD CONSTRAINT fk_flagged_item_django_content_type
	FOREIGN KEY (content_type_id) REFERENCES django_content_type (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: closed_by_id_refs_id_56e9d00c ***************/
ALTER TABLE question ADD CONSTRAINT closed_by_id_refs_id_56e9d00c
	FOREIGN KEY (closed_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: deleted_by_id_refs_id_56e9d00c ***************/
ALTER TABLE question ADD CONSTRAINT deleted_by_id_refs_id_56e9d00c
	FOREIGN KEY (deleted_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_question_auth_user ***************/
ALTER TABLE question ADD CONSTRAINT fk_question_auth_user
	FOREIGN KEY (author_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: last_activity_by_id_refs_id_56e9d00c ***************/
ALTER TABLE question ADD CONSTRAINT last_activity_by_id_refs_id_56e9d00c
	FOREIGN KEY (last_activity_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: last_edited_by_id_refs_id_56e9d00c ***************/
ALTER TABLE question ADD CONSTRAINT last_edited_by_id_refs_id_56e9d00c
	FOREIGN KEY (last_edited_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: locked_by_id_refs_id_56e9d00c ***************/
ALTER TABLE question ADD CONSTRAINT locked_by_id_refs_id_56e9d00c
	FOREIGN KEY (locked_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_question_revision_auth_user ***************/
ALTER TABLE question_revision ADD CONSTRAINT fk_question_revision_auth_user
	FOREIGN KEY (author_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_question_revision_question ***************/
ALTER TABLE question_revision ADD CONSTRAINT fk_question_revision_question
	FOREIGN KEY (question_id) REFERENCES question (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_question_tags_question ***************/
ALTER TABLE question_tags ADD CONSTRAINT fk_question_tags_question
	FOREIGN KEY (question_id) REFERENCES question (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_question_tags_tag ***************/
ALTER TABLE question_tags ADD CONSTRAINT fk_question_tags_tag
	FOREIGN KEY (tag_id) REFERENCES tag (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_repute_auth_user ***************/
ALTER TABLE repute ADD CONSTRAINT fk_repute_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_repute_question ***************/
ALTER TABLE repute ADD CONSTRAINT fk_repute_question
	FOREIGN KEY (question_id) REFERENCES question (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_tag_auth_user ***************/
ALTER TABLE tag ADD CONSTRAINT fk_tag_auth_user
	FOREIGN KEY (created_by_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_user_badge_auth_user ***************/
ALTER TABLE user_badge ADD CONSTRAINT fk_user_badge_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_user_badge_badge ***************/
ALTER TABLE user_badge ADD CONSTRAINT fk_user_badge_badge
	FOREIGN KEY (badge_id) REFERENCES badge (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_user_favorite_questions_auth_user ***************/
ALTER TABLE user_favorite_questions ADD CONSTRAINT fk_user_favorite_questions_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_user_favorite_questions_question ***************/
ALTER TABLE user_favorite_questions ADD CONSTRAINT fk_user_favorite_questions_question
	FOREIGN KEY (question_id) REFERENCES question (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_vote_auth_user ***************/
ALTER TABLE vote ADD CONSTRAINT fk_vote_auth_user
	FOREIGN KEY (user_id) REFERENCES auth_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION;

/************ Foreign Key: fk_vote_django_content_type ***************/
ALTER TABLE vote ADD CONSTRAINT fk_vote_django_content_type
	FOREIGN KEY (content_type_id) REFERENCES django_content_type (id) ON UPDATE NO ACTION ON DELETE NO ACTION;