-- Add fields to games for RSS channel

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 = 'games' AND n.nspname = 'games' AND a.attname = 'fo_forum_url'
    ) THEN
        ALTER TABLE games.games ADD COLUMN fo_forum_url VARCHAR(512) NULL;
    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 = 'games' AND n.nspname = 'games' AND a.attname = 'create_ts'
    ) THEN
        ALTER TABLE games.games ADD COLUMN create_ts TIMESTAMP WITHOUT TIME ZONE NULL;
    END IF;
END
$$;