-
Notifications
You must be signed in to change notification settings - Fork 48
Implement abstract interface for log writes #35
Conversation
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.
Opinions from a user of the library:
There seems to be quite a bit of destructive and unrelated changes.
- Modified the command line handling
- Modified the output channel from stdout to stderr (if I interpreted the changes correctly)
- Added new dependencies, some of which might be an overkill
- Made destructive changes to the signatures of existing functions.
How I envision implementing this issue so that it's as clean as possible:
Create new functions
runMigrationA :: (String -> IO ()) -> MIgrationContext -> IO (MigrationResult String)
runMigrationA logger context =
-- Copy the implementation of the original 'runMigration' here, replacing the calls to putStrLn with the logger callback
runMigration :: MigrationContext -> IO (MigrationResult String)
runMigration = runMigrationA putStrLn
This way you would expose the more powerful version, but leave the interface and behavior of the original runMigration
as is, accomodating the maintainers wish for signature changes. Also no changes to cabal packages, no changes to cli handling, no changes to stdout/stderr. If one wants to add MonadIO
, MonadUnliftIO
support, they could be added in a separate MR.
That means no destructive signature changes to existing public functions or data-types - only extensions.
@@ -71,20 +73,23 @@ import System.Directory (getDirectoryContents) | |||
-- a 'MigrationError' is returned. | |||
-- | |||
-- It is recommended to wrap 'runMigration' inside a database transaction. | |||
runMigration :: MigrationContext -> IO (MigrationResult String) | |||
runMigration (MigrationContext cmd verbose con) = case cmd of | |||
runMigration |
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.
You have modified the signature of an existing function which is against the maintainers wishes:
That means no destructive signature changes to existing public functions or data-types - only extensions.
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.
Yes, and this is mentioned in the description. It’s not really that destructive. All the existing code is still compatible, except just in case you annotated MigrationContext
type explicitly.
I’d like to hear what do you mean specifically by a “destructive change”?
Since I was giving
Partially correct. Not for everything. I changed output specifically for those messages which are representing errors.
Original wish from #34 was:
In order to solve this I had to use
Yes, this mentioned in the description of this MR. If you didn’t explicitly annotate
This signature is insufficient in my strong opinion. It doesn’t give you any information whether it is an error or just an info message. I would define it as
This would not work since the code intersects all over the place. I’d implement
I absolutely don’t see in what way this is “more powerful”. Could you be more specific? As I said before I’m closing this MR in favor of making a new one. I’ll reduce the amount of changes to:
|
Closes #34
What it brings to the table:
MonadIO
instead of monomorphicIO
migrationContextVerbose
which, as before, can be just aBool
but also any custom typeMigrationVerbosity
that provides an abstract interface for log writesMigrationVerbosity
forBool
stderr
instead ofstdout
--help
and--quiet
for their shorthands-h
and-q
MigrationContext
type (because new type variable has been added)Generally it gives you an ability to redirect log messages somewhere else instead of just writing them directly to
stdout
.