diff --git a/CHANGELOG.md b/CHANGELOG.md index 45b26f07f..4df5ba982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/PostgREST/Admin.hs b/src/PostgREST/Admin.hs index b5122f306..41f326eeb 100644 --- a/src/PostgREST/Admin.hs +++ b/src/PostgREST/Admin.hs @@ -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 @@ -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 diff --git a/test/io/test_io.py b/test/io/test_io.py index 31d714d0d..f7d9aa5a6 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -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"