--- clients-integration-id


EXEC sp_RENAME 'clients.external_id' , 'integration_id', 'COLUMN';
DROP INDEX clients_org_id_external_id_uniq ON clients;

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

EXEC sp_RENAME 'client_sessions.external' , 'integration', 'COLUMN';

DROP INDEX client_sessions_org_id_external_id_uniq on client_sessions;
EXEC sp_RENAME 'client_sessions.external_token' , 'integration_credentials', 'COLUMN';

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