Skip to content

Return more information from Migrator::run #4059

@SorteKanin

Description

@SorteKanin

I have found these related issues/pull requests

I have not found any similar feature request.

Description

Right now Migrator::run returns (), meaning the only thing you know after running migrations is that it didn't fail.

In particular, the method provides no information about:

  1. If any migrations actually ran at all.
  2. How many migrations ran.
  3. Which migrations ran.

This information could be useful for diagnostics and observability.

Prefered solution

A simple solution that gives at least a bit more information: Make Migrator::run return usize instead of (), where the return value is the number of migrations run. This doesn't cover use case number 3 above though.

A better solution which is probably also more future-proof would be returning some form of collection, probably of Migration? I.e. basically a Vec<Migration> containing all the migrations that was run (in the order they were run). Maybe it would even be possible to just return a subslice of those that were run, i.e. return &[Migration]?

Is this a breaking change? Why or why not?

It could be, if Migrator::run changes. A non-breaking way to do this would be to implement a new function, called maybe something like run_info which implements this, and then simply implement run in terms of run_info, but discard the return value, which would preserve the current behavior while allowing opting in to the new behavior..

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions