@@ -25,8 +25,9 @@ import (
25
25
"code.gitea.io/gitea/modules/setting"
26
26
)
27
27
28
- const _MIN_DB_VER = 4
28
+ const minDBVersion = 4
29
29
30
+ // Migration describes on migration from lower version to high version
30
31
type Migration interface {
31
32
Description () string
32
33
Migrate (* xorm.Engine ) error
@@ -37,31 +38,34 @@ type migration struct {
37
38
migrate func (* xorm.Engine ) error
38
39
}
39
40
41
+ // NewMigration creates a new migration
40
42
func NewMigration (desc string , fn func (* xorm.Engine ) error ) Migration {
41
43
return & migration {desc , fn }
42
44
}
43
45
46
+ // Description returns the migration's description
44
47
func (m * migration ) Description () string {
45
48
return m .description
46
49
}
47
50
51
+ // Migrate executes the migration
48
52
func (m * migration ) Migrate (x * xorm.Engine ) error {
49
53
return m .migrate (x )
50
54
}
51
55
52
- // The version table. Should have only one row with id==1
56
+ // Version describes the version table. Should have only one row with id==1
53
57
type Version struct {
54
58
ID int64 `xorm:"pk autoincr"`
55
59
Version int64
56
60
}
57
61
58
62
// This is a sequence of migrations. Add new migrations to the bottom of the list.
59
63
// If you want to "retire" a migration, remove it from the top of the list and
60
- // update _MIN_VER_DB accordingly
64
+ // update minDBVersion accordingly
61
65
var migrations = []Migration {
62
66
// v0 -> v4: before 0.6.0 -> 0.7.33
63
67
NewMigration ("fix locale file load panic" , fixLocaleFileLoadPanic ), // V4 -> V5:v0.6.0
64
- NewMigration ("trim action compare URL prefix" , trimCommitActionAppUrlPrefix ), // V5 -> V6:v0.6.3
68
+ NewMigration ("trim action compare URL prefix" , trimCommitActionAppURLPrefix ), // V5 -> V6:v0.6.3
65
69
NewMigration ("generate issue-label from issue" , issueToIssueLabel ), // V6 -> V7:v0.6.4
66
70
NewMigration ("refactor attachment table" , attachmentRefactor ), // V7 -> V8:v0.6.4
67
71
NewMigration ("rename pull request fields" , renamePullRequestFields ), // V8 -> V9:v0.6.16
@@ -89,27 +93,27 @@ func Migrate(x *xorm.Engine) error {
89
93
} else if ! has {
90
94
// If the version record does not exist we think
91
95
// it is a fresh installation and we can skip all migrations.
92
- currentVersion .Version = int64 (_MIN_DB_VER + len (migrations ))
96
+ currentVersion .Version = int64 (minDBVersion + len (migrations ))
93
97
94
98
if _ , err = x .InsertOne (currentVersion ); err != nil {
95
99
return fmt .Errorf ("insert: %v" , err )
96
100
}
97
101
}
98
102
99
103
v := currentVersion .Version
100
- if _MIN_DB_VER > v {
104
+ if minDBVersion > v {
101
105
log .Fatal (4 , `Gogs no longer supports auto-migration from your previously installed version.
102
106
Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to current version.` )
103
107
return nil
104
108
}
105
109
106
- if int (v - _MIN_DB_VER ) > len (migrations ) {
110
+ if int (v - minDBVersion ) > len (migrations ) {
107
111
// User downgraded Gogs.
108
- currentVersion .Version = int64 (len (migrations ) + _MIN_DB_VER )
112
+ currentVersion .Version = int64 (len (migrations ) + minDBVersion )
109
113
_ , err = x .Id (1 ).Update (currentVersion )
110
114
return err
111
115
}
112
- for i , m := range migrations [v - _MIN_DB_VER :] {
116
+ for i , m := range migrations [v - minDBVersion :] {
113
117
log .Info ("Migration: %s" , m .Description ())
114
118
if err = m .Migrate (x ); err != nil {
115
119
return fmt .Errorf ("do migrate: %v" , err )
@@ -144,7 +148,7 @@ func fixLocaleFileLoadPanic(_ *xorm.Engine) error {
144
148
return nil
145
149
}
146
150
147
- func trimCommitActionAppUrlPrefix (x * xorm.Engine ) error {
151
+ func trimCommitActionAppURLPrefix (x * xorm.Engine ) error {
148
152
type PushCommit struct {
149
153
Sha1 string
150
154
Message string
@@ -155,7 +159,7 @@ func trimCommitActionAppUrlPrefix(x *xorm.Engine) error {
155
159
type PushCommits struct {
156
160
Len int
157
161
Commits []* PushCommit
158
- CompareUrl string
162
+ CompareURL string `json:"CompareUrl"`
159
163
}
160
164
161
165
type Action struct {
@@ -186,11 +190,11 @@ func trimCommitActionAppUrlPrefix(x *xorm.Engine) error {
186
190
return fmt .Errorf ("unmarshal action content[%d]: %v" , actID , err )
187
191
}
188
192
189
- infos := strings .Split (pushCommits .CompareUrl , "/" )
193
+ infos := strings .Split (pushCommits .CompareURL , "/" )
190
194
if len (infos ) <= 4 {
191
195
continue
192
196
}
193
- pushCommits .CompareUrl = strings .Join (infos [len (infos )- 4 :], "/" )
197
+ pushCommits .CompareURL = strings .Join (infos [len (infos )- 4 :], "/" )
194
198
195
199
p , err := json .Marshal (pushCommits )
196
200
if err != nil {
@@ -463,127 +467,159 @@ func generateOrgRandsAndSalt(x *xorm.Engine) (err error) {
463
467
return sess .Commit ()
464
468
}
465
469
470
+ // TAction defines the struct for migrating table action
466
471
type TAction struct {
467
472
ID int64 `xorm:"pk autoincr"`
468
473
CreatedUnix int64
469
474
}
470
475
476
+ // TableName will be invoked by XORM to customrize the table name
471
477
func (t * TAction ) TableName () string { return "action" }
472
478
479
+ // TNotice defines the struct for migrating table notice
473
480
type TNotice struct {
474
481
ID int64 `xorm:"pk autoincr"`
475
482
CreatedUnix int64
476
483
}
477
484
485
+ // TableName will be invoked by XORM to customrize the table name
478
486
func (t * TNotice ) TableName () string { return "notice" }
479
487
488
+ // TComment defines the struct for migrating table comment
480
489
type TComment struct {
481
490
ID int64 `xorm:"pk autoincr"`
482
491
CreatedUnix int64
483
492
}
484
493
494
+ // TableName will be invoked by XORM to customrize the table name
485
495
func (t * TComment ) TableName () string { return "comment" }
486
496
497
+ // TIssue defines the struct for migrating table issue
487
498
type TIssue struct {
488
499
ID int64 `xorm:"pk autoincr"`
489
500
DeadlineUnix int64
490
501
CreatedUnix int64
491
502
UpdatedUnix int64
492
503
}
493
504
505
+ // TableName will be invoked by XORM to customrize the table name
494
506
func (t * TIssue ) TableName () string { return "issue" }
495
507
508
+ // TMilestone defines the struct for migrating table milestone
496
509
type TMilestone struct {
497
510
ID int64 `xorm:"pk autoincr"`
498
511
DeadlineUnix int64
499
512
ClosedDateUnix int64
500
513
}
501
514
515
+ // TableName will be invoked by XORM to customrize the table name
502
516
func (t * TMilestone ) TableName () string { return "milestone" }
503
517
518
+ // TAttachment defines the struct for migrating table attachment
504
519
type TAttachment struct {
505
520
ID int64 `xorm:"pk autoincr"`
506
521
CreatedUnix int64
507
522
}
508
523
524
+ // TableName will be invoked by XORM to customrize the table name
509
525
func (t * TAttachment ) TableName () string { return "attachment" }
510
526
527
+ // TLoginSource defines the struct for migrating table login_source
511
528
type TLoginSource struct {
512
529
ID int64 `xorm:"pk autoincr"`
513
530
CreatedUnix int64
514
531
UpdatedUnix int64
515
532
}
516
533
534
+ // TableName will be invoked by XORM to customrize the table name
517
535
func (t * TLoginSource ) TableName () string { return "login_source" }
518
536
537
+ // TPull defines the struct for migrating table pull_request
519
538
type TPull struct {
520
539
ID int64 `xorm:"pk autoincr"`
521
540
MergedUnix int64
522
541
}
523
542
543
+ // TableName will be invoked by XORM to customrize the table name
524
544
func (t * TPull ) TableName () string { return "pull_request" }
525
545
546
+ // TRelease defines the struct for migrating table release
526
547
type TRelease struct {
527
548
ID int64 `xorm:"pk autoincr"`
528
549
CreatedUnix int64
529
550
}
530
551
552
+ // TableName will be invoked by XORM to customrize the table name
531
553
func (t * TRelease ) TableName () string { return "release" }
532
554
555
+ // TRepo defines the struct for migrating table repository
533
556
type TRepo struct {
534
557
ID int64 `xorm:"pk autoincr"`
535
558
CreatedUnix int64
536
559
UpdatedUnix int64
537
560
}
538
561
562
+ // TableName will be invoked by XORM to customrize the table name
539
563
func (t * TRepo ) TableName () string { return "repository" }
540
564
565
+ // TMirror defines the struct for migrating table mirror
541
566
type TMirror struct {
542
567
ID int64 `xorm:"pk autoincr"`
543
568
UpdatedUnix int64
544
569
NextUpdateUnix int64
545
570
}
546
571
572
+ // TableName will be invoked by XORM to customrize the table name
547
573
func (t * TMirror ) TableName () string { return "mirror" }
548
574
575
+ // TPublicKey defines the struct for migrating table public_key
549
576
type TPublicKey struct {
550
577
ID int64 `xorm:"pk autoincr"`
551
578
CreatedUnix int64
552
579
UpdatedUnix int64
553
580
}
554
581
582
+ // TableName will be invoked by XORM to customrize the table name
555
583
func (t * TPublicKey ) TableName () string { return "public_key" }
556
584
585
+ // TDeployKey defines the struct for migrating table deploy_key
557
586
type TDeployKey struct {
558
587
ID int64 `xorm:"pk autoincr"`
559
588
CreatedUnix int64
560
589
UpdatedUnix int64
561
590
}
562
591
592
+ // TableName will be invoked by XORM to customrize the table name
563
593
func (t * TDeployKey ) TableName () string { return "deploy_key" }
564
594
595
+ // TAccessToken defines the struct for migrating table access_token
565
596
type TAccessToken struct {
566
597
ID int64 `xorm:"pk autoincr"`
567
598
CreatedUnix int64
568
599
UpdatedUnix int64
569
600
}
570
601
602
+ // TableName will be invoked by XORM to customrize the table name
571
603
func (t * TAccessToken ) TableName () string { return "access_token" }
572
604
605
+ // TUser defines the struct for migrating table user
573
606
type TUser struct {
574
607
ID int64 `xorm:"pk autoincr"`
575
608
CreatedUnix int64
576
609
UpdatedUnix int64
577
610
}
578
611
612
+ // TableName will be invoked by XORM to customrize the table name
579
613
func (t * TUser ) TableName () string { return "user" }
580
614
615
+ // TWebhook defines the struct for migrating table webhook
581
616
type TWebhook struct {
582
617
ID int64 `xorm:"pk autoincr"`
583
618
CreatedUnix int64
584
619
UpdatedUnix int64
585
620
}
586
621
622
+ // TableName will be invoked by XORM to customrize the table name
587
623
func (t * TWebhook ) TableName () string { return "webhook" }
588
624
589
625
func convertDateToUnix (x * xorm.Engine ) (err error ) {
0 commit comments