Skip to content

Configurable server_settings #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2024
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Ability to configure the database runtime parameters ([#92](https://github.com/stac-utils/stac-fastapi-pgstac/pull/92))

## [2.4.11] - 2023-12-01

### Changed
Expand Down
15 changes: 15 additions & 0 deletions stac_fastapi/pgstac/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Type
from urllib.parse import quote

from pydantic import BaseModel, Extra
from stac_fastapi.types.config import ApiSettings

from stac_fastapi.pgstac.types.base_item_cache import (
Expand Down Expand Up @@ -32,6 +33,13 @@
]


class ServerSettings(BaseModel, extra=Extra.allow):
"""Server runtime parameters."""

search_path: str = "pgstac,public"
application_name: str = "pgstac"


class Settings(ApiSettings):
"""Postgres-specific API settings.

Expand All @@ -58,6 +66,8 @@ class Settings(ApiSettings):
db_max_queries: int = 50000
db_max_inactive_conn_lifetime: float = 300

server_settings: ServerSettings = ServerSettings()

use_api_hydrate: bool = False
base_item_cache: Type[BaseItemCache] = DefaultBaseItemCache
invalid_id_chars: List[str] = DEFAULT_INVALID_ID_CHARS
Expand All @@ -78,3 +88,8 @@ def writer_connection_string(self):
def testing_connection_string(self):
"""Create testing psql connection string."""
return f"postgresql://{self.postgres_user}:{quote(self.postgres_pass)}@{self.postgres_host_writer}:{self.postgres_port}/pgstactestdb"

class Config(ApiSettings.Config):
"""Model config."""

env_nested_delimiter = "__"
5 changes: 1 addition & 4 deletions stac_fastapi/pgstac/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ async def create_pool(self, connection_string: str, settings):
max_queries=settings.db_max_queries,
max_inactive_connection_lifetime=settings.db_max_inactive_conn_lifetime,
init=con_init,
server_settings={
"search_path": "pgstac,public",
"application_name": "pgstac",
},
server_settings=settings.server_settings.dict(),
)
return pool