-- Add field for team id:

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 = 'team_id'
    ) THEN
        ALTER TABLE games.players ADD COLUMN team_id INT NOT NULL DEFAULT -1;
    END IF;
END
$$;