Created
August 4, 2016 03:52
-
-
Save maxcobmara/b4c4480d8197fd714d6278e4e29f2c9b to your computer and use it in GitHub Desktop.
Denormalise a status via Rails migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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