dev: improve postgrest-watch experience
* speed up io tests * avoid infinite loop while watching io tests * improve auto-complete with postgrest-watch postgrest-run * detect when files are added or deleted
This commit is contained in:
committed by
Wolfgang Walther
parent
7d6d015822
commit
d218a9eaff
+3
-1
@@ -14,7 +14,9 @@ let
|
|||||||
''
|
''
|
||||||
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
||||||
|
|
||||||
${silver-searcher}/bin/ag -l . "$rootdir" | ${entr}/bin/entr -r "$@"
|
while true; do
|
||||||
|
(! ${silver-searcher}/bin/ag -l . "$rootdir" | ${entr}/bin/entr -dr "$@")
|
||||||
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
pushCachix =
|
pushCachix =
|
||||||
|
|||||||
+4
-2
@@ -16,7 +16,8 @@ let
|
|||||||
${nixpkgs-fmt}/bin/nixpkgs-fmt "$rootdir" > /dev/null 2> /dev/null
|
${nixpkgs-fmt}/bin/nixpkgs-fmt "$rootdir" > /dev/null 2> /dev/null
|
||||||
|
|
||||||
# Format Haskell files
|
# Format Haskell files
|
||||||
${silver-searcher}/bin/ag -l -g '\.l?hs$' . "$rootdir" \
|
# --vimgrep fixes a bug in ag: https://github.com/ggreer/the_silver_searcher/issues/753
|
||||||
|
${silver-searcher}/bin/ag -l --vimgrep -g '\.l?hs$' . "$rootdir" \
|
||||||
| xargs ${stylish-haskell}/bin/stylish-haskell -i
|
| xargs ${stylish-haskell}/bin/stylish-haskell -i
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@@ -35,7 +36,8 @@ let
|
|||||||
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
||||||
|
|
||||||
# Lint Haskell files
|
# Lint Haskell files
|
||||||
${silver-searcher}/bin/ag -l -g '\.l?hs$' "$rootdir" \
|
# --vimgrep fixes a bug in ag: https://github.com/ggreer/the_silver_searcher/issues/753
|
||||||
|
${silver-searcher}/bin/ag -l --vimgrep -g '\.l?hs$' "$rootdir" \
|
||||||
| xargs ${hlint}/bin/hlint -X QuasiQuotes -X NoPatternSynonyms
|
| xargs ${hlint}/bin/hlint -X QuasiQuotes -X NoPatternSynonyms
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
|
|||||||
+2
-1
@@ -13,6 +13,7 @@
|
|||||||
, postgrest
|
, postgrest
|
||||||
, postgrestStatic
|
, postgrestStatic
|
||||||
, postgrestProfiled
|
, postgrestProfiled
|
||||||
|
, procps
|
||||||
, runtimeShell
|
, runtimeShell
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
@@ -78,7 +79,7 @@ let
|
|||||||
name
|
name
|
||||||
''
|
''
|
||||||
env="$(cat ${postgrest.env})"
|
env="$(cat ${postgrest.env})"
|
||||||
export PATH="$env/bin:${curl}/bin:$PATH"
|
export PATH="$env/bin:${curl}/bin:${procps}/bin:$PATH"
|
||||||
|
|
||||||
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
||||||
cd "$rootdir"
|
cd "$rootdir"
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ lib.overrideDerivation postgrest.env (
|
|||||||
|
|
||||||
shellHook =
|
shellHook =
|
||||||
''
|
''
|
||||||
complete -c postgrest-watch
|
source ${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh
|
||||||
|
complete -F _command postgrest-watch
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+28
-34
@@ -88,8 +88,7 @@ readSecretFromFile(){
|
|||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
if pgrStarted
|
if pgrStarted
|
||||||
then
|
then
|
||||||
@@ -113,8 +112,7 @@ readDbUriFromStdin(){
|
|||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
if pgrStarted
|
if pgrStarted
|
||||||
then
|
then
|
||||||
@@ -131,8 +129,7 @@ reqWithRoleClaimKey(){
|
|||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
authorsJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign('$2', 'reallyreallyreallyreallyverysafe');")
|
authorsJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign('$2', 'reallyreallyreallyreallyverysafe');")
|
||||||
httpStatus="$( authorsStatus "$authorsJwt" )"
|
httpStatus="$( authorsStatus "$authorsJwt" )"
|
||||||
@@ -151,8 +148,7 @@ invalidRoleClaimKey(){
|
|||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
if pgrStarted
|
if pgrStarted
|
||||||
then
|
then
|
||||||
@@ -169,8 +165,7 @@ ensureIatClaimWorks(){
|
|||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
for i in {1..10}; do \
|
for i in {1..10}; do \
|
||||||
iatJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign(row_to_json(r), 'reallyreallyreallyreallyverysafe') from ( select 'postgrest_test_author' as role, extract(epoch from now()) as iat) r")
|
iatJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign(row_to_json(r), 'reallyreallyreallyreallyverysafe') from ( select 'postgrest_test_author' as role, extract(epoch from now()) as iat) r")
|
||||||
@@ -186,16 +181,16 @@ ensureIatClaimWorks(){
|
|||||||
pgrStop
|
pgrStop
|
||||||
}
|
}
|
||||||
|
|
||||||
# ensure app settings don't reset on pool timeout of 10 seconds, see https://github.com/PostgREST/postgrest/issues/1141
|
# ensure app settings don't reset on pool timeout, see https://github.com/PostgREST/postgrest/issues/1141
|
||||||
|
# pool timeout set to 1s to shorten runtime
|
||||||
ensureAppSettings(){
|
ensureAppSettings(){
|
||||||
pgrStart "./configs/app-settings.config"
|
pgrStart "./configs/app-settings.config"
|
||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
sleep 11
|
sleep 2
|
||||||
response=$(curl -s "http://localhost:$pgrPort/rpc/get_guc_value?name=app.settings.external_api_secret")
|
response=$(curl -s "http://localhost:$pgrPort/rpc/get_guc_value?name=app.settings.external_api_secret")
|
||||||
if test "$response" = "\"0123456789abcdef\""
|
if test "$response" = "\"0123456789abcdef\""
|
||||||
then
|
then
|
||||||
@@ -207,15 +202,17 @@ ensureAppSettings(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkAppSettingsReload(){
|
checkAppSettingsReload(){
|
||||||
pgrStart "./configs/sigusr2-settings.config"
|
configFile=$(mktemp)
|
||||||
|
trap "rm -f $configFile" ERR RETURN
|
||||||
|
cat "./configs/sigusr2-settings.config" > "$configFile"
|
||||||
|
pgrStart "$configFile"
|
||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
# change setting
|
# change setting
|
||||||
replaceConfigValue "app.settings.name_var" "Jane" ./configs/sigusr2-settings.config
|
replaceConfigValue "app.settings.name_var" "Jane" "$configFile"
|
||||||
# reload
|
# reload
|
||||||
kill -s SIGUSR2 $pgrPID
|
kill -s SIGUSR2 $pgrPID
|
||||||
response=$(curl -s "http://localhost:$pgrPort/rpc/get_guc_value?name=app.settings.name_var")
|
response=$(curl -s "http://localhost:$pgrPort/rpc/get_guc_value?name=app.settings.name_var")
|
||||||
@@ -226,21 +223,21 @@ checkAppSettingsReload(){
|
|||||||
ko "app.settings.name_var config not reloaded with SIGUSR2. Got: $response"
|
ko "app.settings.name_var config not reloaded with SIGUSR2. Got: $response"
|
||||||
fi
|
fi
|
||||||
pgrStop
|
pgrStop
|
||||||
# go back to original setting
|
|
||||||
replaceConfigValue "app.settings.name_var" "John" ./configs/sigusr2-settings.config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkJwtSecretReload(){
|
checkJwtSecretReload(){
|
||||||
pgrStart "./configs/sigusr2-settings.config"
|
configFile=$(mktemp)
|
||||||
|
trap "rm -f $configFile" ERR RETURN
|
||||||
|
cat "./configs/sigusr2-settings.config" > "$configFile"
|
||||||
|
pgrStart "$configFile"
|
||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
secret="reallyreallyreallyreallyverysafe"
|
secret="reallyreallyreallyreallyverysafe"
|
||||||
# change setting
|
# change setting
|
||||||
replaceConfigValue "jwt-secret" "$secret" ./configs/sigusr2-settings.config
|
replaceConfigValue "jwt-secret" "$secret" "$configFile"
|
||||||
# reload
|
# reload
|
||||||
kill -s SIGUSR2 $pgrPID
|
kill -s SIGUSR2 $pgrPID
|
||||||
payload='{"role":"postgrest_test_author"}'
|
payload='{"role":"postgrest_test_author"}'
|
||||||
@@ -253,20 +250,20 @@ checkJwtSecretReload(){
|
|||||||
ko "jwt-secret config not reloaded with SIGUSR2. Got: $httpStatus"
|
ko "jwt-secret config not reloaded with SIGUSR2. Got: $httpStatus"
|
||||||
fi
|
fi
|
||||||
pgrStop
|
pgrStop
|
||||||
# go back to original setting
|
|
||||||
replaceConfigValue "jwt-secret" "invalidinvalidinvalidinvalidinvalid" ./configs/sigusr2-settings.config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDbSchemaReload(){
|
checkDbSchemaReload(){
|
||||||
pgrStart "./configs/sigusr2-settings.config"
|
configFile=$(mktemp)
|
||||||
|
trap "rm -f $configFile" ERR RETURN
|
||||||
|
cat "./configs/sigusr2-settings.config" > "$configFile"
|
||||||
|
pgrStart "$configFile"
|
||||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
# add v1 schema to db-schema
|
# add v1 schema to db-schema
|
||||||
replaceConfigValue "db-schema" "test, v1" ./configs/sigusr2-settings.config
|
replaceConfigValue "db-schema" "test, v1" "$configFile"
|
||||||
# reload
|
# reload
|
||||||
kill -s SIGUSR2 $pgrPID
|
kill -s SIGUSR2 $pgrPID
|
||||||
kill -s SIGUSR1 $pgrPID
|
kill -s SIGUSR1 $pgrPID
|
||||||
@@ -278,8 +275,6 @@ checkDbSchemaReload(){
|
|||||||
ko "db-schema config not reloaded with SIGUSR2. Got: $httpStatus"
|
ko "db-schema config not reloaded with SIGUSR2. Got: $httpStatus"
|
||||||
fi
|
fi
|
||||||
pgrStop
|
pgrStop
|
||||||
# go back to original setting
|
|
||||||
replaceConfigValue "db-schema" "test" ./configs/sigusr2-settings.config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceConfigValue(){
|
replaceConfigValue(){
|
||||||
@@ -295,8 +290,7 @@ socketConnection(){
|
|||||||
while pgrStarted && test "$( getSocketStatus )" -ne 200
|
while pgrStarted && test "$( getSocketStatus )" -ne 200
|
||||||
do
|
do
|
||||||
# wait for the server to start
|
# wait for the server to start
|
||||||
sleep 0.1 \
|
sleep 0.1
|
||||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
|
||||||
done
|
done
|
||||||
if test $( getSocketStatus ) -eq 200
|
if test $( getSocketStatus ) -eq 200
|
||||||
then
|
then
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ db-uri = "$(POSTGREST_TEST_CONNECTION)"
|
|||||||
db-schema = "test"
|
db-schema = "test"
|
||||||
db-anon-role = "postgrest_test_anonymous"
|
db-anon-role = "postgrest_test_anonymous"
|
||||||
db-pool = 1
|
db-pool = 1
|
||||||
|
db-pool-timeout = 1
|
||||||
server-host = "127.0.0.1"
|
server-host = "127.0.0.1"
|
||||||
server-port = 49421
|
server-port = 49421
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user