-- Add allowed client type for user in the game
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_type t
INNER JOIN pg_namespace p ON t.typnamespace=p.oid
WHERE t.typname='client_types' AND p.nspname='auth'
) THEN
.client_types AS ENUM ('p', 'o', 'm');
END IF;
IF NOT EXISTS (
SELECT 1 FROM pg_class c
INNER JOIN pg_namespace n ON n.oid = c.relnamespace
INNER JOIN pg_attribute a ON a.attrelid = c.oid
WHERE c.relname = 'players' AND n.nspname = 'games' AND a.attname = 'client_type'
) THEN
games.players ADD COLUMN client_type auth.client_types NOT NULL DEFAULT 'p';
END IF;
END
$$;