1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-04 15:24:23 +01:00
fab-manager/db/migrate/20160725131950_singleize_event_categories.rb

21 lines
536 B
Ruby
Raw Normal View History

# frozen_string_literal:true
class SingleizeEventCategories < ActiveRecord::Migration[4.2]
def up
execute 'UPDATE events AS e
SET category_id = ec.category_id
FROM events_categories AS ec
WHERE e.id = ec.event_id;'
end
def down
execute 'INSERT INTO events_categories
(event_id, category_id, created_at, updated_at)
SELECT id, category_id, now(), now()
FROM events;'
execute 'UPDATE events
SET category_id = NULL;'
end
end