Skip to content

Commit 1c81e60

Browse files
committed
Update the migration to handle the MCPB changes too
Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent b6f12cb commit 1c81e60

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

internal/database/migrations/009_migrate_canonical_package_refs.sql

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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
68
CREATE OR REPLACE FUNCTION convert_oci_package_to_canonical(pkg jsonb)
@@ -64,6 +66,32 @@ BEGIN
6466
END;
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
6896
CREATE OR REPLACE FUNCTION ensure_transport_field(pkg jsonb)
6997
RETURNS 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
140171
DROP FUNCTION IF EXISTS convert_oci_package_to_canonical(jsonb);
172+
DROP FUNCTION IF EXISTS convert_mcpb_package_to_canonical(jsonb);
141173
DROP FUNCTION IF EXISTS ensure_transport_field(jsonb);
142174
DROP FUNCTION IF EXISTS convert_packages_array(jsonb);

0 commit comments

Comments
 (0)