diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f609610..1433c30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,20 +89,20 @@ jobs: - name: Run Benchmark run: python -m pytest tests/benchmarks.py --benchmark-only --benchmark-columns 'min, max, mean, median' --benchmark-json output.json --asyncio-mode=strict - - name: Store and benchmark result - uses: benchmark-action/github-action-benchmark@v1 - with: - name: TiFeatures Benchmarks - tool: 'pytest' - output-file-path: output.json - alert-threshold: '130%' - comment-on-alert: true - fail-on-alert: true - # GitHub API token to make a commit comment - github-token: ${{ secrets.GITHUB_TOKEN }} - # Make a commit on `gh-pages` only if master - auto-push: ${{ github.ref == 'refs/heads/master' }} - benchmark-data-dir-path: benchmarks + # - name: Store and benchmark result + # uses: benchmark-action/github-action-benchmark@v1 + # with: + # name: TiFeatures Benchmarks + # tool: 'pytest' + # output-file-path: output.json + # alert-threshold: '130%' + # comment-on-alert: true + # fail-on-alert: true + # # GitHub API token to make a commit comment + # github-token: ${{ secrets.GITHUB_TOKEN }} + # # Make a commit on `gh-pages` only if master + # auto-push: ${{ github.ref == 'refs/heads/master' }} + # benchmark-data-dir-path: benchmarks publish: needs: [tests] diff --git a/tifeatures/db.py b/tifeatures/db.py index a7e634f..163b1de 100644 --- a/tifeatures/db.py +++ b/tifeatures/db.py @@ -1,6 +1,6 @@ """tifeatures.db: database events.""" -from typing import Optional +from typing import Any, Optional from buildpg import asyncpg @@ -46,9 +46,9 @@ async def connect_to_db( ) -async def register_table_catalog(app: FastAPI) -> None: +async def register_table_catalog(app: FastAPI, **kwargs: Any) -> None: """Register Table catalog.""" - app.state.table_catalog = await get_table_index(app.state.pool) + app.state.table_catalog = await get_table_index(app.state.pool, **kwargs) async def close_db_connection(app: FastAPI) -> None: diff --git a/tifeatures/main.py b/tifeatures/main.py index 193eb46..a0577d3 100644 --- a/tifeatures/main.py +++ b/tifeatures/main.py @@ -10,7 +10,7 @@ from tifeatures.factory import Endpoints from tifeatures.layer import FunctionRegistry from tifeatures.middleware import CacheControlMiddleware -from tifeatures.settings import APISettings +from tifeatures.settings import APISettings, PostgresSettings from fastapi import FastAPI @@ -19,6 +19,7 @@ from starlette_cramjam.middleware import CompressionMiddleware settings = APISettings() +postgres_settings = PostgresSettings() app = FastAPI( title=settings.name, @@ -66,8 +67,12 @@ @app.on_event("startup") async def startup_event() -> None: """Connect to database on startup.""" - await connect_to_db(app) - await register_table_catalog(app) + await connect_to_db(app, settings=postgres_settings) + await register_table_catalog( + app, + schemas=postgres_settings.db_schemas, + tables=postgres_settings.db_tables, + ) @app.on_event("shutdown") diff --git a/tifeatures/settings.py b/tifeatures/settings.py index a21ef0f..e45c305 100644 --- a/tifeatures/settings.py +++ b/tifeatures/settings.py @@ -1,7 +1,7 @@ """tifeatures config.""" from functools import lru_cache -from typing import Any, Dict, Optional +from typing import Any, Dict, List, Optional import pydantic @@ -56,6 +56,9 @@ class PostgresSettings(pydantic.BaseSettings): db_max_queries: int = 50000 db_max_inactive_conn_lifetime: float = 300 + db_schemas: List[str] = ["public"] + db_tables: Optional[List[str]] + class Config: """model config"""