From 2b677f2bbcbe75c1b1faee723c4b40846748f2bd Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 4 May 2017 18:18:27 -0400 Subject: [PATCH 1/3] =Updated models to match ilikecats' merged database --- main.go | 3 +-- models.go | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 9528a674..b637d8f8 100644 --- a/main.go +++ b/main.go @@ -23,8 +23,7 @@ func getDBHandle() *gorm.DB { dbInit, err := gorm.Open("sqlite3", "./nyaa.db") // Migrate the schema of Torrents - dbInit.AutoMigrate(&Torrents{}) - dbInit.AutoMigrate(&Sub_Categories{}) + dbInit.AutoMigrate(&Torrents{}, &Categories{}, &Sub_Categories{}, &Statuses{}) checkErr(err) return dbInit diff --git a/models.go b/models.go index 4735d830..6e62ba16 100644 --- a/models.go +++ b/models.go @@ -2,7 +2,6 @@ package main import ( "errors" - "github.com/jinzhu/gorm" "html" "html/template" "strconv" @@ -19,18 +18,28 @@ type Categories struct { type Sub_Categories struct { Sub_category_id int Sub_category_name string - Parent_id int + Parent_id int Torrents []Torrents `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` } +type Statuses struct { + Status_id int + Status_name string + Torrents []Torrents `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` +} + type Torrents struct { - gorm.Model Id int `gorm:"column:torrent_id"` Name string `gorm:"column:torrent_name"` Category_id int `gorm:"column:category_id"` Sub_category_id int `gorm:"column:sub_category_id"` - Status int `gorm:"column:status_id"` + Status_id int `gorm:"column:status_id"` Hash string `gorm:"column:torrent_hash"` + Date int `gorm:"column:date"` + Downloads int `gorm:"column:downloads"` + Filesize string `gorm:"column:filesize"` + Description []byte `gorm:"column:description"` + Statuses Statuses `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` Categories Categories `gorm:"ForeignKey:category_id;AssociationForeignKey:category_id"` Sub_Categories Sub_Categories `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` } @@ -134,7 +143,7 @@ func (t *Torrents) toJson() TorrentsJson { res := TorrentsJson{ Id: strconv.Itoa(t.Id), Name: html.UnescapeString(t.Name), - Status: t.Status, + Status: t.Status_id, Hash: t.Hash, Magnet: safe(magnet)} return res From d273671ab01941591c0984e273ba620a92d8ecb6 Mon Sep 17 00:00:00 2001 From: Lietzu Date: Thu, 4 May 2017 18:52:46 -0400 Subject: [PATCH 2/3] Configured models to match ilikecats' merged db, and expanded automigration --- main.go | 1 + models.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6845edc5..27b3e64a 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ func getDBHandle() *gorm.DB { // Migrate the schema of Torrents dbInit.AutoMigrate(&Torrents{}, &Categories{}, &Sub_Categories{}, &Statuses{}) + checkErr(err) return dbInit } diff --git a/models.go b/models.go index 8fb5f467..2ceb83fd 100644 --- a/models.go +++ b/models.go @@ -135,7 +135,7 @@ func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs dbQuery = db.Model(&torrents).Where(parameters.conditions, parameters.params...) } else { dbQuery = db.Model(&torrents) - } + } if (orderBy == "") { orderBy = "torrent_id DESC" } // Default OrderBy if limit != 0 || offset != 0 { // if limits provided From 9f11bbd9f53c3797304858cc397db2ba61c07448 Mon Sep 17 00:00:00 2001 From: Lietzu Date: Thu, 4 May 2017 19:03:25 -0400 Subject: [PATCH 3/3] Changed models to reflect ilikecat's new merged db v2 --- models.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models.go b/models.go index 2ceb83fd..3fb9ff9a 100644 --- a/models.go +++ b/models.go @@ -2,6 +2,7 @@ package main import ( "errors" + "github.com/jinzhu/gorm" "html" "html/template" "strconv"