Browse Source

数据集独立表结构变化及数据升级

dataset_independetn
ychao_1983 3 years ago
parent
commit
910886900b
3 changed files with 44 additions and 3 deletions
  1. +21
    -0
      models/custom_migrations.go
  2. +20
    -3
      models/dataset.go
  3. +3
    -0
      models/models.go

+ 21
- 0
models/custom_migrations.go View File

@@ -19,6 +19,7 @@ type CustomMigrationStatic struct {

var customMigrations = []CustomMigration{
{"Custom v1 Topic struct change to support chinese", syncTopicStruct},
{"Dataset upgrade", upgradeDataset},
}

var customMigrationsStatic = []CustomMigrationStatic{
@@ -50,6 +51,26 @@ func MigrateCustomStatic(x *xorm.Engine, static *xorm.Engine) {
}
}

func upgradeDataset(x *xorm.Engine) error {

query := "update dataset set status=2 where status!=2 and id not in (select distinct a.id from dataset a,attachment b where a.id=b.dataset_id )"

_, err := x.Exec(query)
if err != nil {
return err
}
datasetRepo := new(DatasetRepoInfo)
total, err := x.Count(datasetRepo)
if err == nil && total == 0 {
query := "INSERT INTO dataset_repo_info ( data_set_id, repo_id, user_id, created_unix, updated_unix) SELECT id, repo_id, user_id, created_unix,updated_unix FROM dataset WHERE status != 2"
_, err := x.Exec(query)
return err
} else {
return err
}

}

func syncTopicStruct(x *xorm.Engine) error {

query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);"


+ 20
- 3
models/dataset.go View File

@@ -16,9 +16,11 @@ const (
)

type Dataset struct {
ID int64 `xorm:"pk autoincr"`
Title string `xorm:"INDEX NOT NULL"`
Status int32 `xorm:"INDEX"` // normal_private: 0, pulbic: 1, is_delete: 2
ID int64 `xorm:"pk autoincr"`
Title string `xorm:"INDEX NOT NULL"`
Status int32 `xorm:"INDEX"` // normal_private: 0, pulbic: 1, is_delete: 2
Scope string //领域
Topics []string `xorm:"TEXT JSON"` //分类,实现方式类似项目的主题
Category string
Description string `xorm:"TEXT"`
DownloadTimes int64
@@ -45,6 +47,21 @@ type DatasetRepoInfo struct {
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
}

type DatasetStar struct {
ID int64 `xorm:"pk autoincr"`
UID int64 `xorm:"UNIQUE(s)"`
DatasetID int64 `xorm:"UNIQUE(s)"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
}

type DatasetTopic struct {
ID int64
Name string `xorm:"UNIQUE VARCHAR(105)"`
DatasetCount int
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
}

func (d *Dataset) IsPrivate() bool {
switch d.Status {
case DatasetStatusPrivate:


+ 3
- 0
models/models.go View File

@@ -129,6 +129,9 @@ func init() {
new(LanguageStat),
new(EmailHash),
new(Dataset),
new(DatasetRepoInfo),
new(DatasetStar),
new(DatasetTopic),
new(Cloudbrain),
new(FileChunk),
new(BlockChain),


Loading…
Cancel
Save