mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
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.
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user