--- drop-org-id


ALTER TABLE channels
  DROP COLUMN org_id CASCADE;
CREATE UNIQUE INDEX channels_name_nondeleted_uniq
  ON channels (lower(name))
  WHERE deleted = FALSE;


ALTER TABLE client_sessions
  DROP COLUMN org_id CASCADE;
CREATE UNIQUE INDEX client_sessions_integration_credentials_id_uniq
  ON client_sessions (integration_credentials)
  WHERE integration_credentials IS NOT NULL;


ALTER TABLE clients
  DROP COLUMN org_id CASCADE;
CREATE UNIQUE INDEX clients_integration_id_uniq
  ON clients (integration_id)
  WHERE integration_id IS NOT NULL;

ALTER TABLE user_agents
  DROP COLUMN org_id CASCADE;
CREATE UNIQUE INDEX user_agents_org_id_user_agent_uniq
  ON user_agents (lower(user_agent));

ALTER TABLE user_events
  DROP COLUMN org_id CASCADE;

ALTER TABLE user_groups
  DROP COLUMN org_id CASCADE;
CREATE UNIQUE INDEX user_groups_name_nondeleted_uniq
  ON user_groups (lower(name))
  WHERE deleted IS FALSE;


ALTER TABLE users
  DROP COLUMN org_id CASCADE;
