pgxn / pgxn-manager

Interface for managing extensions on PGXN
http://pgxn.org
47 stars 18 forks source link

check_prev_versions() and check_later_versions() Should Show Conflicting Extension Distribution #54

Closed theory closed 3 years ago

theory commented 7 years ago

Typical output for a conflicting distribution is:

One or more extension versions are greater than later versions:
  * “quantile 1.2.0” > “quantile 1.1.0”

What that doesn't show is what distribution the conflicting extension is in, which can be very useful. So add that data with a patch like this:

--- a/sql/14-dist_processing.sql
+++ b/sql/14-dist_processing.sql
@@ -28,18 +28,31 @@ DECLARE
 BEGIN
     IF as_of IS NULL THEN
         versions := ARRAY(
-            SELECT format('“%s %s” < “%s %s”', de.extension, provided[i][2], de.extension, MAX(de.ext_version))
+            SELECT format(
+                '“%s %s” > “%s %s” in %s %s',
+                de.extension, provided[i][2],
+                de.extension, MAX(de.ext_version),
+                d.name, d.version
+            )
               FROM distribution_extensions de
               JOIN generate_subscripts(provided, 1) i
                 ON provided[i][1] = de.extension
                AND provided[i][2]::semver < de.ext_version
-             GROUP BY de.extension, provided[i][2]
+              JOIN distributions d
+                ON de.distribution = d.name
+               AND de.dist_version = d.version
+             GROUP BY de.extension, provided[i][2], d.name, d.version
              ORDER BY de.extension
         );
     ELSE
         -- Make sure extension versions are >= than in previous releases
         versions := ARRAY(
-            SELECT format('“%s %s” < “%s %s”', de.extension, provided[i][2], de.extension, MAX(de.ext_version))
+            SELECT format(
+                '“%s %s” < “%s %s” in %s %s',
+                de.extension, provided[i][2],
+                de.extension, MAX(de.ext_version),
+                d.name, d.version
+            )
               FROM distribution_extensions de
               JOIN generate_subscripts(provided, 1) i
                 ON provided[i][1] = de.extension
@@ -48,7 +61,7 @@ BEGIN
                 ON de.distribution = d.name
                AND de.dist_version = d.version
                AND d.created_at < as_of
-             GROUP BY de.extension, provided[i][2]
+             GROUP BY de.extension, provided[i][2], d.name, d.version
              ORDER BY de.extension
         );
     END IF;
@@ -62,7 +75,6 @@ $$;

 -- Disallow end-user from using this function.
 REVOKE ALL ON FUNCTION check_prev_versions(TEXT[][], TIMESTAMPTZ) FROM PUBLIC;
-
 CREATE OR REPLACE FUNCTION check_later_versions(
     provided TEXT[][],
     as_of    TIMESTAMPTZ
@@ -70,9 +82,14 @@ CREATE OR REPLACE FUNCTION check_later_versions(
 DECLARE
     versions TEXT[];
 BEGIN
-    -- Make sure extension versions are >= than in later releases
+    -- Make sure extension versions are <= than in later releases
     versions := ARRAY(
-        SELECT format('“%s %s” > “%s %s”', de.extension, provided[i][2], de.extension, MIN(de.ext_version))
+        SELECT format(
+            '“%s %s” > “%s %s” in %s %s',
+            de.extension, provided[i][2],
+            de.extension, MIN(de.ext_version),
+            d.name, d.version
+        )
           FROM distribution_extensions de
           JOIN generate_subscripts(provided, 1) i
             ON provided[i][1] = de.extension
@@ -81,7 +98,7 @@ BEGIN
             ON de.distribution = d.name
            AND de.dist_version = d.version
            AND d.created_at > as_of
-         GROUP BY de.extension, provided[i][2]
+         GROUP BY de.extension, provided[i][2], d.name, d.version
          ORDER BY de.extension
     );
     IF array_length(versions, 1) > 0 THEN