forked from bugzilla/harmony
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.pm
More file actions
4402 lines (3684 loc) · 156 KB
/
DB.pm
File metadata and controls
4402 lines (3684 loc) · 156 KB
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
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
package Bugzilla::Install::DB;
# NOTE: This package may "use" any modules that it likes,
# localconfig is available, and params are up to date.
use 5.10.1;
use strict;
use warnings;
use Bugzilla::Constants;
use Bugzilla::Hook;
use Bugzilla::Install ();
use Bugzilla::Install::Util qw(indicate_progress install_string);
use Bugzilla::Util;
use Bugzilla::Series;
use Bugzilla::BugUrl;
use Bugzilla::Field;
use Date::Parse;
use Date::Format;
use IO::File;
use List::MoreUtils qw(uniq);
use URI;
use URI::QueryParam;
# NOTE: This is NOT the function for general table updates. See
# update_table_definitions for that. This is only for the fielddefs table.
sub update_fielddefs_definition {
my $dbh = Bugzilla->dbh;
# 2005-02-21 - LpSolit@gmail.com - Bug 279910
# qacontact_accessible and assignee_accessible field names no longer exist
# in the 'bugs' table. Their corresponding entries in the 'bugs_activity'
# table should therefore be marked as obsolete, meaning that they cannot
# be used anymore when querying the database - they are not deleted in
# order to keep track of these fields in the activity table.
if (!$dbh->bz_column_info('fielddefs', 'obsolete')) {
$dbh->bz_add_column('fielddefs', 'obsolete',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
print "Marking qacontact_accessible and assignee_accessible as",
" obsolete fields...\n";
$dbh->do(
"UPDATE fielddefs SET obsolete = 1
WHERE name = 'qacontact_accessible'
OR name = 'assignee_accessible'"
);
}
# 2005-08-10 Myk Melez <myk@mozilla.org> bug 287325
# Record each field's type and whether or not it's a custom field,
# in fielddefs.
$dbh->bz_add_column('fielddefs', 'type',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => 0});
$dbh->bz_add_column('fielddefs', 'custom',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_add_column('fielddefs', 'enter_bug',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
# Change the name of the fieldid column to id, so that fielddefs
# can use Bugzilla::Object easily. We have to do this up here, because
# otherwise adding these field definitions will fail.
$dbh->bz_rename_column('fielddefs', 'fieldid', 'id');
# If the largest fielddefs sortkey is less than 100, then
# we're using the old sorting system, and we should convert
# it to the new one before adding any new definitions.
if (!$dbh->selectrow_arrayref(
'SELECT COUNT(id) FROM fielddefs WHERE sortkey >= 100'))
{
print "Updating the sortkeys for the fielddefs table...\n";
my $field_ids
= $dbh->selectcol_arrayref('SELECT id FROM fielddefs ORDER BY sortkey');
my $sortkey = 100;
foreach my $field_id (@$field_ids) {
$dbh->do('UPDATE fielddefs SET sortkey = ? WHERE id = ?',
undef, $sortkey, $field_id);
$sortkey += 100;
}
}
$dbh->bz_add_column('fielddefs', 'visibility_field_id', {TYPE => 'INT3'});
$dbh->bz_add_column('fielddefs', 'value_field_id', {TYPE => 'INT3'});
$dbh->bz_add_index('fielddefs', 'fielddefs_value_field_id_idx',
['value_field_id']);
# Bug 344878
if (!$dbh->bz_column_info('fielddefs', 'buglist')) {
$dbh->bz_add_column('fielddefs', 'buglist',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
# Set non-multiselect custom fields as valid buglist fields
# Note that default fields will be handled in Field.pm
$dbh->do('UPDATE fielddefs SET buglist = 1 WHERE custom = 1 AND type != '
. FIELD_TYPE_MULTI_SELECT);
}
#2008-08-26 elliotte_martin@yahoo.com - Bug 251556
$dbh->bz_add_column('fielddefs', 'reverse_desc', {TYPE => 'TINYTEXT'});
$dbh->do(
'UPDATE fielddefs SET buglist = 1
WHERE custom = 1 AND type = ' . FIELD_TYPE_MULTI_SELECT
);
$dbh->bz_add_column('fielddefs', 'is_mandatory',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_add_index('fielddefs', 'fielddefs_is_mandatory_idx', ['is_mandatory']);
# 2010-04-05 dkl@redhat.com - Bug 479400
_migrate_field_visibility_value();
$dbh->bz_add_column('fielddefs', 'is_numeric',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->do(
'UPDATE fielddefs SET is_numeric = 1 WHERE type = ' . FIELD_TYPE_BUG_ID);
Bugzilla::Hook::process('install_update_db_fielddefs');
# Remember, this is not the function for adding general table changes.
# That is below. Add new changes to the fielddefs table above this
# comment.
}
# Small changes can be put directly into this function.
# However, larger changes (more than three or four lines) should
# go into their own private subroutine, and you should call that
# subroutine from this function. That keeps this function readable.
#
# This function runs in historical order--from upgrades that older
# installations need, to upgrades that newer installations need.
# The order of items inside this function should only be changed if
# absolutely necessary.
#
# The subroutines should have long, descriptive names, so that you
# can easily see what is being done, just by reading this function.
#
# This function is mostly self-documenting. If you're curious about
# what each of the added/removed columns does, you should see the schema
# docs at:
# http://www.ravenbrook.com/project/p4dti/tool/cgi/bugzilla-schema/
#
# When you add a change, you should only add a comment if you want
# to describe why the change was made. You don't need to describe
# the purpose of a column.
#
sub update_table_definitions {
my $old_params = shift;
my $dbh = Bugzilla->dbh;
_update_pre_checksetup_bugzillas();
$dbh->bz_add_column('attachments', 'submitter_id',
{TYPE => 'INT3', NOTNULL => 1}, 0);
$dbh->bz_rename_column('bugs_activity', 'when', 'bug_when');
_add_bug_vote_cache();
_update_product_name_definition();
$dbh->bz_add_column('profiles', 'disabledtext',
{TYPE => 'MEDIUMTEXT', NOTNULL => 1}, '');
_populate_longdescs();
_update_bugs_activity_field_to_fieldid();
if (!$dbh->bz_column_info('bugs', 'lastdiffed')) {
$dbh->bz_add_column('bugs', 'lastdiffed', {TYPE => 'DATETIME'});
$dbh->do('UPDATE bugs SET lastdiffed = NOW()');
}
_add_unique_login_name_index_to_profiles();
$dbh->bz_add_column('profiles', 'mybugslink',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
_update_component_user_fields_to_ids();
$dbh->bz_add_column('bugs', 'everconfirmed', {TYPE => 'BOOLEAN', NOTNULL => 1},
1);
_populate_milestones_table();
# 2000-03-22 Changed the default value for target_milestone to be "---"
# (which is still not quite correct, but much better than what it was
# doing), and made the size of the value field in the milestones table match
# the size of the target_milestone field in the bugs table.
$dbh->bz_alter_column('bugs', 'target_milestone',
{TYPE => 'varchar(20)', NOTNULL => 1, DEFAULT => "'---'"});
$dbh->bz_alter_column('milestones', 'value',
{TYPE => 'varchar(20)', NOTNULL => 1});
_add_products_defaultmilestone();
# 2000-03-24 Added unique indexes into the cc and keyword tables. This
# prevents certain database inconsistencies, and, moreover, is required for
# new generalized list code to work.
if ( !$dbh->bz_index_info('cc', 'cc_bug_id_idx')
|| !$dbh->bz_index_info('cc', 'cc_bug_id_idx')->{TYPE})
{
$dbh->bz_drop_index('cc', 'cc_bug_id_idx');
$dbh->bz_add_index('cc', 'cc_bug_id_idx',
{TYPE => 'UNIQUE', FIELDS => [qw(bug_id who)]});
}
if ( !$dbh->bz_index_info('keywords', 'keywords_bug_id_idx')
|| !$dbh->bz_index_info('keywords', 'keywords_bug_id_idx')->{TYPE})
{
$dbh->bz_drop_index('keywords', 'keywords_bug_id_idx');
$dbh->bz_add_index('keywords', 'keywords_bug_id_idx',
{TYPE => 'UNIQUE', FIELDS => [qw(bug_id keywordid)]});
}
_copy_from_comments_to_longdescs();
_populate_duplicates_table();
if (!$dbh->bz_column_info('email_setting', 'user_id')) {
$dbh->bz_add_column('profiles', 'emailflags', {TYPE => 'MEDIUMTEXT'});
}
if (!$dbh->bz_index_info('email_rates', 'email_rates_message_ts_idx')) {
$dbh->bz_add_index('email_rates', 'email_rates_message_ts_idx', ['message_ts']);
}
$dbh->bz_add_column('groups', 'isactive',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
$dbh->bz_add_column('attachments', 'isobsolete',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_drop_column("profiles", "emailnotification");
$dbh->bz_drop_column("profiles", "newemailtech");
# 2003-11-19; chicks@chicks.net; bug 225973: fix field size to accommodate
# wider algorithms such as Blowfish. Note that this needs to be run
# before recrypting passwords in the following block.
$dbh->bz_alter_column('profiles', 'cryptpassword', {TYPE => 'varchar(128)'});
_recrypt_plaintext_passwords();
# 2001-06-15 kiko@async.com.br - Change bug:version size to avoid
# truncates re http://bugzilla.mozilla.org/show_bug.cgi?id=9352
$dbh->bz_alter_column('bugs', 'version', {TYPE => 'varchar(64)', NOTNULL => 1});
_update_bugs_activity_to_only_record_changes();
# bug 90933: Make disabledtext NOT NULL
if (!$dbh->bz_column_info('profiles', 'disabledtext')->{NOTNULL}) {
$dbh->bz_alter_column("profiles", "disabledtext",
{TYPE => 'MEDIUMTEXT', NOTNULL => 1}, '');
}
$dbh->bz_add_column("bugs", "reporter_accessible",
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
$dbh->bz_add_column("bugs", "cclist_accessible",
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
$dbh->bz_add_column("bugs_activity", "attach_id", {TYPE => 'INT5'});
_delete_logincookies_cryptpassword_and_handle_invalid_cookies();
# qacontact/assignee should always be able to see bugs: bug 97471
$dbh->bz_drop_column("bugs", "qacontact_accessible");
$dbh->bz_drop_column("bugs", "assignee_accessible");
# 2002-02-20 jeff.hedlund@matrixsi.com - bug 24789 time tracking
$dbh->bz_add_column("longdescs", "work_time",
{TYPE => 'decimal(5,2)', NOTNULL => 1, DEFAULT => '0'});
$dbh->bz_add_column("bugs", "estimated_time",
{TYPE => 'decimal(5,2)', NOTNULL => 1, DEFAULT => '0'});
$dbh->bz_add_column("bugs", "remaining_time",
{TYPE => 'decimal(5,2)', NOTNULL => 1, DEFAULT => '0'});
$dbh->bz_add_column("bugs", "deadline", {TYPE => 'DATETIME'});
_use_ip_instead_of_hostname_in_logincookies();
$dbh->bz_add_column('longdescs', 'isprivate',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_add_column('attachments', 'isprivate',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_add_column("bugs", "alias", {TYPE => "varchar(20)"});
$dbh->bz_add_index('bugs', 'bugs_alias_idx',
{TYPE => 'UNIQUE', FIELDS => [qw(alias)]});
_move_quips_into_db();
$dbh->bz_drop_column("namedqueries", "watchfordiffs");
_use_ids_for_products_and_components();
_convert_groups_system_from_groupset();
_convert_attachment_statuses_to_flags();
_remove_spaces_and_commas_from_flagtypes();
_setup_usebuggroups_backward_compatibility();
_remove_user_series_map();
# 2006-08-03 remi_zara@mac.com bug 346241, make series.creator nullable
# This must happen before calling _copy_old_charts_into_database().
if ($dbh->bz_column_info('series', 'creator')->{NOTNULL}) {
$dbh->bz_alter_column('series', 'creator', {TYPE => 'INT3'});
$dbh->do("UPDATE series SET creator = NULL WHERE creator = 0");
}
_copy_old_charts_into_database();
_add_user_group_map_grant_type();
_add_group_group_map_grant_type();
$dbh->bz_add_column("profiles", "extern_id", {TYPE => 'varchar(64)'});
$dbh->bz_add_column('flagtypes', 'grant_group_id', {TYPE => 'INT3'});
$dbh->bz_add_column('flagtypes', 'request_group_id', {TYPE => 'INT3'});
# mailto is no longer just userids
$dbh->bz_rename_column('whine_schedules', 'mailto_userid', 'mailto');
$dbh->bz_add_column('whine_schedules', 'mailto_type',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => '0'});
_add_longdescs_already_wrapped();
# Moved enum types to separate tables so we need change the old enum
# types to standard varchars in the bugs table.
$dbh->bz_alter_column('bugs', 'bug_status',
{TYPE => 'varchar(64)', NOTNULL => 1});
# 2005-03-23 Tomas.Kopal@altap.cz - add default value to resolution,
# bug 286695
$dbh->bz_alter_column('bugs', 'resolution',
{TYPE => 'varchar(64)', NOTNULL => 1, DEFAULT => "''"});
$dbh->bz_alter_column('bugs', 'priority',
{TYPE => 'varchar(64)', NOTNULL => 1});
$dbh->bz_alter_column('bugs', 'bug_severity',
{TYPE => 'varchar(64)', NOTNULL => 1});
$dbh->bz_alter_column('bugs', 'rep_platform',
{TYPE => 'varchar(64)', NOTNULL => 1}, '');
$dbh->bz_alter_column('bugs', 'op_sys', {TYPE => 'varchar(64)', NOTNULL => 1});
# When migrating quips from the '$datadir/comments' file to the DB,
# the user ID should be NULL instead of 0 (which is an invalid user ID).
if ($dbh->bz_column_info('quips', 'userid')->{NOTNULL}) {
$dbh->bz_alter_column('quips', 'userid', {TYPE => 'INT3'});
print "Changing owner to NULL for quips where the owner is", " unknown...\n";
$dbh->do('UPDATE quips SET userid = NULL WHERE userid = 0');
}
_convert_attachments_filename_from_mediumtext();
$dbh->bz_add_column('quips', 'approved',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
# 2002-12-20 Bug 180870 - remove manual shadowdb replication code
$dbh->bz_drop_table("shadowlog");
_rename_votes_count_and_force_group_refresh();
# 2004/02/15 - Summaries shouldn't be null - see bug 220232
if (!exists $dbh->bz_column_info('bugs', 'short_desc')->{NOTNULL}) {
$dbh->bz_alter_column('bugs', 'short_desc',
{TYPE => 'MEDIUMTEXT', NOTNULL => 1}, '');
}
$dbh->bz_add_column('products', 'classification_id',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => '1'});
_fix_group_with_empty_name();
$dbh->bz_add_index('bugs_activity', 'bugs_activity_who_idx', [qw(who)]);
# Add defaults for some fields that should have them but didn't.
$dbh->bz_alter_column('bugs', 'status_whiteboard',
{TYPE => 'MEDIUMTEXT', NOTNULL => 1, DEFAULT => "''"});
if ($dbh->bz_column_info('bugs', 'votes')) {
$dbh->bz_alter_column('bugs', 'votes',
{TYPE => 'INT3', NOTNULL => 1, DEFAULT => '0'});
}
$dbh->bz_alter_column('bugs', 'lastdiffed', {TYPE => 'DATETIME'});
# 2005-03-09 qa_contact should be NULL instead of 0, bug 285534
if ($dbh->bz_column_info('bugs', 'qa_contact')->{NOTNULL}) {
$dbh->bz_alter_column('bugs', 'qa_contact', {TYPE => 'INT3'});
$dbh->do("UPDATE bugs SET qa_contact = NULL WHERE qa_contact = 0");
}
# 2005-03-27 initialqacontact should be NULL instead of 0, bug 287483
if ($dbh->bz_column_info('components', 'initialqacontact')->{NOTNULL}) {
$dbh->bz_alter_column('components', 'initialqacontact', {TYPE => 'INT3'});
}
$dbh->do("UPDATE components SET initialqacontact = NULL "
. "WHERE initialqacontact = 0");
_migrate_email_prefs_to_new_table();
_initialize_new_email_prefs();
_change_all_mysql_booleans_to_tinyint();
# make classification_id field type be consistent with DB:Schema
$dbh->bz_alter_column('products', 'classification_id',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => '1'});
# initialowner was accidentally NULL when we checked-in Schema,
# when it really should be NOT NULL.
$dbh->bz_alter_column('components', 'initialowner',
{TYPE => 'INT3', NOTNULL => 1}, 0);
# 2005-03-28 - bug 238800 - index flags.type_id for editflagtypes.cgi
$dbh->bz_add_index('flags', 'flags_type_id_idx', [qw(type_id)]);
# For a short time, the flags_type_id_idx was misnamed in upgraded installs.
$dbh->bz_drop_index('flags', 'type_id');
# 2005-04-28 - LpSolit@gmail.com - Bug 7233: add an index to versions
$dbh->bz_alter_column('versions', 'value',
{TYPE => 'varchar(64)', NOTNULL => 1});
_add_versions_product_id_index();
if (!exists $dbh->bz_column_info('milestones', 'sortkey')->{DEFAULT}) {
$dbh->bz_alter_column('milestones', 'sortkey',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => 0});
}
# 2005-06-14 - LpSolit@gmail.com - Bug 292544
$dbh->bz_alter_column('bugs', 'creation_ts', {TYPE => 'DATETIME'});
_fix_whine_queries_title_and_op_sys_value();
_fix_attachments_submitter_id_idx();
_copy_attachments_thedata_to_attach_data();
_fix_broken_all_closed_series();
# 2005-08-14 bugreport@peshkin.net -- Bug 304583
# Get rid of leftover DERIVED group permissions
use constant GRANT_DERIVED => 1;
$dbh->do("DELETE FROM user_group_map WHERE grant_type = " . GRANT_DERIVED);
_rederive_regex_groups();
# PUBLIC is a reserved word in Oracle.
$dbh->bz_rename_column('series', 'public', 'is_public');
# 2005-11-04 LpSolit@gmail.com - Bug 305927
$dbh->bz_alter_column('groups', 'userregexp',
{TYPE => 'TINYTEXT', NOTNULL => 1, DEFAULT => "''"});
_clean_control_characters_from_short_desc();
# 2005-12-07 altlst@sonic.net -- Bug 225221
$dbh->bz_add_column('longdescs', 'comment_id',
{TYPE => 'INTSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
_stop_storing_inactive_flags();
_change_short_desc_from_mediumtext_to_varchar();
# 2006-07-01 wurblzap@gmail.com -- Bug 69000
$dbh->bz_add_column('namedqueries', 'id',
{TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
_move_namedqueries_linkinfooter_to_its_own_table();
_add_classifications_sortkey();
_move_data_nomail_into_db();
# The products table lacked sensible defaults.
if ($dbh->bz_column_info('products', 'milestoneurl')) {
$dbh->bz_alter_column('products', 'milestoneurl',
{TYPE => 'TINYTEXT', NOTNULL => 1, DEFAULT => "''"});
}
if ($dbh->bz_column_info('products', 'disallownew')) {
$dbh->bz_alter_column('products', 'disallownew',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 0});
if ($dbh->bz_column_info('products', 'votesperuser')) {
$dbh->bz_alter_column('products', 'votesperuser',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => 0});
$dbh->bz_alter_column('products', 'votestoconfirm',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => 0});
}
}
# 2006-08-04 LpSolit@gmail.com - Bug 305941
$dbh->bz_drop_column('profiles', 'refreshed_when');
$dbh->bz_drop_column('groups', 'last_changed');
# 2006-08-06 LpSolit@gmail.com - Bug 347521
$dbh->bz_alter_column('flagtypes', 'id',
{TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
$dbh->bz_alter_column('keyworddefs', 'id',
{TYPE => 'SMALLSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
# 2006-08-19 LpSolit@gmail.com - Bug 87795
$dbh->bz_alter_column('tokens', 'userid', {TYPE => 'INT3'});
$dbh->bz_drop_index('bugs', 'bugs_short_desc_idx');
# The profiles table was missing some defaults.
$dbh->bz_alter_column('profiles', 'disabledtext',
{TYPE => 'MEDIUMTEXT', NOTNULL => 1, DEFAULT => "''"});
$dbh->bz_alter_column('profiles', 'realname',
{TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"});
_update_longdescs_who_index();
$dbh->bz_add_column('setting', 'subclass', {TYPE => 'varchar(32)'});
$dbh->bz_alter_column('longdescs', 'thetext',
{TYPE => 'LONGTEXT', NOTNULL => 1}, '');
# 2006-10-20 LpSolit@gmail.com - Bug 189627
$dbh->bz_add_column('group_control_map', 'editcomponents',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_add_column('group_control_map', 'editbugs',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_add_column('group_control_map', 'canconfirm',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
# 2006-11-07 LpSolit@gmail.com - Bug 353656
$dbh->bz_add_column('longdescs', 'type',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => '0'});
$dbh->bz_add_column('longdescs', 'extra_data', {TYPE => 'varchar(255)'});
$dbh->bz_add_column('versions', 'id',
{TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
$dbh->bz_add_column('milestones', 'id',
{TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
_fix_uppercase_custom_field_names();
_fix_uppercase_index_names();
# 2007-05-17 LpSolit@gmail.com - Bug 344965
_initialize_workflow_for_upgrade($old_params);
# 2007-08-08 LpSolit@gmail.com - Bug 332149
$dbh->bz_add_column('groups', 'icon_url', {TYPE => 'TINYTEXT'});
# 2007-08-21 wurblzap@gmail.com - Bug 365378
_make_lang_setting_dynamic();
# 2007-11-29 xiaoou.wu@oracle.com - Bug 153129
_change_text_types();
# 2007-09-09 LpSolit@gmail.com - Bug 99215
_fix_attachment_modification_date();
$dbh->bz_drop_index('longdescs', 'longdescs_thetext_idx');
_populate_bugs_fulltext();
# 2008-01-18 xiaoou.wu@oracle.com - Bug 414292
$dbh->bz_alter_column('series', 'query', {TYPE => 'MEDIUMTEXT', NOTNULL => 1});
# Add FK to multi select field tables
_add_foreign_keys_to_multiselects();
# 2008-07-28 tfu@redhat.com - Bug 431669
$dbh->bz_alter_column('group_control_map', 'product_id',
{TYPE => 'INT2', NOTNULL => 1});
# 2008-09-07 LpSolit@gmail.com - Bug 452893
_fix_illegal_flag_modification_dates();
_add_visibility_value_to_value_tables();
# 2009-03-02 arbingersys@gmail.com - Bug 423613
_add_extern_id_index();
# 2009-03-31 LpSolit@gmail.com - Bug 478972
$dbh->bz_alter_column('group_control_map', 'entry',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_alter_column('group_control_map', 'canedit',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
# 2009-01-16 oreomike@gmail.com - Bug 302420
$dbh->bz_add_column('whine_events', 'mailifnobugs',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
_convert_disallownew_to_isactive();
$dbh->bz_alter_column('bugs_activity', 'added', {TYPE => 'varchar(255)'});
$dbh->bz_add_index('bugs_activity', 'bugs_activity_added_idx', ['added']);
# 2009-09-28 LpSolit@gmail.com - Bug 519032
$dbh->bz_drop_column('series', 'last_viewed');
# 2009-09-28 LpSolit@gmail.com - Bug 399073
_fix_logincookies_ipaddr();
# 2009-11-01 LpSolit@gmail.com - Bug 525025
_fix_invalid_custom_field_names();
_set_attachment_comment_types();
$dbh->bz_drop_column('products', 'milestoneurl');
_add_allows_unconfirmed_to_product_table();
_convert_flagtypes_fks_to_set_null();
_fix_decimal_types();
_fix_series_creator_fk();
# 2009-11-14 dkl@redhat.com - Bug 310450
$dbh->bz_add_column('bugs_activity', 'comment_id', {TYPE => 'INT4'});
# 2010-04-07 LpSolit@gmail.com - Bug 69621
$dbh->bz_drop_column('bugs', 'keywords');
# 2010-05-07 ewong@pw-wspx.org - Bug 463945
$dbh->bz_alter_column('group_control_map', 'membercontrol',
{TYPE => 'INT1', NOTNULL => 1, DEFAULT => CONTROLMAPNA});
$dbh->bz_alter_column('group_control_map', 'othercontrol',
{TYPE => 'INT1', NOTNULL => 1, DEFAULT => CONTROLMAPNA});
# Add NOT NULL to some columns that need it, and DEFAULT to
# attachments.ispatch.
$dbh->bz_alter_column('attachments', 'ispatch',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_alter_column('keyworddefs', 'description',
{TYPE => 'MEDIUMTEXT', NOTNULL => 1}, '');
$dbh->bz_alter_column('products', 'description',
{TYPE => 'MEDIUMTEXT', NOTNULL => 1}, '');
# Change the default of allows_unconfirmed to TRUE as part
# of the new workflow.
$dbh->bz_alter_column('products', 'allows_unconfirmed',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
# 2010-07-18 LpSolit@gmail.com - Bug 119703
_remove_attachment_isurl();
# 2009-05-07 ghendricks@novell.com - Bug 77193
_add_isactive_to_product_fields();
# 2010-10-09 LpSolit@gmail.com - Bug 505165
$dbh->bz_alter_column('flags', 'setter_id', {TYPE => 'INT3', NOTNULL => 1});
# 2010-10-09 LpSolit@gmail.com - Bug 451735
_fix_series_indexes();
$dbh->bz_add_column('bug_see_also', 'id',
{TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
_rename_tags_to_tag();
# 2011-01-29 LpSolit@gmail.com - Bug 616185
_migrate_user_tags();
_populate_bug_see_also_class();
# 2011-06-15 dkl@mozilla.com - Bug 658929
_migrate_disabledtext_boolean();
# 2011-10-11 miketosh - Bug 690173
_on_delete_set_null_for_audit_log_userid();
# 2011-11-01 glob@mozilla.com - Bug 240437
$dbh->bz_add_column('profiles', 'last_seen_date', {TYPE => 'DATETIME'});
# 2011-11-28 dkl@mozilla.com - Bug 685611
_fix_notnull_defaults();
# 2012-02-15 LpSolit@gmail.com - Bug 722113
if ($dbh->bz_index_info('profile_search', 'profile_search_user_id')) {
$dbh->bz_drop_index('profile_search', 'profile_search_user_id');
$dbh->bz_add_index('profile_search', 'profile_search_user_id_idx',
[qw(user_id)]);
}
# 2012-06-06 dkl@mozilla.com - Bug 762288
$dbh->bz_alter_column('bugs_activity', 'removed', {TYPE => 'varchar(255)'});
$dbh->bz_add_index('bugs_activity', 'bugs_activity_removed_idx', ['removed']);
# 2012-06-13 dkl@mozilla.com - Bug 764457
$dbh->bz_add_column('bugs_activity', 'id',
{TYPE => 'INTSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
# 2012-06-13 dkl@mozilla.com - Bug 764466
$dbh->bz_add_column('profiles_activity', 'id',
{TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
# 2012-07-24 dkl@mozilla.com - Bug 776972
# BMO - we change this to BIGSERIAL further down
#$dbh->bz_alter_column('bugs_activity', 'id',
# {TYPE => 'INTSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
# 2012-07-24 dkl@mozilla.com - Bug 776982
_fix_longdescs_primary_key();
# 2012-08-02 dkl@mozilla.com - Bug 756953
_fix_dependencies_dupes();
# 2013-02-04 dkl@mozilla.com - Bug 824346
_fix_flagclusions_indexes();
# 2012-04-15 Frank@Frank-Becker.de - Bug 740536
$dbh->bz_add_index('audit_log', 'audit_log_class_idx', ['class', 'at_time']);
# 2013-08-16 glob@mozilla.com - Bug 905925
$dbh->bz_add_index('attachments', 'attachments_ispatch_idx', ['ispatch']);
# 2014-06-09 dylan@mozilla.com - Bug 1022923
$dbh->bz_add_index('bug_user_last_visit',
'bug_user_last_visit_last_visit_ts_idx',
['last_visit_ts']);
# 2014-07-14 sgreen@redhat.com - Bug 726696
$dbh->bz_alter_column('tokens', 'tokentype',
{TYPE => 'varchar(16)', NOTNULL => 1});
# 2014-07-27 LpSolit@gmail.com - Bug 1044561
_fix_user_api_keys_indexes();
# 2018-06-14 dylan@mozilla.com - Bug 1468818
$dbh->bz_add_column('longdescs', 'is_markdown',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
# 2014-10-?? dkl@mozilla.com - Bug 1062940
$dbh->bz_alter_column('bugs', 'alias', {TYPE => 'varchar(40)'});
# 2015-05-13 dylan@mozilla.com - Bug 1160430
$dbh->bz_add_column('keyworddefs', 'is_active',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
$dbh->bz_add_column('user_api_keys', 'app_id', {TYPE => 'varchar(64)'});
$dbh->bz_add_index('user_api_keys', 'user_api_keys_user_id_app_id_idx',
[qw(user_id app_id)]);
$dbh->bz_add_column('user_api_keys', 'sticky',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
_add_attach_size();
_fix_disable_mail();
# 2015-07-25 dylan@mozilla.com - Bug 1179856
$dbh->bz_alter_column('tokens', 'token',
{TYPE => 'varchar(22)', NOTNULL => 1, PRIMARYKEY => 1});
# 2015-08-20 dylan@mozilla.com - Bug 1196092
$dbh->bz_alter_column('logincookies', 'cookie',
{TYPE => 'varchar(22)', NOTNULL => 1});
$dbh->bz_add_index('logincookies', 'logincookies_cookie_idx',
{TYPE => 'UNIQUE', FIELDS => ['cookie']});
$dbh->bz_add_column('logincookies', 'id',
{TYPE => 'INTSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
$dbh->bz_add_column('user_api_keys', 'last_used_ip', {TYPE => 'varchar(40)'});
_add_restrict_ipaddr();
$dbh->bz_add_column('profiles', 'password_change_required',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
$dbh->bz_add_column('profiles', 'password_change_reason',
{TYPE => 'varchar(64)'});
$dbh->bz_add_column('profiles', 'mfa',
{TYPE => 'varchar(8)',, DEFAULT => "''"});
$dbh->bz_add_column('profiles', 'mfa_required_date', {TYPE => 'DATETIME'});
# 2019-05-08 imadueme@mozilla.com - Bug 1550145
$dbh->bz_add_column('profiles', 'forget_after_date', {TYPE => 'DATETIME'});
_migrate_group_owners();
$dbh->bz_add_column('groups', 'idle_member_removal',
{TYPE => 'INT2', NOTNULL => 1, DEFAULT => '0'});
_migrate_preference_categories();
# 2016-09-01 dkl@mozilla.com - Bug 1268317
$dbh->bz_add_column('components', 'triage_owner_id', {TYPE => 'INT3'});
$dbh->bz_add_column('profiles', 'nickname',
{TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"});
$dbh->bz_add_index('profiles', 'profiles_nickname_idx', [qw(nickname)]);
$dbh->bz_add_index('profiles', 'profiles_realname_ft_idx',
{TYPE => 'FULLTEXT', FIELDS => ['realname']});
_migrate_nicknames();
# Bug 1354589 - dkl@mozilla.com
_populate_oauth2_scopes();
# Bug 1510109, 1252298 - kohei.yoshino@gmail.com
$dbh->bz_add_column('products', 'bug_description_template',
{TYPE => 'MEDIUMTEXT'});
$dbh->bz_add_column('components', 'bug_description_template',
{TYPE => 'MEDIUMTEXT'});
# Bug 1522341, 1541617, 1546788 - kohei.yoshino@gmail.com
$dbh->bz_add_column('bugs', 'bug_type', {TYPE => 'varchar(20)'});
$dbh->bz_add_column('components', 'default_bug_type', {TYPE => 'varchar(20)'});
$dbh->bz_add_column('products', 'default_bug_type', {TYPE => 'varchar(20)'});
$dbh->bz_alter_column('bugs', 'bug_type',
{TYPE => 'varchar(20)', NOTNULL => 1}, '--');
_add_oauth2_jwt_support();
# Bug 1565403 - kohei.yoshino@gmail.com
$dbh->bz_add_column('bugs', 'filed_via',
{TYPE => 'varchar(40)', NOTNULL => 1, DEFAULT => "'unknown'"});
# Bug 1576667 - dkl@mozilla.com
_populate_api_keys_creation_ts();
# Bug 1612290 - dkl@mozilla.com
$dbh->bz_add_column('profiles', 'bounce_count', {TYPE => 'INT1', NOTNULL => 1, DEFAULT => 0});
# Bug 1588221 - dkl@mozilla.com
$dbh->bz_alter_column('bugs_activity', 'attach_id', {TYPE => 'INT5'});
$dbh->bz_alter_column('attachments', 'attach_id',
{TYPE => 'BIGSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
$dbh->bz_alter_column('attach_data', 'id',
{TYPE => 'INT5', NOTNULL => 1, PRIMARYKEY => 1});
$dbh->bz_alter_column('flags', 'attach_id', {TYPE => 'INT5'});
$dbh->bz_alter_column('user_request_log', 'attach_id', {TYPE => 'INT5', NOTNULL => 0});
_populate_attachment_storage_class();
################################################################
# New --TABLE-- changes should go *** A B O V E *** this point #
################################################################
Bugzilla::Hook::process('install_update_db');
# We do this here because otherwise the foreign key from
# products.classification_id to classifications.id will fail
# (because products.classification_id defaults to "1", so on upgraded
# installations it's already been set before the first Classification
# exists).
Bugzilla::Install::create_default_classification();
$dbh->bz_setup_foreign_keys();
}
# Subroutines should be ordered in the order that they are called.
# Thus, newer subroutines should be at the bottom.
sub _update_pre_checksetup_bugzillas {
my $dbh = Bugzilla->dbh;
# really old fields that were added before checksetup.pl existed
# but aren't in very old bugzilla's (like 2.1)
# Steve Stock (sstock@iconnect-inc.com)
$dbh->bz_add_column('bugs', 'target_milestone',
{TYPE => 'varchar(20)', NOTNULL => 1, DEFAULT => "'---'"});
$dbh->bz_add_column('bugs', 'qa_contact', {TYPE => 'INT3'});
$dbh->bz_add_column('bugs', 'status_whiteboard',
{TYPE => 'MEDIUMTEXT', NOTNULL => 1, DEFAULT => "''"});
if (!$dbh->bz_column_info('products', 'isactive')) {
$dbh->bz_add_column('products', 'disallownew',
{TYPE => 'BOOLEAN', NOTNULL => 1}, 0);
}
$dbh->bz_add_column('components', 'initialqacontact', {TYPE => 'TINYTEXT'});
$dbh->bz_add_column('components', 'description',
{TYPE => 'MEDIUMTEXT', NOTNULL => 1}, '');
}
sub _add_bug_vote_cache {
my $dbh = Bugzilla->dbh;
# 1999-10-11 Restructured voting database to add a cached value in each
# bug recording how many total votes that bug has. While I'm at it,
# I removed the unused "area" field from the bugs database. It is
# distressing to realize that the bugs table has reached the maximum
# number of indices allowed by MySQL (16), which may make future
# enhancements awkward.
# (P.S. All is not lost; it appears that the latest betas of MySQL
# support a new table format which will allow 32 indices.)
if ($dbh->bz_column_info('bugs', 'area')) {
$dbh->bz_drop_column('bugs', 'area');
$dbh->bz_add_column('bugs', 'votes',
{TYPE => 'INT3', NOTNULL => 1, DEFAULT => 0});
$dbh->bz_add_index('bugs', 'bugs_votes_idx', [qw(votes)]);
$dbh->bz_add_column('products', 'votesperuser', {TYPE => 'INT2', NOTNULL => 1},
0);
}
}
sub _update_product_name_definition {
my $dbh = Bugzilla->dbh;
# The product name used to be very different in various tables.
#
# It was varchar(16) in bugs
# tinytext in components
# tinytext in products
# tinytext in versions
#
# tinytext is equivalent to varchar(255), which is quite huge, so I change
# them all to varchar(64).
# Only do this if these fields still exist - they're removed in
# a later change
if ($dbh->bz_column_info('products', 'product')) {
$dbh->bz_alter_column('bugs', 'product', {TYPE => 'varchar(64)', NOTNULL => 1});
$dbh->bz_alter_column('components', 'program', {TYPE => 'varchar(64)'});
$dbh->bz_alter_column('products', 'product', {TYPE => 'varchar(64)'});
$dbh->bz_alter_column('versions', 'program',
{TYPE => 'varchar(64)', NOTNULL => 1});
}
}
# A helper for the function below.
sub _write_one_longdesc {
my ($id, $who, $when, $buffer) = (@_);
my $dbh = Bugzilla->dbh;
$buffer = trim($buffer);
return if !$buffer;
$dbh->do(
"INSERT INTO longdescs (bug_id, who, bug_when, thetext)
VALUES (?,?,?,?)", undef, $id, $who,
time2str("%Y/%m/%d %H:%M:%S", $when), $buffer
);
}
sub _populate_longdescs {
my $dbh = Bugzilla->dbh;
# 2000-01-20 Added a new "longdescs" table, which is supposed to have
# all the long descriptions in it, replacing the old long_desc field
# in the bugs table. The below hideous code populates this new table
# with things from the old field, with ugly parsing and heuristics.
if ($dbh->bz_column_info('bugs', 'long_desc')) {
my ($total) = $dbh->selectrow_array("SELECT COUNT(*) FROM bugs");
print "Populating new long_desc table. This is slow. There are",
" $total\nbugs to process; a line of dots will be printed",
" for each 50.\n\n";
local $| = 1;
# On MySQL, longdescs doesn't benefit from transactions, but this
# doesn't hurt.
$dbh->bz_start_transaction();
$dbh->do('DELETE FROM longdescs');
my $sth = $dbh->prepare(
"SELECT bug_id, creation_ts, reporter,
long_desc FROM bugs ORDER BY bug_id"
);
$sth->execute();
my $count = 0;
while (my ($id, $createtime, $reporterid, $desc) = $sth->fetchrow_array()) {
$count++;
indicate_progress({total => $total, current => $count});
$desc =~ s/\r//g;
my $who = $reporterid;
my $when = str2time($createtime);
my $buffer = "";
foreach my $line (split(/\n/, $desc)) {
$line =~ s/\s+$//g; # Trim trailing whitespace.
if ($line =~ /^------- Additional Comments From ([^\s]+)\s+(\d.+\d)\s+-------$/)
{
my $name = $1;
my $date = str2time($2);
# Oy, what a hack. The creation time is accurate to the
# second. But the long text only contains things accurate
# to the And so, if someone makes a comment within a
# minute of the original bug creation, then the comment can
# come *before* the bug creation. So, we add 59 seconds to
# the time of all comments, so that they are always
# considered to have happened at the *end* of the given
# minute, not the beginning.
$date += 59;
if ($date >= $when) {
_write_one_longdesc($id, $who, $when, $buffer);
$buffer = "";
$when = $date;
my $s2 = $dbh->prepare("SELECT userid FROM profiles " . "WHERE login_name = ?");
$s2->execute($name);
($who) = ($s2->fetchrow_array());
if (!$who) {
# This username doesn't exist. Maybe someone
# renamed them or something. Invent a new profile
# entry disabled, just to represent them.
$dbh->do(
"INSERT INTO profiles (login_name,
cryptpassword, disabledtext)
VALUES (?,?,?)", undef, $name, '*',
"Account created only to maintain" . " database integrity"
);
$who = $dbh->bz_last_key('profiles', 'userid');
}
next;
}
}
$buffer .= $line . "\n";
}
_write_one_longdesc($id, $who, $when, $buffer);
} # while loop