-- Revert to the original (buggy) bare ON DELETE SET NULL composite FKs so that
-- this migration is a faithful inverse of 0015 up. Constraint names and column
-- references match the definitions in 0003_workspace.up.sql and 0006_acp.up.sql.

-- ============ acp_sessions -> requirements ============
ALTER TABLE acp_sessions DROP CONSTRAINT acp_sessions_req_project_fk;
ALTER TABLE acp_sessions ADD CONSTRAINT acp_sessions_req_project_fk
  FOREIGN KEY (project_id, requirement_id)
  REFERENCES requirements (project_id, id) MATCH SIMPLE
  ON DELETE SET NULL;

-- ============ acp_sessions -> issues ============
ALTER TABLE acp_sessions DROP CONSTRAINT acp_sessions_issue_project_fk;
ALTER TABLE acp_sessions ADD CONSTRAINT acp_sessions_issue_project_fk
  FOREIGN KEY (project_id, issue_id)
  REFERENCES issues (project_id, id) MATCH SIMPLE
  ON DELETE SET NULL;

-- ============ issues -> workspaces ============
ALTER TABLE issues DROP CONSTRAINT issues_project_workspace_fk;
ALTER TABLE issues ADD CONSTRAINT issues_project_workspace_fk
  FOREIGN KEY (project_id, workspace_id)
  REFERENCES workspaces (project_id, id) MATCH SIMPLE
  ON DELETE SET NULL;
