=Updated models to match ilikecats' merged database
Cette révision appartient à :
Parent
d3fee1eae6
révision
2b677f2bbc
3
main.go
3
main.go
|
@ -23,8 +23,7 @@ func getDBHandle() *gorm.DB {
|
||||||
dbInit, err := gorm.Open("sqlite3", "./nyaa.db")
|
dbInit, err := gorm.Open("sqlite3", "./nyaa.db")
|
||||||
|
|
||||||
// Migrate the schema of Torrents
|
// Migrate the schema of Torrents
|
||||||
dbInit.AutoMigrate(&Torrents{})
|
dbInit.AutoMigrate(&Torrents{}, &Categories{}, &Sub_Categories{}, &Statuses{})
|
||||||
dbInit.AutoMigrate(&Sub_Categories{})
|
|
||||||
|
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
return dbInit
|
return dbInit
|
||||||
|
|
19
models.go
19
models.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
"html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -19,18 +18,28 @@ type Categories struct {
|
||||||
type Sub_Categories struct {
|
type Sub_Categories struct {
|
||||||
Sub_category_id int
|
Sub_category_id int
|
||||||
Sub_category_name string
|
Sub_category_name string
|
||||||
Parent_id int
|
Parent_id int
|
||||||
Torrents []Torrents `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"`
|
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 {
|
type Torrents struct {
|
||||||
gorm.Model
|
|
||||||
Id int `gorm:"column:torrent_id"`
|
Id int `gorm:"column:torrent_id"`
|
||||||
Name string `gorm:"column:torrent_name"`
|
Name string `gorm:"column:torrent_name"`
|
||||||
Category_id int `gorm:"column:category_id"`
|
Category_id int `gorm:"column:category_id"`
|
||||||
Sub_category_id int `gorm:"column:sub_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"`
|
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"`
|
Categories Categories `gorm:"ForeignKey:category_id;AssociationForeignKey:category_id"`
|
||||||
Sub_Categories Sub_Categories `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_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{
|
res := TorrentsJson{
|
||||||
Id: strconv.Itoa(t.Id),
|
Id: strconv.Itoa(t.Id),
|
||||||
Name: html.UnescapeString(t.Name),
|
Name: html.UnescapeString(t.Name),
|
||||||
Status: t.Status,
|
Status: t.Status_id,
|
||||||
Hash: t.Hash,
|
Hash: t.Hash,
|
||||||
Magnet: safe(magnet)}
|
Magnet: safe(magnet)}
|
||||||
return res
|
return res
|
||||||
|
|
Référencer dans un nouveau ticket