-- Revert correspondent uniqueness to global name
DROP INDEX IF EXISTS correspondents_tenant_name_unique;
ALTER TABLE correspondents ADD CONSTRAINT correspondents_name_unique UNIQUE (name);

-- Revert tag uniqueness to global label
DROP INDEX IF EXISTS tags_tenant_label_unique;
ALTER TABLE tags ADD CONSTRAINT tags_label_key UNIQUE (label);

-- Revert document filename uniqueness to global folder scope
DROP INDEX IF EXISTS documents_tenant_folder_filename_unique;
CREATE UNIQUE INDEX documents_unique_folder_filename
    ON documents (
        COALESCE(folder_id, '00000000-0000-0000-0000-000000000000'::uuid),
        filename
    )
    WHERE deleted_at IS NULL;
