add: config db-timezone-enabled for optional querying of timezones
To avoid repeated querying of `pg_timezone_names` every time schema cache is reset, `Prefer: timezone` can be disabled by setting `db-timezone-enabled = false`. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
committed by
Steve Chavez
parent
bd5de884fa
commit
d6c338d588
@@ -18,6 +18,7 @@ db-root-spec = "open_alias"
|
||||
db-schemas = "provided_through_alias"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = false
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = "other_root"
|
||||
db-schemas = "test,other_tenant1,other_tenant2"
|
||||
db-config = true
|
||||
db-pre-config = "postgrest.other_preconf"
|
||||
db-timezone-enabled = false
|
||||
db-tx-end = "rollback-allow-override"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = "https://otherexample.org"
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = "root"
|
||||
db-schemas = "test,tenant1,tenant2"
|
||||
db-config = true
|
||||
db-pre-config = "postgrest.preconf"
|
||||
db-timezone-enabled = false
|
||||
db-tx-end = "commit-allow-override"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = "https://example.org"
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = "openapi_v3"
|
||||
db-schemas = "multi,tenant,setup"
|
||||
db-config = false
|
||||
db-pre-config = "postgrest.pre_config"
|
||||
db-timezone-enabled = false
|
||||
db-tx-end = "rollback-allow-override"
|
||||
db-uri = "tmp_db"
|
||||
jwt-aud = "https://postgrest.org"
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = ""
|
||||
db-schemas = "public"
|
||||
db-config = true
|
||||
db-pre-config = ""
|
||||
db-timezone-enabled = true
|
||||
db-tx-end = "commit"
|
||||
db-uri = "postgresql://"
|
||||
jwt-aud = ""
|
||||
|
||||
@@ -20,6 +20,7 @@ PGRST_DB_ROOT_SPEC: openapi_v3
|
||||
PGRST_DB_SCHEMAS: multi, tenant,setup
|
||||
PGRST_DB_CONFIG: false
|
||||
PGRST_DB_PRE_CONFIG: "postgrest.pre_config"
|
||||
PGRST_DB_TIMEZONE_ENABLED: false
|
||||
PGRST_DB_TX_END: rollback-allow-override
|
||||
PGRST_DB_URI: tmp_db
|
||||
PGRST_DB_USE_LEGACY_GUCS: false
|
||||
|
||||
@@ -18,6 +18,7 @@ db-root-spec = "openapi_v3"
|
||||
db-schemas = "multi, tenant,setup"
|
||||
db-config = false
|
||||
db-pre-config = "postgrest.pre_config"
|
||||
db-timezone-enabled = false
|
||||
db-tx-end = "rollback-allow-override"
|
||||
db-uri = "tmp_db"
|
||||
jwt-aud = "https://postgrest.org"
|
||||
|
||||
@@ -13,6 +13,7 @@ ALTER ROLE db_config_authenticator SET pgrst.db_pre_request = 'test.custom_heade
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_prepared_statements = 'false';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_root_spec = 'root';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_schemas = 'test, tenant1, tenant2';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_timezone_enabled = 'false';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_tx_end = 'commit-allow-override';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.jwt_aud = 'https://example.org';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.jwt_cache_max_entries = '86400';
|
||||
@@ -67,6 +68,7 @@ ALTER ROLE other_authenticator SET pgrst.db_pre_request = 'test.other_custom_hea
|
||||
ALTER ROLE other_authenticator SET pgrst.db_prepared_statements = 'false';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_root_spec = 'other_root';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_schemas = 'test, other_tenant1, other_tenant2';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_timezone_enabled = 'false';
|
||||
ALTER ROLE other_authenticator SET pgrst.jwt_aud = 'https://otherexample.org';
|
||||
ALTER ROLE other_authenticator SET pgrst.jwt_secret = 'ODERREALLYREALLYREALLYREALLYVERYSAFE';
|
||||
ALTER ROLE other_authenticator SET pgrst.jwt_secret_is_base64 = 'false';
|
||||
|
||||
@@ -91,6 +91,7 @@ baseCfg = let secret = encodeUtf8 "reallyreallyreallyreallyverysafe" in
|
||||
, configDbSchemas = fromList ["test"]
|
||||
, configDbConfig = False
|
||||
, configDbPreConfig = Nothing
|
||||
, configDbTimezoneEnabled = True
|
||||
, configDbUri = "postgresql://"
|
||||
, configFilePath = Nothing
|
||||
, configJWKS = rightToMaybe $ parseSecret secret
|
||||
|
||||
@@ -10,9 +10,9 @@ import Test.Hspec.Wai.JSON
|
||||
import Protolude hiding (get)
|
||||
import SpecHelper
|
||||
|
||||
spec :: SpecWith ((), Application)
|
||||
spec =
|
||||
describe "test Prefer: timezone" $ do
|
||||
enabledSpec :: SpecWith ((), Application)
|
||||
enabledSpec =
|
||||
describe "test Prefer: timezone with db-timezone-enabled is true" $ do
|
||||
context "test Prefer: timezone=America/Los_Angeles" $ do
|
||||
it "should change timezone with handling=strict" $
|
||||
request methodGet "/timestamps"
|
||||
@@ -60,3 +60,34 @@ spec =
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = [matchContentTypeJson
|
||||
, "Preference-Applied" <:> "handling=lenient"]}
|
||||
|
||||
|
||||
disabledSpec :: SpecWith ((), Application)
|
||||
disabledSpec =
|
||||
describe "test Prefer: timezone with db-timezone-enabled is false" $ do
|
||||
context "test Prefer: timezone=America/Los_Angeles when timezone is disabled" $ do
|
||||
it "should throw error with handling=strict" $
|
||||
request methodGet "/timestamps"
|
||||
[("Prefer", "handling=strict, timezone=America/Los_Angeles")]
|
||||
""
|
||||
`shouldRespondWith`
|
||||
[json|{"code":"PGRST122","details":"Invalid preferences: timezone=America/Los_Angeles","hint":null,"message":"Invalid preferences given with handling=strict"}|]
|
||||
{ matchStatus = 400 }
|
||||
|
||||
it "should return with default timezone without handling or with handling=lenient" $ do
|
||||
request methodGet "/timestamps"
|
||||
[("Prefer", "timezone=America/Los_Angeles")]
|
||||
""
|
||||
`shouldRespondWith`
|
||||
[json|[{"t":"2023-10-18T12:37:59.611+00:00"}, {"t":"2023-10-18T14:37:59.611+00:00"}, {"t":"2023-10-18T16:37:59.611+00:00"}]|]
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = [matchContentTypeJson]}
|
||||
|
||||
request methodGet "/timestamps"
|
||||
[("Prefer", "handling=lenient, timezone=America/Los_Angeles")]
|
||||
""
|
||||
`shouldRespondWith`
|
||||
[json|[{"t":"2023-10-18T12:37:59.611+00:00"}, {"t":"2023-10-18T14:37:59.611+00:00"}, {"t":"2023-10-18T16:37:59.611+00:00"}]|]
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = [matchContentTypeJson
|
||||
, "Preference-Applied" <:> "handling=lenient"]}
|
||||
|
||||
+10
-1
@@ -128,6 +128,7 @@ main = do
|
||||
unicodeApp = appDbs testUnicodeCfg
|
||||
multipleSchemaApp = appDbs testMultipleSchemaCfg
|
||||
ignorePrivOpenApi = appDbs testIgnorePrivOpenApiCfg
|
||||
timezoneDisabled = appDbs testCfgTimezoneDisabled
|
||||
|
||||
|
||||
let analyze :: IO ()
|
||||
@@ -157,7 +158,6 @@ main = do
|
||||
, ("Feature.Query.PlanSpec.disabledSpec" , Feature.Query.PlanSpec.disabledSpec)
|
||||
, ("Feature.Query.Preferences.HandlingSpec" , Feature.Query.Preferences.HandlingSpec.spec)
|
||||
, ("Feature.Query.Preferences.MaxAffectedSpec" , Feature.Query.Preferences.MaxAffectedSpec.spec)
|
||||
, ("Feature.Query.Preferences.TimezoneSpec" , Feature.Query.Preferences.TimezoneSpec.spec)
|
||||
, ("Feature.Query.QuerySpec" , Feature.Query.QuerySpec.spec)
|
||||
, ("Feature.Query.RawOutputTypesSpec" , Feature.Query.RawOutputTypesSpec.spec)
|
||||
, ("Feature.Query.RelatedQueriesSpec" , Feature.Query.RelatedQueriesSpec.spec)
|
||||
@@ -257,6 +257,15 @@ main = do
|
||||
parallel $ before withApp $
|
||||
describe "Feature.Query.AggregateFunctionsDisallowedSpec." Feature.Query.AggregateFunctionsSpec.disallowed
|
||||
|
||||
-- this test runs with db-timezone-enabled = true
|
||||
parallel $ before withApp $
|
||||
describe "Feature.Query.Preferences.TimezoneSpec.enabledSpec" Feature.Query.Preferences.TimezoneSpec.enabledSpec
|
||||
|
||||
-- this test runs with db-timezone-enabled = false
|
||||
parallel $ before timezoneDisabled $
|
||||
describe "Feature.Query.Preferences.TimezoneSpec.disabledSpec" Feature.Query.Preferences.TimezoneSpec.disabledSpec
|
||||
|
||||
|
||||
-- Note: the rollback tests can not run in parallel, because they test persistance and
|
||||
-- this results in race conditions
|
||||
|
||||
|
||||
@@ -132,6 +132,7 @@ baseCfg = let secret = encodeUtf8 "reallyreallyreallyreallyverysafe" in
|
||||
, configDbSchemas = fromList ["test"]
|
||||
, configDbConfig = False
|
||||
, configDbPreConfig = Nothing
|
||||
, configDbTimezoneEnabled = True
|
||||
, configDbUri = "postgresql://"
|
||||
, configFilePath = Nothing
|
||||
, configJWKS = rightToMaybe $ parseSecret secret
|
||||
@@ -254,6 +255,9 @@ testCfgServerTiming = baseCfg { configDbPlanEnabled = True }
|
||||
testCfgAggregatesEnabled :: AppConfig
|
||||
testCfgAggregatesEnabled = baseCfg { configDbAggregates = True }
|
||||
|
||||
testCfgTimezoneDisabled :: AppConfig
|
||||
testCfgTimezoneDisabled = baseCfg { configDbTimezoneEnabled = False }
|
||||
|
||||
analyzeTable :: Text -> IO ()
|
||||
analyzeTable tableName =
|
||||
void $ readProcess "psql" ["-U", "postgres", "--set", "ON_ERROR_STOP=1", "-a", "-c", toS $ "ANALYZE test.\"" <> tableName <> "\""] []
|
||||
|
||||
Reference in New Issue
Block a user