7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/generators/active_recall/templates/migrate_okubo_to_active_recall.rb', line 7
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
|