Skip to content

Commit

Permalink
Also backfill spree_line_items pre_tax_amount for impending null cons…
Browse files Browse the repository at this point in the history
…traint.

Line items might also have a null pre_tax_amount, so we should backfill
those as well before trying to make that column not allow null.
  • Loading branch information
Andrew Thal committed Nov 11, 2015
1 parent 25c34fe commit 575b6b2
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ def change
WHERE pre_tax_amount IS NULL;
SQL

# set pre_tax_amount on line_items to discounted_amount - included_tax_total
# so that the null: false option on the line_item pre_tax_amount doesn't generate
# errors.
#
execute(<<-SQL)
UPDATE spree_line_items
SET pre_tax_amount = (price * quantity + promo_total) - included_tax_total
WHERE pre_tax_amount IS NULL;
SQL

change_column :spree_line_items, :pre_tax_amount, :decimal, precision: 12, scale: 4, default: 0.0, null: false
change_column :spree_shipments, :pre_tax_amount, :decimal, precision: 12, scale: 4, default: 0.0, null: false
end
Expand Down

0 comments on commit 575b6b2

Please sign in to comment.