Sha256: e553178c14349d3dab4709ec021eeaf2f37040fc30d3eb193ab9ad50c9ce7df3

Contents?: true

Size: 1.53 KB

Versions: 10

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

# This migration comes from spree (originally 20161014221052)
class AddAvailableToColumnsAndRemoveDisplayOnFromPaymentMethods < ActiveRecord::Migration[5.0]
  def up
    add_column(:spree_payment_methods, :available_to_users, :boolean, default: true)
    add_column(:spree_payment_methods, :available_to_admin, :boolean, default: true)
    execute("UPDATE spree_payment_methods "\
             "SET available_to_users=#{quoted_false} "\
             "WHERE NOT (display_on='front_end' OR display_on='' OR display_on IS NULL)")
    execute("UPDATE spree_payment_methods "\
             "SET available_to_admin=#{quoted_false} "\
             "WHERE NOT (display_on='back_end' OR display_on='' OR display_on IS NULL)")
    remove_column(:spree_payment_methods, :display_on)
  end

  def down
    add_column(:spree_payment_methods, :display_on, :string)
    execute("UPDATE spree_payment_methods "\
            "SET display_on='' "\
            "WHERE (available_to_users=#{quoted_true} AND available_to_admin=#{quoted_true})")
    execute("UPDATE spree_payment_methods "\
            "SET display_on='front_end' "\
            "WHERE (available_to_users=#{quoted_true} AND NOT available_to_admin=#{quoted_true})")
    execute("UPDATE spree_payment_methods "\
            "SET display_on='back_end' "\
            "WHERE (available_to_admin=#{quoted_true} AND NOT available_to_users=#{quoted_true})")
    remove_column(:spree_payment_methods, :available_to_users)
    remove_column(:spree_payment_methods, :available_to_admin)
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
solidus_prototypes-1.6.0 spec/dummy/db/migrate/20231107091956_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_prototypes-1.5.1 spec/dummy/db/migrate/20231107091956_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_prototypes-1.5.0 spec/dummy/db/migrate/20231107091956_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_prototypes-1.4.0 spec/dummy/db/migrate/20231107091956_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_prototypes-1.3.0 spec/dummy/db/migrate/20230326093414_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_reports-1.2.0 spec/dummy/db/migrate/20230326095722_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_prototypes-1.2.0 spec/dummy/db/migrate/20221122203140_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_prototypes-1.1.1 spec/dummy/db/migrate/20221014070455_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_reports-1.1.0 spec/dummy/db/migrate/20221012211946_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb
solidus_prototypes-1.1.0 spec/dummy/db/migrate/20221012201054_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb