Update to pg v9

This commit is contained in:
Las Zenow 2019-11-06 06:53:41 +00:00
parent 91beca9a55
commit defaa2ae0b
9 changed files with 75 additions and 44 deletions

4
go.mod
View file

@ -4,11 +4,10 @@ go 1.14
require (
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
github.com/go-pg/pg v7.1.7+incompatible
github.com/go-pg/pg/v9 v9.0.1
github.com/gorilla/mux v1.7.3
github.com/gorilla/securecookie v1.1.1
github.com/gorilla/sessions v1.2.0
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jmhodges/gocld2 v0.0.0-20180523203442-58c6ee0ad8b6
github.com/meskio/epubgo v0.0.0-20160213181628-90dd5d78197f
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
@ -17,5 +16,4 @@ require (
github.com/prometheus/client_golang v1.2.1
github.com/prometheus/common v0.7.0
golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59
mellium.im/sasl v0.2.1 // indirect
)

29
go.sum
View file

@ -23,6 +23,14 @@ github.com/go-pg/pg v7.1.7+incompatible h1:MXeUtzJtt9hie8LSANh0FvaS7ANQ535qD3Q5d
github.com/go-pg/pg v7.1.7+incompatible/go.mod h1:a2oXow+aFOrvwcKs3eIA0lNFmMilrxK2sOkB5NWe0vA=
github.com/go-pg/pg v8.0.6+incompatible h1:Hi7yUJ2zwmHFq1Mar5XqhCe3NJ7j9r+BaiNmd+vqf+A=
github.com/go-pg/pg v8.0.6+incompatible/go.mod h1:a2oXow+aFOrvwcKs3eIA0lNFmMilrxK2sOkB5NWe0vA=
github.com/go-pg/pg/v9 v9.0.0-beta.14/go.mod h1:T2Sr6bpTCOr2lUqOUMiXLMJqZHSUBKk1LdgSqjwhZfA=
github.com/go-pg/pg/v9 v9.0.1 h1:euvT6+PFzq2coNOsE39B3RF4WvUzQYCQ6J4yS8BTdnY=
github.com/go-pg/pg/v9 v9.0.1/go.mod h1:Tm/Q3Vt6gdQOH6TTN1H/xLlIXc+Qrka7TZ6uREtu/eA=
github.com/go-pg/urlstruct v0.1.0/go.mod h1:2Nag+BIny6G/KYCkdt++ZnqU/VinzimGapKfs4kwlN0=
github.com/go-pg/urlstruct v0.2.6 h1:TReWM/GETx98RSfxO1mOOVic8tJCeJC5SgdeDpIy0FY=
github.com/go-pg/urlstruct v0.2.6/go.mod h1:dxENwVISWSOX+k87hDt0ueEJadD+gZWv3tHzwfmZPu8=
github.com/go-pg/zerochecker v0.1.1 h1:av77Qe7Gs+1oYGGh51k0sbZ0bUaxJEdeP0r8YE64Dco=
github.com/go-pg/zerochecker v0.1.1/go.mod h1:NJZ4wKL0NmTtz0GKCoJ8kym6Xn/EQzXRl2OnAe7MmDo=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -48,6 +56,11 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/meskio/epubgo v0.0.0-20160213181628-90dd5d78197f h1:2/bW7eP5YZd+O2oo6xP7P0tCIhY+ozRTxFwWdF4CTAo=
@ -60,8 +73,10 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY=
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -89,16 +104,23 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/vmihailenco/tagparser v0.1.0 h1:u6yzKTY6gW/KxL/K2NTEQUOSXZipyGiIRarGjJKmQzU=
github.com/vmihailenco/tagparser v0.1.0/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59 h1:PyXRxSVbvzDGuqYXjHndV7xDzJ7w2K8KD9Ef8GB7KOE=
golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -108,14 +130,21 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=

View file

@ -4,26 +4,26 @@ import (
"strings"
"time"
"github.com/go-pg/pg"
"github.com/go-pg/pg/v9"
)
// Book metadata
type Book struct {
ID string `sql:"type:varchar(16)"`
ID string `pg:"type:varchar(16)"`
Title string
Authors []string `sql:"authors" pg:",array"`
Authors []string `pg:"authors,array"`
Contributor string
Publisher string
Description string
Tags []string `sql:"tags" pg:",array"`
Tags []string `pg:"tags,array"`
Date string
Lang string `sql:"type:varchar(3)"`
Isbn string `sql:"type:varchar(13)"`
FileSize int `sql:"type:integer"`
Cover bool `sql:",notnull"`
Active bool `sql:",notnull"`
UploadDate time.Time `sql:"type:timestamp"`
Tsv string `sql:"type:tsvector"`
Lang string `pg:"type:varchar(3)"`
Isbn string `pg:"type:varchar(13)"`
FileSize int `pg:"type:integer"`
Cover bool `pg:",notnull"`
Active bool `pg:",notnull"`
UploadDate time.Time `pg:"type:timestamp"`
Tsv string `pg:"type:tsvector"`
Visit *Visit
}
@ -156,7 +156,7 @@ func (db *pgDB) ActiveBook(id string) error {
func (db *pgDB) IsBookActive(id string) bool {
var active []bool
err := db.sql.Model(&Book{}).
Column("active").
Relation("active").
Where("id = ?", id).
Select(&active)
if err != nil || len(active) != 1 {

View file

@ -3,8 +3,8 @@ package database
import (
"time"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
"github.com/go-pg/pg/v9"
"github.com/go-pg/pg/v9/orm"
)
type DB interface {

View file

@ -1,7 +1,7 @@
package database
import (
"github.com/go-pg/pg"
"github.com/go-pg/pg/v9"
)
type BookLister interface {
@ -15,20 +15,20 @@ type BookLister interface {
}
type BookList struct {
ID int `sql:"type:serial"`
ListID string `sql:"type:varchar(16)"`
ID int `pg:"type:serial"`
ListID string `pg:"type:varchar(16)"`
Title string
Description []string `sql:"description" pg:",array"`
UserID int `sql:"type:integer"`
Description []string `pg:"description,array"`
UserID int `pg:"type:integer"`
User *User
Books []Book `pg:"many2many:book_list_entries"`
}
type BookListEntry struct {
ID int `sql:"type:serial"`
BookListID int `sql:"type:integer"`
ID int `pg:"type:serial"`
BookListID int `pg:"type:integer"`
BookList *BookList
BookID string `sql:"type:varchar(16)"`
BookID string `pg:"type:varchar(16)"`
Book *Book
}
@ -80,7 +80,8 @@ func (db *pgDB) UpdateBookList(listID, title string, description []string) error
func (db *pgDB) GetBookList(listID string) (*BookList, error) {
var bookList BookList
err := db.sql.Model(&bookList).
Column("Books", "User").
Relation("Books").
Relation("User").
Where("list_id = ?", listID).
Select()
return &bookList, err
@ -95,7 +96,8 @@ func (db *pgDB) GetListsByUser(username string) ([]BookList, error) {
}
err = db.sql.Model(&bookLists).
Column("Books", "User").
Relation("Books").
Relation("User").
Where("user_id = ?", user.ID).
Select()
return bookLists, err
@ -106,7 +108,7 @@ func (db *pgDB) GetListsByBook(bookID string) ([]BookList, error) {
var bookListEntries []BookListEntry
err := db.sql.Model(&bookListEntries).
Column("BookList").
Relation("BookList").
Where("book_id = ?", bookID).
Select()
if err != nil || len(bookListEntries) == 0 {
@ -125,7 +127,8 @@ func (db *pgDB) GetListsByBook(bookID string) ([]BookList, error) {
whereQuery += ")"
err = db.sql.Model(&bookLists).
Column("Books", "User").
Relation("Books").
Relation("User").
Where(whereQuery, listIDs...).
Select()
return bookLists, err

View file

@ -7,8 +7,8 @@ import (
// New entry in the news table
type New struct {
ID int `sql:"type:serial"`
Date time.Time `sql:"type:timestamp"`
ID int `pg:"type:serial"`
Date time.Time `pg:"type:timestamp"`
Text string
}

View file

@ -7,10 +7,10 @@ import (
)
type Visit struct {
ID int `sql:"type:serial"`
Downloads int `sql:"type:integer,notnull"`
Views int `sql:"type:integer,notnull"`
BookID string `sql:"type:varchar(16),unique"`
ID int `pg:"type:serial"`
Downloads int `pg:"type:integer,notnull"`
Views int `pg:"type:integer,notnull"`
BookID string `pg:"type:varchar(16),unique"`
Book *Book
}

View file

@ -12,15 +12,15 @@ const (
)
type Submission struct {
ID int `sql:"type:serial"`
SubmissionID string `sql:"type:varchar(16)"`
ID int `pg:"type:serial"`
SubmissionID string `pg:"type:varchar(16)"`
Filename string
Status string
Comment string
LastModified time.Time
UserID int `sql:"type:integer,unique"`
UserID int `pg:"type:integer,unique"`
User *User
BookID string `sql:"type:varchar(16),unique"`
BookID string `pg:"type:varchar(16),unique"`
Book *Book
}
@ -78,7 +78,7 @@ func (db *pgDB) GetComment(bookID string) (string, error) {
func (db *pgDB) GetSubmission(submissionID string) (submission []Submission, err error) {
err = db.sql.Model(&submission).
Column("Book").
Relation("Book").
Where("submission_id = ?", submissionID).
Select()
return
@ -86,7 +86,8 @@ func (db *pgDB) GetSubmission(submissionID string) (submission []Submission, err
func (db *pgDB) GetUserSubmissions(userName string) (submission []Submission, err error) {
err = db.sql.Model(&submission).
Column("Book", "User").
Relation("Book").
Relation("User").
Where("username = ?", userName).
Order("last_modified DESC").
Select()

View file

@ -16,11 +16,11 @@ import (
var alphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9_\-\.]+$`).MatchString
type User struct {
ID int `sql:"type:serial"`
Username string `sql:"type:varchar(255),unique"`
ID int `pg:"type:serial"`
Username string `pg:"type:varchar(255),unique"`
Password []byte
Salt []byte
Role string `sql:"type:varchar(255)"`
Role string `pg:"type:varchar(255)"`
LastLogin time.Time
}