-- Create separate databases for each service
SELECT 'CREATE DATABASE game_sessions'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'game_sessions')\gexec
SELECT 'CREATE DATABASE questions'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'questions')\gexec
SELECT 'CREATE DATABASE users'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'users')\gexec
SELECT 'CREATE DATABASE leaderboards'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'leaderboards')\gexec
SELECT 'CREATE DATABASE admin'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'admin')\gexec

-- Grant privileges
GRANT ALL PRIVILEGES ON DATABASE game_sessions TO knowfoolery;
GRANT ALL PRIVILEGES ON DATABASE questions TO knowfoolery;
GRANT ALL PRIVILEGES ON DATABASE users TO knowfoolery;
GRANT ALL PRIVILEGES ON DATABASE leaderboards TO knowfoolery;
GRANT ALL PRIVILEGES ON DATABASE admin TO knowfoolery;
