Skip to content

Support u64 version parts in SQL function semver_no_prerelease #1846

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

Merged
merged 2 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DROP FUNCTION to_semver_no_prerelease(text);
DROP TYPE semver_triple;

-- Restores the type and function to what they were created as in
-- migrations/20170308140537_create_to_semver_no_prerelease/up.sql

CREATE TYPE semver_triple AS (
major int4,
minor int4,
teeny int4
);

CREATE FUNCTION to_semver_no_prerelease(text) RETURNS semver_triple IMMUTABLE AS $$
SELECT (
split_part($1, '.', 1)::int4,
split_part($1, '.', 2)::int4,
split_part(split_part($1, '+', 1), '.', 3)::int4
)::semver_triple
WHERE strpos($1, '-') = 0
$$ LANGUAGE SQL
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
DROP FUNCTION to_semver_no_prerelease(text);
DROP TYPE semver_triple;

CREATE TYPE semver_triple AS (
major numeric,
minor numeric,
teeny numeric
);

CREATE FUNCTION to_semver_no_prerelease(text) RETURNS semver_triple IMMUTABLE AS $$
SELECT (
split_part($1, '.', 1)::numeric,
split_part($1, '.', 2)::numeric,
split_part(split_part($1, '+', 1), '.', 3)::numeric
)::semver_triple
WHERE strpos($1, '-') = 0
$$ LANGUAGE SQL
;
25 changes: 25 additions & 0 deletions src/tests/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,31 @@ fn reverse_dependencies_includes_published_by_user_when_present() {
);
}

#[test]
fn reverse_dependencies_query_supports_u64_version_number_parts() {
let (app, anon, user) = TestApp::init().with_user();
let user = user.as_model();

let large_but_valid_version_number = format!("1.0.{}", std::u64::MAX);

app.db(|conn| {
let c1 = CrateBuilder::new("c1", user.id).expect_build(conn);
// The crate that depends on c1...
CrateBuilder::new("c2", user.id)
// ...has a patch version at the limits of what the semver crate supports
.version(VersionBuilder::new(&large_but_valid_version_number).dependency(&c1, None))
.expect_build(conn);
});

let deps = anon.reverse_dependencies("c1");
assert_eq!(deps.dependencies.len(), 1);
assert_eq!(deps.meta.total, 1);
assert_eq!(deps.dependencies[0].crate_id, "c1");
assert_eq!(deps.versions.len(), 1);
assert_eq!(deps.versions[0].krate, "c2");
assert_eq!(deps.versions[0].num, large_but_valid_version_number);
}

#[test]
fn author_license_and_description_required() {
let (_, _, _, token) = TestApp::init().with_token();
Expand Down