-- AP0.5: Minimal initiatives (Vorhaben), actions (Maßnahmen), action_assignments CREATE TABLE initiatives ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE, title VARCHAR(255) NOT NULL, goal TEXT NOT NULL DEFAULT '', status VARCHAR(32) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'paused', 'completed', 'archived')), priority VARCHAR(16) NOT NULL DEFAULT 'normal' CHECK (priority IN ('low', 'normal', 'high')), owner_actor_id UUID NOT NULL REFERENCES actors(id) ON DELETE RESTRICT, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); CREATE INDEX idx_initiatives_tenant ON initiatives(tenant_id); CREATE INDEX idx_initiatives_owner ON initiatives(owner_actor_id); CREATE TABLE actions ( 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 'open' CHECK (status IN ('open', 'in_progress', 'blocked', 'done', 'discarded')), priority VARCHAR(16) NOT NULL DEFAULT 'normal' CHECK (priority IN ('low', 'normal', 'high')), created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); CREATE INDEX idx_actions_tenant ON actions(tenant_id); CREATE INDEX idx_actions_initiative ON actions(initiative_id); CREATE INDEX idx_actions_status ON actions(tenant_id, status); CREATE TABLE action_assignments ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE, action_id UUID NOT NULL REFERENCES actions(id) ON DELETE CASCADE, actor_id UUID NOT NULL REFERENCES actors(id) ON DELETE CASCADE, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), UNIQUE (action_id, actor_id) ); CREATE INDEX idx_action_assignments_tenant ON action_assignments(tenant_id); CREATE INDEX idx_action_assignments_actor ON action_assignments(actor_id); CREATE INDEX idx_action_assignments_action ON action_assignments(action_id);