CREATE TABLE organization_members (
  member_id         VARCHAR(40)  PRIMARY KEY,
  organization_id   VARCHAR(40)  NOT NULL REFERENCES organizations(organization_id),
  agent_id          VARCHAR(40)  NOT NULL REFERENCES agents(agent_id),
  role              VARCHAR(20)  NOT NULL DEFAULT 'member',
  joined_at         TIMESTAMPTZ  NOT NULL DEFAULT NOW(),
  CONSTRAINT organization_members_role_check CHECK (role IN ('member', 'admin')),
  UNIQUE (organization_id, agent_id)
);
CREATE INDEX idx_org_members_org_id ON organization_members(organization_id);
CREATE INDEX idx_org_members_agent_id ON organization_members(agent_id);
