CREATE TABLE role_permissions (
    role_id INT REFERENCES roles(id) ON DELETE CASCADE,
    permission_id INT REFERENCES permissions(id) ON DELETE CASCADE,
    PRIMARY KEY (role_id, permission_id)
);

-- ✅ ตัวอย่าง mapping:
-- สมมุติ role_id 1 = superadmin, role_id 2 = admin, role_id 3 = user

-- ให้ admin ทุกสิทธิ์
INSERT INTO role_permissions (role_id, permission_id)
SELECT 1, id FROM permissions;

INSERT INTO role_permissions (role_id, permission_id)
SELECT 2, id FROM permissions;

-- ให้ user เฉพาะ view
INSERT INTO role_permissions (role_id, permission_id)
SELECT 3, id FROM permissions WHERE name IN ('user:view', 'report:view');