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