Skip to content

Commit

Permalink
Fixes #1133
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Mar 7, 2025
1 parent 99d97af commit a8ab5d8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions db/migrate/20240726083740_alter_articles_add_versioning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,46 @@ def up
))
end

# insert article_versions for articles lacking them (assumed db inconsistencies due to bugs in older foodsoft versions):
articles = select_all('SELECT articles.* FROM articles LEFT JOIN article_versions ON article_versions.article_id = articles.id WHERE article_versions.id IS NULL')
articles.each do |article|
insert(%(
INSERT INTO article_versions (
article_id,
price,
tax,
deposit,
name,
article_category_id,
unit,
note,
availability,
manufacturer,
origin,
order_number,
unit_quantity,
created_at,
updated_at
) VALUES (
#{quote article['id']},
#{quote article['price']},
#{quote article['tax']},
#{quote article['deposit']},
#{quote article['name']},
#{quote article['article_category_id']},
#{quote article['unit']},
#{quote article['note']},
#{quote article['availability']},
#{quote article['manufacturer']},
#{quote article['origin']},
#{quote article['order_number']},
#{quote article['unit_quantity']},
#{quote article['created_at']},
#{quote article['updated_at']}
)
))
end

remove_index :articles, %i[name supplier_id]

# drop article columns (now superfluous as they exist in article_versions):
Expand Down

0 comments on commit a8ab5d8

Please sign in to comment.