DROP INDEX IF EXISTS idx_unique_users;
DROP INDEX IF EXISTS idx_unique_pipeline;
DROP INDEX IF EXISTS idx_unique_step;
DROP INDEX IF EXISTS idx_unique_field;
DROP INDEX IF EXISTS idx_unique_tag;

ALTER TABLE question
    DROP COLUMN IF EXISTS utm,
    DROP COLUMN IF EXISTS rules;

DROP TABLE IF EXISTS tags;
DROP TABLE IF EXISTS fields;

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

DROP TABLE IF EXISTS steps;
DROP TABLE IF EXISTS pipelines;
DROP TABLE IF EXISTS tokens;
DROP TABLE IF EXISTS users;