clarion/db/migrate/20141105100827_create_propo...

16 lines
730 B
Ruby
Raw Permalink Normal View History

class CreatePropositionsForExistingEvents < ActiveRecord::Migration[4.2]
def up
2019-04-28 21:10:54 +03:00
events = execute "SELECT * FROM events"
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"]}')"
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'"
end
end