From 35d5f887ce7c88933d7e4c2f0acd2aeedd18c214 Mon Sep 17 00:00:00 2001 From: "Alessandro (Ale) Segala" <43508+ItalyPaleAle@users.noreply.github.com> Date: Mon, 21 Jul 2025 07:36:22 +0200 Subject: [PATCH] fix: migration fails on postgres (#762) --- .../postgres/20250705000000_normalize.up.sql | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/backend/resources/migrations/postgres/20250705000000_normalize.up.sql b/backend/resources/migrations/postgres/20250705000000_normalize.up.sql index 27c5700f..068f066b 100644 --- a/backend/resources/migrations/postgres/20250705000000_normalize.up.sql +++ b/backend/resources/migrations/postgres/20250705000000_normalize.up.sql @@ -1,25 +1,34 @@ -- Normalize (form NFC) all existing values in the database -UPDATE api_keys SET - name = normalize(name, 'nfc'), - description = normalize(description, 'nfc'); +DO $$ +BEGIN + -- This function is available only if the server's encoding is UTF8 + IF current_setting('server_encoding') = 'UTF8' THEN + UPDATE api_keys SET + name = normalize(name, NFC), + description = normalize(description, NFC); -UPDATE app_config_variables SET - "value" = normalize("value", 'nfc') -WHERE "key" = 'appName'; + UPDATE app_config_variables SET + "value" = normalize("value", NFC) + WHERE "key" = 'appName'; -UPDATE custom_claims SET - "key" = normalize("key", 'nfc'), - "value" = normalize("value", 'nfc'); + UPDATE custom_claims SET + "key" = normalize("key", NFC), + "value" = normalize("value", NFC); -UPDATE oidc_clients SET - name = normalize(name, 'nfc'); + UPDATE oidc_clients SET + name = normalize(name, NFC); -UPDATE users SET - username = normalize(username, 'nfc'), - email = normalize(email, 'nfc'), - first_name = normalize(first_name, 'nfc'), - last_name = normalize(last_name, 'nfc'); + UPDATE users SET + username = normalize(username, NFC), + email = normalize(email, NFC), + first_name = normalize(first_name, NFC), + last_name = normalize(last_name, NFC); -UPDATE user_groups SET - friendly_name = normalize(friendly_name, 'nfc'), - "name" = normalize("name", 'nfc'); + UPDATE user_groups SET + friendly_name = normalize(friendly_name, NFC), + "name" = normalize("name", NFC); + ELSE + RAISE NOTICE 'Skipping normalization: server_encoding is %', current_setting('server_encoding'); + END IF; +END; +$$ LANGUAGE plpgsql; \ No newline at end of file