generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 142
/
migrations.go
2134 lines (1927 loc) · 87.6 KB
/
migrations.go
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
package sqlstore
import (
"encoding/json"
"time"
sq "github.com/Masterminds/squirrel"
"github.com/blang/semver"
"github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/mattermost/mattermost-plugin-playbooks/server/app"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/pkg/errors"
)
type Migration struct {
fromVersion semver.Version
toVersion semver.Version
migrationFunc func(sqlx.Ext, *SQLStore) error
}
const MySQLCharset = "DEFAULT CHARACTER SET utf8mb4"
var migrations = []Migration{
{
fromVersion: semver.MustParse("0.0.0"),
toVersion: semver.MustParse("0.1.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_System (
SKey VARCHAR(64) PRIMARY KEY,
SValue VARCHAR(1024) NULL
)
` + MySQLCharset); err != nil {
return errors.Wrapf(err, "failed creating table IR_System")
}
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_Incident (
ID VARCHAR(26) PRIMARY KEY,
Name VARCHAR(1024) NOT NULL,
Description VARCHAR(4096) NOT NULL,
IsActive BOOLEAN NOT NULL,
CommanderUserID VARCHAR(26) NOT NULL,
TeamID VARCHAR(26) NOT NULL,
ChannelID VARCHAR(26) NOT NULL UNIQUE,
CreateAt BIGINT NOT NULL,
EndAt BIGINT NOT NULL DEFAULT 0,
DeleteAt BIGINT NOT NULL DEFAULT 0,
ActiveStage BIGINT NOT NULL,
PostID VARCHAR(26) NOT NULL DEFAULT '',
PlaybookID VARCHAR(26) NOT NULL DEFAULT '',
ChecklistsJSON TEXT NOT NULL,
INDEX IR_Incident_TeamID (TeamID),
INDEX IR_Incident_TeamID_CommanderUserID (TeamID, CommanderUserID),
INDEX IR_Incident_ChannelID (ChannelID)
)
` + MySQLCharset); err != nil {
return errors.Wrapf(err, "failed creating table IR_Incident")
}
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_Playbook (
ID VARCHAR(26) PRIMARY KEY,
Title VARCHAR(1024) NOT NULL,
Description VARCHAR(4096) NOT NULL,
TeamID VARCHAR(26) NOT NULL,
CreatePublicIncident BOOLEAN NOT NULL,
CreateAt BIGINT NOT NULL,
DeleteAt BIGINT NOT NULL DEFAULT 0,
ChecklistsJSON TEXT NOT NULL,
NumStages BIGINT NOT NULL DEFAULT 0,
NumSteps BIGINT NOT NULL DEFAULT 0,
INDEX IR_Playbook_TeamID (TeamID),
INDEX IR_PlaybookMember_PlaybookID (ID)
)
` + MySQLCharset); err != nil {
return errors.Wrapf(err, "failed creating table IR_Playbook")
}
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_PlaybookMember (
PlaybookID VARCHAR(26) NOT NULL REFERENCES IR_Playbook(ID),
MemberID VARCHAR(26) NOT NULL,
INDEX IR_PlaybookMember_PlaybookID (PlaybookID),
INDEX IR_PlaybookMember_MemberID (MemberID)
)
` + MySQLCharset); err != nil {
return errors.Wrapf(err, "failed creating table IR_PlaybookMember")
}
} else {
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_System (
SKey VARCHAR(64) PRIMARY KEY,
SValue VARCHAR(1024) NULL
);
`); err != nil {
return errors.Wrapf(err, "failed creating table IR_System")
}
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_Incident (
ID TEXT PRIMARY KEY,
Name TEXT NOT NULL,
Description TEXT NOT NULL,
IsActive BOOLEAN NOT NULL,
CommanderUserID TEXT NOT NULL,
TeamID TEXT NOT NULL,
ChannelID TEXT NOT NULL UNIQUE,
CreateAt BIGINT NOT NULL,
EndAt BIGINT NOT NULL DEFAULT 0,
DeleteAt BIGINT NOT NULL DEFAULT 0,
ActiveStage BIGINT NOT NULL,
PostID TEXT NOT NULL DEFAULT '',
PlaybookID TEXT NOT NULL DEFAULT '',
ChecklistsJSON JSON NOT NULL
);
`); err != nil {
return errors.Wrapf(err, "failed creating table IR_Incident")
}
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_Playbook (
ID TEXT PRIMARY KEY,
Title TEXT NOT NULL,
Description TEXT NOT NULL,
TeamID TEXT NOT NULL,
CreatePublicIncident BOOLEAN NOT NULL,
CreateAt BIGINT NOT NULL,
DeleteAt BIGINT NOT NULL DEFAULT 0,
ChecklistsJSON JSON NOT NULL,
NumStages BIGINT NOT NULL DEFAULT 0,
NumSteps BIGINT NOT NULL DEFAULT 0
);
`); err != nil {
return errors.Wrapf(err, "failed creating table IR_Playbook")
}
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_PlaybookMember (
PlaybookID TEXT NOT NULL REFERENCES IR_Playbook(ID),
MemberID TEXT NOT NULL,
UNIQUE (PlaybookID, MemberID)
);
`); err != nil {
return errors.Wrapf(err, "failed creating table IR_PlaybookMember")
}
if _, err := e.Exec(createPGIndex("IR_Incident_TeamID", "IR_Incident", "TeamID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_Incident_TeamID")
}
if _, err := e.Exec(createPGIndex("IR_Incident_TeamID_CommanderUserID", "IR_Incident", "TeamID, CommanderUserID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_Incident_TeamID_CommanderUserID")
}
if _, err := e.Exec(createPGIndex("IR_Incident_ChannelID", "IR_Incident", "ChannelID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_Incident_ChannelID")
}
if _, err := e.Exec(createPGIndex("IR_Playbook_TeamID", "IR_Playbook", "TeamID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_Playbook_TeamID")
}
if _, err := e.Exec(createPGIndex("IR_PlaybookMember_PlaybookID", "IR_PlaybookMember", "PlaybookID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_PlaybookMember_PlaybookID")
}
if _, err := e.Exec(createPGIndex("IR_PlaybookMember_MemberID", "IR_PlaybookMember", "MemberID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_PlaybookMember_MemberID ")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.1.0"),
toVersion: semver.MustParse("0.2.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
// prior to v1.0.0 of the plugin, this migration was used to trigger the data migration from the kvstore
return nil
},
},
{
fromVersion: semver.MustParse("0.2.0"),
toVersion: semver.MustParse("0.3.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "ActiveStageTitle", "VARCHAR(1024) DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ActiveStageTitle to table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "ActiveStageTitle", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ActiveStageTitle to table IR_Incident")
}
}
getPlaybookRunsQuery := sqlStore.builder.
Select("ID", "ActiveStage", "ChecklistsJSON").
From("IR_Incident")
var playbookRuns []struct {
ID string
ActiveStage int
ChecklistsJSON json.RawMessage
}
if err := sqlStore.selectBuilder(e, &playbookRuns, getPlaybookRunsQuery); err != nil {
return errors.Wrapf(err, "failed getting playbook runs to update their ActiveStageTitle")
}
for _, playbookRun := range playbookRuns {
var checklists []app.Checklist
if err := json.Unmarshal(playbookRun.ChecklistsJSON, &checklists); err != nil {
return errors.Wrapf(err, "failed to unmarshal checklists json for playbook run id: '%s'", playbookRun.ID)
}
numChecklists := len(checklists)
if numChecklists == 0 {
continue
}
if playbookRun.ActiveStage < 0 || playbookRun.ActiveStage >= numChecklists {
sqlStore.log.Warnf("index %d out of bounds, playbook ru n'%s' has %d stages: setting ActiveStageTitle to the empty string", playbookRun.ActiveStage, playbookRun.ID, numChecklists)
continue
}
playbookRunUpdate := sqlStore.builder.
Update("IR_Incident").
Set("ActiveStageTitle", checklists[playbookRun.ActiveStage].Title).
Where(sq.Eq{"ID": playbookRun.ID})
if _, err := sqlStore.execBuilder(e, playbookRunUpdate); err != nil {
return errors.Errorf("failed updating the ActiveStageTitle field of playbook run '%s'", playbookRun.ID)
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.3.0"),
toVersion: semver.MustParse("0.4.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_StatusPosts (
IncidentID VARCHAR(26) NOT NULL REFERENCES IR_Incident(ID),
PostID VARCHAR(26) NOT NULL,
CONSTRAINT posts_unique UNIQUE (IncidentID, PostID),
INDEX IR_StatusPosts_IncidentID (IncidentID),
INDEX IR_StatusPosts_PostID (PostID)
)
` + MySQLCharset); err != nil {
return errors.Wrapf(err, "failed creating table IR_StatusPosts")
}
if err := addColumnToMySQLTable(e, "IR_Incident", "ReminderPostID", "VARCHAR(26)"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderPostID to table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Incident", "BroadcastChannelID", "VARCHAR(26) DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column BroadcastChannelID to table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "BroadcastChannelID", "VARCHAR(26) DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column BroadcastChannelID to table IR_Playbook")
}
} else {
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_StatusPosts (
IncidentID TEXT NOT NULL REFERENCES IR_Incident(ID),
PostID TEXT NOT NULL,
UNIQUE (IncidentID, PostID)
);
`); err != nil {
return errors.Wrapf(err, "failed creating table IR_StatusPosts")
}
if _, err := e.Exec(createPGIndex("IR_StatusPosts_IncidentID", "IR_StatusPosts", "IncidentID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_StatusPosts_IncidentID")
}
if _, err := e.Exec(createPGIndex("IR_StatusPosts_PostID", "IR_StatusPosts", "PostID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_StatusPosts_PostID ")
}
if err := addColumnToPGTable(e, "IR_Incident", "ReminderPostID", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderPostID to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Incident", "BroadcastChannelID", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column BroadcastChannelID to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Playbook", "BroadcastChannelID", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column BroadcastChannelID to table IR_Playbook")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.4.0"),
toVersion: semver.MustParse("0.5.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "PreviousReminder", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column PreviousReminder to table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "ReminderMessageTemplate", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderMessageTemplate to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET ReminderMessageTemplate = '' WHERE ReminderMessageTemplate IS NULL"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderMessageTemplate to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Incident", "ReminderMessageTemplate", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderMessageTemplate to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Incident SET ReminderMessageTemplate = '' WHERE ReminderMessageTemplate IS NULL"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderMessageTemplate to table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "ReminderTimerDefaultSeconds", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderTimerDefaultSeconds to table IR_Playbook")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "PreviousReminder", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column PreviousReminder to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Playbook", "ReminderMessageTemplate", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderMessageTemplate to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Incident", "ReminderMessageTemplate", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderMessageTemplate to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "ReminderTimerDefaultSeconds", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderTimerDefaultSeconds to table IR_Playbook")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.5.0"),
toVersion: semver.MustParse("0.6.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "CurrentStatus", "VARCHAR(1024) NOT NULL DEFAULT 'Active'"); err != nil {
return errors.Wrapf(err, "failed adding column CurrentStatus to table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_StatusPosts", "Status", "VARCHAR(1024) NOT NULL DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column Status to table IR_StatusPosts")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "CurrentStatus", "TEXT NOT NULL DEFAULT 'Active'"); err != nil {
return errors.Wrapf(err, "failed adding column CurrentStatus to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_StatusPosts", "Status", "TEXT NOT NULL DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column Status to table IR_StatusPosts")
}
}
if _, err := e.Exec("UPDATE IR_Incident SET CurrentStatus = 'Resolved' WHERE EndAt != 0"); err != nil {
return errors.Wrapf(err, "failed adding column ReminderMessageTemplate to table IR_Incident")
}
return nil
},
},
{
fromVersion: semver.MustParse("0.6.0"),
toVersion: semver.MustParse("0.7.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_TimelineEvent
(
ID VARCHAR(26) NOT NULL,
IncidentID VARCHAR(26) NOT NULL REFERENCES IR_Incident(ID),
CreateAt BIGINT NOT NULL,
DeleteAt BIGINT NOT NULL DEFAULT 0,
EventAt BIGINT NOT NULL,
EventType VARCHAR(32) NOT NULL DEFAULT '',
Summary VARCHAR(256) NOT NULL DEFAULT '',
Details VARCHAR(4096) NOT NULL DEFAULT '',
PostID VARCHAR(26) NOT NULL DEFAULT '',
SubjectUserID VARCHAR(26) NOT NULL DEFAULT '',
CreatorUserID VARCHAR(26) NOT NULL DEFAULT '',
INDEX IR_TimelineEvent_ID (ID),
INDEX IR_TimelineEvent_IncidentID (IncidentID)
)
` + MySQLCharset); err != nil {
return errors.Wrapf(err, "failed creating table IR_TimelineEvent")
}
} else {
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_TimelineEvent
(
ID TEXT NOT NULL,
IncidentID TEXT NOT NULL REFERENCES IR_Incident(ID),
CreateAt BIGINT NOT NULL,
DeleteAt BIGINT NOT NULL DEFAULT 0,
EventAt BIGINT NOT NULL,
EventType TEXT NOT NULL DEFAULT '',
Summary TEXT NOT NULL DEFAULT '',
Details TEXT NOT NULL DEFAULT '',
PostID TEXT NOT NULL DEFAULT '',
SubjectUserID TEXT NOT NULL DEFAULT '',
CreatorUserID TEXT NOT NULL DEFAULT ''
)
`); err != nil {
return errors.Wrapf(err, "failed creating table IR_TimelineEvent")
}
if _, err := e.Exec(createPGIndex("IR_TimelineEvent_ID", "IR_TimelineEvent", "ID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_TimelineEvent_ID")
}
if _, err := e.Exec(createPGIndex("IR_TimelineEvent_IncidentID", "IR_TimelineEvent", "IncidentID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_TimelineEvent_IncidentID")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.7.0"),
toVersion: semver.MustParse("0.8.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "ReporterUserID", "varchar(26) NOT NULL DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ReporterUserID to table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "ReporterUserID", "TEXT NOT NULL DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ReporterUserID to table IR_Incident")
}
}
if _, err := e.Exec(`UPDATE IR_Incident SET ReporterUserID = CommanderUserID WHERE ReporterUserID = ''`); err != nil {
return errors.Wrapf(err, "Failed to migrate ReporterUserID")
}
return nil
},
},
{
fromVersion: semver.MustParse("0.8.0"),
toVersion: semver.MustParse("0.9.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "ConcatenatedInvitedUserIDs", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedInvitedUserIDs to table IR_Incident")
}
if _, err := e.Exec("UPDATE IR_Incident SET ConcatenatedInvitedUserIDs = '' WHERE ConcatenatedInvitedUserIDs IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column ConcatenatedInvitedUserIDs of table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "ConcatenatedInvitedUserIDs", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedInvitedUserIDs to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET ConcatenatedInvitedUserIDs = '' WHERE ConcatenatedInvitedUserIDs IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column ConcatenatedInvitedUserIDs of table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "InviteUsersEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column InviteUsersEnabled to table IR_Playbook")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "ConcatenatedInvitedUserIDs", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedInvitedUserIDs to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Playbook", "ConcatenatedInvitedUserIDs", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedInvitedUserIDs to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "InviteUsersEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column InviteUsersEnabled to table IR_Playbook")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.9.0"),
toVersion: semver.MustParse("0.10.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "DefaultCommanderID", "VARCHAR(26) DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column DefaultCommanderID to table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "DefaultCommanderID", "VARCHAR(26) DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column DefaultCommanderID to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "DefaultCommanderEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column DefaultCommanderEnabled to table IR_Playbook")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "DefaultCommanderID", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column DefaultCommanderID to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Playbook", "DefaultCommanderID", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column DefaultCommanderID to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "DefaultCommanderEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column DefaultCommanderEnabled to table IR_Playbook")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.10.0"),
toVersion: semver.MustParse("0.11.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if _, err := e.Exec(`
UPDATE IR_Incident
INNER JOIN Channels ON IR_Incident.ChannelID = Channels.ID
SET IR_Incident.CreateAt = Channels.CreateAt,
IR_Incident.DeleteAt = Channels.DeleteAt
WHERE IR_Incident.CreateAt = 0
AND IR_Incident.DeleteAt = 0
AND IR_Incident.ChannelID = Channels.ID
`); err != nil {
return errors.Wrap(err, "failed updating table IR_Incident with Channels' CreateAt and DeleteAt values")
}
} else {
if _, err := e.Exec(`
UPDATE IR_Incident
SET CreateAt = Channels.CreateAt,
DeleteAt = Channels.DeleteAt
FROM Channels
WHERE IR_Incident.CreateAt = 0
AND IR_Incident.DeleteAt = 0
AND IR_Incident.ChannelID = Channels.ID
`); err != nil {
return errors.Wrap(err, "failed updating table IR_Incident with Channels' CreateAt and DeleteAt values")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.11.0"),
toVersion: semver.MustParse("0.12.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "AnnouncementChannelID", "VARCHAR(26) DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column AnnouncementChannelID to table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "AnnouncementChannelID", "VARCHAR(26) DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column AnnouncementChannelID to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "AnnouncementChannelEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column AnnouncementChannelEnabled to table IR_Playbook")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "AnnouncementChannelID", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column AnnouncementChannelID to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Playbook", "AnnouncementChannelID", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column AnnouncementChannelID to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "AnnouncementChannelEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column AnnouncementChannelEnabled to table IR_Playbook")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.12.0"),
toVersion: semver.MustParse("0.13.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "WebhookOnCreationURL", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnCreationURL to table IR_Incident")
}
if _, err := e.Exec("UPDATE IR_Incident SET WebhookOnCreationURL = '' WHERE WebhookOnCreationURL IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column WebhookOnCreationURL of table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "WebhookOnCreationURL", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnCreationURL to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET WebhookOnCreationURL = '' WHERE WebhookOnCreationURL IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column WebhookOnCreationURL of table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "WebhookOnCreationEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnCreationEnabled to table IR_Playbook")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "WebhookOnCreationURL", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnCreationURL to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Playbook", "WebhookOnCreationURL", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnCreationURL to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "WebhookOnCreationEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnCreationEnabled to table IR_Playbook")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.13.0"),
toVersion: semver.MustParse("0.14.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "ConcatenatedInvitedGroupIDs", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedInvitedGroupIDs to table IR_Incident")
}
if _, err := e.Exec("UPDATE IR_Incident SET ConcatenatedInvitedGroupIDs = '' WHERE ConcatenatedInvitedGroupIDs IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column ConcatenatedInvitedGroupIDs of table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "ConcatenatedInvitedGroupIDs", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedInvitedGroupIDs to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET ConcatenatedInvitedGroupIDs = '' WHERE ConcatenatedInvitedGroupIDs IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column ConcatenatedInvitedGroupIDs of table IR_Playbook")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "ConcatenatedInvitedGroupIDs", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedInvitedGroupIDs to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Playbook", "ConcatenatedInvitedGroupIDs", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedInvitedGroupIDs to table IR_Playbook")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.14.0"),
toVersion: semver.MustParse("0.15.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "Retrospective", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column Retrospective to table IR_Incident")
}
if _, err := e.Exec("UPDATE IR_Incident SET Retrospective = '' WHERE Retrospective IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column Retrospective of table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "Retrospective", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column Retrospective to table IR_Incident")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.15.0"),
toVersion: semver.MustParse("0.16.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Playbook", "MessageOnJoin", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column MessageOnJoin to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET MessageOnJoin = '' WHERE MessageOnJoin IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column MessageOnJoin of table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "MessageOnJoinEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column MessageOnJoinEnabled to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Incident", "MessageOnJoin", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column MessageOnJoin to table IR_Incident")
}
if _, err := e.Exec("UPDATE IR_Incident SET MessageOnJoin = '' WHERE MessageOnJoin IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column MessageOnJoin of table IR_Incident")
}
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_ViewedChannel
(
ChannelID VARCHAR(26) NOT NULL,
UserID VARCHAR(26) NOT NULL,
UNIQUE INDEX IR_ViewedChannel_ChannelID_UserID (ChannelID, UserID)
)
` + MySQLCharset); err != nil {
return errors.Wrapf(err, "failed creating table IR_ViewedChannel")
}
} else {
if err := addColumnToPGTable(e, "IR_Playbook", "MessageOnJoin", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column MessageOnJoin to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "MessageOnJoinEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column MessageOnJoinEnabled to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Incident", "MessageOnJoin", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column MessageOnJoin to table IR_Incident")
}
if _, err := e.Exec(`
CREATE TABLE IF NOT EXISTS IR_ViewedChannel
(
ChannelID TEXT NOT NULL,
UserID TEXT NOT NULL
)
`); err != nil {
return errors.Wrapf(err, "failed creating table IR_ViewedChannel")
}
if _, err := e.Exec(createUniquePGIndex("IR_ViewedChannel_ChannelID_UserID", "IR_ViewedChannel", "ChannelID, UserID")); err != nil {
return errors.Wrapf(err, "failed creating index IR_ViewedChannel_ChannelID_UserID")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.16.0"),
toVersion: semver.MustParse("0.17.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "RetrospectivePublishedAt", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectivePublishedAt to table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "RetrospectivePublishedAt", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectivePublishedAt to table IR_Incident")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.17.0"),
toVersion: semver.MustParse("0.18.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "RetrospectiveReminderIntervalSeconds", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectiveReminderIntervalSeconds to table IR_Incident")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "RetrospectiveReminderIntervalSeconds", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectiveReminderIntervalSeconds to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Incident", "RetrospectiveWasCanceled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectiveWasCanceled to table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "RetrospectiveReminderIntervalSeconds", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectiveReminderIntervalSeconds to table IR_Incident")
}
if err := addColumnToPGTable(e, "IR_Playbook", "RetrospectiveReminderIntervalSeconds", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectiveReminderIntervalSeconds to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Incident", "RetrospectiveWasCanceled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectiveWasCanceled to table IR_Incident")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.18.0"),
toVersion: semver.MustParse("0.19.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Playbook", "RetrospectiveTemplate", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectiveReminderIntervalSeconds to table IR_Playbook")
}
} else {
if err := addColumnToPGTable(e, "IR_Playbook", "RetrospectiveTemplate", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column RetrospectiveReminderIntervalSeconds to table IR_Playbook")
}
}
if _, err := e.Exec("UPDATE IR_Playbook SET RetrospectiveTemplate = '' WHERE RetrospectiveTemplate IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column RetrospectiveTemplate of table IR_Playbook")
}
return nil
},
},
{
fromVersion: semver.MustParse("0.19.0"),
toVersion: semver.MustParse("0.20.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Playbook", "WebhookOnStatusUpdateURL", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnStatusUpdateURL to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET WebhookOnStatusUpdateURL = '' WHERE WebhookOnStatusUpdateURL IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column WebhookOnStatusUpdateURL of table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "WebhookOnStatusUpdateEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnStatusUpdateEnabled to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Incident", "WebhookOnStatusUpdateURL", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnStatusUpdateURL to table IR_Incident")
}
if _, err := e.Exec("UPDATE IR_Incident SET WebhookOnStatusUpdateURL = '' WHERE WebhookOnStatusUpdateURL IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column WebhookOnStatusUpdateURL of table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Playbook", "WebhookOnStatusUpdateURL", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnStatusUpdateURL to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "WebhookOnStatusUpdateEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnStatusUpdateEnabled to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Incident", "WebhookOnStatusUpdateURL", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column WebhookOnStatusUpdateURL to table IR_Incident")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.20.0"),
toVersion: semver.MustParse("0.21.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Playbook", "ConcatenatedSignalAnyKeywords", "TEXT"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedSignalAnyKeywords to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET ConcatenatedSignalAnyKeywords = '' WHERE ConcatenatedSignalAnyKeywords IS NULL"); err != nil {
return errors.Wrapf(err, "failed setting default value in column ConcatenatedSignalAnyKeywords of table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "SignalAnyKeywordsEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column SignalAnyKeywordsEnabled to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Playbook", "UpdateAt", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column UpdateAt to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET UpdateAt = CreateAt"); err != nil {
return errors.Wrapf(err, "failed setting default value in column UpdateAt of table IR_Playbook")
}
if _, err := e.Exec(`ALTER TABLE IR_Playbook ADD INDEX IR_Playbook_UpdateAt (UpdateAt)`); err != nil {
me, ok := err.(*mysql.MySQLError)
if !ok || me.Number != 1061 { // not a Duplicate key name error
return errors.Wrapf(err, "failed creating index IR_Playbook_UpdateAt")
}
}
} else {
if err := addColumnToPGTable(e, "IR_Playbook", "ConcatenatedSignalAnyKeywords", "TEXT DEFAULT ''"); err != nil {
return errors.Wrapf(err, "failed adding column ConcatenatedSignalAnyKeywords to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "SignalAnyKeywordsEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column SignalAnyKeywordsEnabled to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Playbook", "UpdateAt", "BIGINT NOT NULL DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column UpdateAt to table IR_Playbook")
}
if _, err := e.Exec("UPDATE IR_Playbook SET UpdateAt = CreateAt"); err != nil {
return errors.Wrapf(err, "failed setting default value in column UpdateAt of table IR_Playbook")
}
if _, err := e.Exec(createPGIndex("IR_Playbook_UpdateAt", "IR_Playbook", "UpdateAt")); err != nil {
return errors.Wrapf(err, "failed creating index IR_Playbook_UpdateAt")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.21.0"),
toVersion: semver.MustParse("0.22.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Incident", "LastStatusUpdateAt", "BIGINT DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column LastStatusUpdateAt to table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Incident", "LastStatusUpdateAt", "BIGINT DEFAULT 0"); err != nil {
return errors.Wrapf(err, "failed adding column LastStatusUpdateAt to table IR_Incident")
}
}
var lastUpdateAts []struct {
ID string
LastStatusUpdateAt int64
}
// Fill in the LastStatusUpdateAt column as either the most recent status post, or
// if no posts: the playbook run's CreateAt.
lastUpdateAtSelect := sqlStore.builder.
Select("i.Id as ID", "COALESCE(MAX(p.CreateAt), i.CreateAt) as LastStatusUpdateAt").
From("IR_Incident as i").
LeftJoin("IR_StatusPosts as sp on i.Id = sp.IncidentId").
LeftJoin("Posts as p on sp.PostId = p.Id").
GroupBy("i.Id")
if err := sqlStore.selectBuilder(e, &lastUpdateAts, lastUpdateAtSelect); err != nil {
return errors.Wrapf(err, "failed getting incidents to update their LastStatusUpdateAt")
}
for _, row := range lastUpdateAts {
incidentUpdate := sqlStore.builder.
Update("IR_Incident").
Set("LastStatusUpdateAt", row.LastStatusUpdateAt).
Where(sq.Eq{"ID": row.ID})
if _, err := sqlStore.execBuilder(e, incidentUpdate); err != nil {
return errors.Wrapf(err, "failed to update incident's LastStatusUpdateAt for id: %s", row.ID)
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.22.0"),
toVersion: semver.MustParse("0.23.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Playbook", "ExportChannelOnArchiveEnabled", "BOOLEAN NOT NULL DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column ExportChannelOnArchiveEnabled to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Incident", "ExportChannelOnArchiveEnabled", "BOOLEAN NOT NULL DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column ExportChannelOnArchiveEnabled to table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Playbook", "ExportChannelOnArchiveEnabled", "BOOLEAN NOT NULL DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column ExportChannelOnArchiveEnabled to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Incident", "ExportChannelOnArchiveEnabled", "BOOLEAN NOT NULL DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column ExportChannelOnArchiveEnabled to table IR_Incident")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.23.0"),
toVersion: semver.MustParse("0.24.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := addColumnToMySQLTable(e, "IR_Playbook", "CategorizeChannelEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column CategorizeChannelEnabled to table IR_Playbook")
}
if err := addColumnToMySQLTable(e, "IR_Incident", "CategorizeChannelEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column CategorizeChannelEnabled to table IR_Incident")
}
} else {
if err := addColumnToPGTable(e, "IR_Playbook", "CategorizeChannelEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column CategorizeChannelEnabled to table IR_Playbook")
}
if err := addColumnToPGTable(e, "IR_Incident", "CategorizeChannelEnabled", "BOOLEAN DEFAULT FALSE"); err != nil {
return errors.Wrapf(err, "failed adding column CategorizeChannelEnabled to table IR_Incident")
}
}
return nil
},
},
{
fromVersion: semver.MustParse("0.24.0"),
toVersion: semver.MustParse("0.25.0"),
migrationFunc: func(e sqlx.Ext, sqlStore *SQLStore) error {
if e.DriverName() == model.DatabaseDriverMysql {
if err := renameColumnMySQL(e, "IR_Playbook", "ExportChannelOnArchiveEnabled", "ExportChannelOnFinishedEnabled", "BOOLEAN NOT NULL DEFAULT FALSE"); err != nil {
return errors.Wrap(err, "failed changing column ExportChannelOnArchiveEnabled to ExportChannelOnFinishedEnabled in table IR_Playbook")
}