-- Add field to store timestamp of joining game

DO $$
BEGIN
    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 = 'create_ts'
    ) THEN
        ALTER TABLE games.players ADD COLUMN create_ts TIMESTAMP WITHOUT TIME ZONE NULL;
    END IF;
END
$$;