Skip to content

Commit

Permalink
feat: dump schema cache through admin API (#3233)
Browse files Browse the repository at this point in the history
  • Loading branch information
taimoorzaeem authored Feb 20, 2024
1 parent fac7aca commit 32e1900
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #3171, Add an ability to dump config via admin API - @skywriter
- #3061, Apply all function settings as transaction-scoped settings - @taimoorzaeem
- #3171, Log schema cache stats to stderr - @steve-chavez
- #3210, Dump schema cache through admin API - @taimoorzaeem

### Fixed

Expand Down
4 changes: 4 additions & 0 deletions src/PostgREST/Admin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module PostgREST.Admin
( runAdmin
) where

import qualified Data.Aeson as JSON
import qualified Hasql.Session as SQL
import qualified Network.HTTP.Types.Status as HTTP
import qualified Network.Wai as Wai
Expand Down Expand Up @@ -51,6 +52,9 @@ admin appState appConfig req respond = do
["config"] -> do
config <- AppState.getConfig appState
respond $ Wai.responseLBS HTTP.status200 [] (LBS.fromStrict $ encodeUtf8 $ Config.toText config)
["schema_cache"] -> do
sCache <- AppState.getSchemaCache appState
respond $ Wai.responseLBS HTTP.status200 [] (maybe mempty JSON.encode sCache)
_ ->
respond $ Wai.responseLBS HTTP.status404 [] mempty

Expand Down
9 changes: 9 additions & 0 deletions test/io/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,15 @@ def test_admin_config(defaultenv):
assert "admin-server-port" in response.text


def test_admin_schema_cache(defaultenv):
"Should get a success response from the admin server containing current schema cache"

with run(env=defaultenv) as postgrest:
response = postgrest.admin.get("/schema_cache")
assert response.status_code == 200
assert '"dbTables":[[{"qiName":"authors_only"' in response.text


def test_admin_ready_w_channel(defaultenv):
"Should get a success response from the admin server ready endpoint when the LISTEN channel is enabled"

Expand Down

0 comments on commit 32e1900

Please sign in to comment.