some cleanup
This commit is contained in:
@@ -32,9 +32,7 @@ var serveCmd = &cobra.Command{
|
||||
}
|
||||
conf := *config.Conf
|
||||
ctx := context.Background()
|
||||
db_url := "postgres://" + conf.Database.User + ":" + conf.Database.Password + "@" + conf.Database.Host + ":" + strconv.Itoa(conf.Database.Port) + "/" + conf.Database.Name
|
||||
db_url = db_url + "?sslmode=disable"
|
||||
conn, err := pgxpool.New(ctx, db_url)
|
||||
conn, err := pgxpool.New(ctx, conf.Database.URL().String())
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
@@ -3,8 +3,11 @@ package config
|
||||
import (
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/pelletier/go-toml"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var confPath string
|
||||
@@ -18,7 +21,7 @@ func init() {
|
||||
Server: Server{
|
||||
Host: "127.0.0.1",
|
||||
Port: 8080,
|
||||
FrontendUrls: []string{"http://localhost:5173"},
|
||||
FrontendUrls: []string{"http://localhost:5173", "http://127.0.0.1:5173"},
|
||||
},
|
||||
Database: Database{
|
||||
User: "pp",
|
||||
@@ -75,6 +78,17 @@ type Database struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// URL returns the Postgres connection URL. The local dev database has no SSL.
|
||||
func (d Database) URL() *url.URL {
|
||||
return &url.URL{
|
||||
Scheme: "postgres",
|
||||
User: url.UserPassword(d.User, d.Password),
|
||||
Host: net.JoinHostPort(d.Host, strconv.Itoa(d.Port)),
|
||||
Path: "/" + d.Name,
|
||||
RawQuery: "sslmode=disable",
|
||||
}
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Server Server
|
||||
Database Database
|
||||
|
||||
@@ -5,9 +5,6 @@ import (
|
||||
"github.com/amacneil/dbmate/v2/pkg/dbmate"
|
||||
_ "github.com/amacneil/dbmate/v2/pkg/driver/postgres"
|
||||
"log"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Q *Queries
|
||||
@@ -19,23 +16,7 @@ func RunDbMigrations() error {
|
||||
return err
|
||||
}
|
||||
conf := *config.Conf
|
||||
dbUrl, err := url.Parse(strings.Join([]string{
|
||||
"postgresql://",
|
||||
conf.Database.User,
|
||||
":",
|
||||
conf.Database.Password,
|
||||
"@",
|
||||
conf.Database.Host,
|
||||
":",
|
||||
strconv.Itoa(conf.Database.Port),
|
||||
"/",
|
||||
conf.Database.Name,
|
||||
"?sslmode=disable",
|
||||
}, ""))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
db := dbmate.New(dbUrl)
|
||||
db := dbmate.New(conf.Database.URL())
|
||||
db.FS = MigrationsFs
|
||||
db.MigrationsDir = []string{"migrations"}
|
||||
migrations, err := db.FindMigrations()
|
||||
|
||||
Reference in New Issue
Block a user