Sha256: db57c6e3367a10aef35c69fd919d698aa8a60590854271e6f76d508dd3a68d54
Contents?: true
Size: 981 Bytes
Versions: 9
Compression:
Stored size: 981 Bytes
Contents
# frozen_string_literal: true class MigrateOkuboToActiveRecall < ActiveRecord::Migration[5.2] DECK_SQL = 'SELECT "okubo_decks".* FROM "okubo_decks"' ITEM_SQL = 'SELECT "okubo_items".* FROM "okubo_items"' def self.up connection = ActiveRecord::Base.connection decks = connection.execute(DECK_SQL).to_a.map(&:symbolize_keys) items = connection.execute(ITEM_SQL).to_a.map(&:symbolize_keys) decks.each do |deck_attributes| deck_create_attributes = deck_attributes.except(:id, :created_at, :updated_at) deck = ActiveRecall::Deck.create!(deck_create_attributes) items.select do |item_attributes| deck_attributes[:id] == item_attributes[:deck_id] end.each do |item_attributes| item_create_attributes = item_attributes .except(:id, :created_at, :updated_at) .merge(deck_id: deck.id) ActiveRecall::Item.create!(item_create_attributes) end end end def self.down true end end
Version data entries
9 entries across 9 versions & 1 rubygems