Files
web_work/migrations/004_grant_admin_to_admin_mail.sql
kirill.khorkov f4f57bd153 fix
2025-12-17 01:24:01 +03:00

43 lines
1.4 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
UPDATE users
SET is_admin = TRUE,
is_active = TRUE,
updated_at = CURRENT_TIMESTAMP
WHERE email = 'admin@mail.ru';
DO $$
DECLARE
updated_count INTEGER;
user_info RECORD;
BEGIN
GET DIAGNOSTICS updated_count = ROW_COUNT;
IF updated_count > 0 THEN
SELECT user_id, email, full_name, is_admin, is_active
INTO user_info
FROM users
WHERE email = 'admin@mail.ru';
RAISE NOTICE 'Пользователь % (ID: %) успешно получил права администратора',
user_info.email, user_info.user_id;
RAISE NOTICE 'ФИО: %, Админ: %, Активен: %',
user_info.full_name, user_info.is_admin, user_info.is_active;
ELSE
INSERT INTO users (email, password_hash, full_name, phone, city, is_admin, is_active)
VALUES (
'admin@mail.ru',
'$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
'Администратор',
'+79129991223',
'Москва',
TRUE,
TRUE
)
ON CONFLICT (email) DO UPDATE
SET is_admin = TRUE,
is_active = TRUE,
updated_at = CURRENT_TIMESTAMP;
RAISE NOTICE 'Пользователь admin@mail.ru создан/обновлен с правами администратора';
END IF;
END $$;