Ensure that the article_id is set for every article_price
This addresses the TODO from dc92de771e.
This commit is contained in:
parent
26aecbbe9e
commit
3a6276aece
3 changed files with 22 additions and 8 deletions
|
|
@ -0,0 +1,20 @@
|
|||
class EnsureArticleForArticlePrice < ActiveRecord::Migration
|
||||
class ArticlePrice < ActiveRecord::Base; end
|
||||
|
||||
def change
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
execute <<-SQL
|
||||
UPDATE article_prices SET article_id = (
|
||||
SELECT article_id FROM order_articles
|
||||
WHERE article_price_id = article_prices.id
|
||||
)
|
||||
WHERE article_id IS NULL
|
||||
SQL
|
||||
ArticlePrice.where(article_id: nil).destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
change_column_null :article_prices, :article_id, false
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue