Skip to content

Instantly share code, notes, and snippets.

@khalsah
khalsah / migrate.rb
Created May 11, 2011 — forked from zacclark/migrate.rb
VHGDB - Migrating statuses to actions
View migrate.rb
class MoveStatusDataToStatusChangeActions < ActiveRecord::Migration
def self.up
execute <<-EOQ
INSERT INTO actions(status_code, attendance_id, type, occurred_at, created_at, updated_at, archived_title, archived_company_id)
SELECT
statuses.status, statuses.attendance_id, 'StatusChangeAction', statuses.created_at, statuses.created_at, statuses.updated_at, titles.title, companies.id
FROM statuses
JOIN attendances ON attendances.id = statuses.attendance_id
JOIN people ON people.id = attendances.person_id
JOIN employments ON employments.id = people.current_employment_id