Skip to content

Commit

Permalink
Allow updates to old versions.
Browse files Browse the repository at this point in the history
Not reindexing, but new releases of previous major or minor versions. Useful
for maintaining previous versions of an extension.
  • Loading branch information
theory committed May 4, 2021
1 parent e79af5c commit d2bd3bf
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Changes
Expand Up @@ -11,6 +11,13 @@ Revision history for Perl extension PGXN::Manager
- Updated all URLs with HTTPS variants to use HTTPS.
- Regenerated the HOWTO HTML using MultiMarkdown, so as to get heading
IDs for direct linking and with a language class for the code examples.
- Distribution versions are now allowed to be less than than previous
release versions if they update existing major or minor versions. So if
you have versions 2.0.0, 2.2.1, and 2.4.2, you can release 2.0.1,
2.2.2, 2.4.3, 2.5.0, or 3.0.0, but not 2.0.0-r1, 2.2.0, or 2.3.0. This
should allow for the release of updates to older versions without
otherwise creating new major or minor versions that were not previously
released. Thanks to Geoff Montee for the report! (#52).

0.16.0 2015-08-31T18:25:24Z
- Updated the `Makefile` example in the HOWTO to extract the extension
Expand Down
33 changes: 28 additions & 5 deletions sql/14-dist_processing.sql
Expand Up @@ -3,16 +3,39 @@ CREATE OR REPLACE FUNCTION check_dist_version (
version SEMVER
) RETURNS VOID LANGUAGE plpgsql STABLE SECURITY DEFINER AS $$
DECLARE
prev_version SEMVER;
max_version SEMVER;
min_version SEMVER;
maj_version SEMVER;
BEGIN
-- Make sure the version is greater than previous release versions.
SELECT MAX(d.version) INTO prev_version
-- Allow lower version if higher than existing minor version or higher than existing major version.
SELECT MAX(d.version),
MAX(d.version) FILTER (WHERE get_semver_major(d.version) = get_semver_major(check_dist_version.version) AND get_semver_minor(d.version) = get_semver_minor(check_dist_version.version)),
MAX(d.version) FILTER (WHERE get_semver_major(d.version) = get_semver_major(check_dist_version.version))
INTO max_version, min_version, maj_version
FROM distributions d
WHERE d.name = dist;
IF version < prev_version THEN
RAISE EXCEPTION 'Distribution “% %” version less than in previous release “% %”',
dist, version, dist, prev_version;

-- Allow if no previous, or version is higher than any x.y.z version.
IF max_version IS NULL OR version > max_version THEN RETURN; END IF;

-- Allow if higher than existing instance of same x.y version.
IF min_version IS NOT NULL THEN
IF version > min_version THEN RETURN; END IF;
RAISE EXCEPTION 'Distribution “% %” version not greater than previous minor release “% %”',
dist, version, dist, min_version;
END IF;

-- Allow if higher than existing instance of same x version.
IF maj_version IS NOT NULL THEN
IF version > maj_version THEN RETURN; END IF;
RAISE EXCEPTION 'Distribution “% %” version not greater than previous major release “% %”',
dist, version, dist, maj_version;
END IF;

-- No previous major or minor found and not higher than anything else, so bail.
RAISE EXCEPTION 'Distribution “% %” version not greater than previous release “% %”',
dist, version, dist, max_version;
END;
$$;

Expand Down
47 changes: 38 additions & 9 deletions t/version_checks.pg
@@ -1,5 +1,5 @@
BEGIN;
SELECT plan(71);
SELECT plan(82);
--SELECT * FROM no_plan();

-- Check that we have the functions we think we have.
Expand Down Expand Up @@ -58,31 +58,60 @@ SELECT lives_ok(
SELECT throws_ok(
$$ SELECT check_dist_version('widgets', '1.0.0-r1') $$,
'P0001',
'Distribution “widgets 1.0.0-r1” version less than in previous release “widgets 1.0.0”',
'Distribution “widgets 1.0.0-r1” version not greater than previous minor release “widgets 1.0.0”',
'Should get error from check_dist_version() for lower version'
);

-- Insert a few more versions.
SELECT lives_ok($$
INSERT INTO distributions (name, version, creator, sha1, meta, created_at)
VALUES ('widgets', '1.1.0', 'theory', 'ick', '', NOW() - '3 days'::interval)
VALUES ('widgets', '0.2.0', 'theory', 'ick', '', NOW() - '4 days'::interval)
, ('widgets', '1.1.0', 'theory', 'ick', '', NOW() - '3 days'::interval)
, ('widgets', '1.2.0-beta', 'theory', 'yeesh', '', NOW() - '2 days'::interval)
, ('widgets', '1.3.0', 'theory', 'sick', '', NOW() - '1 day'::interval)
, ('widgets', '1.3.2', 'theory', 'sick', '', NOW() - '16 hour'::interval)
$$, 'Create more widgets releases');

-- Should die on all lower version.
SELECT diag(version) FROM distributions WHERE name = 'widgets' ORDER BY version;

-- Should die on all existing versions lower than existing max versions.
SELECT throws_ok(
$$ SELECT check_dist_version('widgets', '$$ || version || $$')$$,
'P0001',
'Distribution “widgets ' || version || '” version not greater than previous minor release “widgets ' || version || '”',
'Should get error from check_dist_version() for version ' || version
) FROM unnest(ARRAY['1.0.0', '1.1.0', '1.2.0-beta', '1.3.2']) AS f(version);

-- Should die on all versions <= than existing version
SELECT throws_ok(
$$ SELECT check_dist_version('widgets', '$$ || version || $$')$$,
'P0001',
'Distribution “widgets ' || version || '” version not greater than previous major release “widgets ' || existing || '”',
'Should get error from check_dist_version() for version ' || version
) FROM (VALUES
('0.1.0', '0.2.0'),
('0.1.1', '0.2.0')
) f(version, existing);

-- Should fail on lower versions of existing minor versions and major versions
SELECT throws_ok(
$$ SELECT check_dist_version('widgets', '$$ || version || $$')$$,
'P0001',
'Distribution “widgets ' || version || '” version less than in previous release “widgets 1.3.0”',
'Distribution “widgets ' || version || '” version not greater than previous minor release “widgets ' || existing || '”',
'Should get error from check_dist_version() for version ' || version
) FROM unnest(ARRAY['0.1.0', '1.0.0', '1.2.0', '1.3.0-r1']) AS f(version);
) FROM (VALUES
('1.2.0-alpha', '1.2.0-beta'),
('1.3.1', '1.3.2'),
('1.1.0-x', '1.1.0'),
('1.3.0-r1', '1.3.2'),
('1.3.2', '1.3.2')
) f(version, existing);

-- But higher versions should be fine.
SELECT lives_ok(
$$ SELECT check_dist_version('widgets', '$$ || version || $$')$$,
'Should get no error from check_dist_version() for version ' || version
) FROM unnest(ARRAY['1.3.1', '1.4.0', '2.10.20']) AS f(version);
) FROM unnest(ARRAY['1.3.3', '1.4.0', '2.10.20', '1.0.1', '1.1.2', '0.2.1', '0.3.0']) AS f(version);

-- Add a different distribution.
SELECT lives_ok($$
Expand All @@ -94,13 +123,13 @@ $$, 'Create pair 4.0.0');
SELECT lives_ok(
$$ SELECT check_dist_version('widgets', '$$ || version || $$')$$,
'Still should get no error from check_dist_version() for version ' || version
) FROM unnest(ARRAY['1.3.1', '1.4.0', '2.10.20', '5.5.5']) AS f(version);
) FROM unnest(ARRAY['1.3.3', '1.4.0', '2.10.20', '5.5.5']) AS f(version);

-- But now "pair" lower versions should die.
SELECT throws_ok(
$$ SELECT check_dist_version('pair', '$$ || version || $$')$$,
'P0001',
'Distribution “pair ' || version || '” version less than in previous release “pair 4.0.0”',
'Distribution “pair ' || version || '” version not greater than previous release “pair 4.0.0”',
'Should get error from check_dist_version() for pair version ' || version
) FROM unnest(ARRAY['0.1.0', '1.0.0', '1.2.0', '3.9.0']) AS f(version);

Expand Down

0 comments on commit d2bd3bf

Please sign in to comment.