Skip to content

Instantly share code, notes, and snippets.

@maxcobmara
Created August 4, 2016 03:52
Show Gist options
  • Save maxcobmara/b4c4480d8197fd714d6278e4e29f2c9b to your computer and use it in GitHub Desktop.
Save maxcobmara/b4c4480d8197fd714d6278e4e29f2c9b to your computer and use it in GitHub Desktop.
Denormalise a status via Rails migration
class DenormalizeProjectStatus < ActiveRecord::Migration
def up
add_column :projects, :status, :string, limit: 32
execute %q(UPDATE projects p SET status = (SELECT name FROM statuses s WHERE s.id = p.status_id))
change_column :projects, :status, :string, null: false, limit: 32
remove_column :projects, :status_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment