From b2d59d9c9e71ebfefdee3a367366d090da598067 Mon Sep 17 00:00:00 2001 From: Witold Brzozowski Date: Mon, 19 Feb 2024 14:07:59 +0100 Subject: [PATCH] Fix account name migration (#239) --- .../resources/scripts/V3_3_0_1__add_user_account_name.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/resources/scripts/V3_3_0_1__add_user_account_name.sql b/src/main/resources/scripts/V3_3_0_1__add_user_account_name.sql index 8d5881fc..0ae164ec 100644 --- a/src/main/resources/scripts/V3_3_0_1__add_user_account_name.sql +++ b/src/main/resources/scripts/V3_3_0_1__add_user_account_name.sql @@ -1 +1,7 @@ -ALTER TABLE users ADD COLUMN account_name VARCHAR(63) NOT NULL UNIQUE; \ No newline at end of file +ALTER TABLE users ADD COLUMN account_name VARCHAR(63); + +UPDATE users SET account_name = SUBSTRING(mail FROM 1 FOR POSITION('@' IN mail) - 1); + +ALTER TABLE users ALTER COLUMN account_name SET NOT NULL; + +CREATE UNIQUE INDEX users_account_name_index ON users (account_name); \ No newline at end of file