--- clients-integration-id


ALTER TABLE clients
  RENAME COLUMN external_id TO integration_id;
DROP INDEX clients_org_id_external_id_uniq;

CREATE UNIQUE INDEX clients_org_id_integration_id_uniq
  ON clients (org_id, integration_id);

ALTER TABLE client_sessions
  RENAME COLUMN external TO integration;

ALTER TABLE client_sessions
  RENAME COLUMN external_token TO integration_credentials;

DROP INDEX client_sessions_org_id_external_id_uniq;

CREATE UNIQUE INDEX client_sessions_org_id_integration_credentials_id_uniq
  ON client_sessions (org_id, integration_credentials)
  WHERE integration_credentials IS NOT NULL;
