11-- Migrate package references to canonical format
2- -- This migration converts OCI packages to use canonical single-line references
3- -- and ensures all packages have required transport field
2+ -- This migration:
3+ -- - Converts OCI packages to use canonical single-line references (registry/namespace/image:tag)
4+ -- - Removes redundant version and registryBaseUrl fields from MCPB packages
5+ -- - Ensures all packages have required transport field
46
57-- Helper function to convert OCI package to canonical reference format
68CREATE OR REPLACE FUNCTION convert_oci_package_to_canonical (pkg jsonb)
6466END;
6567$$;
6668
69+ -- Helper function to convert MCPB package to canonical reference format
70+ CREATE OR REPLACE FUNCTION convert_mcpb_package_to_canonical (pkg jsonb)
71+ RETURNS jsonb
72+ LANGUAGE plpgsql
73+ AS $$
74+ DECLARE
75+ result jsonb;
76+ BEGIN
77+ -- Start with the original package
78+ result := pkg;
79+
80+ -- Only process MCPB packages
81+ IF pkg- >> ' registryType' != ' mcpb' THEN
82+ RETURN result;
83+ END IF;
84+
85+ -- Remove version field if it exists (version is embedded in the download URL)
86+ result := result - ' version' ;
87+
88+ -- Remove registryBaseUrl field if it exists (not needed for MCPB)
89+ result := result - ' registryBaseUrl' ;
90+
91+ RETURN result;
92+ END;
93+ $$;
94+
6795-- Helper function to ensure transport field exists
6896CREATE OR REPLACE FUNCTION ensure_transport_field (pkg jsonb)
6997RETURNS jsonb
@@ -113,7 +141,10 @@ BEGIN
113141 -- First convert OCI packages to canonical format
114142 pkg := convert_oci_package_to_canonical(pkg);
115143
116- -- Then ensure transport field exists
144+ -- Then convert MCPB packages to canonical format
145+ pkg := convert_mcpb_package_to_canonical(pkg);
146+
147+ -- Finally ensure transport field exists
117148 pkg := ensure_transport_field(pkg);
118149
119150 -- Add to result array
@@ -138,5 +169,6 @@ WHERE value ? 'packages'
138169
139170-- Clean up helper functions
140171DROP FUNCTION IF EXISTS convert_oci_package_to_canonical(jsonb);
172+ DROP FUNCTION IF EXISTS convert_mcpb_package_to_canonical(jsonb);
141173DROP FUNCTION IF EXISTS ensure_transport_field(jsonb);
142174DROP FUNCTION IF EXISTS convert_packages_array(jsonb);
0 commit comments