From a96dbd563b52ea2848add34f98fb1d892f9bd2b7 Mon Sep 17 00:00:00 2001 From: Florian Lentsch Date: Fri, 5 Feb 2021 11:42:50 +0100 Subject: [PATCH] Migrations for new `received` order state (s. #779) --- ...210205090257_introduce_received_state_in_orders.rb | 11 +++++++++++ db/schema.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210205090257_introduce_received_state_in_orders.rb diff --git a/db/migrate/20210205090257_introduce_received_state_in_orders.rb b/db/migrate/20210205090257_introduce_received_state_in_orders.rb new file mode 100644 index 00000000..ffeff588 --- /dev/null +++ b/db/migrate/20210205090257_introduce_received_state_in_orders.rb @@ -0,0 +1,11 @@ +class IntroduceReceivedStateInOrders < ActiveRecord::Migration[5.2] + def up + Order.where(state: 'finished').each do |order| + order.update_attribute(:state, 'received') if order.order_articles.where('units_received IS NOT NULL').any? + end + end + + def down + Order.where(state: 'received').update_all(state: 'finished') + end +end diff --git a/db/schema.rb b/db/schema.rb index f1d27004..d9d16f3b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_12_05_010000) do +ActiveRecord::Schema.define(version: 2021_02_05_090257) do create_table "article_categories", force: :cascade do |t| t.string "name", default: "", null: false