From fb17f4c095d9d61cab55b89621abc1b558103556 Mon Sep 17 00:00:00 2001 From: Adaline Simonian Date: Tue, 14 Jan 2025 22:21:01 -0800 Subject: [PATCH] fix: rename 'no' roles to 'nb' --- migrations/085-rename-bokmaal-locale.sql | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/migrations/085-rename-bokmaal-locale.sql b/migrations/085-rename-bokmaal-locale.sql index 8c03629a0..4348d473f 100644 --- a/migrations/085-rename-bokmaal-locale.sql +++ b/migrations/085-rename-bokmaal-locale.sql @@ -57,6 +57,25 @@ UPDATE translations SET locale = 'nb' WHERE locale = 'no'; +-- The users.roles column is a pipe-separated string of items like: +-- - +-- e.g. "nl-some-route|nn-*|en-*" +-- +-- We want to rename "no-" to "nb-", but *only* if it is at the start of +-- the role token (immediately after "|" or at the start of the string). +-- We do NOT rename "en-no-something". + +-- a) Replace occurrences after a pipe: "|no-" => "|nb-" +UPDATE users +SET roles = REPLACE(roles, '|no-', '|nb-') +WHERE roles LIKE '%|no-%'; + +-- b) If the string *starts* with "no-", rename it to "nb-" +-- (We add a check for roles starting with 'no-') +UPDATE users +SET roles = 'nb-' || SUBSTR(roles, 4) -- remove "no-" and prepend "nb-" +WHERE roles LIKE 'no-%'; + -- Down UPDATE blog_reactions @@ -110,3 +129,13 @@ WHERE locale = 'nb'; UPDATE translations SET locale = 'no' WHERE locale = 'nb'; + +-- Same as above, but for nb -> no + +UPDATE users +SET roles = REPLACE(roles, '|nb-', '|no-') +WHERE roles LIKE '%|nb-%'; + +UPDATE users +SET roles = 'no-' || SUBSTR(roles, 4) +WHERE roles LIKE 'nb-%';