Skip to content

Commit c68ad09

Browse files
authored
Postgres DSN (#322)
* Allow specifying Postgres DSN
1 parent 6f286c9 commit c68ad09

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

bitmagnet.io/setup/configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ nav_order: 2
1010
**bitmagnet** exposes quite a few configuration options. You shouldn't have to worry about most of them, but they are available for tinkering. If you're using the [example docker-compose file]({% link setup/installation.md %}#docker) then things _should_ "just work". I'll only cover only some of the more important options here:
1111

1212
- `postgres.host`, `postgres.name` `postgres.user` `postgres.password` (default: `localhost`, `bitmagnet`, `postgres`, _empty_): Set these values to configure connection to your Postgres database.
13+
- `postgres.dsn`: Alternatively a Postgres Data Source Name (DSN) can be specified. If specified, all other `postgres.*` options are ignored.
1314
- `tmdb.api_key`: This is quite an important one, please [see below](#obtaining-a-tmdb-api-key) for more details.
1415
- `tmdb.enabled` (default: `true`): Specify `false` to disable the TMDB API integration.
1516
- `dht_crawler.save_files_threshold` (default: `100`): Some torrents contain many thousands of files, which impacts performance and uses a lot of database disk space. This parameter sets a maximum limit for the number of files saved by the crawler with each torrent.

internal/database/postgres/config.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
)
77

88
type Config struct {
9+
DSN string
910
Host string
1011
User string
1112
Port uint
@@ -27,7 +28,10 @@ func NewDefaultConfig() Config {
2728
}
2829
}
2930

30-
func (c *Config) DSN() string {
31+
func (c *Config) CreateDSN() string {
32+
if c.DSN != "" {
33+
return c.DSN
34+
}
3135
vals := dbValues(c)
3236
p := make([]string, 0, len(vals))
3337
for k, v := range vals {

internal/database/postgres/postgres.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func New(p Params) (Result, error) {
3232
waitGroup := &sync.WaitGroup{}
3333
lazyPool := lazy.New(func() (*pgxpool.Pool, error) {
3434
ctx, cancel := context.WithCancel(context.Background())
35-
pl, plErr := pgxpool.New(ctx, p.Config.DSN())
35+
pl, plErr := pgxpool.New(ctx, p.Config.CreateDSN())
3636
if plErr != nil {
3737
cancel()
3838
return nil, plErr

0 commit comments

Comments
 (0)