# encoding: utf-8
#--
#   Copyright (C) 2012 Gitorious AS
#   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#++

class AddProjectIdToComments < ActiveRecord::Migration
  def self.up
    add_column  :comments, :project_id, :integer
    add_index   :comments, :project_id
    Comment::reset_column_information

    Comment.all.each do |comment|
      comment.update_attributes(:project_id => comment.repository.project_id)
    end
  end

  def self.down
    remove_column :comments, :project_id
  end
end
