-- Share chat between servers (2020-10-03)

-- Choose one server where chat will remain alive

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 = 'chat_history' AND n.nspname = 'public' AND a.attname = 'server_id'
    ) THEN
        ALTER TABLE chat_history ADD COLUMN server_id INT NOT NULL DEFAULT 1;
    END IF;
END
$$;