Sha256: fed498c56239abb7a740dbd54f4124ca36b5caaa0b551fd68405e938971fa2db

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

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

    drop_table :spree_store_credit_update_reasons
    rename_column :spree_store_credit_events, :update_reason_id, :store_credit_reason_id
  end

  def down
    create_table :spree_store_credit_update_reasons do |t|
      t.string :name

      t.timestamps
    end

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

    drop_table :spree_store_credit_reasons
    rename_column :spree_store_credit_events, :store_credit_reason_id, :update_reason_id
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_core-2.8.1 db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb
solidus_core-2.8.0 db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb