Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions datastore/datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ go mod tidy

The following environment variables are supported:

| Variable | Mandatory | Default value | Description |
| :-- | :-- | :-- | :-- |
| Variable | Mandatory | Default value | Description |
|:------------------| :-- | :-- | :-- |
| `SERVERPORT` | No | `50050` | Server port number. |
| `PGHOST` | No | `localhost` | PostgreSQL host. |
| `PGPORT` | No | `5433` | PostgreSQL port number. |
| `PGBUSER` | No | `postgres` | PostgreSQL user name. |
| `PGUSER` | No | `postgres` | PostgreSQL user name. |
| `PGPASSWORD` | No | `mysecretpassword` | PostgreSQL password. |
| `PGDBNAME` | No | `data` | PostgreSQL database name. |
| `ENABLE_SSL` | No | `disable` | Weather to use ssl for connection |
| `DYNAMICTIME` | No | `true` | Whether the valid time range is _dynamic_ or _static_ (defined below). |
| `LOTIME` | No | `86400` | The _earliest_ valid time as seconds to be either [1] subtracted from the current time (if the valid time range is _dynamic_) or [2] added to UNIX epoch (1970-01-01T00:00:00Z) (if the valid time range is _static_). In the case of a _static_ valid time range, the `LOTIME` can optionally be specified as an ISO-8601 datetime of the exact form `2023-10-10T00:00:00Z`. |
| `HITIME` | No | `-600` | Same as `LOTIME`, but for the _latest_ valid time. Note a default leeway of 10 minutes into the future to reduce risk of missing visual observations. |
Expand Down
13 changes: 6 additions & 7 deletions datastore/datastore/storagebackend/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"datastore/common"
"datastore/datastore"
"fmt"
_ "github.com/lib/pq"
"log"
"regexp"
"strconv"
"strings"
"time"

_ "github.com/lib/pq"
)

// PostgreSQL is an implementation of the StorageBackend interface that
Expand Down Expand Up @@ -118,10 +117,10 @@ func setUpsertTSSelectCmd() {

// openDB opens database identified by host/port/user/password/dbname.
// Returns (DB, nil) upon success, otherwise (..., error).
func openDB(host, port, user, password, dbname string) (*sql.DB, error) {
func openDB(host, port, user, password, dbname, enable_ssl string) (*sql.DB, error) {
connInfo := fmt.Sprintf(
"host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
host, port, user, password, dbname)
"host=%s port=%s user=%s password=%s dbname=%s sslmode=%s",
host, port, user, password, dbname, enable_ssl)

db, err := sql.Open("postgres", connInfo)
if err != nil {
Expand All @@ -147,10 +146,10 @@ func NewPostgreSQL() (*PostgreSQL, error) {
user := common.Getenv("PGUSER", "postgres")
password := common.Getenv("PGPASSWORD", "mysecretpassword")
dbname := common.Getenv("PGDBNAME", "data")

enable_ssl := common.Getenv("ENABLE_SSL", "disable")
var err error

sbe.Db, err = openDB(host, port, user, password, dbname)
sbe.Db, err = openDB(host, port, user, password, dbname, enable_ssl)
if err != nil {
return nil, fmt.Errorf("openDB() failed: %v", err)
}
Expand Down
15 changes: 8 additions & 7 deletions datastore/migrate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ The other path: `./migrate/data/not_supported_yet`, contains an example migratio

There are a few environment variables needed to run the migrate script.

| Name | Requiered | Explenation |
|------------|------|--------------|
| DB_USER | Yes | The username for the database |
| DB_PASS | Yes | The password for the user |
| DB_URL | Yes | URL or IP to the postgis database |
| DB_PORT | No | Database port, default `5432` |
| ENABLE_SSL | No | Wether to use ssl for connection, defailt `disable`|
| Name | Requiered | Explenation |
|------------|-----------|------------------------------------------------------|
| DB_USER | Yes | The username for the database |
| DB_PASS | Yes | The password for the user |
| DB_URL | Yes | URL or IP to the postgis database |
| DB_NAME | No | PostgreSQL database name, default `data` |
| DB_PORT | No | Database port, default `5432` |
| ENABLE_SSL | No | Weather to use ssl for connection, default `disable` |
2 changes: 1 addition & 1 deletion datastore/migrate/run-migrate.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

exec migrate -path /migrations -database "postgres://${DB_USER}:${DB_PASS}@${DB_URL}:${DB_PORT:-5432}/data?sslmode=${ENABLE_SSL:-disable}" up
exec migrate -path /migrations -database "postgres://${DB_USER}:${DB_PASS}@${DB_URL}:${DB_PORT:-5432}/${DB_NAME:-data}?sslmode=${ENABLE_SSL:-disable}" up
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
- DB_USER=postgres
- DB_PASS=mysecretpassword
- DB_URL=db
- DB_NAME=data
depends_on:
db:
condition: service_healthy
Expand All @@ -51,6 +52,7 @@ services:
environment:
- PGHOST=db
- PGPORT=5432
- PGDBNAME=data
- DYNAMICTIME=$DYNAMICTIME
- LOTIME=$LOTIME
- HITIME=$HITIME
Expand Down