-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Remove soft delete from prices #6400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mamhoff
wants to merge
2
commits into
solidusio:main
Choose a base branch
from
mamhoff:remove-soft-delete-from-prices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Spree | ||
| # Implements all of the methods that Discard implements, but without a deleted_at column. | ||
| # Deprecates all usages of Discard methods. | ||
| module HardDeletable | ||
| extend ActiveSupport::Concern | ||
|
|
||
| def discarded? = false | ||
| def undiscarded? = true | ||
| def kept? = true | ||
| def deleted_at = nil | ||
|
|
||
| included do | ||
| def self.kept | ||
| all | ||
| end | ||
|
|
||
| def self.discarded | ||
| none | ||
| end | ||
|
|
||
| def self.discard_all | ||
| destroy_all | ||
| end | ||
|
|
||
| def self.with_discarded | ||
| all | ||
| end | ||
| class << self | ||
| deprecate :kept, :discarded, :with_discarded, :discard_all, deprecator: Spree.deprecator | ||
| end | ||
|
|
||
| alias_method :discard, :destroy | ||
| alias_method :discard!, :destroy | ||
|
|
||
| deprecate :discard, :discard!, deprecator: Spree.deprecator | ||
| deprecate :discarded?, :undiscarded?, :kept?, :deleted_at, deprecator: Spree.deprecator | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,9 +39,7 @@ def price_for_options(price_options) | |
| # | ||
| # @return [Array<Spree::Price>] | ||
| def sorted_prices_for(variant) | ||
| variant.prices.select do |price| | ||
| variant.discarded? || price.kept? | ||
| end.sort_by do |price| | ||
| variant.prices.sort_by do |price| | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we create a new price selector and make optional, deprecating the old one? |
||
| [ | ||
| price.country_iso.nil? ? 0 : 1, | ||
| price.updated_at || Time.zone.now, | ||
|
|
||
15 changes: 15 additions & 0 deletions
15
core/db/migrate/20251223220550_remove_soft_deleted_prices.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class RemoveSoftDeletedPrices < ActiveRecord::Migration[7.0] | ||
| def up | ||
| discarded_prices = Spree::Price.where.not(deleted_at: nil) | ||
| affected_variant_ids = discarded_prices.map(&:variant_id).uniq | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be faster discarded_prices.pluck("DISTINCT(variant_id)") |
||
| discarded_prices.delete_all | ||
| Spree::Variant.where(id: affected_variant_ids).find_each(&:touch) | ||
| remove_column :spree_prices, :deleted_at | ||
| end | ||
|
|
||
| def down | ||
| add_column :spree_prices, :deleted_at, :timestamp, null: true | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe Spree::HardDeletable do | ||
| let(:hard_deletable_migration) do | ||
| Class.new(ActiveRecord::Migration[5.1]) do | ||
| def change | ||
| create_table(:hard_deletable_items) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| let(:hard_deletable_item_class) do | ||
| Class.new(Spree::Base) do | ||
| include Spree::HardDeletable | ||
|
|
||
| def self.name | ||
| "HardDeletableItem" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| let(:hard_deletable_item) { hard_deletable_item_class.new } | ||
|
|
||
| around do |example| | ||
| hard_deletable_migration.migrate(:up) | ||
| example.run | ||
| hard_deletable_migration.migrate(:down) | ||
| end | ||
|
|
||
| before do | ||
| expect(Spree.deprecator).to receive(:warn) | ||
| end | ||
|
|
||
| describe ".with_discarded" do | ||
| it "is deprecated and returns all" do | ||
| expect(hard_deletable_item_class.with_discarded.to_sql).to eq(hard_deletable_item_class.all.to_sql) | ||
| end | ||
| end | ||
|
|
||
| describe ".kept" do | ||
| it "is deprecated and returns all" do | ||
| expect(hard_deletable_item_class.kept.to_sql).to eq(hard_deletable_item_class.all.to_sql) | ||
| end | ||
| end | ||
|
|
||
| describe ".discarded" do | ||
| it "is deprecated and returns none" do | ||
| expect(hard_deletable_item_class.discarded.to_sql).to eq(hard_deletable_item_class.none.to_sql) | ||
| end | ||
| end | ||
|
|
||
| describe ".discard_all" do | ||
| it "is deprecated and calls #destroy_all" do | ||
| expect(hard_deletable_item_class).to receive(:destroy_all) | ||
| hard_deletable_item_class.discard_all | ||
| end | ||
| end | ||
|
|
||
| describe "#deleted_at" do | ||
| subject { hard_deletable_item.deleted_at } | ||
| it { is_expected.to be nil } | ||
| end | ||
|
|
||
| describe "#discarded?" do | ||
| subject { hard_deletable_item.discarded? } | ||
| it { is_expected.to be false } | ||
| end | ||
|
|
||
| describe "#undiscarded?" do | ||
| subject { hard_deletable_item.undiscarded? } | ||
| it { is_expected.to be true } | ||
| end | ||
|
|
||
| describe "#kept?" do | ||
| subject { hard_deletable_item.kept? } | ||
| it { is_expected.to be true } | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍 worth a DeadCode episode!