From c734eacb9724f1b4b92ca007cb5bcee6f131c683 Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 21 May 2020 10:47:26 +0800 Subject: [PATCH] add dataset migration --- models/dataset.go | 23 ++++++++++++++++++++++ models/migrations/migrations.go | 1 + models/migrations/v140.go | 34 +++++++++++++++++++++++++++++++++ models/models.go | 1 + 4 files changed, 59 insertions(+) create mode 100644 models/dataset.go create mode 100644 models/migrations/v140.go diff --git a/models/dataset.go b/models/dataset.go new file mode 100644 index 000000000..0f0e83b56 --- /dev/null +++ b/models/dataset.go @@ -0,0 +1,23 @@ +package models + +import ( + "code.gitea.io/gitea/modules/timeutil" +) + +// Issue represents an issue or pull request of repository. +type Dataset struct { + ID int64 `xorm:"pk autoincr"` + Title string `xorm:"INDEX NOT NULL"` + Status int32 `xorm:"INDEX"` + Category string + Description string `xorm:"TEXT"` + Download_times int64 + License string + Task string + Release_id int64 `xorm:"INDEX"` + User_id int64 `xorm:"INDEX"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + + Attachments []*Attachment `xorm:"-"` +} diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 00d84da2e..367a8d876 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -212,6 +212,7 @@ var migrations = []Migration{ NewMigration("Add ResolveDoerID to Comment table", addResolveDoerIDCommentColumn), // v139 -> v140 NewMigration("prepend refs/heads/ to issue refs", prependRefsHeadsToIssueRefs), + NewMigration("add dataset migration", addDatasetTable), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v140.go b/models/migrations/v140.go new file mode 100644 index 000000000..bad436197 --- /dev/null +++ b/models/migrations/v140.go @@ -0,0 +1,34 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import ( + "fmt" + + "code.gitea.io/gitea/modules/timeutil" + "xorm.io/xorm" +) + +func addDatasetTable(x *xorm.Engine) error { + type Dataset struct { + ID int64 `xorm:"pk autoincr"` + Title string `xorm:"INDEX NOT NULL"` + Status int32 `xorm:"INDEX"` + Category string + Description string `xorm:"TEXT"` + Download_times int64 + License string + Task string + Release_id int64 `xorm:"INDEX"` + User_id int64 `xorm:"INDEX"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + } + + if err := x.Sync2(new(Dataset)); err != nil { + return fmt.Errorf("Sync2: %v", err) + } + return nil +} diff --git a/models/models.go b/models/models.go index c818c6510..e3d7d934f 100644 --- a/models/models.go +++ b/models/models.go @@ -125,6 +125,7 @@ func init() { new(Task), new(LanguageStat), new(EmailHash), + new(Dataset), ) gonicNames := []string{"SSL", "UID"}