-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor: merge transaction end configs to a single config #4162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
56b73ef
to
ab14728
Compare
General opinion on the PR: I'm undecided whether that's an overall net-plus and don't see why it's needed, yet. |
See, our From a consistent |
ab14728
to
d6669ae
Compare
I don't see any state in the db-tx fields. There might be a single config option and two fields, but that doesn't mean there is no clear mapping between them. |
d6669ae
to
c50fbda
Compare
c50fbda
to
b7be022
Compare
See in #3101 (comment): data AppConfig = AppConfig
{
...
, configDbTxAllowOverride :: Bool
, configDbTxRollbackAll :: Bool
...
} Here marking these two configs as |
-- RollbackAll AllowOverride | ||
Nothing -> pure $ f (False, False) | ||
Just "commit" -> pure $ f (False, False) | ||
Just "commit-allow-override" -> pure $ f (False, True) | ||
Just "rollback" -> pure $ f (True, False) | ||
Just "rollback-allow-override" -> pure $ f (True, True) | ||
Nothing -> pure TxCommit -- default | ||
Just "commit" -> pure TxCommit | ||
Just "commit-allow-override" -> pure TxCommitAllowOverride | ||
Just "rollback" -> pure TxRollback | ||
Just "rollback-allow-override" -> pure TxRollbackAllowOverride |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, see how this change is much cleaner and less confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, yeah. I always found these booleans a bit confusing.
isTxRollback = case configDbTxEnd of | ||
TxRollback -> True | ||
TxRollbackAllowOverride -> True | ||
TxCommit -> False | ||
TxCommitAllowOverride -> False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this part is not looking like a net gain. Is there any other way to do it?
isTxOverrideAllowed = case configDbTxEnd conf of | ||
TxCommitAllowOverride -> True | ||
TxRollbackAllowOverride -> True | ||
TxCommit -> False | ||
TxRollback -> False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part also overall seems more verbose. Maybe at define it next to the types? Perhaps both these boolean results can be shortened somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shortening is already there - in the code that is removed!
I get the point that having two fields for a single config is inconsistent with all of the other ones but I still don't see the need for GADTs. I'd suggest to keep it the simplest way possible for now. I think we would just need a type like: data PgrstConfig= {
pcFileName :: Text
, pcEnvName :: Text
, pcInDbName :: Maybe Text
, pcDescription :: Text
...
}
Besides that I think there is a benefit for typing these values instead of being Bools: data DbTxEnd
= TxCommit
| TxCommitAllowOverride
| TxRollback
| TxRollbackAllowOverride
deriving (Eq) That being we can deduplicate these descriptions later on: postgrest/src/PostgREST/CLI.hs Lines 182 to 189 in c1eb8af
postgrest/docs/references/configuration.rst Lines 533 to 543 in c1eb8af
Right now they're not consistent and unnecessarily separate. I think there's a future where we could generate the config docs automatically from our Config module. @wolfgangwalther WDYT? |
I think it's impossible to judge a small refactor PR like this without knowing the bigger picture where we want to get to. There are multiple different ideas on how to evolve the config module, but they need to be prototyped to see whether they actually work, where the limitations are etc. It makes zero sense to start refactoring stuff before that. |
Assuming we want to deduplicate the descriptions as I mentioned above (which to me looks like an obvious benefit), how can we do it gradually? Feeding the descriptiosn to the CLI seems possible now with interpolation. For docs, I'm thinking we would need a new CLI option like postgrest/docs/references/configuration.rst Lines 149 to 938 in c1eb8af
It needs to be in one go since we need to ensure the alphabetical order of the configs. Once that's done we could concatenate configuration.rst with this dump, maybe once Now to do that in one big PR might be too complicated and hard. Would a partial |
I'm not saying we need to introduce it all in one commit, far from it. But before we have something that we know we want to work towards, we can't judge whether our steps are in the right direction. We need a prototype of how the solution should look like. And then we can commit steps towards it. |
Agreed. Without a clear design, it is hard to know what might or might not work out. |
This slightly cleans up config module. End goal is closing #3101.
Notes
One thing I noticed with config module is that the fields in
AppConfig
don't one-to-one map to end-user configs. This interferes with SSoT principle.