From 948e7ce8c48acdb4fd1bfecc8555628a6272905d Mon Sep 17 00:00:00 2001 From: pantsudev Date: Wed, 14 Jun 2017 16:42:15 +1000 Subject: [PATCH] Add unique constraint to hash, email and username --- model/torrent.go | 6 +++--- model/user.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/model/torrent.go b/model/torrent.go index 49042f9d..7036fd9c 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -45,7 +45,7 @@ type Feed struct { type Torrent struct { ID uint `gorm:"column:torrent_id;primary_key"` Name string `gorm:"column:torrent_name"` - Hash string `gorm:"column:torrent_hash"` + Hash string `gorm:"column:torrent_hash;unique"` Category int `gorm:"column:category"` SubCategory int `gorm:"column:sub_category"` Status int `gorm:"column:status"` @@ -60,8 +60,8 @@ type Torrent struct { AnidbID string `gorm:"column:anidb_id"` Trackers string `gorm:"column:trackers"` // Indicates the language of the torrent's content (eg. subs, dubs, raws, manga TLs) - Language string `gorm:"column:language"` - DeletedAt *time.Time + Language string `gorm:"column:language"` + DeletedAt *time.Time Uploader *User `gorm:"AssociationForeignKey:UploaderID;ForeignKey:user_id"` OldUploader string `gorm:"-"` // ??????? diff --git a/model/user.go b/model/user.go index ac3ad1aa..fd95a765 100644 --- a/model/user.go +++ b/model/user.go @@ -24,9 +24,9 @@ const ( // User model type User struct { ID uint `gorm:"column:user_id;primary_key"` - Username string `gorm:"column:username"` + Username string `gorm:"column:username;unique"` Password string `gorm:"column:password"` - Email string `gorm:"column:email"` + Email string `gorm:"column:email;unique"` Status int `gorm:"column:status"` CreatedAt time.Time `gorm:"column:created_at"` UpdatedAt time.Time `gorm:"column:updated_at"`