Skip to content
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

Make fn Migrations::max_schema_version public. #171

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

fluffysquirrels
Copy link

@fluffysquirrels fluffysquirrels commented Jul 5, 2024

Addresses #170

fn Migrations::max_schema_version(&self) is a currently private method that returns the number of available migrations wrapped in SchemaVersion.

I would like access to this value in my own code. I'm using Migrations::from_directory() and include_dir! to construct my Migrations, so getting the count myself is non-trivial AFAICT.

My use case is to work out whether any migrations will be run by fn Migrations::to_latest() before running it, and if so to take a backup first.

The library code change is effectively 1 line (1 more to disable a clippy lint on the now-public method, 1 more to improve documentation IMO). Since this adds a new method to the public API I put 2 asserts into an existing test to avoid regressions.

@coveralls
Copy link

Coverage Status

coverage: 95.224%. remained the same
when pulling 21dd0d4 on fluffysquirrels:pub-max_schema_version
into ce9ea7a on cljoly:master.

@coveralls
Copy link

Coverage Status

coverage: 95.224%. remained the same
when pulling cf1bb17 on fluffysquirrels:pub-max_schema_version
into ce9ea7a on cljoly:master.

@coveralls
Copy link

Coverage Status

coverage: 95.224%. remained the same
when pulling 9421e03 on fluffysquirrels:pub-max_schema_version
into ce9ea7a on cljoly:master.

@cljoly
Copy link
Owner

cljoly commented Jul 7, 2024

@fluffysquirrels thanks for your PR, I've suggested a few improvements. The most important one is adding the same change to the async part of the crate (unfortunately, these things have to be manually synced).

Please feel free to challenge those suggestions.

@coveralls
Copy link

Coverage Status

coverage: 94.97% (-0.3%) from 95.224%
when pulling 2edbc02 on fluffysquirrels:pub-max_schema_version
into ce9ea7a on cljoly:master.

@cljoly
Copy link
Owner

cljoly commented Jul 7, 2024

Overall, lgtm, but let's hold merging a little bit: I've posted a comment to further discuss alternative approaches

@fluffysquirrels
Copy link
Author

Overall, lgtm, but let's hold merging a little bit: I've posted a comment to further discuss alternative approaches

Cool. Your changes look good.

I will probably update the PR with a few suggestions from issue #170 so we can see how it looks.

@fluffysquirrels
Copy link
Author

fluffysquirrels commented Jul 9, 2024

I will probably update the PR with a few suggestions from issue #170 so we can see how it looks.

Just pushed a new version with this.

I also wrapped AsyncMigrations.migrations in an Arc to reduce the cloning work done when running an async method. It was unrelated but a small change and seemed like a quick win.

@coveralls
Copy link

coveralls commented Jul 9, 2024

Coverage Status

coverage: 95.029% (+1.0%) from 94.03%
when pulling 99b1764 on fluffysquirrels:pub-max_schema_version
into 313e532 on cljoly:master.

///
/// For most common scenarios, you should be able to just call
/// [`Migrations::to_latest`], which already checks the schema version.
///
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do decide to add this method, might be worth adding a code example with the if.

Maybe also worth having a full example of an actual backup process to make sure that there is nothing awkward with the lifetimes.

warn!("no migration defined");
Err(Error::MigrationDefinition(
MigrationDefinitionError::NoMigrationsDefined,
))
}
SchemaVersion::Inside(v) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep the SchemaVersion type here. It's not just any integer, it's a schema version and those are off by one, effectively, from the index in the migrations vector.

warn!("no migrations defined");
Err(Error::MigrationDefinition(
MigrationDefinitionError::NoMigrationsDefined,
))
}
SchemaVersion::Inside(v) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let’s keep SchemaVersion.

@cljoly cljoly added this to the Version 1.3.0 milestone Jul 22, 2024
@cljoly cljoly added the enhancement New feature or request label Jul 22, 2024
@cljoly
Copy link
Owner

cljoly commented Jul 28, 2024

@fluffysquirrels I’ve incorporated the Arc change separately to master and fixed some clippy warnings that came up with the latest rust version. Feel free to squash your commits together when you rebase.

Alex Helfet and others added 7 commits September 23, 2024 08:11
We have to keep the APIs exposed by the two structs as in sync as
possible.
Here, we are telling the compiler that we have already performed a check
even though it can’t seem to detect it (for instance, clippy emits a
warning because of the expect).
@cljoly cljoly force-pushed the pub-max_schema_version branch from ae25dbd to 61f95de Compare September 23, 2024 07:15
@cljoly
Copy link
Owner

cljoly commented Sep 23, 2024

Rebased on master

@cljoly cljoly modified the milestones: Version 1.3.0, Version 1.4.0 Oct 1, 2024
@cljoly
Copy link
Owner

cljoly commented Oct 1, 2024

As this is not quite ready yet, I’ve pushed it back to the next stable version 1.4.0 (which could be published as soon as this is ready, potentially).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants