From 68193efcf6d79dbbf36daacf6f2dd327acb87e7b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 15 Feb 2022 11:43:43 +1100 Subject: [PATCH] Keep old customers.name column for compatibilty Our app code will try to access the old attribute while the migration is running. That would lead to errors during checkout. --- db/migrate/20220105085729_split_customers_name.rb | 9 +++++---- db/schema.rb | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/db/migrate/20220105085729_split_customers_name.rb b/db/migrate/20220105085729_split_customers_name.rb index 50e5409c9f..ccf7bd364e 100644 --- a/db/migrate/20220105085729_split_customers_name.rb +++ b/db/migrate/20220105085729_split_customers_name.rb @@ -1,6 +1,9 @@ +# frozen_string_literal: true + class SplitCustomersName < ActiveRecord::Migration[6.1] class SpreeAddress < ApplicationRecord end + class Customer < ApplicationRecord belongs_to :bill_address, class_name: "SpreeAddress" end @@ -8,7 +11,6 @@ class SplitCustomersName < ActiveRecord::Migration[6.1] def up add_column :customers, :first_name, :string, null: false, default: "" add_column :customers, :last_name, :string, null: false, default: "" - rename_column :customers, :name, :backup_name migrate_customer_name_data! end @@ -16,12 +18,11 @@ class SplitCustomersName < ActiveRecord::Migration[6.1] def down remove_column :customers, :first_name remove_column :customers, :last_name - rename_column :customers, :backup_name, :name end def migrate_customer_name_data! - Customer.where(first_name: "", last_name: "").where.not(backup_name: [nil, ""]).find_each do |customer| - name_words = customer.backup_name.split(' ') + Customer.where(first_name: "", last_name: "").where.not(name: [nil, ""]).find_each do |customer| + name_words = customer.name.split(' ') next if name_words.empty? customer.update( diff --git a/db/schema.rb b/db/schema.rb index 468d478a93..ef2c12e7d2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -51,7 +51,7 @@ ActiveRecord::Schema.define(version: 2022_01_18_053107) do t.datetime "updated_at", null: false t.integer "bill_address_id" t.integer "ship_address_id" - t.string "backup_name", limit: 255 + t.string "name", limit: 255 t.boolean "allow_charges", default: false, null: false t.datetime "terms_and_conditions_accepted_at" t.string "first_name", default: "", null: false