22-- This migration:
33-- - Converts OCI packages to use canonical single-line references (registry/namespace/image:tag)
44-- - Removes redundant version and registryBaseUrl fields from MCPB packages
5+ -- - Removes package-type-specific forbidden fields (e.g., fileSha256 from non-MCPB packages)
56-- - Ensures all packages have required transport field
67
78-- Helper function to convert OCI package to canonical reference format
9293END;
9394$$;
9495
96+ -- Helper function to remove package-type-specific forbidden fields
97+ CREATE OR REPLACE FUNCTION remove_forbidden_fields (pkg jsonb)
98+ RETURNS jsonb
99+ LANGUAGE plpgsql
100+ AS $$
101+ DECLARE
102+ result jsonb;
103+ registry_type text ;
104+ BEGIN
105+ result := pkg;
106+ registry_type := pkg- >> ' registryType' ;
107+
108+ -- Remove fileSha256 from non-MCPB packages (it's MCPB-only)
109+ IF registry_type != ' mcpb' AND result ? ' fileSha256' THEN
110+ result := result - ' fileSha256' ;
111+ END IF;
112+
113+ RETURN result;
114+ END;
115+ $$;
116+
95117-- Helper function to ensure transport field exists
96118CREATE OR REPLACE FUNCTION ensure_transport_field (pkg jsonb)
97119RETURNS jsonb
@@ -144,6 +166,9 @@ BEGIN
144166 -- Then convert MCPB packages to canonical format
145167 pkg := convert_mcpb_package_to_canonical(pkg);
146168
169+ -- Remove package-type-specific forbidden fields
170+ pkg := remove_forbidden_fields(pkg);
171+
147172 -- Finally ensure transport field exists
148173 pkg := ensure_transport_field(pkg);
149174
@@ -170,5 +195,6 @@ WHERE value ? 'packages'
170195-- Clean up helper functions
171196DROP FUNCTION IF EXISTS convert_oci_package_to_canonical(jsonb);
172197DROP FUNCTION IF EXISTS convert_mcpb_package_to_canonical(jsonb);
198+ DROP FUNCTION IF EXISTS remove_forbidden_fields(jsonb);
173199DROP FUNCTION IF EXISTS ensure_transport_field(jsonb);
174200DROP FUNCTION IF EXISTS convert_packages_array(jsonb);
0 commit comments