DROP TABLE IF EXISTS BitrixTokens;
DROP TABLE IF EXISTS StepBitrix;

DROP TABLE IF EXISTS PipelineBitrix;

DROP TABLE IF EXISTS BitrixAccounts;

DROP TABLE IF EXISTS BitrixAccountUsers;

DROP TABLE IF EXISTS BitrixFields;

DROP TABLE IF EXISTS BitrixRule;

DROP TABLE IF EXISTS bitrixCRMStatuses;

DROP TABLE IF EXISTS bitrixContact;

DO $$
BEGIN
    IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'CustomFieldsType') THEN
DROP TYPE CustomFieldsType;
END IF;
END $$;

DO $$
BEGIN
    IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'FieldsType') THEN
DROP TYPE FieldsType;
END IF;
END $$;

DROP INDEX IF EXISTS idx_unique_pipeline_bitrix;
DROP INDEX IF EXISTS idx_unique_step_bitrix;
DROP INDEX IF EXISTS idx_unique_field_bitrix;
ALTER TABLE answer DROP COLUMN IF EXISTS version;
