Skip to content

Commit 27d6685

Browse files
authored
golint fixed for models/migrations (#291)
1 parent 1d0f811 commit 27d6685

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

models/migrations/migrations.go

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import (
2525
"code.gitea.io/gitea/modules/setting"
2626
)
2727

28-
const _MIN_DB_VER = 4
28+
const minDBVersion = 4
2929

30+
// Migration describes on migration from lower version to high version
3031
type Migration interface {
3132
Description() string
3233
Migrate(*xorm.Engine) error
@@ -37,31 +38,34 @@ type migration struct {
3738
migrate func(*xorm.Engine) error
3839
}
3940

41+
// NewMigration creates a new migration
4042
func NewMigration(desc string, fn func(*xorm.Engine) error) Migration {
4143
return &migration{desc, fn}
4244
}
4345

46+
// Description returns the migration's description
4447
func (m *migration) Description() string {
4548
return m.description
4649
}
4750

51+
// Migrate executes the migration
4852
func (m *migration) Migrate(x *xorm.Engine) error {
4953
return m.migrate(x)
5054
}
5155

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
5357
type Version struct {
5458
ID int64 `xorm:"pk autoincr"`
5559
Version int64
5660
}
5761

5862
// This is a sequence of migrations. Add new migrations to the bottom of the list.
5963
// 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
6165
var migrations = []Migration{
6266
// v0 -> v4: before 0.6.0 -> 0.7.33
6367
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
6569
NewMigration("generate issue-label from issue", issueToIssueLabel), // V6 -> V7:v0.6.4
6670
NewMigration("refactor attachment table", attachmentRefactor), // V7 -> V8:v0.6.4
6771
NewMigration("rename pull request fields", renamePullRequestFields), // V8 -> V9:v0.6.16
@@ -89,27 +93,27 @@ func Migrate(x *xorm.Engine) error {
8993
} else if !has {
9094
// If the version record does not exist we think
9195
// 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))
9397

9498
if _, err = x.InsertOne(currentVersion); err != nil {
9599
return fmt.Errorf("insert: %v", err)
96100
}
97101
}
98102

99103
v := currentVersion.Version
100-
if _MIN_DB_VER > v {
104+
if minDBVersion > v {
101105
log.Fatal(4, `Gogs no longer supports auto-migration from your previously installed version.
102106
Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to current version.`)
103107
return nil
104108
}
105109

106-
if int(v-_MIN_DB_VER) > len(migrations) {
110+
if int(v-minDBVersion) > len(migrations) {
107111
// User downgraded Gogs.
108-
currentVersion.Version = int64(len(migrations) + _MIN_DB_VER)
112+
currentVersion.Version = int64(len(migrations) + minDBVersion)
109113
_, err = x.Id(1).Update(currentVersion)
110114
return err
111115
}
112-
for i, m := range migrations[v-_MIN_DB_VER:] {
116+
for i, m := range migrations[v-minDBVersion:] {
113117
log.Info("Migration: %s", m.Description())
114118
if err = m.Migrate(x); err != nil {
115119
return fmt.Errorf("do migrate: %v", err)
@@ -144,7 +148,7 @@ func fixLocaleFileLoadPanic(_ *xorm.Engine) error {
144148
return nil
145149
}
146150

147-
func trimCommitActionAppUrlPrefix(x *xorm.Engine) error {
151+
func trimCommitActionAppURLPrefix(x *xorm.Engine) error {
148152
type PushCommit struct {
149153
Sha1 string
150154
Message string
@@ -155,7 +159,7 @@ func trimCommitActionAppUrlPrefix(x *xorm.Engine) error {
155159
type PushCommits struct {
156160
Len int
157161
Commits []*PushCommit
158-
CompareUrl string
162+
CompareURL string `json:"CompareUrl"`
159163
}
160164

161165
type Action struct {
@@ -186,11 +190,11 @@ func trimCommitActionAppUrlPrefix(x *xorm.Engine) error {
186190
return fmt.Errorf("unmarshal action content[%d]: %v", actID, err)
187191
}
188192

189-
infos := strings.Split(pushCommits.CompareUrl, "/")
193+
infos := strings.Split(pushCommits.CompareURL, "/")
190194
if len(infos) <= 4 {
191195
continue
192196
}
193-
pushCommits.CompareUrl = strings.Join(infos[len(infos)-4:], "/")
197+
pushCommits.CompareURL = strings.Join(infos[len(infos)-4:], "/")
194198

195199
p, err := json.Marshal(pushCommits)
196200
if err != nil {
@@ -463,127 +467,159 @@ func generateOrgRandsAndSalt(x *xorm.Engine) (err error) {
463467
return sess.Commit()
464468
}
465469

470+
// TAction defines the struct for migrating table action
466471
type TAction struct {
467472
ID int64 `xorm:"pk autoincr"`
468473
CreatedUnix int64
469474
}
470475

476+
// TableName will be invoked by XORM to customrize the table name
471477
func (t *TAction) TableName() string { return "action" }
472478

479+
// TNotice defines the struct for migrating table notice
473480
type TNotice struct {
474481
ID int64 `xorm:"pk autoincr"`
475482
CreatedUnix int64
476483
}
477484

485+
// TableName will be invoked by XORM to customrize the table name
478486
func (t *TNotice) TableName() string { return "notice" }
479487

488+
// TComment defines the struct for migrating table comment
480489
type TComment struct {
481490
ID int64 `xorm:"pk autoincr"`
482491
CreatedUnix int64
483492
}
484493

494+
// TableName will be invoked by XORM to customrize the table name
485495
func (t *TComment) TableName() string { return "comment" }
486496

497+
// TIssue defines the struct for migrating table issue
487498
type TIssue struct {
488499
ID int64 `xorm:"pk autoincr"`
489500
DeadlineUnix int64
490501
CreatedUnix int64
491502
UpdatedUnix int64
492503
}
493504

505+
// TableName will be invoked by XORM to customrize the table name
494506
func (t *TIssue) TableName() string { return "issue" }
495507

508+
// TMilestone defines the struct for migrating table milestone
496509
type TMilestone struct {
497510
ID int64 `xorm:"pk autoincr"`
498511
DeadlineUnix int64
499512
ClosedDateUnix int64
500513
}
501514

515+
// TableName will be invoked by XORM to customrize the table name
502516
func (t *TMilestone) TableName() string { return "milestone" }
503517

518+
// TAttachment defines the struct for migrating table attachment
504519
type TAttachment struct {
505520
ID int64 `xorm:"pk autoincr"`
506521
CreatedUnix int64
507522
}
508523

524+
// TableName will be invoked by XORM to customrize the table name
509525
func (t *TAttachment) TableName() string { return "attachment" }
510526

527+
// TLoginSource defines the struct for migrating table login_source
511528
type TLoginSource struct {
512529
ID int64 `xorm:"pk autoincr"`
513530
CreatedUnix int64
514531
UpdatedUnix int64
515532
}
516533

534+
// TableName will be invoked by XORM to customrize the table name
517535
func (t *TLoginSource) TableName() string { return "login_source" }
518536

537+
// TPull defines the struct for migrating table pull_request
519538
type TPull struct {
520539
ID int64 `xorm:"pk autoincr"`
521540
MergedUnix int64
522541
}
523542

543+
// TableName will be invoked by XORM to customrize the table name
524544
func (t *TPull) TableName() string { return "pull_request" }
525545

546+
// TRelease defines the struct for migrating table release
526547
type TRelease struct {
527548
ID int64 `xorm:"pk autoincr"`
528549
CreatedUnix int64
529550
}
530551

552+
// TableName will be invoked by XORM to customrize the table name
531553
func (t *TRelease) TableName() string { return "release" }
532554

555+
// TRepo defines the struct for migrating table repository
533556
type TRepo struct {
534557
ID int64 `xorm:"pk autoincr"`
535558
CreatedUnix int64
536559
UpdatedUnix int64
537560
}
538561

562+
// TableName will be invoked by XORM to customrize the table name
539563
func (t *TRepo) TableName() string { return "repository" }
540564

565+
// TMirror defines the struct for migrating table mirror
541566
type TMirror struct {
542567
ID int64 `xorm:"pk autoincr"`
543568
UpdatedUnix int64
544569
NextUpdateUnix int64
545570
}
546571

572+
// TableName will be invoked by XORM to customrize the table name
547573
func (t *TMirror) TableName() string { return "mirror" }
548574

575+
// TPublicKey defines the struct for migrating table public_key
549576
type TPublicKey struct {
550577
ID int64 `xorm:"pk autoincr"`
551578
CreatedUnix int64
552579
UpdatedUnix int64
553580
}
554581

582+
// TableName will be invoked by XORM to customrize the table name
555583
func (t *TPublicKey) TableName() string { return "public_key" }
556584

585+
// TDeployKey defines the struct for migrating table deploy_key
557586
type TDeployKey struct {
558587
ID int64 `xorm:"pk autoincr"`
559588
CreatedUnix int64
560589
UpdatedUnix int64
561590
}
562591

592+
// TableName will be invoked by XORM to customrize the table name
563593
func (t *TDeployKey) TableName() string { return "deploy_key" }
564594

595+
// TAccessToken defines the struct for migrating table access_token
565596
type TAccessToken struct {
566597
ID int64 `xorm:"pk autoincr"`
567598
CreatedUnix int64
568599
UpdatedUnix int64
569600
}
570601

602+
// TableName will be invoked by XORM to customrize the table name
571603
func (t *TAccessToken) TableName() string { return "access_token" }
572604

605+
// TUser defines the struct for migrating table user
573606
type TUser struct {
574607
ID int64 `xorm:"pk autoincr"`
575608
CreatedUnix int64
576609
UpdatedUnix int64
577610
}
578611

612+
// TableName will be invoked by XORM to customrize the table name
579613
func (t *TUser) TableName() string { return "user" }
580614

615+
// TWebhook defines the struct for migrating table webhook
581616
type TWebhook struct {
582617
ID int64 `xorm:"pk autoincr"`
583618
CreatedUnix int64
584619
UpdatedUnix int64
585620
}
586621

622+
// TableName will be invoked by XORM to customrize the table name
587623
func (t *TWebhook) TableName() string { return "webhook" }
588624

589625
func convertDateToUnix(x *xorm.Engine) (err error) {

models/migrations/v14.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ func setCommentUpdatedWithCreated(x *xorm.Engine) (err error) {
2323
return nil
2424
}
2525

26+
// UserV14 describes the added fields for migrating from v13 -> v14
2627
type UserV14 struct {
2728
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
2829
}
2930

31+
// TableName will be invoked by XORM to customrize the table name
3032
func (*UserV14) TableName() string {
3133
return "user"
3234
}

0 commit comments

Comments
 (0)