fix(db): preserve distinct named envs in migration

This commit is contained in:
Devin Foley committed 2026-06-20 00:53:52 -07:00
1 parent ee7a3a58a5
commit eea8da12aa
1 file changed
+5 -2
@@ -11,17 +11,20 @@ BEGIN
SELECT
e.id,
CASE
-- Only collapse classes that are globally singleton by design.
-- Named remote environments may legitimately differ across companies
-- even when they share the same display name.
WHEN e.driver = 'local' THEN '__paperclip_builtin_local__'
WHEN e.driver = 'sandbox' AND (e.metadata ->> 'managedByPaperclip')::boolean = true
THEN '__paperclip_managed_sandbox__'
ELSE e.driver || ':' || e.name
ELSE e.id::text
END AS group_key,
row_number() OVER (
PARTITION BY CASE
WHEN e.driver = 'local' THEN '__paperclip_builtin_local__'
WHEN e.driver = 'sandbox' AND (e.metadata ->> 'managedByPaperclip')::boolean = true
THEN '__paperclip_managed_sandbox__'
ELSE e.driver || ':' || e.name
ELSE e.id::text
END
ORDER BY e.created_at ASC, e.id ASC
) AS rn