In every case originating in or removed to a court of competent jurisdiction, in which different liens are claimed against the same property, the court, in the judgment, must declare the rank of such lien or class of liens, which shall be in the following order:
(1) All persons performing labor;
(2) All persons furnishing material;
And the proceeds of the sale of the property must be applied to each lien or class of liens in the order of its rank; and personal judgment may be rendered in an action brought to foreclose a lien, against any party personally liable for any debt for which the lien is claimed, and if the lien be established, the judgment shall provide for the enforcement thereof upon the property liable as in case of foreclosure of mortgages; and the amount realized by such enforcement of the lien shall be credited upon the proper personal judgment, and the deficiency, if any, remaining unsatisfied, shall stand as a personal judgment, and may be collected by execution against the party liable therefor. The court may allow, as part of the costs of the action, the moneys paid for filing or recording the claim, and a reasonable attorney's fee in the action.