rosa-build/db/migrate/20130403202853_add_name_wit...

23 lines
628 B
Ruby
Raw Normal View History

2013-04-03 22:06:13 +01:00
class AddNameWithOwnerToProject < ActiveRecord::Migration
def up
add_column :projects, :owner_uname, :string
execute <<-SQL
UPDATE projects SET owner_uname = owners.uname
FROM users as owners
WHERE projects.owner_type = 'User' AND projects.owner_id = owners.id
SQL
execute <<-SQL
UPDATE projects SET owner_uname = owners.uname
FROM groups as owners
WHERE projects.owner_type = 'Group' AND projects.owner_id = owners.id
SQL
2013-04-08 19:53:15 +01:00
change_column :projects, :owner_uname, :string, :null => false
2013-04-03 22:06:13 +01:00
end
def down
remove_column :projects, :owner_uname
end
end