-- AP0.8: Operating Model Extension I — blockers, backlog_items, milestones CREATE TABLE blockers ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE, initiative_id UUID NOT NULL REFERENCES initiatives(id) ON DELETE CASCADE, action_id UUID NULL REFERENCES actions(id) ON DELETE SET NULL, title VARCHAR(255) NOT NULL, description TEXT NOT NULL DEFAULT '', status VARCHAR(32) NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'in_progress', 'resolved', 'accepted_risk', 'dismissed')), reported_by_actor_id UUID NULL REFERENCES actors(id) ON DELETE SET NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); CREATE INDEX idx_blockers_tenant_initiative ON blockers(tenant_id, initiative_id); CREATE INDEX idx_blockers_tenant_status ON blockers(tenant_id, status); CREATE TABLE backlog_items ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE, initiative_id UUID NOT NULL REFERENCES initiatives(id) ON DELETE CASCADE, title VARCHAR(255) NOT NULL, description TEXT NOT NULL DEFAULT '', status VARCHAR(32) NOT NULL DEFAULT 'new' CHECK (status IN ('new', 'triaged', 'accepted', 'rejected', 'converted')), priority VARCHAR(16) NOT NULL DEFAULT 'normal' CHECK (priority IN ('low', 'normal', 'high')), converted_action_id UUID NULL REFERENCES actions(id) ON DELETE SET NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); CREATE INDEX idx_backlog_items_tenant_initiative ON backlog_items(tenant_id, initiative_id); CREATE INDEX idx_backlog_items_tenant_status ON backlog_items(tenant_id, status); CREATE TABLE milestones ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE, initiative_id UUID NOT NULL REFERENCES initiatives(id) ON DELETE CASCADE, title VARCHAR(255) NOT NULL, goal_description TEXT NOT NULL DEFAULT '', status VARCHAR(32) NOT NULL DEFAULT 'planned' CHECK (status IN ('planned', 'active', 'at_risk', 'reached', 'moved', 'discarded')), target_date DATE NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); CREATE INDEX idx_milestones_tenant_initiative ON milestones(tenant_id, initiative_id); CREATE INDEX idx_milestones_tenant_status ON milestones(tenant_id, status);