Skip to content

Commit a25b6ac

Browse files
Configurable server_settings (#92)
Co-authored-by: Vincent Sarago <vincent.sarago@gmail.com>
1 parent 07350f5 commit a25b6ac

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Ability to configure the database runtime parameters ([#92](https://github.com/stac-utils/stac-fastapi-pgstac/pull/92))
8+
59
## [2.4.11] - 2023-12-01
610

711
### Changed

stac_fastapi/pgstac/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import List, Type
44
from urllib.parse import quote
55

6+
from pydantic import BaseModel, Extra
67
from stac_fastapi.types.config import ApiSettings
78

89
from stac_fastapi.pgstac.types.base_item_cache import (
@@ -32,6 +33,13 @@
3233
]
3334

3435

36+
class ServerSettings(BaseModel, extra=Extra.allow):
37+
"""Server runtime parameters."""
38+
39+
search_path: str = "pgstac,public"
40+
application_name: str = "pgstac"
41+
42+
3543
class Settings(ApiSettings):
3644
"""Postgres-specific API settings.
3745
@@ -58,6 +66,8 @@ class Settings(ApiSettings):
5866
db_max_queries: int = 50000
5967
db_max_inactive_conn_lifetime: float = 300
6068

69+
server_settings: ServerSettings = ServerSettings()
70+
6171
use_api_hydrate: bool = False
6272
base_item_cache: Type[BaseItemCache] = DefaultBaseItemCache
6373
invalid_id_chars: List[str] = DEFAULT_INVALID_ID_CHARS
@@ -78,3 +88,8 @@ def writer_connection_string(self):
7888
def testing_connection_string(self):
7989
"""Create testing psql connection string."""
8090
return f"postgresql://{self.postgres_user}:{quote(self.postgres_pass)}@{self.postgres_host_writer}:{self.postgres_port}/pgstactestdb"
91+
92+
class Config(ApiSettings.Config):
93+
"""Model config."""
94+
95+
env_nested_delimiter = "__"

stac_fastapi/pgstac/db.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ async def create_pool(self, connection_string: str, settings):
132132
max_queries=settings.db_max_queries,
133133
max_inactive_connection_lifetime=settings.db_max_inactive_conn_lifetime,
134134
init=con_init,
135-
server_settings={
136-
"search_path": "pgstac,public",
137-
"application_name": "pgstac",
138-
},
135+
server_settings=settings.server_settings.dict(),
139136
)
140137
return pool

0 commit comments

Comments
 (0)