diff --git a/backend/migrations/032_update_superadmin_lol.sql b/backend/migrations/032_update_superadmin_lol.sql index d08cdf9..df6f2ae 100644 --- a/backend/migrations/032_update_superadmin_lol.sql +++ b/backend/migrations/032_update_superadmin_lol.sql @@ -3,18 +3,20 @@ -- Increase status column length to support 'force_change_password' (21 chars) ALTER TABLE users ALTER COLUMN status TYPE VARCHAR(50); --- Update only the intended superadmin identifier to avoid unique constraint conflicts. -UPDATE users -SET - identifier = 'lol', - email = 'lol@gohorsejobs.com', - full_name = 'Dr. Horse Expert', - name = 'Dr. Horse Expert', - status = 'force_change_password', - updated_at = CURRENT_TIMESTAMP -WHERE identifier = 'superadmin'; +-- Safely change the superadmin identifier ONLY if 'lol' is not already taken. +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM users WHERE identifier = 'lol') THEN + UPDATE users + SET identifier = 'lol', + updated_at = CURRENT_TIMESTAMP + WHERE identifier = 'superadmin'; + ELSE + RAISE NOTICE 'Skipping identifier change: ''lol'' already exists'; + END IF; +END$$; --- If there is a separate user with email 'admin@gohorsejobs.com', update non-identifier fields only +-- Update non-identifier fields for the superadmin row (if present) UPDATE users SET email = 'lol@gohorsejobs.com', @@ -22,4 +24,4 @@ SET name = 'Dr. Horse Expert', status = 'force_change_password', updated_at = CURRENT_TIMESTAMP -WHERE email = 'admin@gohorsejobs.com' AND identifier <> 'lol'; +WHERE identifier = 'superadmin' OR identifier = 'lol' OR email = 'admin@gohorsejobs.com';