Skip to content

Commit b6a47f7

Browse files
committed
Update the migration to remove fileSha256 properties
Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent 1c81e60 commit b6a47f7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

internal/database/migrations/009_migrate_canonical_package_refs.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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
@@ -92,6 +93,27 @@ BEGIN
9293
END;
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
96118
CREATE OR REPLACE FUNCTION ensure_transport_field(pkg jsonb)
97119
RETURNS 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
171196
DROP FUNCTION IF EXISTS convert_oci_package_to_canonical(jsonb);
172197
DROP FUNCTION IF EXISTS convert_mcpb_package_to_canonical(jsonb);
198+
DROP FUNCTION IF EXISTS remove_forbidden_fields(jsonb);
173199
DROP FUNCTION IF EXISTS ensure_transport_field(jsonb);
174200
DROP FUNCTION IF EXISTS convert_packages_array(jsonb);

0 commit comments

Comments
 (0)