2019-04-28 11:56:16 +03:00
|
|
|
class CreatePropositionsForExistingEvents < ActiveRecord::Migration[4.2]
|
2015-04-17 02:01:28 +03:00
|
|
|
def up
|
2019-04-28 21:10:54 +03:00
|
|
|
events = execute "SELECT * FROM events"
|
2015-04-17 02:01:28 +03:00
|
|
|
|
|
|
|
events.each do |event|
|
|
|
|
execute "INSERT INTO propositions (proposer_id, proposition_accepting_id, proposition_accepting_type, proposable_id, proposable_type, status, created_at, updated_at)
|
2019-04-28 21:10:54 +03:00
|
|
|
VALUES (#{event["user_id"]}, #{event["track_id"]}, 'Track', #{event["id"]}, 'Event', #{event["state"]}, '#{event["created_at"]}', '#{event["updated_at"]}')"
|
2015-04-17 02:01:28 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2019-04-28 21:10:54 +03:00
|
|
|
event_ids = execute("SELECT * FROM events").map { |event| event["id"] }
|
|
|
|
execute "DELETE FROM propositions WHERE proposable_id IN (#{event_ids.join(", ")}) AND proposable_type = 'Event'"
|
2015-04-17 02:01:28 +03:00
|
|
|
end
|
|
|
|
end
|