deckhearth/scripts/promote-user-to-admin.sql
2025-07-22 07:23:03 -05:00

37 lines
No EOL
1 KiB
SQL

-- Promote test user to admin role
-- Run this script directly against your Neon database
-- First, let's see the current user and roles
SELECT
u.id,
u.username,
u.email,
ARRAY_AGG(r.name) as current_roles
FROM users u
LEFT JOIN user_roles ur ON u.id = ur.user_id
LEFT JOIN roles r ON ur.role_id = r.id
WHERE u.username = 'testuser'
GROUP BY u.id, u.username, u.email;
-- Get the admin role ID
SELECT id as admin_role_id FROM roles WHERE name = 'admin';
-- Add the user to admin role (assuming user ID is 1 and admin role ID is 2)
-- You may need to adjust these IDs based on the output above
INSERT INTO user_roles (user_id, role_id)
SELECT 1, id FROM roles WHERE name = 'admin'
ON CONFLICT DO NOTHING;
-- Verify the promotion worked
SELECT
u.id,
u.username,
u.email,
u.first_name,
u.last_name,
ARRAY_AGG(DISTINCT r.name) as roles
FROM users u
LEFT JOIN user_roles ur ON u.id = ur.user_id
LEFT JOIN roles r ON ur.role_id = r.id
WHERE u.username = 'testuser'
GROUP BY u.id, u.username, u.email, u.first_name, u.last_name;