Skip to content

Commit

Permalink
Marketplace: Use Lockbox.migrate for safety
Browse files Browse the repository at this point in the history
@KellyAH found Lockbox's guide to migrating data: https://github.com/zinc-collective/convene/pull/1169/files#r1124067175

And it's way better!
  • Loading branch information
zspencer committed Mar 3, 2023
1 parent 0727632 commit 2fdd8a3
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/furniture/marketplace/cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Cart < Record
has_many :cart_products, dependent: :destroy, inverse_of: :cart
has_many :products, through: :cart_products, inverse_of: :carts

has_encrypted :delivery_address, migrating: true

enum status: {
pre_checkout: "pre_checkout",
paid: "paid"
Expand Down
2 changes: 1 addition & 1 deletion app/furniture/marketplace/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Order < Record
has_many :ordered_products, inverse_of: :order, foreign_key: :cart_id
has_many :products, through: :ordered_products, inverse_of: :orders

has_encrypted :delivery_address
has_encrypted :delivery_address, migrating: true

enum status: {
pre_checkout: "pre_checkout",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class MarketplaceEncryptOrderDeliveryAddress < ActiveRecord::Migration[7.0]
def change
rename_column :marketplace_orders, :delivery_address, :deprecated_delivery_address
add_column :marketplace_orders, :delivery_address_ciphertext, :text
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
t.uuid "shopper_id"
t.string "status", default: "pre_checkout", null: false
t.string "stripe_session_id"
t.string "deprecated_delivery_address"
t.string "delivery_address"
t.string "contact_email"
t.text "delivery_address_ciphertext"
t.index ["marketplace_id"], name: "index_marketplace_orders_on_marketplace_id"
Expand Down
7 changes: 1 addition & 6 deletions lib/tasks/release.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
namespace :release do
desc "Ensures any post-release / pre-deploy behavior has occurred"
task after_build: [:environment, "db:prepare"] do
# @todo Delete after running in prod
Marketplace::Order.all.find_each do |order|
next unless order.deprecated_delivery_address.present?

order.update(delivery_address: order.deprecated_delivery_address, deprecated_delivery_address: nil)
end
Lockbox.migrate(Marketplace::Order)
SystemTestSpace.prepare
end
end

0 comments on commit 2fdd8a3

Please sign in to comment.