mirror of
https://github.com/amigan/aim-oscar-server.git
synced 2025-01-31 04:52:37 -05:00
sqlite -> postgres
This commit is contained in:
parent
3205129e73
commit
7af076ff6a
3 changed files with 78 additions and 9 deletions
4
go.mod
4
go.mod
|
@ -4,9 +4,11 @@ go 1.16
|
|||
|
||||
require (
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/uptrace/bun v1.0.19
|
||||
github.com/uptrace/bun v1.0.20
|
||||
github.com/uptrace/bun/dbfixture v1.0.19
|
||||
github.com/uptrace/bun/dialect/pgdialect v1.0.20 // indirect
|
||||
github.com/uptrace/bun/dialect/sqlitedialect v1.0.19
|
||||
github.com/uptrace/bun/driver/pgdriver v1.0.20 // indirect
|
||||
github.com/uptrace/bun/driver/sqliteshim v1.0.19
|
||||
github.com/uptrace/bun/extra/bundebug v1.0.19
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
|
|
13
go.sum
13
go.sum
|
@ -35,10 +35,16 @@ github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYm
|
|||
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
|
||||
github.com/uptrace/bun v1.0.19 h1:Jl5GbcnLqeo4mHLVbF+LvzVXiXTrwQOdIVvuMO+5zXI=
|
||||
github.com/uptrace/bun v1.0.19/go.mod h1:Uv7z0z+7dXnUS9P5hMF0hdiM/4M+xOUHQCrZpyDrpRc=
|
||||
github.com/uptrace/bun v1.0.20 h1:/T4p9C9tEN75U3cFMBr5njlP+rBfs4An8BmlQQPbcfE=
|
||||
github.com/uptrace/bun v1.0.20/go.mod h1:Uv7z0z+7dXnUS9P5hMF0hdiM/4M+xOUHQCrZpyDrpRc=
|
||||
github.com/uptrace/bun/dbfixture v1.0.19 h1:1jKjs6vluS4e5F0U5kF3RW5SPCGbTj+64WiCbVIy09U=
|
||||
github.com/uptrace/bun/dbfixture v1.0.19/go.mod h1:1mHn2Np4I3vDrGDWb6zzce+4D4StFwpMXBdtCxizRt8=
|
||||
github.com/uptrace/bun/dialect/pgdialect v1.0.20 h1:1Yajz0M2AhOzvxFEQSAQ8TpqzSRFxYOg+saksIQ0dmU=
|
||||
github.com/uptrace/bun/dialect/pgdialect v1.0.20/go.mod h1:Z2UoOgTKHXgFOuInXsJKkNQJiFIaPkCvsj0EayOI2yk=
|
||||
github.com/uptrace/bun/dialect/sqlitedialect v1.0.19 h1:Oy0scO7sXbVBk9k6xc2yFF/X1maW5UU6uqO6coX/5/8=
|
||||
github.com/uptrace/bun/dialect/sqlitedialect v1.0.19/go.mod h1:KXvO5WJYf+JNrabpLR9CdflPjOqbkIjoBalxePvoysU=
|
||||
github.com/uptrace/bun/driver/pgdriver v1.0.20 h1:CEWHL5NS5FQIJAJxY40t0llwe8XxVlsblbgi9Upm0fA=
|
||||
github.com/uptrace/bun/driver/pgdriver v1.0.20/go.mod h1:KAONvCIiI4A6HdMTZ8zCdGxh7P6+23Todz+bL8HRzV4=
|
||||
github.com/uptrace/bun/driver/sqliteshim v1.0.19 h1:nW7dfsEgAJ0Xv9HmRuRyeC3FOiINZSr6VZAHKv6sY5c=
|
||||
github.com/uptrace/bun/driver/sqliteshim v1.0.19/go.mod h1:qeC2X9mnTDJzVHf30Ef4xsUp9k3yQOkp7+adAnBt4/w=
|
||||
github.com/uptrace/bun/extra/bundebug v1.0.19 h1:PBajhIUkeHk3ZOpH9ZLPhfGxiZlBS70nV/Nmufk4B7s=
|
||||
|
@ -50,9 +56,12 @@ github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV
|
|||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
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-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
|
||||
|
@ -62,6 +71,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
|
@ -73,6 +83,7 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
@ -106,6 +117,8 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v
|
|||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
lukechampine.com/uint128 v1.1.1 h1:pnxCASz787iMf+02ssImqk6OLt+Z5QHMoZyUXR4z6JU=
|
||||
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w=
|
||||
mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ=
|
||||
modernc.org/cc/v3 v3.33.6/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.33.9/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
modernc.org/cc/v3 v3.33.11/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
|
||||
|
|
70
main.go
70
main.go
|
@ -7,21 +7,24 @@ import (
|
|||
"aim-oscar/util"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"database/sql"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dbfixture"
|
||||
"github.com/uptrace/bun/dialect/sqlitedialect"
|
||||
"github.com/uptrace/bun/driver/sqliteshim"
|
||||
"github.com/uptrace/bun/dialect/pgdialect"
|
||||
"github.com/uptrace/bun/driver/pgdriver"
|
||||
"github.com/uptrace/bun/extra/bundebug"
|
||||
)
|
||||
|
||||
|
@ -32,6 +35,11 @@ var (
|
|||
OSCAR_BOS_HOST = OSCAR_HOST
|
||||
OSCAR_BOS_PORT = OSCAR_PORT
|
||||
OSCAR_BOS_ADDRESS = OSCAR_BOS_HOST + ":" + OSCAR_BOS_PORT
|
||||
DB_URL = ""
|
||||
DB_USER = ""
|
||||
DB_USER_FILE = ""
|
||||
DB_PASSWORD = ""
|
||||
DB_PASSWORD_FILE = ""
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -59,6 +67,18 @@ func init() {
|
|||
var oscarBOSPort string
|
||||
flag.StringVar(&oscarBOSPort, "bosport", OSCAR_BOS_PORT, "BOS port")
|
||||
|
||||
if dbUrl, ok := os.LookupEnv("DB_URL"); ok {
|
||||
DB_URL = dbUrl
|
||||
}
|
||||
|
||||
if dbUserFile, ok := os.LookupEnv("DB_USER_FILE"); ok {
|
||||
DB_USER_FILE = dbUserFile
|
||||
}
|
||||
|
||||
if dbPasswordFile, ok := os.LookupEnv("DB_PASSWORD_FILE"); ok {
|
||||
DB_PASSWORD_FILE = dbPasswordFile
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
|
||||
OSCAR_HOST = oscarHost
|
||||
|
@ -68,16 +88,50 @@ func init() {
|
|||
OSCAR_BOS_HOST = oscarBOSHost
|
||||
OSCAR_BOS_PORT = oscarBOSPort
|
||||
OSCAR_BOS_ADDRESS = OSCAR_BOS_HOST + ":" + OSCAR_BOS_PORT
|
||||
|
||||
log.Println(os.Environ())
|
||||
|
||||
if DB_URL == "" {
|
||||
log.Fatalln("DB Url not specified")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// Set up the DB
|
||||
sqldb, err := sql.Open(sqliteshim.ShimName, "file:aim.db")
|
||||
dbUser, err := ioutil.ReadFile(DB_USER_FILE)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
db := bun.NewDB(sqldb, sqlitedialect.New())
|
||||
DB_USER = strings.TrimSpace(string(dbUser))
|
||||
if DB_USER == "" {
|
||||
log.Fatalln("DB User not specified")
|
||||
}
|
||||
|
||||
dbPassword, err := ioutil.ReadFile(DB_PASSWORD_FILE)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
DB_PASSWORD = strings.TrimSpace(string(dbPassword))
|
||||
if DB_PASSWORD == "" {
|
||||
log.Fatalln("DB password not specified")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
pgconn := pgdriver.NewConnector(
|
||||
pgdriver.WithNetwork("tcp"),
|
||||
pgdriver.WithAddr(DB_URL),
|
||||
pgdriver.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}),
|
||||
pgdriver.WithUser(DB_USER),
|
||||
pgdriver.WithPassword(DB_PASSWORD),
|
||||
pgdriver.WithDatabase("postgres"),
|
||||
pgdriver.WithInsecure(true),
|
||||
pgdriver.WithTimeout(5*time.Second),
|
||||
pgdriver.WithDialTimeout(5*time.Second),
|
||||
pgdriver.WithReadTimeout(5*time.Second),
|
||||
pgdriver.WithWriteTimeout(5*time.Second),
|
||||
)
|
||||
|
||||
// Set up the DB
|
||||
sqldb := sql.OpenDB(pgconn)
|
||||
db := bun.NewDB(sqldb, pgdialect.New())
|
||||
db.SetConnMaxIdleTime(15 * time.Second)
|
||||
db.SetConnMaxLifetime(1 * time.Minute)
|
||||
|
||||
|
@ -89,7 +143,7 @@ func main() {
|
|||
|
||||
// dev: load in fixtures to test against
|
||||
fixture := dbfixture.New(db, dbfixture.WithRecreateTables())
|
||||
err = fixture.Load(context.Background(), os.DirFS("./models"), "fixtures.yml")
|
||||
err := fixture.Load(context.Background(), os.DirFS("./models"), "fixtures.yml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue