diff --git a/models/dataset.go b/models/dataset.go index 096ab291c..e5b252ce6 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -101,11 +101,28 @@ type SearchDatasetOptions struct { } func CreateDataset(dataset *Dataset) (err error) { - if _, err = x.Insert(dataset); err != nil { + + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { return err } - return nil + datasetByRepoId := &Dataset{RepoID: dataset.RepoID} + has, err := sess.Get(datasetByRepoId) + if err != nil { + return err + } + if has { + return fmt.Errorf("The dataset already exists.") + } + + if _, err = sess.Insert(dataset); err != nil { + return err + } + return sess.Commit() + } func SearchDataset(opts *SearchDatasetOptions) (DatasetList, int64, error) {