Revision 1298:4f746d8966dd db

View differences:

db/migrate/001_setup.rb
1
# redMine - project management software
1
# Redmine - project management software
2 2
# Copyright (C) 2006  Jean-Philippe Lang
3 3
#
4 4
# This program is free software; you can redistribute it and/or
......
292 292
                       :lastname => "Admin",
293 293
                       :mail => "admin@example.net",
294 294
                       :mail_notification => true,
295
                       :language => "en",
296 295
                       :status => 1
297 296
  end
298 297

  
db/migrate/002_issue_move.rb
7 7
  end
8 8

  
9 9
  def self.down
10
    Permission.find(:first, :conditions => ["controller=? and action=?", 'projects', 'move_issues']).destroy
10
    Permission.where("controller=? and action=?", 'projects', 'move_issues').first.destroy
11 11
  end
12 12
end
db/migrate/003_issue_add_note.rb
7 7
  end
8 8

  
9 9
  def self.down
10
    Permission.find(:first, :conditions => ["controller=? and action=?", 'issues', 'add_note']).destroy
10
    Permission.where("controller=? and action=?", 'issues', 'add_note').first.destroy
11 11
  end
12 12
end
db/migrate/004_export_pdf.rb
8 8
  end
9 9

  
10 10
  def self.down
11
    Permission.find(:first, :conditions => ["controller=? and action=?", 'projects', 'export_issues_pdf']).destroy
12
    Permission.find(:first, :conditions => ["controller=? and action=?", 'issues', 'export_pdf']).destroy
11
    Permission.where("controller=? and action=?", 'projects', 'export_issues_pdf').first.destroy
12
    Permission.where("controller=? and action=?", 'issues', 'export_pdf').first.destroy
13 13
  end
14 14
end
db/migrate/006_calendar_and_activity.rb
9 9
  end
10 10

  
11 11
  def self.down
12
    Permission.find(:first, :conditions => ["controller=? and action=?", 'projects', 'activity']).destroy
13
    Permission.find(:first, :conditions => ["controller=? and action=?", 'projects', 'calendar']).destroy
14
    Permission.find(:first, :conditions => ["controller=? and action=?", 'projects', 'gantt']).destroy
12
    Permission.where("controller=? and action=?", 'projects', 'activity').first.destroy
13
    Permission.where("controller=? and action=?", 'projects', 'calendar').first.destroy
14
    Permission.where("controller=? and action=?", 'projects', 'gantt').first.destroy
15 15
  end
16 16
end
db/migrate/007_create_journals.rb
28 28
    Permission.create :controller => "issues", :action => "history", :description => "label_history", :sort => 1006, :is_public => true, :mail_option => 0, :mail_enabled => 0
29 29

  
30 30
    # data migration
31
    IssueHistory.find(:all, :include => :issue).each {|h|
31
    IssueHistory.all.each {|h|
32 32
      j = Journal.new(:journalized => h.issue, :user_id => h.author_id, :notes => h.notes, :created_on => h.created_on)
33 33
      j.details << JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :value => h.status_id)
34 34
      j.save
......
51 51

  
52 52
    add_index "issue_histories", ["issue_id"], :name => "issue_histories_issue_id"
53 53

  
54
    Permission.find(:first, :conditions => ["controller=? and action=?", 'issues', 'history']).destroy
54
    Permission.where("controller=? and action=?", 'issues', 'history').first.destroy
55 55
  end
56 56
end
db/migrate/012_add_comments_permissions.rb
8 8
  end
9 9

  
10 10
  def self.down
11
    Permission.find(:first, :conditions => ["controller=? and action=?", 'news', 'add_comment']).destroy
12
    Permission.find(:first, :conditions => ["controller=? and action=?", 'news', 'destroy_comment']).destroy
11
    Permission.where("controller=? and action=?", 'news', 'add_comment').first.destroy
12
    Permission.where("controller=? and action=?", 'news', 'destroy_comment').first.destroy
13 13
  end
14 14
end
db/migrate/014_add_queries_permissions.rb
7 7
  end
8 8

  
9 9
  def self.down
10
    Permission.find(:first, :conditions => ["controller=? and action=?", 'projects', 'add_query']).destroy
10
    Permission.where("controller=? and action=?", 'projects', 'add_query').first.destroy
11 11
  end
12 12
end
db/migrate/016_add_repositories_permissions.rb
12 12
  end
13 13

  
14 14
  def self.down
15
    Permission.find(:first, :conditions => ["controller=? and action=?", 'repositories', 'show']).destroy
16
    Permission.find(:first, :conditions => ["controller=? and action=?", 'repositories', 'browse']).destroy
17
    Permission.find(:first, :conditions => ["controller=? and action=?", 'repositories', 'entry']).destroy
18
    Permission.find(:first, :conditions => ["controller=? and action=?", 'repositories', 'revisions']).destroy
19
    Permission.find(:first, :conditions => ["controller=? and action=?", 'repositories', 'revision']).destroy
20
    Permission.find(:first, :conditions => ["controller=? and action=?", 'repositories', 'diff']).destroy
15
    Permission.where("controller=? and action=?", 'repositories', 'show').first.destroy
16
    Permission.where("controller=? and action=?", 'repositories', 'browse').first.destroy
17
    Permission.where("controller=? and action=?", 'repositories', 'entry').first.destroy
18
    Permission.where("controller=? and action=?", 'repositories', 'revisions').first.destroy
19
    Permission.where("controller=? and action=?", 'repositories', 'revision').first.destroy
20
    Permission.where("controller=? and action=?", 'repositories', 'diff').first.destroy
21 21
  end
22 22
end
db/migrate/019_add_issue_status_position.rb
1 1
class AddIssueStatusPosition < ActiveRecord::Migration
2 2
  def self.up
3 3
    add_column :issue_statuses, :position, :integer, :default => 1
4
    IssueStatus.find(:all).each_with_index {|status, i| status.update_attribute(:position, i+1)}
4
    IssueStatus.all.each_with_index {|status, i| status.update_attribute(:position, i+1)}
5 5
  end
6 6

  
7 7
  def self.down
db/migrate/021_add_tracker_position.rb
1 1
class AddTrackerPosition < ActiveRecord::Migration
2 2
  def self.up
3 3
    add_column :trackers, :position, :integer, :default => 1
4
    Tracker.find(:all).each_with_index {|tracker, i| tracker.update_attribute(:position, i+1)}
4
    Tracker.all.each_with_index {|tracker, i| tracker.update_attribute(:position, i+1)}
5 5
  end
6 6

  
7 7
  def self.down
db/migrate/022_serialize_possibles_values.rb
1 1
class SerializePossiblesValues < ActiveRecord::Migration
2 2
  def self.up
3
    CustomField.find(:all).each do |field|
3
    CustomField.all.each do |field|
4 4
      if field.possible_values and field.possible_values.is_a? String
5 5
        field.possible_values = field.possible_values.split('|')
6 6
        field.save
db/migrate/024_add_roadmap_permission.rb
7 7
  end
8 8

  
9 9
  def self.down
10
    Permission.find(:first, :conditions => ["controller=? and action=?", 'projects', 'roadmap']).destroy
10
    Permission.where("controller=? and action=?", 'projects', 'roadmap').first.destroy
11 11
  end
12 12
end
db/migrate/065_add_settings_updated_on.rb
2 2
  def self.up
3 3
    add_column :settings, :updated_on, :timestamp
4 4
    # set updated_on
5
    Setting.find(:all).each(&:save)
5
    Setting.all.each(&:save)
6 6
  end
7 7

  
8 8
  def self.down
db/migrate/068_create_enabled_modules.rb
7 7
    add_index :enabled_modules, [:project_id], :name => :enabled_modules_project_id
8 8

  
9 9
    # Enable all modules for existing projects
10
    Project.find(:all).each do |project|
10
    Project.all.each do |project|
11 11
      project.enabled_module_names = Redmine::AccessControl.available_project_modules
12 12
    end
13 13
  end
db/migrate/072_add_enumerations_position.rb
1 1
class AddEnumerationsPosition < ActiveRecord::Migration
2 2
  def self.up
3 3
    add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position')
4
    Enumeration.find(:all).group_by(&:opt).each do |opt, enums|
4
    Enumeration.all.group_by(&:opt).each do |opt, enums|
5 5
      enums.each_with_index do |enum, i|
6 6
        # do not call model callbacks
7 7
        Enumeration.update_all "position = #{i+1}", {:id => enum.id}
db/migrate/078_add_custom_fields_position.rb
1 1
class AddCustomFieldsPosition < ActiveRecord::Migration
2 2
  def self.up
3 3
    add_column(:custom_fields, :position, :integer, :default => 1)
4
    CustomField.find(:all).group_by(&:type).each  do |t, fields|
4
    CustomField.all.group_by(&:type).each  do |t, fields|
5 5
      fields.each_with_index do |field, i|
6 6
        # do not call model callbacks
7 7
        CustomField.update_all "position = #{i+1}", {:id => field.id}
db/migrate/081_create_projects_trackers.rb
7 7
    add_index :projects_trackers, :project_id, :name => :projects_trackers_project_id
8 8

  
9 9
    # Associates all trackers to all projects (as it was before)
10
    tracker_ids = Tracker.find(:all).collect(&:id)
11
    Project.find(:all).each do |project|
10
    tracker_ids = Tracker.all.collect(&:id)
11
    Project.all.each do |project|
12 12
      project.tracker_ids = tracker_ids
13 13
    end
14 14
  end
db/migrate/091_change_changesets_revision_to_string.rb
1 1
class ChangeChangesetsRevisionToString < ActiveRecord::Migration
2 2
  def self.up
3
    # Some backends (eg. SQLServer 2012) do not support changing the type
4
    # of an indexed column so the index needs to be dropped first
5
    # BUT this index is renamed with some backends (at least SQLite3) for
6
    # some (unknown) reasons, thus we check for the other name as well
7
    # so we don't end up with 2 identical indexes
8
    if index_exists? :changesets, [:repository_id, :revision], :name => :changesets_repos_rev
9
      remove_index  :changesets, :name => :changesets_repos_rev
10
    end
11
    if index_exists? :changesets, [:repository_id, :revision], :name => :altered_changesets_repos_rev
12
      remove_index  :changesets, :name => :altered_changesets_repos_rev
13
    end
14

  
3 15
    change_column :changesets, :revision, :string, :null => false
16

  
17
    add_index :changesets, [:repository_id, :revision], :unique => true, :name => :changesets_repos_rev
4 18
  end
5 19

  
6 20
  def self.down
21
    if index_exists? :changesets, :changesets_repos_rev
22
      remove_index  :changesets, :name => :changesets_repos_rev
23
    end
24
    if index_exists? :changesets, [:repository_id, :revision], :name => :altered_changesets_repos_rev
25
      remove_index  :changesets, :name => :altered_changesets_repos_rev
26
    end
27

  
7 28
    change_column :changesets, :revision, :integer, :null => false
29

  
30
    add_index :changesets, [:repository_id, :revision], :unique => true, :name => :changesets_repos_rev
8 31
  end
9 32
end
db/migrate/096_add_commit_access_permission.rb
1 1
class AddCommitAccessPermission < ActiveRecord::Migration
2 2
  def self.up
3
    Role.find(:all).select { |r| not r.builtin? }.each do |r|
3
    Role.all.select { |r| not r.builtin? }.each do |r|
4 4
      r.add_permission!(:commit_access)
5 5
    end
6 6
  end
7 7

  
8 8
  def self.down
9
    Role.find(:all).select { |r| not r.builtin? }.each do |r|
9
    Role.all.select { |r| not r.builtin? }.each do |r|
10 10
      r.remove_permission!(:commit_access)
11 11
    end
12 12
  end
db/migrate/097_add_view_wiki_edits_permission.rb
1 1
class AddViewWikiEditsPermission < ActiveRecord::Migration
2 2
  def self.up
3
    Role.find(:all).each do |r|
3
    Role.all.each do |r|
4 4
      r.add_permission!(:view_wiki_edits) if r.has_permission?(:view_wiki_pages)
5 5
    end
6 6
  end
7 7

  
8 8
  def self.down
9
    Role.find(:all).each do |r|
9
    Role.all.each do |r|
10 10
      r.remove_permission!(:view_wiki_edits)
11 11
    end
12 12
  end
db/migrate/099_add_delete_wiki_pages_attachments_permission.rb
1 1
class AddDeleteWikiPagesAttachmentsPermission < ActiveRecord::Migration
2 2
  def self.up
3
    Role.find(:all).each do |r|
3
    Role.all.each do |r|
4 4
      r.add_permission!(:delete_wiki_pages_attachments) if r.has_permission?(:edit_wiki_pages)
5 5
    end
6 6
  end
7 7

  
8 8
  def self.down
9
    Role.find(:all).each do |r|
9
    Role.all.each do |r|
10 10
      r.remove_permission!(:delete_wiki_pages_attachments)
11 11
    end
12 12
  end
db/migrate/20090312194159_add_projects_trackers_unique_index.rb
10 10

  
11 11
  # Removes duplicates in projects_trackers table
12 12
  def self.remove_duplicates
13
    Project.find(:all).each do |project|
13
    Project.all.each do |project|
14 14
      ids = project.trackers.collect(&:id)
15 15
      unless ids == ids.uniq
16 16
        project.trackers.clear
db/migrate/20090503121505_populate_member_roles.rb
1 1
class PopulateMemberRoles < ActiveRecord::Migration
2 2
  def self.up
3 3
    MemberRole.delete_all
4
    Member.find(:all).each do |member|
4
    Member.all.each do |member|
5 5
      MemberRole.create!(:member_id => member.id, :role_id => member.role_id)
6 6
    end
7 7
  end
db/migrate/20091114105931_add_view_issues_permission.rb
1 1
class AddViewIssuesPermission < ActiveRecord::Migration
2 2
  def self.up
3
    Role.find(:all).each do |r|
3
    Role.all.each do |r|
4 4
      r.add_permission!(:view_issues)
5 5
    end
6 6
  end
7 7

  
8 8
  def self.down
9
    Role.find(:all).each do |r|
9
    Role.all.each do |r|
10 10
      r.remove_permission!(:view_issues)
11 11
    end
12 12
  end
db/migrate/20100819172912_enable_calendar_and_gantt_modules_where_appropriate.rb
1 1
class EnableCalendarAndGanttModulesWhereAppropriate < ActiveRecord::Migration
2 2
  def self.up
3
    EnabledModule.find(:all, :conditions => ["name = ?", 'issue_tracking']).each do |e|
3
    EnabledModule.where(:name => 'issue_tracking').all.each do |e|
4 4
      EnabledModule.create(:name => 'calendar', :project_id => e.project_id)
5 5
      EnabledModule.create(:name => 'gantt', :project_id => e.project_id)
6 6
    end
db/migrate/20121209123234_add_queries_type.rb
1
class AddQueriesType < ActiveRecord::Migration
2
  def up
3
    add_column :queries, :type, :string
4
  end
5

  
6
  def down
7
    remove_column :queries, :type
8
  end
9
end
db/migrate/20121209123358_update_queries_to_sti.rb
1
class UpdateQueriesToSti < ActiveRecord::Migration
2
  def up
3
    ::Query.update_all :type => 'IssueQuery'
4
  end
5

  
6
  def down
7
    ::Query.update_all :type => nil
8
  end
9
end
db/migrate/20121213084931_add_attachments_disk_directory.rb
1
class AddAttachmentsDiskDirectory < ActiveRecord::Migration
2
  def up
3
    add_column :attachments, :disk_directory, :string
4
  end
5

  
6
  def down
7
    remove_column :attachments, :disk_directory
8
  end
9
end
db/migrate/20130110122628_split_documents_permissions.rb
1
class SplitDocumentsPermissions < ActiveRecord::Migration
2
  def up
3
    # :manage_documents permission split into 3 permissions:
4
    # :add_documents, :edit_documents and :delete_documents
5
    Role.all.each do |role|
6
      if role.has_permission?(:manage_documents)
7
        role.add_permission! :add_documents, :edit_documents, :delete_documents
8
        role.remove_permission! :manage_documents
9
      end
10
    end
11
  end
12

  
13
  def down
14
    Role.all.each do |role|
15
      if role.has_permission?(:add_documents) ||
16
          role.has_permission?(:edit_documents) ||
17
          role.has_permission?(:delete_documents)
18
        role.remove_permission! :add_documents, :edit_documents, :delete_documents
19
        role.add_permission! :manage_documents
20
      end
21
    end
22
  end
23
end
db/migrate/20130201184705_add_unique_index_on_tokens_value.rb
1
class AddUniqueIndexOnTokensValue < ActiveRecord::Migration
2
  def up
3
    say_with_time "Adding unique index on tokens, this may take some time..." do
4
      # Just in case
5
      duplicates = Token.connection.select_values("SELECT value FROM #{Token.table_name} GROUP BY value HAVING COUNT(id) > 1")
6
      Token.where(:value => duplicates).delete_all
7
  
8
      add_index :tokens, :value, :unique => true, :name => 'tokens_value'
9
    end
10
  end
11

  
12
  def down
13
    remove_index :tokens, :name => 'tokens_value'
14
  end
15
end
db/migrate/20130202090625_add_projects_inherit_members.rb
1
class AddProjectsInheritMembers < ActiveRecord::Migration
2
  def up
3
    add_column :projects, :inherit_members, :boolean, :default => false, :null => false
4
  end
5

  
6
  def down
7
    remove_column :projects, :inherit_members
8
  end
9
end
db/migrate/20130207175206_add_unique_index_on_custom_fields_trackers.rb
1
class AddUniqueIndexOnCustomFieldsTrackers < ActiveRecord::Migration
2
  def up
3
    table_name = "#{CustomField.table_name_prefix}custom_fields_trackers#{CustomField.table_name_suffix}"
4
    duplicates = CustomField.connection.select_rows("SELECT custom_field_id, tracker_id FROM #{table_name} GROUP BY custom_field_id, tracker_id HAVING COUNT(*) > 1")
5
    duplicates.each do |custom_field_id, tracker_id|
6
      # Removes duplicate rows
7
      CustomField.connection.execute("DELETE FROM #{table_name} WHERE custom_field_id=#{custom_field_id} AND tracker_id=#{tracker_id}")
8
      # And insert one
9
      CustomField.connection.execute("INSERT INTO #{table_name} (custom_field_id, tracker_id) VALUES (#{custom_field_id}, #{tracker_id})")
10
    end
11

  
12
    if index_exists? :custom_fields_trackers, [:custom_field_id, :tracker_id]
13
      remove_index :custom_fields_trackers, [:custom_field_id, :tracker_id]
14
    end
15
    add_index :custom_fields_trackers, [:custom_field_id, :tracker_id], :unique => true
16
  end
17

  
18
  def down
19
    if index_exists? :custom_fields_trackers, [:custom_field_id, :tracker_id]
20
      remove_index :custom_fields_trackers, [:custom_field_id, :tracker_id]
21
    end
22
    add_index :custom_fields_trackers, [:custom_field_id, :tracker_id]
23
  end
24
end
db/migrate/20130207181455_add_unique_index_on_custom_fields_projects.rb
1
class AddUniqueIndexOnCustomFieldsProjects < ActiveRecord::Migration
2
  def up
3
    table_name = "#{CustomField.table_name_prefix}custom_fields_projects#{CustomField.table_name_suffix}"
4
    duplicates = CustomField.connection.select_rows("SELECT custom_field_id, project_id FROM #{table_name} GROUP BY custom_field_id, project_id HAVING COUNT(*) > 1")
5
    duplicates.each do |custom_field_id, project_id|
6
      # Removes duplicate rows
7
      CustomField.connection.execute("DELETE FROM #{table_name} WHERE custom_field_id=#{custom_field_id} AND project_id=#{project_id}")
8
      # And insert one
9
      CustomField.connection.execute("INSERT INTO #{table_name} (custom_field_id, project_id) VALUES (#{custom_field_id}, #{project_id})")
10
    end
11

  
12
    if index_exists? :custom_fields_projects, [:custom_field_id, :project_id]
13
      remove_index :custom_fields_projects, [:custom_field_id, :project_id]
14
    end
15
    add_index :custom_fields_projects, [:custom_field_id, :project_id], :unique => true
16
  end
17

  
18
  def down
19
    if index_exists? :custom_fields_projects, [:custom_field_id, :project_id]
20
      remove_index :custom_fields_projects, [:custom_field_id, :project_id]
21
    end
22
    add_index :custom_fields_projects, [:custom_field_id, :project_id]
23
  end
24
end
db/migrate/20130215073721_change_users_lastname_length_to_255.rb
1
class ChangeUsersLastnameLengthTo255 < ActiveRecord::Migration
2
  def self.up
3
    change_column :users, :lastname, :string, :limit => 255, :default => '', :null => false
4
  end
5

  
6
  def self.down
7
    change_column :users, :lastname, :string, :limit => 30, :default => '', :null => false
8
  end
9
end
db/migrate/20130215111127_add_issues_closed_on.rb
1
class AddIssuesClosedOn < ActiveRecord::Migration
2
  def up
3
    add_column :issues, :closed_on, :datetime, :default => nil
4
  end
5

  
6
  def down
7
    remove_column :issues, :closed_on
8
  end
9
end
db/migrate/20130215111141_populate_issues_closed_on.rb
1
class PopulateIssuesClosedOn < ActiveRecord::Migration
2
  def up
3
    closed_status_ids = IssueStatus.where(:is_closed => true).pluck(:id)
4
    if closed_status_ids.any?
5
      # First set closed_on for issues that have been closed once
6
      closed_status_values = closed_status_ids.map {|status_id| "'#{status_id}'"}.join(',')
7
      subselect = "SELECT MAX(#{Journal.table_name}.created_on)" +
8
        " FROM #{Journal.table_name}, #{JournalDetail.table_name}" +
9
        " WHERE #{Journal.table_name}.id = #{JournalDetail.table_name}.journal_id" +
10
        " AND #{Journal.table_name}.journalized_type = 'Issue' AND #{Journal.table_name}.journalized_id = #{Issue.table_name}.id" +
11
        " AND #{JournalDetail.table_name}.property = 'attr' AND #{JournalDetail.table_name}.prop_key = 'status_id'" +
12
        " AND #{JournalDetail.table_name}.old_value NOT IN (#{closed_status_values})" +
13
        " AND #{JournalDetail.table_name}.value IN (#{closed_status_values})"
14
      Issue.update_all "closed_on = (#{subselect})"
15

  
16
      # Then set closed_on for closed issues that weren't up updated by the above UPDATE
17
      # No journal was found so we assume that they were closed on creation
18
      Issue.update_all "closed_on = created_on", {:status_id => closed_status_ids, :closed_on => nil}
19
    end
20
  end
21

  
22
  def down
23
    Issue.update_all :closed_on => nil
24
  end
25
end
db/migrate/20130217094251_remove_issues_default_fk_values.rb
1
class RemoveIssuesDefaultFkValues < ActiveRecord::Migration
2
  def up
3
    change_column_default :issues, :tracker_id, nil
4
    change_column_default :issues, :project_id, nil
5
    change_column_default :issues, :status_id, nil
6
    change_column_default :issues, :assigned_to_id, nil
7
    change_column_default :issues, :priority_id, nil
8
    change_column_default :issues, :author_id, nil
9
  end
10

  
11
  def down
12
    change_column_default :issues, :tracker_id, 0
13
    change_column_default :issues, :project_id, 0
14
    change_column_default :issues, :status_id, 0
15
    change_column_default :issues, :assigned_to_id, 0
16
    change_column_default :issues, :priority_id, 0
17
    change_column_default :issues, :author_id, 0
18
  end
19
end

Also available in: Unified diff