CREATE TABLE IF NOT EXISTS channels ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), community_id uuid REFERENCES communities (id) ON DELETE CASCADE, category_id uuid REFERENCES channel_categories (id) ON DELETE SET NULL, name text NOT NULL, type text NOT NULL CHECK (type IN ('text', 'dm', 'group_dm')), visibility text NOT NULL DEFAULT 'public' CHECK (visibility IN ('public', 'private')), topic text, created_at timestamptz DEFAULT now() );