-- Migration 004: Object Groups (G-pre1)
-- Schema: compliance
-- Run: ssh macmini "docker exec -i bp-core-postgres psql -U breakpilot -d breakpilot_db" < control-pipeline/migrations/004_object_groups.sql

SET search_path TO compliance, public;

CREATE TABLE IF NOT EXISTS object_groups (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    group_id INTEGER NOT NULL,
    canonical_name VARCHAR(200) NOT NULL,
    member_count INTEGER DEFAULT 0,
    members JSONB DEFAULT '[]',
    top_controls_count INTEGER DEFAULT 0,
    created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_object_groups_group_id ON object_groups(group_id);
CREATE INDEX IF NOT EXISTS idx_object_groups_canonical ON object_groups(canonical_name);
