Skip to content

Commit 32e1900

Browse files
authored
feat: dump schema cache through admin API (#3233)
1 parent fac7aca commit 32e1900

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111
- #3171, Add an ability to dump config via admin API - @skywriter
1212
- #3061, Apply all function settings as transaction-scoped settings - @taimoorzaeem
1313
- #3171, Log schema cache stats to stderr - @steve-chavez
14+
- #3210, Dump schema cache through admin API - @taimoorzaeem
1415

1516
### Fixed
1617

src/PostgREST/Admin.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module PostgREST.Admin
44
( runAdmin
55
) where
66

7+
import qualified Data.Aeson as JSON
78
import qualified Hasql.Session as SQL
89
import qualified Network.HTTP.Types.Status as HTTP
910
import qualified Network.Wai as Wai
@@ -51,6 +52,9 @@ admin appState appConfig req respond = do
5152
["config"] -> do
5253
config <- AppState.getConfig appState
5354
respond $ Wai.responseLBS HTTP.status200 [] (LBS.fromStrict $ encodeUtf8 $ Config.toText config)
55+
["schema_cache"] -> do
56+
sCache <- AppState.getSchemaCache appState
57+
respond $ Wai.responseLBS HTTP.status200 [] (maybe mempty JSON.encode sCache)
5458
_ ->
5559
respond $ Wai.responseLBS HTTP.status404 [] mempty
5660

test/io/test_io.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,15 @@ def test_admin_config(defaultenv):
642642
assert "admin-server-port" in response.text
643643

644644

645+
def test_admin_schema_cache(defaultenv):
646+
"Should get a success response from the admin server containing current schema cache"
647+
648+
with run(env=defaultenv) as postgrest:
649+
response = postgrest.admin.get("/schema_cache")
650+
assert response.status_code == 200
651+
assert '"dbTables":[[{"qiName":"authors_only"' in response.text
652+
653+
645654
def test_admin_ready_w_channel(defaultenv):
646655
"Should get a success response from the admin server ready endpoint when the LISTEN channel is enabled"
647656

0 commit comments

Comments
 (0)