Sha256: 5d80db3f3a04aace28c8c3e45cafccf32e4d35fdb98bc6d27c6a1d59523e9126

Contents?: true

Size: 1.77 KB

Versions: 10

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

# This migration comes from spree (originally 20180710170104)
class CreateSpreeStoreCreditReasonsTable < ActiveRecord::Migration[5.1]
  class StoreCreditUpdateReason < ActiveRecord::Base
    self.table_name = "spree_store_credit_update_reasons"
  end

  class StoreCreditReason < ActiveRecord::Base
    self.table_name = "spree_store_credit_reasons"
  end

  def up
    create_table :spree_store_credit_reasons do |t|
      t.string :name
      t.boolean :active, default: true

      t.timestamps
    end

    StoreCreditUpdateReason.all.each do |update_reason|
      StoreCreditReason.create!(name: update_reason.name)
    end

    add_column :spree_store_credit_events, :store_credit_reason_id, :integer
    execute "update spree_store_credit_events set store_credit_reason_id = update_reason_id"

    # TODO: table spree_store_credit_update_reasons and column
    # column spree_store_credit_update_reasons.update_reason_id
    # must be dropped in a future Solidus release
  end

  def down
    # This table and column  may not exist anymore as another irreversible
    # migration may have removed it later. They must be added back or the
    # `up` method would fail
    unless table_exists? :spree_store_credit_update_reasons
      create_table :spree_store_credit_update_reasons do |t|
        t.string :name

        t.timestamps
      end

      unless column_exists? :spree_store_credit_events, :update_reason_id
        add_column :spree_store_credit_events, :update_reason_id, :integer
      end
    end

    StoreCreditReason.all.each do |store_credit_reason|
      StoreCreditUpdateReason.create!(name: store_credit_reason.name)
    end

    drop_table :spree_store_credit_reasons
    remove_column :spree_store_credit_events, :store_credit_reason_id
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
solidus_prototypes-1.6.0 spec/dummy/db/migrate/20231107091974_create_spree_store_credit_reasons_table.spree.rb
solidus_prototypes-1.5.1 spec/dummy/db/migrate/20231107091974_create_spree_store_credit_reasons_table.spree.rb
solidus_prototypes-1.5.0 spec/dummy/db/migrate/20231107091974_create_spree_store_credit_reasons_table.spree.rb
solidus_prototypes-1.4.0 spec/dummy/db/migrate/20231107091974_create_spree_store_credit_reasons_table.spree.rb
solidus_prototypes-1.3.0 spec/dummy/db/migrate/20230326093432_create_spree_store_credit_reasons_table.spree.rb
solidus_reports-1.2.0 spec/dummy/db/migrate/20230326095740_create_spree_store_credit_reasons_table.spree.rb
solidus_prototypes-1.2.0 spec/dummy/db/migrate/20221122203158_create_spree_store_credit_reasons_table.spree.rb
solidus_prototypes-1.1.1 spec/dummy/db/migrate/20221014070473_create_spree_store_credit_reasons_table.spree.rb
solidus_reports-1.1.0 spec/dummy/db/migrate/20221012211964_create_spree_store_credit_reasons_table.spree.rb
solidus_prototypes-1.1.0 spec/dummy/db/migrate/20221012201072_create_spree_store_credit_reasons_table.spree.rb