DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1
        FROM vclib.t_entities
        WHERE baseentity = (
            SELECT entityid
            FROM vclib.t_entities
            WHERE entname = 'USER_SEARCHES' AND "schema" = 'VCLib'
        )
    ) THEN
        ALTER TABLE vclib.t_user_searches DROP CONSTRAINT IF EXISTS fk_t_entities_t_user_searches_type_;
        ALTER TABLE vclib.t_user_searches DROP COLUMN IF EXISTS type_;
    END IF;
END $$;