| @@ -19,6 +19,7 @@ type CustomMigrationStatic struct { | |||||
| var customMigrations = []CustomMigration{ | var customMigrations = []CustomMigration{ | ||||
| {"Custom v1 Topic struct change to support chinese", syncTopicStruct}, | {"Custom v1 Topic struct change to support chinese", syncTopicStruct}, | ||||
| {"Dataset upgrade", upgradeDataset}, | |||||
| } | } | ||||
| var customMigrationsStatic = []CustomMigrationStatic{ | 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 { | func syncTopicStruct(x *xorm.Engine) error { | ||||
| query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);" | query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);" | ||||
| @@ -16,9 +16,11 @@ const ( | |||||
| ) | ) | ||||
| type Dataset struct { | 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 | Category string | ||||
| Description string `xorm:"TEXT"` | Description string `xorm:"TEXT"` | ||||
| DownloadTimes int64 | DownloadTimes int64 | ||||
| @@ -45,6 +47,21 @@ type DatasetRepoInfo struct { | |||||
| UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | 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 { | func (d *Dataset) IsPrivate() bool { | ||||
| switch d.Status { | switch d.Status { | ||||
| case DatasetStatusPrivate: | case DatasetStatusPrivate: | ||||
| @@ -129,6 +129,9 @@ func init() { | |||||
| new(LanguageStat), | new(LanguageStat), | ||||
| new(EmailHash), | new(EmailHash), | ||||
| new(Dataset), | new(Dataset), | ||||
| new(DatasetRepoInfo), | |||||
| new(DatasetStar), | |||||
| new(DatasetTopic), | |||||
| new(Cloudbrain), | new(Cloudbrain), | ||||
| new(FileChunk), | new(FileChunk), | ||||
| new(BlockChain), | new(BlockChain), | ||||